单片机原理课程设计基于AT89C52的电子时钟设计说明

ge=date;

lcdwrite(0x80+0x40+add); lcdshuju(0x30+shi); lcdshuju(0x30+ge); }

void mbiao( ) //秒表函数 { lcdwrite(0x80+0x40);

for(num=0;num<16;num++) lcdshuju(table4[num]); start: while(1)

{ if(P1!=0Xf0)

{ delay1ms(100); //延时0.1s去抖动 if(P1!=0Xf0) if(P1==0xd0) //秒表开始计数 {TR1=1; ET1=1; }

else if(P1==0xb0) //秒表暂停计数 { TR1=0; }

else if(P1==0x70) //退出 {return; }

goto start;

} } }

void init() { e=0; rw=0;

lcdwrite(0x38);//显示模式

lcdwrite(0x0c);//开显示,光标不闪烁 lcdwrite(0x80); for(i=0;i<16;i++) {

lcdshuju(table[i]); delay(200); }

lcdwrite(0x80+0x40); for(i=0;i<16;i++)

{

lcdshuju(table1[i]); delay(200); }

delay(500);

lcdwrite(0x01); }

main() {

init(); IE=0X82; TMOD=0x11;

write(0x8E); //关闭写保护 write(0); rst=0;

P0=1; //清屏并光标复位 enable();

P0=0X38; //设置显示模式:8位2行5x7点阵 enable();

P0=6; //文字不动,光标自动右移 enable(); timestart();

while(1) {

readtime(); //读取时间 lcdshow(); //显示时间 baoshi();

if(time1[0]!=0x20) {beep=1;

if(time[0]==alarm[0]) if(time[1]==alarm[1]) if(time[2]==0) showalarm(); } P1=0xf0;

if((P1&0Xf0)!=0Xf0) {

delay1ms(100); //延时0.1s去抖动 if((P1&0Xf0)!=0Xf0) {

j=7;

TH0=TIME/256,TL0=TIME%6;

TR0=1; //关闭时钟 if(P1==0x70) {

settime(); }

else if(P1==0Xb0) {

setalarm(); }

else if(P1==0Xd0) {

TR0=0; if(time1[0]==FLAG) time1[0]=0x20; else

time1[0]=FLAG; write(0xc4); write(time1[0]); rst=0; }

else if(P1==0Xe0&&mbkey==0) 秒表

{

mbiao();

} } }

delay1ms(100); } }

void time0() interrupt 1 using 1 {

i--; if(i==0) {

if(j!=0)

j--; i=20; }

TH0=TIME/256,TL0=TIME%6; }

void timer1() interrupt 3 //秒表定时器开启时钟 开启 // //

{

TH1=(65536-10000)/256; TL1=(65536-10000)%6; ms++;

write_sfm(8,ms); if(ms==1*30) { mbmiao++;

write_sfm(5,mbmiao); } } }

ms=0;

if(mbmiao==60) {

mbmiao=0; mbfen++;

write_sfm(2,mbfen);

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4