在这里先谢谢大家的回贴帮助,刚开始学单片机还不到一个月,有很多东西都不懂,在写程序的时候也有很多东西没有考虑到,这些天一直在反复写这个时钟程序,总算是写好了,实验了一下,感觉还能用,贴出来一下,有什么不对的大家再帮忙指点下,谢谢。
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit rs=P3^5;
sbit lcden=P3^4;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit rd=P3^7;
sbit deep=P2^3;
uchar code table[]=" 20 - - ";
uchar code table1[]=" : : ";
uchar t0,num,k1num;
char miao,shi,fen,nian,ye,ri,week;
void display(uchar shi,uchar ge);
void delay1(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
lcden=0;
P0=com;
delay1(5);
lcden=1;
delay1(5);
lcden=0;
}
void write_date(uchar date)
{
rs=1;
lcden=0;
P0=date;
delay1(5);
lcden=1;
delay1(5);
lcden=0;
}
void write_sfm(uchar add,uchar date)
{
char shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_nyr(uchar add,uchar date)
{
char shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_week(char we)
{
write_com(0x80+12);
switch(we)
{
case 1:write_date('M');delay1(5);
write_date('O');delay1(5);
write_date('N');
break;
case 2:write_date('T');delay1(5);
write_date('U');delay1(5);
write_date('E');
break;
case 3:write_date('W');delay1(5);
write_date('E');delay1(5);
write_date('D');
break;
case 4:write_date('T');delay1(5);
write_date('H');delay1(5);
write_date('U');
break;
case 5:write_date('F');delay1(5);
write_date('R');delay1(5);
write_date('I');
break;
case 6:write_date('S');delay1(5);
write_date('A');delay1(5);
write_date('R');
break;
case 7:write_date('S');delay1(5);
write_date('U');delay1(5);
write_date('N');
break;
}
}
void init()
{
uchar num;
dula=0;
wela=0;
lcden=0;
week=1;
ye=1;
ri=1;
t0=0;
k1num=0;
init_24c02( );
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num