#include
#define uchar unsigned char
void delay(unsigned int n) //???????
{unsigned int x,y;
for(x=0;x
for(y=0;y<123;y++);
}
***it RS=P2^0; //?????***???????????
***it RW=P2^1;
***it E=P2^2;
***it led1=P2^3;
***it led2=P2^4;
int count,fen,miao,shi,k,key,i;
char keyscan();
/*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_initial(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);
}
}*/
unsigned char keyscand(void) //??????躯??
{
unsigned char a,b;
P3=0xf0;
if(P3!=0xf0) //?ж?????а???????
{delay(10);
if(P3!=0xf0) //??????????
{ a=P3; //???????????а?????????
P3=0xf0; //?????
b=P3;}} //???????????а?????????
return a+b;} //??????
void main(void)
{ led1=1;
led2=1;
while(1);
{
P3=0xf0;
key=keyscand();
switch ( key ) //?ж???????????????£?
{
case 0xee: k='0'; break; //???????
case 0xed: k='1'; break;
case 0xeb: k='2'; break;
case 0xe7: k='3'; break;
case 0xde: k='4'; break;
case 0xdd: k='5'; break;
case 0xdb: k='6'; break;
case 0xd7: k='7'; break;
case 0xbe: k='8'; break;
case 0xbd: k='9'; break;
case 0xbb: k='A';break;
case 0xb7: k='B';break;
case 0x7e: k='C';break;
case 0x7d: k='D';break;
case 0x7b: k='E';break;
case 0x77: k='F';break;
}
if(k=0)
{led1=0;}
if(k=1)
led2=0;} }
/* lcd_initial();//?????????
EA=1; //?????
ET0=1; //??????T0?????ж?
TMOD=0x01; //T0???1
TH1=(65536-50000)/256;//????????????50ms
TL1=(65536-50000)%256;
TR0=1;
IT0=1;
EX0=1;
EX1=1;
while(1);*/
/*void timer0() interrupt 1 //?ж?
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
count++; //???????????????????1S
string(0x81,"A331");
string(0x86,"B332");
string(0xCE,"64");
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;}}*/
#include
#define uchar unsigned char
void delay(unsigned int n) //???????
{unsigned int x,y;
for(x=0;x
for(y=0;y<123;y++);
}
***it RS=P2^0; //?????***???????????
***it RW=P2^1;
***it E=P2^2;
***it led1=P2^3;
***it led2=P2^4;
int count,fen,miao,shi,k,key,i;
char keyscan();
/*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_initial(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);
}
}*/
unsigned char keyscand(void) //??????躯??
{
unsigned char a,b;
P3=0xf0;
if(P3!=0xf0) //?ж?????а???????
{delay(10);
if(P3!=0xf0) //??????????
{ a=P3; //???????????а?????????
P3=0xf0; //?????
b=P3;}} //???????????а?????????
return a+b;} //??????
void main(void)
{ led1=1;
led2=1;
while(1);
{
P3=0xf0;
key=keyscand();
switch ( key ) //?ж???????????????£?
{
case 0xee: k='0'; break; //???????
case 0xed: k='1'; break;
case 0xeb: k='2'; break;
case 0xe7: k='3'; break;
case 0xde: k='4'; break;
case 0xdd: k='5'; break;
case 0xdb: k='6'; break;
case 0xd7: k='7'; break;
case 0xbe: k='8'; break;
case 0xbd: k='9'; break;
case 0xbb: k='A';break;
case 0xb7: k='B';break;
case 0x7e: k='C';break;
case 0x7d: k='D';break;
case 0x7b: k='E';break;
case 0x77: k='F';break;
}
if(k=0)
{led1=0;}
if(k=1)
led2=0;} }
/* lcd_initial();//?????????
EA=1; //?????
ET0=1; //??????T0?????ж?
TMOD=0x01; //T0???1
TH1=(65536-50000)/256;//????????????50ms
TL1=(65536-50000)%256;
TR0=1;
IT0=1;
EX0=1;
EX1=1;
while(1);*/
/*void timer0() interrupt 1 //?ж?
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
count++; //???????????????????1S
string(0x81,"A331");
string(0x86,"B332");
string(0xCE,"64");
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;}}*/
举报