rt,小弟想做一个数码管显示程序,效果是通过定时器,每隔1s在数码管上显示0-6,但是做出来的效果是,6一直在亮着,并且亮度很大,而其他的数字都在以1s的间隔闪烁,亮度很小。重点在于显示函数,如果不设置闪烁的效果,只是调用显示函数的话会同时显示出0-6,各位亮度相同,但是一旦给函数的参数变化,就会产生杉树的效果。求大神答疑!代码如下:
#include<reg52.h>
sbit dula = P2^6;
sbit wela = P2^7;
sbit key = P3^2;
unsigned char code DuanMa[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,0x8e};// 显示段码值0~F
unsigned char code WeiMa[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//分别对应相应的数码管点亮,即位码
void display(unsigned char);//显示函数
void delay(unsigned int);//延时函数
unsigned char num;
unsigned char num1;
void main()
{
EA = 1;
ET0 = 1;
TMOD = 0X01;
TR0 = 1;
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
while(1);
}
void delay(unsigned int t)
{
while(t--);
}
void display(unsigned char i)
{
unsigned char j;
for(j=0;j<=i;j++)
{
P0 = 0;
wela = 1;
P0 = WeiMa[j];
wela = 0;
dula = 1;
P0 = DuanMa[j];
dula = 0;
delay(100);
}
}
void
timer_0() interrupt 1
{
if(num == 20)
{
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
num = 0;
num1++;
if(num1 == 1 )
{
num1 = 0;
display(6);
}
}
num ++;
}
一周热门 更多>