⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iar-

📁 IAR_example_EasyARM8962.zip
💻
字号:
/****************************************Copyright (c)****************************************************
**                               Guangzhou ZHIYUAN electronics Co.,LTD.
**                                     
**                                 http://www.embedtools.com		  
**
**--------------File Info---------------------------------------------------------------------------------
** File Name:               time_16_count.c	   
** Last modified Date:      2007.12.24 
** Last Version:            V1.1	  
** Description:             Stellaris系列单片机定时器0库函数的操作		   
** 				            使用定时器实现输入边沿计数并产生中断		  
**--------------------------------------------------------------------------------------------------------
** Created By:              Ni Likao	   
** Created date:            2007.09.17    
** Version:                 V1.0	  
** Descriptions:            KEY1输入边沿,由定时器递减计数,		 
**                          当计数值和匹配值相等时,进入中断:LED3的状态翻转。			  
**
**--------------------------------------------------------------------------------------------------------
** 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 "systick.h"
#include "timer.h"
#include "interrupt.h"

#define  KEY1 GPIO_PIN_4                                                /*  定义KEY1 :PD4               */	   
#define  LED3 GPIO_PIN_6                                                /*  定义LED3 :PB6               */		 

/*********************************************************************************************************
** Function name:           Timer0A_ISR
** Descriptions:            定时器0中断处理程序。工作在下降沿触发模式下。
**                          用KEIL软件时,在Startup.S中添加该中断函数名
** input parameters:        无
** output parameters:       无
** Returned value:          无
** Created By:              Ni Likao 倪力考
** Created date:            2007.09.17
**--------------------------------------------------------------------------------------------------------
** Modified by:             
** Modified date:                     
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/

void Timer0A_ISR (void)
{
    TimerIntClear(TIMER0_BASE, TIMER_CAPA_MATCH);    	                /*  清除定时器0中断             */
    TimerLoadSet(TIMER0_BASE, TIMER_A, 10);  	                        /*  重装定时器装载值为10        */	  
    GPIOPinWrite(GPIO_PORTB_BASE, LED3, GPIOPinRead(GPIO_PORTB_BASE, LED3) ^ LED3);                     
                                                                        /*  翻转GPIO PB6 端口           */ 	   
    TimerEnable(TIMER0_BASE, TIMER_A);                 	                /*  使能定时器0                 */    
}

/*********************************************************************************************************
** Function name:           main	   
** Descriptions:            该范例程序演示了如何使用定时器的边沿计数触发中断。定时器装载值设为10,匹配值设为
**                          6,采用按键对定时器作计数,当计数值到达匹配值时产生一次中断并翻转一次相应的GPIO
**                          (B6端口)。
** input parameters:        无
** output parameters:       无      
** Returned value:          无	 
** Created By:              Ni Likao 倪力考
** Created date:            2007.09.17
**--------------------------------------------------------------------------------------------------------
** 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口外设	            */
    SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOD );       	            /*  使能GPIOD口外设	            */
	
    IntMasterEnable();                                    	            /*  使能全局中断                */		 
    
    GPIOPinTypeTimer( GPIO_PORTD_BASE, KEY1);                           /*  设置PD4为CCP0功能输入口     */
    GPIODirModeSet(GPIO_PORTB_BASE, LED3, GPIO_DIR_MODE_OUT);           /*  设置 GPIO PB6为输出口       */
    GPIOPadConfigSet(GPIO_PORTB_BASE, LED3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
                                                                        /*  配置端口类型                */		 	
    GPIOPinWrite( GPIO_PORTB_BASE, LED3, 0 );                           /*  点亮LED1                    */
    TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_CAP_COUNT); 
    
    /*  
     *  设置定时器0为16位定时器配置,边沿计数捕获模式
     */                                                     
    TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE);	    /*  设置为下降沿捕获            */ 	   
    TimerLoadSet(TIMER0_BASE, TIMER_A, 10);  	         	            /*  设置定时器装载值为10        */		  
    TimerMatchSet(TIMER0_BASE, TIMER_A, 6);                             /*  设置定时器匹配值为6         */		   
    TimerIntEnable(TIMER0_BASE, TIMER_CAPA_MATCH);   		            /*  GPTM捕获B的匹配中断使能     */	 
    TimerEnable(TIMER0_BASE, TIMER_A);                                  /*  使能定时器并开始等待边沿事件*/		  
    IntEnable(INT_TIMER0A);                                             /*  使能定时器0                 */				 
    while (1) {
        ;
    }												           		 
}

/*********************************************************************************************************
  END FILE
*********************************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -