/* 本程序实现了用数码管显示时间的功能,时间计数和现实基本一致(这取决于定时器精度和指令时间)
该程序提供了一种用定时器延时实现传统 delay 的显示方法,后面给出比较
文档最后有该程序对应的原理图,大部分开发板都能直接用这个程序,稍微改下 IO 口即可
如有错误之处请包涵,此篇文档仅作交流之用
*/ /*---------------------定时器方法----------------*/ #include /*----------------全局变量定义区----------------*/ sbit duan_xuan=P2^6; //数码管显示控制 I/O sbit wei_xuan=P2^7; unsigned char minute = 0; //分钟的变量,20*60 次 timer0 中断 unsigned char hour = 0; unsigned char i_num_timer0; //定时器中断次数 unsigned char i_num_timer1; unsigned char disp_min1,disp_min2,disp_hour1,disp_hour2; //分解后的数值变量 unsigned char wei = 1; //用来标记显示哪个数码管 unsigned short uc50ms = 0; //记录 time0 中断次数,此程序用两个变量记录 time0中断次数 /*------定义数码管显示的数字---------*/ unsigned char code duan_table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71 }; /*-----------------函数声明段---