本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本人打算用数码管显示765432,使其递减到765400后保持。使用了定时器,程序如下,却出现数码管显示忽快忽慢,希望高人解疑:
#include<reg52.h>
#define uchar unsigned char
#define ulong unsigned long int
uchar count;
ulong disnum=765432;
uchar code tabledu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code tablewe[]={0xf0,0xf1,0xf2,0xf3,0xf4,0xf5};
void display(uchar,uchar,uchar,uchar,uchar,uchar);
void delay(uchar);
void main()
{
EA=1;
ET1=1;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR1=1;
while(1)
{
if(count==20)
{
count=0;
if(disnum>765400)
disnum--;
}
display(disnum/100000,disnum%100000/10000,disnum%10000/1000,disnum%1000/100,disnum%100/10,disnum%10);
}
}
void tim1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
count++;
}
void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f)
{
P2=tabledu[a];
P1=tablewe[0];
delay(10);
P2=tabledu;
P1=tablewe[1];
delay(10);
P2=tabledu[c];
P1=tablewe[2];
delay(10);
P2=tabledu[d];
P1=tablewe[3];
delay(10);
P2=tabledu[e];
P1=tablewe[4];
delay(10);
P2=tabledu[f];
P1=tablewe[5];
delay(10);
}
void delay(uchar p)
{
uchar m,n;
for(m=p;m>0;m--)
for(n=100;n>0;n--);
} |