ç¨åºï¼
#include<reg52.h>
#include<intrins.h>
sbitledRS=P1^0;
sbitledRW=P1^1;
sbit ledE=P1^2;
sbit keyjia=P2^7;
sbitkeyjian=P2^6;
sbitcontrolLD=P1^3;
bitflag1=1;
bitflag2=1;
unsigned
char code table[]=" guang liangdu
";
unsignedchar code table1[]=" 00 ";
intnum,flag=0,count=0;
charliangdu=3;
voiddelaykt(void) //导é延æ¶
{
unsigned char a;
for(a=2;a>0;a--);
}
voiddelay(int z) //å¯è°å»¶æ¶
{
unsigned x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void
delay9ms(void) //
误差-0.43402777778us 延æ¶9ms
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=224;b>0;b--)
for(a=17;a>0;a--);
}
voidwrite_com(unsigned com) //åæ令
{
ledRS=0;
P0=com;
delay(10);
ledE=1;
delay(20);
ledE=0;
}
voidwrite_date(unsigned date) //åæ°æ®
{
ledRS=1;
P0=date;
delay(10);
ledE=1;
delay(20);
ledE=0;
}
voidwrite_liangdu(unsigned liangdu) //å亮度
{
int shi,ge;
shi=(liangdu-3)/10;
ge=(liangdu-3)%10;
write_com(0x80+0x40+7);
write_date(0x30+shi);
write_date(0x30+ge);
}
voidinit() //åå§å
{
controlLD=1; //触åæ§å¶åå§å
ledRW=0; //液æ¶åå§å
ledE=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x80);
for(num=0;num<15;num++)
{
write_date(table[num]);
delaykt();
}
write_com(0x80+0x40);
for(num=0;num<15;num++)
{
write_date(table1[num]);
delaykt();
}
EA=1; //å¤é¨ä¸æ设置
EX0=1;
IT0=1;
}
voidkeyscanf() //é®çå¤æ
{
if(keyjia==0) //å é®å¤æ
{
delaykt();
if(keyjia==0)
{
if(flag1==1)
{
flag1=0;
liangdu++;
if(liangdu==10)
liangdu=3;
write_com(0x80+0x40+7);
write_liangdu(liangdu);
}
}
}
else if(keyjia!=0)
{
delaykt();
if(keyjia!=0)
flag1=1;
}
if(keyjian==0) //åé®å¤æ
{
delaykt();
if(keyjian==0)
{
if(flag2==1)
{
flag2=0;
liangdu--;
if(liangdu==2)
liangdu=9;
write_com(0x80+0x40+7);
write_liangdu(liangdu);
}
}
}
else if(keyjian!=0)
{
delaykt();
if(keyjian!=0)
flag2=1;
}
}
voidzhongduan() interrupt 0 //å¤é¨ä¸æ
{
flag=1;
}
voidtimepd() //åæ¥æ å¿å¤æä¸å®æ¶å¨è®¾ç½®
{
if(flag==1)
{
flag=0;
TMOD=0x01;
TH0=(65536-1000*(10-liangdu))/256;
TL0=(65536-1000*(10-liangdu))%256;
ET0=1;
TR0=1;
}
}
voidtime0() interrupt 1 //å®æ¶ä¸æç¨åº
{
count=1;
}
voidchufa() //MOS3020触å
{
if(count==1)
{
count=0;
controlLD=0;
delaykt();
controlLD=1;
delay9ms();
controlLD=0;
delaykt();
controlLD=1;
}
}
voidmain()
{
init();
while(1)
{
keyscanf();
timepd();
chufa();
}
}
追é®è°¢è°¢ï¼æå
æ
¢æ
¢ççï¼é£ä¸ªä¸å¥½ææï¼ææ³é®ä¸æå¾åï¼å 为çèµ·æ¥æç¹å°é¾
追ç
å®ç©çå¾å°±æï¼çµè·¯å¾æå¾å»ç»äº