Embeded Timer 사용하기 Real_G 2009. 1. 5. 22:48 반응형 #include "../../../hw_ints.h" #include "../../../hw_memmap.h" #include "../../../hw_types.h" #include "../../../src/debug.h" #include "../../../src/gpio.h" #include "../../../src/interrupt.h" #include "../../../src/sysctl.h" #include "../../../src/watchdog.h" #include "../../../src/timer.h" #include "../rit128x96x4.h" //***************************************************************************** // //! \addtogroup ek_lm3s8962_list //! <h1>Watchdog (watchdog)</h1> //! //! This example application demonstrates the use of the watchdog as a simple //! heartbeat for the system. If the watchdog is not periodically fed, it will //! reset the system. Each time the watchdog is fed, the LED is inverted so //! that it is easy to see that it is being fed, which occurs once every //! second. // //***************************************************************************** //***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine) { } #endif //***************************************************************************** // The interrupt handler for the watchdog. This feeds the dog (so that the // processor does not get reset) and winks the LED. //***************************************************************************** void WatchdogIntHandler(void) { /* // // Clear the watchdog interrupt. // WatchdogIntClear(WATCHDOG_BASE); // // Invert the GPIO F0 value. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) ^ GPIO_PIN_0); */ } void myTimer(void); int main(void) { // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); ///LED Setting-----------------------------* SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);//port A enable GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_1);//port A3을 output type으로 GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_1,GPIO_PIN_1);//LED turn off //Timer Setting-------------------------------* SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//timer0 using TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER);//32-BIT PERIODIC TIMER TimerLoadSet(TIMER0_BASE,TIMER_A,8000000); //8MB이므로 8000000값을 넣어 1초에 한번 값을 클럭을 주게 설정. TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);//timerA interrupt using TimerIntRegister(TIMER0_BASE,TIMER_A, myTimer); //timer interrupt 발생시 myTimer 라는 함수의 이벤트 발생 TimerEnable(TIMER0_BASE,TIMER_A);//timer 시작. while(1){} } int turn =0; void myTimer(void) { if (turn) { GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_1,GPIO_PIN_1); turn=0; } else { GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_1,0); turn=1; }; TimerIntClear(TIMER0_BASE,TIMER_TIMA_TIMEOUT);//timer clear } 반응형 저작자표시 비영리 동일조건 (새창열림)