define uchar unsigned char
sbit RS=P2^0; //?????У???????????
sbit RW=P2^1;
sbit E=P2^2;
sbit led1=P2^3;
sbit led2=P2^4;
int count,fen,miao,shi,key=0,i,d;
uchar c=0;
void delay(unsigned int n) //???????
{unsigned int x,y;
for(x=0;x<n;x++)
for(y=0;y<123;y++);}
void write_command(char com) //д??????????
{
E=0;
RS=0;
RW=0;
P1=com;
E=1;
E=0;
delay(1);
}
void write_data(char dat) //д??????????
{
E=0;
RS=1;
RW=0;
P1=dat;
E=1;
E=0;
delay(1);
}
void lcd_ini
tial(void) //lcd?????
{
write_command(0x38);
write_command(0x0c);
write_command(0x06);
delay(1);
}
void string(uchar position,uchar *s) //??????????
{ write_command(position);
while(*s>0)
{write_data(*s++);
delay(1);
}
}
/******************************************
??????????
???????STC89C52
P2???谴????
S1-4= e7 eb ed ee
S5-8= d7 db dd de
S9-10= b7 bb bd be
S13-16= 77 7b 7d 7e
*****************************************/
unsigned char keyscand(void)
{
unsigned char a,b;
P3=0xf0;
if((P3&0xf0)!=0xf0)
{ delay(2);
if((P3&0xf0)!=0xf0)
{
a=P3&0xf0;
P3=0x0f;
b=P3&0x0f;
}
}
return(a+b);
}
void main(void)
{
led1=0;
led2=0;
lcd_initial();//?????????
EA=1; //?????
ET0=1; //??????T0?????ж?
TMOD=0x01; //T0???1
TH1=(65536-50000)/256;//????????????50ms
TL1=(65536-50000)%256;
TR0=1;
while(1)
{
key=keyscand(); //????????
switch(key) //?ж???????????????£?
{
case 0xee: i=0; break; //???????
case 0xde: i=1; break;
case 0xbe: i=2; break;
case 0x7e: i=3; break;
case 0xed: i=4; break;
case 0xdd: i=5; break;
case 0xbd: i=6; break;
case 0x7d: i=7; break;
case 0xeb: i=8; break;
case 0xdb: i=9; break;
case 0xbb: i=10; break;
case 0x7b: i=11; break;
case 0xe7: i=12; break;
case 0xd7: i=13; break;
case 0xb7: i=14; break;
case 0x77: i=15; break;
}
if(fen==15&&shi==0||fen==15&&shi==1||fen==15&&shi==2)
{
led1=1;
}
if(i==10)
{
led1=0;
delay(10);
c++;
}
if(fen==30&&shi==0||fen==30&&shi==1||fen==30&&shi==2)
{ led2=1;
}
if(i==11)
{
led2=0;
d++;
delay(10);
}
}
}
void timer0() interrupt 1 //?ж?
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
count++; //???????????????????1S
write_command(0x81);
write_data('A');
write_command(0x82);
write_data('3');
write_command(0x83);
write_data('3');
write_command(0x84);
write_data('0'+c);
write_command(0x86);
write_data('B');
write_command(0x87);
write_data('3');
write_command(0x88);
write_data('3');
write_command(0x89);
write_data('0'+d);
write_command(0xce);
write_data('6');
write_command(0xcf);
write_data('4');
write_command(0xC1); //???shi???λ
write_data(0x30+shi/10);
write_command(0xC2); //???shi???λ
write_data(0x30+shi%10);
string(0xC3,":");
write_command(0xC4); //???fen???λ
write_data(0x30+fen/10);
write_command(0xC5); //???fen???λ
write_data(0x30+fen%10);
string(0xC6,":");
write_command(0xC7);
write_data(0x30+miao/10);
write_command(0xC8);
write_data(0x30+miao%10);
if(count==1) //20ms*50=1S
{count=0;
miao++;} //?????miao+1
if(miao==60)
{ miao=0;
fen++;} //?????fen+1
if(fen==60)
{ fen=0;
shi++;}
if(shi==24)
{shi=0;}}
-
一周热门 更多>