#include<reg51.h>
#include<intrins.h>
sbitGND_LCD=P1^7;
sbitrs=P1^0;
sbitrw=P1^1;
sbite=P1^2;
unsignedcharbusy(void);
voidctrl(unsignedchar);
voidwd_h(unsignedchar);
voidwd_l(unsignedchar);
unsignedcharrd(void);
voidwrite(unsignedchar);
voidinit(void);
voidNOP(void);
voiddisp(unsignedchar);
unsignedinttime;
voidint_t0(void)interrupt1{
TL0=TL0+30;TH0=0xfb;
time++;
}
voidwait(unsignedintw){
time=0;
while(time<w){}
}
voidinit(void){
unsignedchari;
P1=0;
for(i=0;i<2;i++){
wd_l(0x30);
wait(5);
}
wd_h(0x20);
ctrl(0x28);
ctrl(0x8);
ctrl(3);
ctrl(6);
disp(0);
ctrl(1);
ctrl(8);
ctrl(0xe);
ctrl(0x80);
}
unsignedcharbusy(void){
P1=0;
return(rd());
}
unsignedcharrd(void){
unsignedchardat0,dat1;
rw=1;
rs=0;
P1=P1|0x78;
e=1;
dat0=P1;
e=0;
e=1;
dat1=P1;
P1=0;
return(((dat0<<1)&0xf0)|((dat1>>3)&0xf));
}
voidctrl(unsignedchardat){
while(busy()>0x7f){};
rw=rs=0;
wd_h(dat);
wd_l(dat);
}
voidwd_h(unsignedchardat){
e=1;
P1=P1|((dat&0xf0)>>1);
e=0;
P1=P1&0x87;
}
voidwd_l(unsignedchardat){
e=1;
P1=P1|((dat&0xf)<<3);
e=0;
P1=0;
}
voidwrite(unsignedchardat){
while(busy()>0x7f){};
rw=0;
rs=1;
wd_h(dat);
wd_l(dat);
}
//===================================================
voiddisp(unsignedchari){
unsignedcharj;
ctrl(1);
ctrl(0x80);
for(j=0;j<6;j++)write(d[i][j]);
write('');
ctrl(0xc0);
write('-');
write('-');
write('-');
write('-');
write('-');
write('-');
write('k');
write('m');
}