我想让数码管每隔一秒就变换显示一下,到了六十九回到零,循环显示,但是数码管一直显示零零啊,哪里错了?快崩溃了。
数码管是八位共阴连接的,动态显示。
下边是源程序
#include <reg51.h>
sbit wscun=P2^3;、*/段锁存*/
sbit dscun=P2^2;*/为锁存*/
unsigned char duanma[10]={0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};/*l零到九的段码*/
unsigned char weima[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};/*位码*/
void display(unsigned char wei,unsigned char num);/*动态显示函数*/
void delay(unsigned char x);/*延时程序*/
unsigned char num=0;/*秒数,零到六十*/
unsigned temp[2];*/缓存数据,用来记下断码*/
void main()
{
TMOD=0x01;/*模式1*/
TH0=0x3c;
TL0=0xb0;
EA=1;/*终端总开关*/
ET0=1;/*定时器0中段开*/
TR0=1;
while(1)
{
temp[0]=duanma[num/10];
temp[1]=duanma[num%10];
display(6,2);/*显示当下秒数*/
}
}
void
time0()interrupt 0/*中断函数,每隔一秒中断*/
{
static unsigned char count=0;
count++;
if(count>=20)
{
num++;/*当下秒数加一*/
if(num==61)
num=0;
}
TH0=0x3c;
TL0=0xb0;
}
void display(unsigned char wei,unsigned char shu)
{
unsigned char i;
for(i=0;i<shu;i++)
{
P0=0;
dscun=1;
dscun=0;
P0=weima[i+wei];
wscun=1;
wscun=0;
P0=temp
;
dscun=1;
dscun=0;
delay(200);
}
}
void delay(unsigned char x)
{
while(--x);
}
程序太麻烦
一周热门 更多>