📄 iar-
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: time32os_per.c
** Last modified Date: 2007.12.24
** Last Version: v1.1
** Description: Stellaris系列单片机的定时器操作例程
** 在本范例中,定时器0被设置为32位的可编程周期触发模式。
**
**--------------------------------------------------------------------------------------------------------
** Created By: Ni Likao
** Created date: 2007.09.19
** Version: v1.0
** Descriptions: 定时器被设置为每秒产生2次中断,
** 每个中断处理器在每一次中断时都翻转一次相应的GPIO端口
**
**--------------------------------------------------------------------------------------------------------
** 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 "sysctl.h"
#include "timer.h"
#include "interrupt.h"
#define PINS1 GPIO_PIN_6 /* 定义LED1 */
/*********************************************************************************************************
** Function name: Timer0A_ISR
** Descriptions: 定时器0中断处理程序。工作在32位周期触发模式下。
** 用KEIL软件时,在Startup.S中添加该中断函数名
** input parameters: 无
** output parameters: 无
** Returned value: 无
** Created By: Ni Likao 倪力考
** Created date: 2007.09.19
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void Timer0A_ISR (void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); /* 清除定时器0中断 */
GPIOPinWrite(GPIO_PORTB_BASE, PINS1, GPIOPinRead(GPIO_PORTB_BASE, PINS1) ^ PINS1);
/* 翻转GPIO B6 端口 */
TimerEnable(TIMER0_BASE, TIMER_A); /* 使能定时器0 */
}
/*********************************************************************************************************
** Function name: main
** Descriptions: 该范例程序演示了如何使用定时器产生周期性中断。定时器设置为每秒产生两次中断;
** 每个中断处理器在每一次中断时都翻转一次相应的GPIO(B6端口),同时,LED指示灯会
** 指示每次中断以及中断的速率,在本范例中,定时器0被设置为32位的可编程周期触发模式
** input parameters: 无
** output parameters: 无
** Returned value: 无
** Created By: Ni Likao 倪力考
** Created date: 2007.09.19
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int main (void)
{
SysCtlClockSet( SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_6MHZ ); /* 设定晶振为时钟源 */
SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 ); /* 使能定时器0外设 */
SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOB ); /* 使能GPIOB口外设 */
IntMasterEnable(); /* 使能全局中断 */
GPIOPinTypeTimer(TIMER0_BASE, TIMER_A);
GPIODirModeSet(GPIO_PORTB_BASE, PINS1, GPIO_DIR_MODE_OUT);
/* 设置 GPIO B6为输出口 */
GPIOPadConfigSet(GPIO_PORTB_BASE, PINS1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
/* 配置端口类型 */
GPIOPinWrite(GPIO_PORTB_BASE, PINS1, 0); /* 初始化IO口 */
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); /* 设置定时器0为周期触发模式 */
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / 2); /* 设置定时器装载值:定时1/2秒 */
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); /* 设置定时器为溢出中断 */
TimerEnable(TIMER0_BASE, TIMER_A); /* 使能定时器0 */
IntEnable(INT_TIMER0A); /* 使能定时器0外设 */
while (1) {
;
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -