C51时钟(3个)和模数转换程序.docx

  1. 1、本文档共12页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C51实时时钟程序(三个)时钟一:#includereg52.h#includeintrins.h#define uchar unsigned char#define uint unsigned intuchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};uchar count=0,secL,secH,minL,minH,hourL,hourH;longint sum;void Delay(uint k){while(k0)k--;}void init_timer0(){TMOD = 0x01;TH0 = (65536-50000)/256;TL0 = (65536-50000)%256;EA = 1;ET0 = 1;TR0 = 1;}void timer0() interrupt 1 {TH0=(65536-50000)/256;TL0=(65536-50000)%256;count++;if(count==20){count = 0;sum++;}if(count20)count = 0;} void calculate(){hourH=sum/60/60%24/10;hourL=sum/60/60%24%10;minH=sum/60%60/10;minL=sum/60%60%10;secH=sum%60/10;secL=sum%10;if(sum==86400)sum=0;}voiddisplay_led(){uchari,temp;temp=0x7f;for(i=0;i8;i++){P2=temp;switch(i){case 0:P0=table[hourH]; break;case 1:P0=table[hourL]; break;case 2:P0=0xbf;break;case 3:P0=table[minH]; break;case 4:P0=table[minL];break;case 5:P0=0xbf;break;case 6:P0=table[secH]; break;case 7:P0=table[secL];break;}Delay(140);P0=0xff;temp=_cror_(temp,1);}}void main(){init_timer0();while(1){calculate();display_led();}}时钟二:#includereg52.h#includeintrins.h#define uchar unsigned char#define uint unsigned intuchar code jian[]={0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d, 0xeb,0xdb,0xbb,0x7b,0xe7,0xd7,0xb7,0x77}; //键值uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//断码uchar count=0,secL,secH,minL,minH,hourL,hourH;ucharkey,n,stop=0,cut=0;sbit beep=P3^0;void delay(uint m)//延时{while(m0)m--;}void keypan()//读键值{ucharL,H,i; P1=0x0f; L=P10x0f;if(L!=0x0f) {delay(100); if(L!=0x0f) L=P10x0f; } P1=0xf0; H=P10xf0;if(H!=0xf0) {delay(100);if(H!=0xf0) H=P10xf0; }key=L+H;for(i=0;i16;i++) {if(key==jian[i]) n=i; }}void init_timer0()//timer0中断{TMOD = 0x01;TH0 = (65536-50000)/256;TL0 = (65536-50000)%256;EA = 1;ET0 = 1;TR0 = 1;}void timer0() interrupt 1 //中断服务{TH0=(65536-50000)/256;TL0=(65536-50000)%256;count++;if(count20)count = 0;} void calculate()//计时计算{if(stop==0){if(count==20){count = 0;secL=secL+1;if(secL

文档评论(0)

189****6140 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档