新闻中心

EEPW首页>嵌入式系统>设计应用> 51单片机,计数溢出

51单片机,计数溢出

作者: 时间:2016-11-23 来源:网络 收藏
51单片机计数溢出,CPU响应中断,执行中断函数过程中,计数器是否已清0开始计数,还是等CPU执行完中断函数后再计数,

请以下面程序为例解释解释

本文引用地址://m.amcfsurvey.com/article/201611/320238.htm

//用T0使隔1秒流水灯亮一次,用T1使隔2秒静态数码管依次显示数字
#include
#include
#define uint unsigned int
#define uchar unsigned char
uchar tcount0,tcount1,temp,num;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void main()
{
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
TH1=(65536-50000)/256;
TL1=(65536-50000)%6;
EA=1;
ET0=1;
ET1=1;
num=0;
temp=0xfe;
tcount0=0;
tcount1=0;
TR0=1;
TR1=1;
while(1);
}
void t0() interrupt1//计数溢出,CPU响应中断
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;//设定回计数初值,但此时计数溢出后已清0仍在计数吗?
tcount0++;
if(tcount0==20)
{
tcount0=0;
P1=temp;
temp=_crol_(temp,1);
}
}
void t1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%6;
tcount1++;
if(tcount1==40)
{
tcount1=0;
if (num==16)
num=0;
P0=table[num];
num++;
}
}



关键词:51单片机计数溢

评论


技术专区

关闭