#include#defineucharunsignedchar#defineuintunsignedintuchartime,temp,shi,ge;sbitduan=P2^2;//定义锁存使能端口段锁存sbitwei=P2^3;//定义锁存使能端口位锁存ucharcodet...
#include
#define uchar unsigned char
#define uint unsigned int
uchar time,temp,shi,ge;
sbit duan=P2^2; //定义锁存使能端口 段锁存
sbit wei=P2^3; //定义锁存使能端口 位锁存
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint z)
{
int x,y;
for(x=z;x>0;x--)
for(y=200;y>0;y--);
}
void init() //初始化子程序
{
duan=0;
wei=0;
time=0;
temp=20;
TMOD=0x01;//采用定时器T0,定时方式、方式1
TH0=(65536-50000)/256;//50毫秒;20次为1秒。
TL0=(65536-50000)%256;
EA=1; //开总中断
ET0=1; //T0溢出中断允许位。为1是打开,为0时禁止
TR0=1; //启动T0定时器
}
void display(uchar shi,uchar ge)
{
duan=1;
P0=table[shi];
duan=0;
P0=0xff;
wei=1;
P0=0xfe;
wei=0;
delay(1);
duan=1;
P0=table[ge];
duan=0;
P0=0xff;
wei=1;
P0=0xfd;
wei=0;
delay(1);
}
void display_shanshuo(uchar shi,uchar ge)//闪烁子程序
{
???????????????????
???????????????????
???????????????????
}
void main()
{
init();
while(1)
{
if(time==20)
{
time=0;
temp--;
if(temp==0)
temp=20;
shi=temp/10;
ge=temp%10;
}
if(temp>10)
display(shi,ge);
if(temp<11)
display_shanshuo(shi,ge);
}
}
void timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
time++;
}
请教各位高手,程序当中的闪烁子程序怎么编写呢?才能实现数码管正常递减并且是相隔1秒的时间在闪烁!
展开