2024年5月30日发(作者:母正卿)
8位数码管显示电子时钟c51单片机程序
/*
8位数码管显示 时间格式 055000 标示05点50分00秒
S1 用于小时加1操作
S2 用于小时减1操作
S3 用于分钟加1操作
S4 用于分钟减1操作
*/
#includereg52.h
sbit KEY1=P3^0; //定义端口参数
sbit KEY2=P3^1;
sbit KEY3=P3^2;
sbit KEY4=P3^3;
sbit LED=P1^2; //定义指示灯参数
code unsigned char
tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//共阴极数码管09
unsigned char StrTab[8]; //定义缓冲区
unsigned char minute=19,hour=23,second; //定义并初始化为
12:30:00
void delay(unsigned int cnt)
{
第 1 页 共 8 页
while(cnt);
}
/**********************************************************
********/
/* 显示处理函数 */
/**********************************************************
********/
void Displaypro(void)
{
StrTab[0]=tab[hour/10]; //显示小时
StrTab[1]=tab[hour%10];
StrTab[2]=0x40; //显示
StrTab[3]=tab[minute/10]; //显示分钟
StrTab[4]=tab[minute%10];
StrTab[5]=0x40; //显示
StrTab[6]=tab[second/10]; //显示秒
StrTab[7]=tab[second%10];
}
main()
{
TMOD |=0x01; //定时器0 10ms inM crystal 用于计时
第 2 页 共 8 页
2024年5月30日发(作者:母正卿)
8位数码管显示电子时钟c51单片机程序
/*
8位数码管显示 时间格式 055000 标示05点50分00秒
S1 用于小时加1操作
S2 用于小时减1操作
S3 用于分钟加1操作
S4 用于分钟减1操作
*/
#includereg52.h
sbit KEY1=P3^0; //定义端口参数
sbit KEY2=P3^1;
sbit KEY3=P3^2;
sbit KEY4=P3^3;
sbit LED=P1^2; //定义指示灯参数
code unsigned char
tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//共阴极数码管09
unsigned char StrTab[8]; //定义缓冲区
unsigned char minute=19,hour=23,second; //定义并初始化为
12:30:00
void delay(unsigned int cnt)
{
第 1 页 共 8 页
while(cnt);
}
/**********************************************************
********/
/* 显示处理函数 */
/**********************************************************
********/
void Displaypro(void)
{
StrTab[0]=tab[hour/10]; //显示小时
StrTab[1]=tab[hour%10];
StrTab[2]=0x40; //显示
StrTab[3]=tab[minute/10]; //显示分钟
StrTab[4]=tab[minute%10];
StrTab[5]=0x40; //显示
StrTab[6]=tab[second/10]; //显示秒
StrTab[7]=tab[second%10];
}
main()
{
TMOD |=0x01; //定时器0 10ms inM crystal 用于计时
第 2 页 共 8 页