单片机二进制时钟

(6页)

'单片机二进制时钟'
单片机二进制时钟[源码&电路]#include <reg52.h>#include <intrins.h>#define uchar unsigned char#define uint unsigned intsbit SET_H=P0^6;sbit SET_M=P0^5;sbit SET_S=P1^6;uchar code DSY_CODE[]= //用于显示时钟的编码{0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b};uint hour=0,min=0,sec=0,count=0;void delay_ms(unsigned char i){ unsigned char j; while(i--) for(j=124;j>0;j--);}void Set_Interrupt_1(){ if(SET_H==0) { delay_ms(100); if(SET_H==0) { TR0=0; if(hour<23) hour++; else hour=0; //delay_ms(50); TR0=1; P0=~DSY_CODE[hour]; P1=~DSY_CODE[min]; P2=~DSY_CODE[sec]; } } }void Set_Interrupt_2(){ if(SET_M==0) { delay_ms(100); if(SET_M==0) { TR0=0; TH0 = (65535-50000)/256; TL0 = (65535-50000)%6; if(min<59) min++; else { min=0; hour++; if(hour==24) hour=0; } // delay_ms(50); TR0=1; P0=~DSY_CODE[hour]; P1=~DSY_CODE[min]; P2=~DSY_CODE[sec]; } }}void Set_Interrupt_3(){ if(SET_S==0) { delay_ms(100); if(SET_S==0) { TR0=0; if(sec<59) sec++; else { sec=0; min++; if(min==60) { min=0; hour++; if(hour==24) hour=0; } } //delay_ms(50); TR0=1; P0=~DSY_CODE[hour]; P1=~DSY_CODE[min]; P2=~DSY_CODE[sec];; } } } void main(){ P0 = 0xff; P1 = 0xff; P2 = 0xff; TMOD = 0x01; TH0 = (65535-50000)/256; TL0 = (65535-50000)%6; //IE = 0x82; ET0=1; TR0 = 1; EA=1; while(1) { Set_Interrupt_1(); Set_Interrupt_2(); Set_Interrupt_3(); }}void Time0() interrupt 1{ TH0 = (65535-50000)/256; TL0 = (65535-50000)%6; if((count+1)!=20) { count++; return; } else { if((sec+1)!=60) { P2=~DSY_CODE[++sec]; } else { sec=0; if((min+1)!=60) { P1=~DSY_CODE[++min]; } else { min=0; if((hour+1)!=60) { P0=~DSY_CODE[++hour]; } else { hour=0; } } } count = 0; } }
关 键 词:
单片机 二进制 时钟
 天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:单片机二进制时钟
链接地址: https://www.wenku365.com/p-44814585.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服点击这里,给天天文库发消息,QQ:1290478887 - 联系我们

本站为“文档C2C交易模式”,即用户上传的文档直接卖给(下载)用户,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有【成交的100%(原创)】。本站是网络服务平台方,若您的权利被侵害,侵权客服QQ:1290478887 欢迎举报。

1290478887@qq.com 2017-2027 https://www.wenku365.com 网站版权所有

粤ICP备19057495号 

收起
展开