TM4C123GH6PM的定時器捕獲中斷實現
阿新 • • 發佈:2019-02-10
#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)替換為自己寫的函式名。