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