#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/watchdog.h"
#include "driverlib/pin_map.h"
#define LED_PERIPH SYSCTL_PERIPH_GPIOF
#define LED_PORT GPIO_PORTF_BASE
#define LCD_PIN_RED GPIO_PIN_1
#define LCD_PIN_BLUE GPIO_PIN_2
#define LCD_PIN_GREEN GPIO_PIN_3
//the sw1 button;
#define BUTTON_PIN GPIO_PIN_4
#define BUTTON_INT INT_GPIOF
bool button_pressed = false;
void gpiof_int_isr(void)
{
static bool is_led_on = false;
uint32_t gpio_ints;
uint32_t gpio_val;
gpio_ints = GPIOIntStatus(LED_PORT,true);
GPIOIntClear(LED_PORT,gpio_ints);
gpio_val = GPIOPinRead(LED_PORT,BUTTON_PIN);
if ((gpio_val & BUTTON_PIN) == BUTTON_PIN)
{
button_pressed = false;
}
else
{
button_pressed = true;
}
}
int main(void)
{
uint8_t i_timer;
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
//使能外设
SysCtlPeripheralEnable(LED_PERIPH);
GPIOPinTypeGPIOOutput(LED_PORT,LCD_PIN_RED);
GPIOPinTypeGPIOOutput(LED_PORT,LCD_PIN_BLUE);
GPIOPinTypeGPIOOutput(LED_PORT,LCD_PIN_GREEN);
//配置GPIO端口为输入,弱上拉
GPIODirModeSet(LED_PORT,BUTTON_PIN,GPIO_BOTH_EDGES);
GPIOPadConfigSet(LED_PORT,BUTTON_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
//配置GPIO中断
IntMasterEnable();
IntEnable(BUTTON_INT);
GPIOIntTypeSet(LED_PORT,BUTTON_PIN,GPIO_BOTH_EDGES);
GPIOIntEnable(LED_PORT,BUTTON_PIN);
GPIOIntRegister(LED_PORT,gpiof_int_isr);
//等待系统时钟初始化
SysCtlDelay(100000);
//初始化看门狗
if(WatchdogLockState(WATCHDOG0_BASE) == true)
{
WatchdogUnlock(WATCHDOG0_BASE);
}
//设置看门狗调试时暂停
WatchdogStallEnable(WATCHDOG0_BASE);
//设置看门狗定时器
WatchdogReloadSet(WATCHDOG0_BASE,SysCtlClockGet());
//设置看门狗复位
WatchdogResetEnable(WATCHDOG0_BASE);
//使能看门狗
WatchdogEnable(WATCHDOG0_BASE);
//锁定看门狗
WatchdogLock(WATCHDOG0_BASE);
for(i_timer = 0; i_timer<3; i_timer ++)
{
//闪烁绿色LED灯
SysCtlDelay(SysctlClockGet()/16);
GPIOPinWrite(LED_PORT,LCD_PIN_GREEN,LCD_PIN_GREEN);
SysCtlDelay(SysCtlClockGet()/16);
GPIOPinWrite(LED_PORT,LCD_PIN_GREEN,~LCD_PIN_GREEN);
}
while(true)
{
//闪烁红色LED灯
SysCtlDelay(SysCtlClockGet()/16);
GPIOPinWrite(LED_PORT,LCD_PIN_RED,LCD_PIN_RED);
SysCtlDelay(SysCtlClockGet()/16);
GPIOPinWrite(LED_PORT,LCD_PIN_RED,~LCD_PIN_RED);
//喂狗
if (button_pressed==false)
{
WatchdogUnlock(WATCHDOG0_BASE);
WatchdogReloadSet(WATCHDOG0_BASE,SysCtlClockGet());
WatchdogLock(WATCHDOG0_BASE);
}
}
}
有大神知道其他可以跑通的程序吗?急求!!!
Ruifeng Zhang:
TM4C123GXL看门狗程序急求!!!
xyz549040622:
回复 Ruifeng Zhang:
www.cnblogs.com/…/5070256.html
github.com/…/watchdog.c
blog.csdn.net/…/47661025
参考上面三个网站。
xyz549040622:
回复 Ruifeng Zhang:
github.com/…/watchdog.c
www.cnblogs.com/…/5070256.html
blog.csdn.net/…/47661025
参考上面三个链接就好了。
xyz549040622:
回复 Ruifeng Zhang:
链接移植审核通不过,没办法,参考这三个链接的代码。
Ruifeng Zhang:
回复 xyz549040622:
非常感谢!!!我看看能不能调出来
xyz549040622:
回复 Ruifeng Zhang:
你这个延时时间太长了吧,有6个nop足够了。时钟都没开启,坑好大。记得任何外设,必须先开启时钟。