51RTOS.com 版权所有 Copyright 20006-2009 我爱嵌入式 ( 51RTOS.com ) All rights reserved 沪ICP备09080633号 |
我爱嵌入式系统
显示"范"
#include<reg51.h>
#include<stdio.h>
#include<intrins.h>
sbit SI=P1^0;
sbit SCK=P1^1;
sbit SO=P1^2;
sbit SCS=P3^5;
sbit E=P1^3;
sbit RS=P1^5;
sbit RW=P1^4;
sbit PSB=P3^4;
sbit RESET=P1^7;
sbit bbc=P0^7;
DELAY();
INPUT(unsigned char I);
DELAY01();
void outbyte(unsigned char outda)
{
unsigned char i,a;
a=outda;
for(i=0;i<8;i++)
{
SCK=0;
if(a&0x80) SI=1;
else SI=0;
a<<=1;
SCK=1;
}
}
unsigned char inbyte(void)
{
unsigned char i,a;
a=0;
for(i=0;i<8;i++)
{
SCK=1;
SCK=0;
a<<=1;
if(SO) a++;
}
return a;
}
unsigned char read_x25045(unsigned int addr)
{
unsigned char b,a;
bit had;
b=addr;
if(b&0x0100) had=1;
else had=0;
SCK=0;
SCS=0;
a=0x03;
if(had) a|=8;
outbyte(a);
a=b;
outbyte(a);
a=inbyte();
SCK=0;
SCS=1;
return a;
}
INITIL()
{
unsigned char f,g,h;
DELAY();
f=0x30;
INPUT(f);
DELAY01();
g=0x01;
INPUT(g);
DELAY01();
h=0x06;
INPUT(h);
DELAY01();
}
CHK_BUSY()
{
RS=0;
RW=1;
E=1;
while(bbc==1){}
E=0;
}
DISPL(unsigned char DAT)
{
CHK_BUSY();
_nop_();
RS=1;
RW=0;
E=1;
P0=DAT;
_nop_();
DELAY01();
_nop_();
E=0;
_nop_();
P0=0xFF;
}
INPUT(unsigned char I)
{
CHK_BUSY();
_nop_();
RS=0;
RW=0;
E=1;
P0=I;
_nop_();
DELAY01();
_nop_();
E=0;
_nop_();
P0=0xFF;
}
DELAY()
{
int i;
i=1;
while(i<100)
{
i=i++;
}
}
DELAY01()
{
int j;
j=1;
while(j<10)
{
j=j++;
}
}
void main()
{
unsigned int addr,adds;
unsigned char q,j;
unsigned char a,b,c,d,e;
addr=0x0190;
adds=0x0191;
RESET=1;
PSB=1;
RW=0;
INITIL();
a=0x0C;
INPUT(a);
DELAY01();
b=0x01;
INPUT(b);
DELAY01();
q=read_x25045(addr);
d=q;
j=read_x25045(adds);
e=j;
c=0x80;
INPUT(c);
DELAY01();
DISPL(d);
DISPL(e);
DELAY01();
_nop_();
}
51RTOS.com 版权所有 Copyright 20006-2009 我爱嵌入式 ( 51RTOS.com ) All rights reserved 沪ICP备09080633号 |