新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機,計數(shù)溢出

51單片機,計數(shù)溢出

作者: 時間:2016-11-23 來源:網(wǎng)絡(luò) 收藏
51單片機,計數(shù)溢出,CPU響應(yīng)中斷,執(zhí)行中斷函數(shù)過程中,計數(shù)器是否已清0開始計數(shù),還是等CPU執(zhí)行完中斷函數(shù)后再計數(shù),

請以下面程序為例解釋解釋

本文引用地址:http://butianyuan.cn/article/201611/320238.htm

//用T0使隔1秒流水燈亮一次,用T1使隔2秒靜態(tài)數(shù)碼管依次顯示數(shù)字
#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() interrupt 1//計數(shù)溢出,CPU響應(yīng)中斷
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;//設(shè)定回計數(shù)初值,但此時計數(shù)溢出后已清0仍在計數(shù)嗎?
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++;
}
}



關(guān)鍵詞: 51單片機計數(shù)溢

評論


技術(shù)專區(qū)

關(guān)閉