📄 wdt_lib.c
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: WDT.c
** Last modified Date: 2007.12.24
** Last Version: v1.1
** Description: 程序正常运行时,使得LED3不断地闪烁,并喂狗。当按键按下时,触发GPIO按键
** 中断,处理器进入死循环,看门狗定时器产生第一个超时信号,进入看门狗中断
** 服务程序,LED4不断闪烁,直到看门狗定时器产生第二次超时信号,导致系统复
** 位,系统再次正常运行,LED4不断地闪烁。使用Stellaris库函数。
**
**--------------------------------------------------------------------------------------------------------
** Created By: shaoxuefeng
** Created date: 2007.09.17
** Version: v1.0
** Descriptions:
**
**--------------------------------------------------------------------------------------------------------
** Modified by: Kang qinhua
** Modified date: 2008.01.12
** Version: v1.1
** Description:
**
*********************************************************************************************************/
/*********************************************************************************************************
系统头文件配置
*********************************************************************************************************/
#include "hw_memmap.h"
#include "hw_types.h"
#include "hw_ints.h"
#include "gpio.h"
#include "interrupt.h"
#include "sysctl.h"
#include "systick.h"
#include "watchdog.h"
#define KEY1 GPIO_PIN_2 /* 定义KEY1 */
#define LED3 GPIO_PIN_6 /* 定义LED3 */
#define LED4 GPIO_PIN_5 /* 定义LED4 */
/*********************************************************************************************************
** Function name: GPIO_PORT_E_ISR
** Descriptions: 使程序进入死循环
** input parameters: NONE
** output parameters: NONE
** Returned value: NONE
** Created by: shaoxuefeng
** Created Date: 2007.09.17
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void GPIO_Port_E_ISR (void)
{
while(1);
}
/*********************************************************************************************************
** Function name: delay
** Descriptions: 延时的多少取决于ulTime的大小
** input parameters: unsigned long ulTime
** output parameters: NONE
** Returned value: NONE
** Created by: shaoxuefeng
** Created Date: 2007.09.17
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void delay (unsigned long ulTime)
{
while (--ulTime != 0); /*延时数量为ulTime个指令周期 */
}
/*********************************************************************************************************
** Function name: Watchdog_Timer_ISR
** Descriptions: 反转LED4
** input parameters: NONE
** output parameters: NONE
** Returned value: NONE
** Created by: shaoxuefeng
** Created Date: 2007.09.17
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void Watchdog_Timer_ISR (void)
{
while(1){
GPIOPinWrite(GPIO_PORTC_BASE,LED4,~GPIOPinRead(GPIO_PORTC_BASE,LED4));
/* 反转LED4 */
delay(100000);
}
}
/*********************************************************************************************************
** Function name: main
** Descriptions: 程序主函数
** input parameters: NONE
** output parameters: NONE
** Returned value: NONE
** Created by: shaoxuefeng
** Created Date: 2007.09.17
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int main(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG); /* 使能看门狗定时器 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); /* 使能GPIO B口 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); /* 使能GPIO C口 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); /* 使能GPIO E口 */
GPIOPadConfigSet(GPIO_PORTE_BASE, KEY1, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIODirModeSet(GPIO_PORTE_BASE, KEY1, GPIO_DIR_MODE_IN); /* 设置连接KEY1的PE2为输入 */
GPIOPadConfigSet(GPIO_PORTB_BASE, LED3, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIODirModeSet(GPIO_PORTB_BASE, LED3, GPIO_DIR_MODE_OUT); /* 设置连接LED3的PB6为输出 */
GPIOPadConfigSet(GPIO_PORTC_BASE, LED4, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIODirModeSet(GPIO_PORTC_BASE, LED4, GPIO_DIR_MODE_OUT); /* 设置连接LED4的PC5为输出 */
IntPrioritySet(INT_WATCHDOG,0x00); /* 设置看门狗中断优先级为高 */
IntPrioritySet(INT_GPIOE,0x40); /* 设置GPIO E口的中断优先级为低*/
GPIOIntTypeSet(GPIO_PORTE_BASE, KEY1, GPIO_FALLING_EDGE); /* 设置KEY1中断触发方式为下降 */
/* 沿触发 */
GPIOPinIntEnable(GPIO_PORTE_BASE, KEY1); /* 使能KEY1中断 */
IntEnable(INT_GPIOE); /* 使能GPIO E口中断 */
IntEnable(INT_WATCHDOG); /* 使能看门狗中断 */
WatchdogReloadSet(WATCHDOG_BASE, 6000000); /* 设置看门狗定时器的重载值 */
WatchdogResetEnable(WATCHDOG_BASE); /* 使能看门狗定时器的复位功能 */
WatchdogEnable(WATCHDOG_BASE); /* 使能看门狗定时器的中断 */
WatchdogLock(WATCHDOG_BASE); /* 使能看门狗定时器的锁定机制 */
while (1) {
GPIOPinWrite(GPIO_PORTB_BASE, LED3, ~GPIOPinRead(GPIO_PORTB_BASE, LED3));
/* 反转LED3 */
delay(500000); /* 延时 */
WatchdogIntClear(WATCHDOG_BASE); /* 清除看门狗的中断标志、"喂狗"*/
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -