TM4C123GH6PM的定時器捕獲中斷實現

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_nvic.h"
#include "inc/hw_ints.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
#include "utils/uartstdio.h"

void Timer0B_Int_Handler();
int main(void)
{
        //system config
	SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL
	                  |SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
 	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	SysCtlDelay(200);//配置完系統寄存器後要延時一段時間

        //GPIO config
	GPIOPinConfigure(GPIO_PB7_T0CCP1);
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_7);

        //Timer config
	TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_CAP_TIME_UP);
	TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_POS_EDGE);
    
        //Int config
	IntEnable(INT_TIMER0B);
	TimerIntEnable(TIMER0_BASE, TIMER_CAPB_EVENT);
	IntMasterEnable();
	TimerEnable(TIMER0_BASE, TIMER_B);

        while(1);
}
void Timer0B_Int_Handler()
{
	TimerIntClear(TIMER0_BASE, TIMER_CAPB_EVENT);
}
在PB7上接入高電平,就可以檢測到上升沿進入中單咯~
要特別注意的:
_要記得在中斷向量表(startup_ccs.c)中先聲明中斷處理函數(extern Timer0B_Int_Handler();),
並將對應的中斷的中斷處理函數(IntDefaultHandler)替換爲自己寫的函數名。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章