数码管动态显示c语言程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
void main()
{
TMOD=0x01;/*设置定时器*/
TH0=0xfc;
TL0=0x18;
TR0=1;
EA=1;/*设置中断*/
ET0=1;
while(1)
{
if(0==TF0)
{
if(cnt>=1000)
{
cnt=0;
sec++;
LEDbuff[0]=LED[sec%10];/*百度文库置数码管显示位*/
//这是一个,四位数码管动态显示c语言程序,每隔一秒加一,直至加到9999为止
#include <reg52.h>
unsigned char code LED[]={0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
unsigned char LEDbuff[]={0xff,0xff,0xff,0xff};
P1=0xff;
switch(i)
{
case 0: SEG_bit_1 = 1;SEG_bit_4 = 0;P1=LEDbuff[0];i++;break;
case 1: SEG_bit_4 = 1;SEG_bit_3 = 0;P1=LEDbuff[1];i++;break;
case 2: SEG_bit_3 = 1;SEG_bit_2 = 0;P1=LEDbuff[2];i++;break;
case 3: SEG_bit_2 = 1;SEG_bit_1 = 0;P1=LEDbuff[3];i=0;break;
default:break;
}
}
//定义数码管的位选段
sbit SEG_bit_1 = P0^1;
sbit SEG_bit_2 = P0^2;
sbit SEG_bit_3 = P0^3;
sbit SEG_bit_4 = P0^4;
unsigned int cnt=0;
unsigned int sec =0;
unsigned char i=0;
LEDbuff[1]=LED[sec/10%10];
LEDbuff[2]=LED[sec/100%10];
LEDbuff[3]=LED[sec/1000%10];
}
}
}
}
void interrupttimer0() interrupt 1/*设置中断函数*/
{
TH0=0xfc;
TL0=0x18;
cnt++;
{
TMOD=0x01;/*设置定时器*/
TH0=0xfc;
TL0=0x18;
TR0=1;
EA=1;/*设置中断*/
ET0=1;
while(1)
{
if(0==TF0)
{
if(cnt>=1000)
{
cnt=0;
sec++;
LEDbuff[0]=LED[sec%10];/*百度文库置数码管显示位*/
//这是一个,四位数码管动态显示c语言程序,每隔一秒加一,直至加到9999为止
#include <reg52.h>
unsigned char code LED[]={0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
unsigned char LEDbuff[]={0xff,0xff,0xff,0xff};
P1=0xff;
switch(i)
{
case 0: SEG_bit_1 = 1;SEG_bit_4 = 0;P1=LEDbuff[0];i++;break;
case 1: SEG_bit_4 = 1;SEG_bit_3 = 0;P1=LEDbuff[1];i++;break;
case 2: SEG_bit_3 = 1;SEG_bit_2 = 0;P1=LEDbuff[2];i++;break;
case 3: SEG_bit_2 = 1;SEG_bit_1 = 0;P1=LEDbuff[3];i=0;break;
default:break;
}
}
//定义数码管的位选段
sbit SEG_bit_1 = P0^1;
sbit SEG_bit_2 = P0^2;
sbit SEG_bit_3 = P0^3;
sbit SEG_bit_4 = P0^4;
unsigned int cnt=0;
unsigned int sec =0;
unsigned char i=0;
LEDbuff[1]=LED[sec/10%10];
LEDbuff[2]=LED[sec/100%10];
LEDbuff[3]=LED[sec/1000%10];
}
}
}
}
void interrupttimer0() interrupt 1/*设置中断函数*/
{
TH0=0xfc;
TL0=0x18;
cnt++;