数字钟实验+程序+仿真

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

程序自己写的,图用proteus仿真的XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51D1LED-YELLOWR1300XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51D1LED-YELLOWR1300K1按一下,分钟加1K2按一下,分钟减1K3按一下,小时加1K4按一下,小时减1实验程序代码:#includereg52.h#defineuintunsignedintuintsec,min,hour,flag;unsignedcharcodetable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段码控制unsignedcharcodedispbit[8]={0x01,0x02,0x08,0x10,0x40,0x80,0x04,0x20};//位选控制查表的方法控制sbitled=P2^0;sbitenter=P3^2;sbitkey1=P2^1;sbitkey2=P2^2;sbitkey3=P2^3;sbitkey4=P2^4;voidinit();voiddelay(unsignedinti);voiddisplay();voidcheck();voidmain(){init();while(1){check();if(flag==20){flag=0;sec++;if(sec==60){sec=0;min++;if(min==60){min=0;hour++;if(hour==24){hour=0;}}}}display();}}voidinit(){//EA=1;//IE0=1;//IT0=0;TMOD=0x01;TH0=(65536-45872)/256;TL0=(65536-45872)%256;EA=1;TR0=1;ET0=1;led=0;}/*voidint_0()interrupt0{while(!key1){while(!key1);hour++;led=~led;}}*/voidT0_time()interrupt1{TH0=(65536-45872)/256;TL0=(65536-45872)%256;flag++;//led=~led;}voiddisplay(){unsignedintnum[8];unsignedcharcodetable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//unsignedintnum1[8]={0xa4,0xc0,0xf9,0xa4,0xbf,0xbf,0xf9,0xc0};intm;num[0]=table[hour/10];num[1]=table[hour%10];num[2]=table[min/10];num[3]=table[min%10];num[4]=table[sec/10];num[5]=table[sec%10];num[6]=0xbf;num[7]=0xbf;for(m=0;m8;m++){P1=dispbit[m];P0=num[m];delay(10);}//delay(2000);/*for(m=0;m8;m++){P1=dispbit[m];P0=num1[m];delay(10);}*/}voiddelay(unsignedinti){charj;for(i;i0;i--)for(j=200;j0;j--);}voidcheck(){P2=0xff;if(key1==0){delay(10);while(!key1);hour++;if(hour==24){hour=0;}}if(key2==0){while(!key2);delay(10);if(hour0){hour--;}elsehour=23;}if(key3==0){delay(10);while(!key3);min++;if(min==60){min=0;if(hour==23)hour=0;elsehour++;}}if(key4==0){while(!key4);delay(10);if(min0){min--;}else{min=59;if(hour0){hour--;}elsehour=23;}}}

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功