?? time32os_per.c
字號(hào):
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: time32os_per.c
** Last modified Date: 2007.09.19
** Last Version: v1.0
** Description: Stellaris系列單片機(jī)的定時(shí)器操作例程
** 在本范例中,定時(shí)器0被設(shè)置為32位的可編程周期觸發(fā)模式。
**
**--------------------------------------------------------------------------------------------------------
** Created By: Ni Likao
** Created date: 2007.09.19
** Version: v1.0
** Descriptions: 定時(shí)器被設(shè)置為每秒產(chǎn)生2次中斷,
** 每個(gè)中斷處理器在每一次中斷時(shí)都翻轉(zhuǎn)一次相應(yīng)的GPIO端口
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** 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: 定時(shí)器0中斷處理程序。工作在32位周期觸發(fā)模式下。
** 用KEIL軟件時(shí),在Startup.S中添加該中斷函數(shù)名
** 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); /* 清除定時(shí)器0中斷 */
GPIOPinWrite(GPIO_PORTB_BASE, PINS1, GPIOPinRead(GPIO_PORTB_BASE, PINS1) ^ PINS1);
/* 翻轉(zhuǎn)GPIO B6 端口 */
TimerEnable(TIMER0_BASE, TIMER_A); /* 使能定時(shí)器0 */
}
/*********************************************************************************************************
** Function name: main
** Descriptions: 該范例程序演示了如何使用定時(shí)器產(chǎn)生周期性中斷。定時(shí)器設(shè)置為每秒產(chǎn)生兩次中斷;
** 每個(gè)中斷處理器在每一次中斷時(shí)都翻轉(zhuǎn)一次相應(yīng)的GPIO(B6端口),同時(shí),LED指示燈會(huì)
** 指示每次中斷以及中斷的速率,在本范例中,定時(shí)器0被設(shè)置為32位的可編程周期觸發(fā)模式
** 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 ); /* 設(shè)定晶振為時(shí)鐘源 */
SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 ); /* 使能定時(shí)器0外設(shè) */
SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOB ); /* 使能GPIOB口外設(shè) */
IntMasterEnable(); /* 使能全局中斷 */
GPIOPinTypeTimer(TIMER0_BASE, TIMER_A);
GPIODirModeSet(GPIO_PORTB_BASE, PINS1, GPIO_DIR_MODE_OUT);
/* 設(shè)置 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); /* 設(shè)置定時(shí)器0為周期觸發(fā)模式 */
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / 2); /* 設(shè)置定時(shí)器裝載值:定時(shí)1/2秒 */
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); /* 設(shè)置定時(shí)器為溢出中斷 */
TimerEnable(TIMER0_BASE, TIMER_A); /* 使能定時(shí)器0 */
IntEnable(INT_TIMER0A); /* 使能定時(shí)器0外設(shè) */
while (1) {
;
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -