一看就会,适合初学者参考
T0,T1同时开中断,和别人的有点不一样
源程序如下
//数码管设计的可调电子钟
//K1,K2分别调整小时和分钟
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]={0xC0,0xF9,0xA4,0xB0,0x99, //共阳段码
0x92,0x82,0xF8,0x80,0x90,0xFF};
uchar DSY_BUFFER[]={0,0,0xBF,0,0,0xBF,0,0}; //显示缓存
uchar Scan_BIT; //扫描位,选择要显示的数码管
uchar DSY_IDX; //显示缓存索引
uchar Key_State; //P1端口按键状态
uchar h,m,s,s100; //十分秒 ,1/100s
void DelayMS(uchar x) //延时
{
uchar i;
while(x--) for(i=0;i<120;i++); }
void Increase_Hour() //小时处理函数
{
if(++h>23)h=0;
DSY_BUFFER[0]=DSY_CODE[h/10];
DSY_BUFFER[1]=DSY_CODE[h%10];
}
void Increase_Minute()//分钟处理函数
{
if(++m>59)
{
m=0;Increase_Hour();
}
DSY_BUFFER[3]=DSY_CODE[m/10];
DSY_BUFFER[4]=DSY_CODE[m%10];
}
void Increase_Second() //秒处理函数
{
if((++s>59))
{