#include "hh_uart.h" #include "hh_led.h" #include "hh_watchdog.h" #include "hh_timer.h"
void SoftTimerFunction1(void);
int main(void) { unsigned char len,cmd[16]; unsigned long ulResetCause; SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ); //分频系数为1,使用外部晶体作为主振荡器,且晶体的频率为6M delay(2000000); LEDInit(); WDTInit(); IntEnable(INT_GPIOA); //允许GPIOA中断 UART0Init(); TimerInit(); InitSoftTimer();/* 初始化软定时器模块 */ SoftTimerRun(0,TICKS_PER_SEC / 2,SoftTimerFunction1); /* 运行两个软定时器 */ while(1){ ulResetCause=SysCtlResetCauseGet(); SysCtlResetCauseClear(ulResetCause); if(ulResetCause & SYSCTL_CAUSE_SW){//软件复位 LED4On(); UART0_put_str("SYSCTL_CAUSE_SW\r\n\r\n"); }else if(ulResetCause & SYSCTL_CAUSE_WDOG){ LED5On(); UART0_put_str("SYSCTL_CAUSE_WDOG\r\n\r\n"); }else if(ulResetCause & SYSCTL_CAUSE_EXT){ LED6On(); UART0_put_str(">----------\r\n"); UART0_put_str(">请选择:\r\n"); UART0_put_str(">1 软复位\r\n"); UART0_put_str(">2 将看门狗中断等级提高到最高\r\n"); UART0_put_str(">3 将看门狗中断等级降低到最低\r\n"); UART0_put_str(">4 停止外设定时器0\r\n"); UART0_put_str(">5 启动外设定时器0\r\n"); UART0_put_str(">6 软件触发GPIOA中断,进入死循环\r\n"); UART0_put_str(">----------\r\n\r\n"); UART0_put_str("SYSCTL_CAUSE_EXT\r\n\r\n"); }else if(ulResetCause & SYSCTL_CAUSE_POR){ UART0_put_str("SYSCTL_CAUSE_POR\r\n\r\n"); } if((len=UART0_get_line(cmd,13))>0){ if(len>3) { UART0_put_str("> command you entered is: "); UART0_put_str(cmd); UART0_put_str("> this is too long! \r\n"); }else{ switch(cmd[0]){ case '1': UART0_put_str(">the command is soft reset\r\n"); delay(2000000); SysCtlReset(); break; case '2': UART0_put_str("promote watchdog interrupt priority to top 1\r\n"); IntPrioritySet(INT_WATCHDOG,1<<5);//最高优先级 break; case '3': UART0_put_str("bring down watchdog interrupt priority to lowest\r\n"); IntPrioritySet(INT_WATCHDOG,7<<5);//最低优先级 break; case '4': UART0_put_str("the command is stop timer0 Peripheral\r\n"); TimerDisable(TIMER0_BASE, TIMER_A); break; case '5': UART0_put_str("the command is restart timer0 Peripheral\r\n"); TimerEnable(TIMER0_BASE, TIMER_A); break; case '6': UART0_put_str("the command is soft GPIOA endless loop\r\n"); HWREG(NVIC_SW_TRIG)=INT_GPIOA-16; break; default : UART0_put_str(">unkown command\r\n"); break; } } } } }
void SoftTimerFunction1(void) { GPIOPinWrite(GPIO_PORTB_BASE,LED3,GPIOPinRead(GPIO_PORTB_BASE,LED3)^LED3);/*翻转*/ SoftTimerRun(0,(TICKS_PER_SEC + 1) / 2,SoftTimerFunction1); }
void GPIOA_ISR(void) { while(1); }
|