基于51单片机的简易计数器设计,求c语言程序!
发布网友
发布时间:2022-04-29 20:37
我来回答
共1个回答
热心网友
时间:2022-06-22 11:26
#include<reg51.h>
#define uchar unsigned char
uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//0-9
unsigned char sec=0,scanled;
unsigned char disdat[2];
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
void dischg()
{
disdat[0]=sec%10;
disdat[1]=sec/10;
}
void t0isr() interrupt 1 //秒计时
{
TH0=0x3c;
TL0=0xb0;
time++;
if(time==20)
{
time=0;
sec++;
if(sec>60)sec=0;
}
dischg();
}
void t1isr() interrupt 3 //显示
{
TH1=0xec;
TL1=0x78;
switch(scanled)
{
case 0:
P2=0x01;
P0=~ledtab[disdat[7]];
break;
case 1:
P2=0x02;
P0=~ledtab[disdat[6]];
break;
default:break;
}
scanled++;
scanled%=2;
}
main()
{
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0xec;
TL1=0x78;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
sec=0;
scanled=0;
time=0;
dischg();
while(1)
{
if(key1==0)
{
while(key1==0);
TR0=0;
}
if(key2==0)
{
while(key2==0);
TR0=1;
}
if(key3==0)
{
while(key3==0);
sec=0;
dischg();
}
}
}追问您好,程序显示“time”undefined identifier