#include
#define uchar unsigned char
uchar i,a;
uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8};
sbit wp=P1^0;
sbit scl=P1^1;
sbit sda=P1^2;
sbit led=P2^0;
void delay()
{
_nop_();
_nop_();
_nop_();
}
void de1s() //误差 0us
{
unsigned char a,b,c;
for(c=167;c>0;c--)
for(b=171;b>0;b--)
for(a=16;a>0;a--);
_nop_(); //if Keil,require use intrins.h
}
void d10ms() //误差 0us
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=38;b>0;b--)
for(a=130;a>0;a--);
}
void write(uchar t)
{
for(i=0;i<8;i++)
{
sda=(bit)(t&0x80); //等价于RLC
scl=1;
scl=0;
t<<=1;
}
sda=1;
scl=1;
delay();
while(sda!=0);
scl=0;
}
void start()
{
sda=1;
scl=1;
delay();
sda=0;
delay();
scl=0;
}
void stop()
{
sda=0;
delay();
scl=1;
delay();
sda=1;
scl=0;
}
void wriic()
{
uchar j;
start();
write(0xae);
write(0x00);
for(j=0;j<8;j++)
{
write(table[j]);
}
stop();
}
uchar read()
{
uchar n,rbyte=0;
for(n=0;n<8;n++)
{
sda=1;
scl=1;
rbyte<<=1;
rbyte|=(uchar)(sda);
scl=0;
}
sda=0;
delay();
scl=1;
delay();
scl=0;
return(rbyte);
}
void reiic()
{
start();
write(0xae);
write(0x00);
start();
write(0xaf);
for(i=0;i<8;i++)
{
P0=read();
de1s();
}
stop();
}
void main()
{
wp=0;
led=0;
SP=0x50;
wriic();
d10ms();
reiic();
while(1);
}
上一篇:LCD12864的串口驱动(asm/c51)
下一篇:STC89C52R并行驱动LCD12864(asm/c51)
推荐阅读最新更新时间:2024-03-16 15:12