51单片机定时器问题
#include<reg51.h>#defineduanxuanP0#defineweixuanP1unsignedcharweixuanbianma[8]={0xfe,...
#include <reg51.h>
#define duanxuan P0
#define weixuan P1
unsigned char weixuanbianma[8] = {
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char duanxuanbianma[10] = {
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char diejia=0;
void delay (unsigned char a)
{
unsigned char i;
while(a--)
for(i=120;i>0;i--);
}
void main()
{
unsigned char h,min,s,t;
unsigned char number=0;
EA=1;
ET0=1;
TR0=1;
TMOD=0x01;
while(1)
{
if(diejia==20)
{
diejia=0;
number++;
}
t=number;
s=t%60;
min=t/60;
h=min%60;
weixuan=weixuanbianma[0];
duanxuan=duanxuanbianma[h/10];
delay(1);
weixuan=weixuanbianma[1];
duanxuan=duanxuanbianma[h%10];
delay(1);
weixuan=weixuanbianma[2];
duanxuan=0x40;
delay(1);
weixuan=weixuanbianma[3];
duanxuan=duanxuanbianma[min/10];
delay(1);
weixuan=weixuanbianma[4];
duanxuan=duanxuanbianma[min%10];
delay(1);
weixuan=weixuanbianma[5];
duanxuan=0x40;
delay(1);
weixuan=weixuanbianma[6];
duanxuan=duanxuanbianma[s/10];
delay(1);
weixuan=weixuanbianma[7];
duanxuan=duanxuanbianma[s%10];
delay(1);
}
}
dingshi () interrupt 1
{
TH0=15535/255;
TL0=15535%255;
diejia++;
}
运行8个数码管全都是亮的,求解 展开
#define duanxuan P0
#define weixuan P1
unsigned char weixuanbianma[8] = {
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char duanxuanbianma[10] = {
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char diejia=0;
void delay (unsigned char a)
{
unsigned char i;
while(a--)
for(i=120;i>0;i--);
}
void main()
{
unsigned char h,min,s,t;
unsigned char number=0;
EA=1;
ET0=1;
TR0=1;
TMOD=0x01;
while(1)
{
if(diejia==20)
{
diejia=0;
number++;
}
t=number;
s=t%60;
min=t/60;
h=min%60;
weixuan=weixuanbianma[0];
duanxuan=duanxuanbianma[h/10];
delay(1);
weixuan=weixuanbianma[1];
duanxuan=duanxuanbianma[h%10];
delay(1);
weixuan=weixuanbianma[2];
duanxuan=0x40;
delay(1);
weixuan=weixuanbianma[3];
duanxuan=duanxuanbianma[min/10];
delay(1);
weixuan=weixuanbianma[4];
duanxuan=duanxuanbianma[min%10];
delay(1);
weixuan=weixuanbianma[5];
duanxuan=0x40;
delay(1);
weixuan=weixuanbianma[6];
duanxuan=duanxuanbianma[s/10];
delay(1);
weixuan=weixuanbianma[7];
duanxuan=duanxuanbianma[s%10];
delay(1);
}
}
dingshi () interrupt 1
{
TH0=15535/255;
TL0=15535%255;
diejia++;
}
运行8个数码管全都是亮的,求解 展开
2个回答
展开全部
假设要求50ms中断,求定时器初值。
晶振11.0592M,每个机器周期时间为:t=12×(1/11.0592M) 单位:us
50ms所需机器周期为:50×1000÷t=46080
那么需要初值为:
0xFFFF-46080=65535-46080=19456=0x4C00
因此,置初值为TH=0x4c,TL=0x00,经过46080个指令周期,计数器将产生50ms定时中断。
如果需要1秒
则连续20次上述中断即可达到
晶振11.0592M,每个机器周期时间为:t=12×(1/11.0592M) 单位:us
50ms所需机器周期为:50×1000÷t=46080
那么需要初值为:
0xFFFF-46080=65535-46080=19456=0x4C00
因此,置初值为TH=0x4c,TL=0x00,经过46080个指令周期,计数器将产生50ms定时中断。
如果需要1秒
则连续20次上述中断即可达到
追问
我想让他实现在数码管上计时的功能啊,时间没有问题
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询