本帖最后由 lzf6929 于 2010-10-20 19:18 编辑
用数码管显示的六位时分秒的计时器,中断程序函数的写法问题。为什么d,num不能自增?
#include <reg52.h>
#define uchar unsigned char
sbit duan=P3^5;
sbit wei=P3^6;
long int num=0;
uchar a;
void delay(uchar);
void display();
void main()
{
TMOD=0X10;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
IE=0X88;
TCON=0X40; //启动计时器1
while(1)
{
display();
}
}
void desk() interrupt 3 //中断函数及计时控制
{
uchar d=0;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
d++;
if(d==20)
{
d=0;
num++;
if(num==86400) num=0;
}
}
void display() //显示数码管的具体计时时间
{
uchar code table1[]={0x3f,0x06,0x5b,0x4f,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code table2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uchar table3[6];
uchar c;
table3[0]=table1[num/36000];
table3[1]=table1[num/3600%10];
table3[2]=table1[num%3600/600];
table3[3]=table1[num%3600/60%10];
table3[4]=table1[num%3600%60/10];
table3[5]=table1[num%3600%60%10];
for(c=0;c<=5;c++)
{
duan=1;
P0=table3[c];
duan=0;
wei=1;
P1=table2[c];
wei=0;
delay(20);
}
}
void delay(uchar a) //延时
{
uchar i,j;
for(j=a;j>0;j--)
for(i=110;i>0;i--);
} |