<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 52單片機Timer2的中斷應用

52單片機Timer2的中斷應用

作者: 時(shí)間:2016-11-11 來(lái)源:網(wǎng)絡(luò ) 收藏
/* This file is an example to use timer2 in mode 0 此程序用于定時(shí)器2模式0*/

#define MSB_reload_value 0x36
/* msb reload value exemple 高位重載值:延時(shí)60ms*/

#define LSB_reload_value 0x36
/* lsb reload value exemple 低位重載值*/

#include "reg_c51.h" //當前文件夾內的文件

/*
* FUNCTION_PURPOSE: This file set up timer 2 in mode 0 (16 bits auto-reload up/down counting timer).
* 用于模式0: 16位自動(dòng)重載 向上/下計時(shí)
* The 16-bits register consist of all 8 bits of TH2 and all 8 bits of TL2.
* 16位寄存器由8位的TH2 和8位的TL2組成
* The EXF2 bit toggles when timer2 overflow or underflow occurs.
* 當timer2向上/下溢出時(shí),置位EXF2位
* EXF2 does not generate interrupt. This bit can be used to provide 17-bit resolution
* FUNCTION_INPUTS: P1.1(T2EX)=0 for down counting or 1 for up counting.
* EXF2位并不引起中斷。此位可以用來(lái)提供17位輸入功能:向上/下計數功能
* FUNCTION_OUTPUTS: void
*/

void main(void)
{
T2MOD &= 0xFC; /* T2OE=0;定時(shí)器2輸出不允許 */
T2MOD |= 0x01; /* DCEN=1;可以設置為向上/下計數:此程序中為向上達到0xff時(shí)溢出*/
EXF2 = 0; /* reset flag 定時(shí)器2外部標志位清除*/
TCLK = 0; RCLK = 0; /* disable baud rate generator 不用于波特率發(fā)生器*/
EXEN2 = 0; /* ignore events on T2EX 視T2EX(P1.1)端信號無(wú)效*/
TH2 = MSB_reload_value; /* Init msb_value 填入初始化值*/
TL2 = LSB_reload_value; /* Init lsb_value */
RCAP2H = MSB_reload_value; /* reload msb_value重載值 */
RCAP2L = LSB_reload_value; /* reload lsb_value */
C_T2 = 0; /* timer mode 定時(shí)模式*/
CP_RL2 = 0; /* reload mode 重載模式*/
EA = 1; /* interupt enable 中斷允許*/
ET2 = 1; /* enable timer2 interrupt 允許T2中斷*/
TR2 = 1; /* timer2 run 開(kāi)始計時(shí)*/
while(1); /* endless */
}
/*
* FUNCTION_PURPOSE: timer2 interrupt
* FUNCTION_INPUTS: void
* FUNCTION_OUTPUTS: P1.2 toggle period = 2
* (65536-reload_value) cycles
*/
void it_timer2(void) interrupt 5
/* interrupt address is 0x002b 定時(shí)器2中斷向量入口*/
{
P0_2 = ~P0_2; /* P1.2 toggle when interrupt. 中斷時(shí)取反*/
TF2 = 0; /* reset interrupt flag 復位中斷標志位*/
}



關(guān)鍵詞: 52單片機Timer2中斷應

評論


技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>