用51单片机设计一个秒表,计时范围从00:00-59:59.
答案:3 悬赏:50 手机版
解决时间 2021-02-03 08:57
- 提问者网友:棒棒糖
- 2021-02-02 22:06
用51单片机设计一个秒表,计时范围从00:00-59:59.
最佳答案
- 五星知识达人网友:西风乍起
- 2021-02-02 22:49
#include<reg51.h>
#include "intrins.h"
#include "absacc.h"
#define uchar unsigned char
uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0xff};//0-9
unsigned char sec=0,min=0,scanled;
unsigned char key=0,mode,time;
unsigned char disdat[4];
void dischg()
{
disdat[3]=sec%10;
disdat[2]=sec/10;
disdat[1]=min%10;
disdat[0]=min/10;
}
void ext0() interrupt 0
{
key++;
key%=3;
}
void t0isr() interrupt 1 //秒计时
{
TH0=0x3c;
TL0=0xb0;
time++;
if(time==20)
{
time=0;
sec++;
if(sec>59)
{
sec=0;
min++;
if(min>59)min=0;
}
}
dischg();
}
void t1isr() interrupt 3 //显示
{
TH1=0xec;
TL1=0x78;
P0=0xff;
switch(scanled)
{
case 1:
P2=0x02;
P0=~(ledtab[disdat[1]]|0x80);
break;
case 2:
P2=0x04;
P0=~ledtab[disdat[2]];
break;
case 3:
P2=0x08;
P0=~ledtab[disdat[3]];
break;
default:break;
}
scanled++;
scanled%=4;
}
main()
{
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0xec;
TL1=0x78;
TR1=1;
TR0=0;
ET0=1;
ET1=1;
EX0=1;
IT0=1;
EA=1;
scanled=0;
time=0;
mode=1;
dischg();
while(1)
{
switch(key)
{
case 0:TR0=0;break;
case 1:TR0=1;break;
case 2:sec=0;min=0;break;
}
}
}
#include "intrins.h"
#include "absacc.h"
#define uchar unsigned char
uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0xff};//0-9
unsigned char sec=0,min=0,scanled;
unsigned char key=0,mode,time;
unsigned char disdat[4];
void dischg()
{
disdat[3]=sec%10;
disdat[2]=sec/10;
disdat[1]=min%10;
disdat[0]=min/10;
}
void ext0() interrupt 0
{
key++;
key%=3;
}
void t0isr() interrupt 1 //秒计时
{
TH0=0x3c;
TL0=0xb0;
time++;
if(time==20)
{
time=0;
sec++;
if(sec>59)
{
sec=0;
min++;
if(min>59)min=0;
}
}
dischg();
}
void t1isr() interrupt 3 //显示
{
TH1=0xec;
TL1=0x78;
P0=0xff;
switch(scanled)
{
case 1:
P2=0x02;
P0=~(ledtab[disdat[1]]|0x80);
break;
case 2:
P2=0x04;
P0=~ledtab[disdat[2]];
break;
case 3:
P2=0x08;
P0=~ledtab[disdat[3]];
break;
default:break;
}
scanled++;
scanled%=4;
}
main()
{
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0xec;
TL1=0x78;
TR1=1;
TR0=0;
ET0=1;
ET1=1;
EX0=1;
IT0=1;
EA=1;
scanled=0;
time=0;
mode=1;
dischg();
while(1)
{
switch(key)
{
case 0:TR0=0;break;
case 1:TR0=1;break;
case 2:sec=0;min=0;break;
}
}
}
全部回答
- 1楼网友:西风乍起
- 2021-02-03 00:37
单片机设计一个秒表,计时范围
这样我才好探讨的,结果的
- 2楼网友:老鼠爱大米
- 2021-02-02 23:46
需要看你的硬件电路,还有必要的元件参数(如:晶振的频率是多少?)。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯