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

📄 iar-

📁 IAR_example_EasyARM8962.zip
💻
字号:
/****************************************Copyright (c)****************************************************
**                            Guangzhou ZHIYUAN electronics Co.,LTD.
**                                      
**                                 http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name:               JTAGGPIO.c
** Latest modified Date:    2007.09.27
** Latest Version:          V1.0
** Descriptions:            JTAG管脚用做GPIO
**
**--------------------------------------------------------------------------------------------------------
** Created by:              Zhao shimin
** Created date:            2007.09.27
** Version:                 V1.0
** Descriptions:            The original version
**
**--------------------------------------------------------------------------------------------------------
** Modified by:             Kang qinhua     
** Modified date:           2008.01.13
** Version:                 v1.1
** Descriptions:            
**
*********************************************************************************************************/

/*  系统库函数头文件  */
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"
#include "interrupt.h"
/********************************************************************************************************/
#define   LED4            GPIO_PIN_0                                    /*  PC0                         */
#define   LED5            GPIO_PIN_1                                    /*  PC1                         */
#define   KEY4            GPIO_PIN_5                                    /*  PB5                         */
#define   JTAGC           GPIO_PIN_0 | GPIO_PIN_1 |GPIO_PIN_2 | GPIO_PIN_3

#define   GPIOB_BASE      0x40005000
#define   GPIOC_BASE      0x40006000

#define   GPIOBLOCK   (*((volatile unsigned long *)(GPIOB_BASE+0x520))) /*GPIOB锁定寄存器,用来锁定GPIOBCR*/
#define   GPIOBCR     (*((volatile unsigned long *)(GPIOB_BASE+0x524))) /*  GPIOB确认寄存器,
                                                                            用来确认对AFSEL的写操作     */ 
#define   GPIOBAFSEL  (*((volatile unsigned long *)(GPIOB_BASE+0x420))) 

#define   GPIOCLOCK   (*((volatile unsigned long *)(GPIOC_BASE+0x520)))
#define   GPIOCCR     (*((volatile unsigned long *)(GPIOC_BASE+0x524))) 
#define   GPIOCAFSEL  (*((volatile unsigned long *)(GPIOC_BASE+0x420))) 
                                                            

/*********************************************************************************************************
** Function name:           main
**
** Descriptions:            主函数初始化休眠模块,使LED闪烁并进入休眠状态
**
** input parameters:        NONE
** output parameters:       NONE
**
** Returned value:          NONE
**
** Created by:              Zhao shimin
** Created Date:            2007.10.09
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int  main(void)
{
    unsigned  long i;
    /*  延时用于在JTAG恢复无效时,擦除程序*/
	for(i = 0; i < 5000000; i++);
	for(i = 0; i < 5000000; i++);
	                                       
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);                        /*  给GPIOB提供时钟             */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);                        /*  给GPIOC提供时钟             */
    
	
    /*  对GPIOBCR寄存器进行解锁操作,允许对它的写操作         */
	GPIOBLOCK = 0x1ACCE551;
	/*  GPIOBCR的对应位设为1,允许对GPIOBAFSEL对应位的写操作  */
	GPIOBCR   = 0xFF;
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD);                                /*  设置管脚为上拉驱动          */
    GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_DIR_MODE_IN);      /*  设置管脚为输出              */
    GPIOBLOCK  = 0x00;   
    /*  对GPIOCCR寄存器进行解锁操作,允许对它的写操作         */
	GPIOCLOCK = 0x1ACCE551;
    /*  GPIOCCR的对应位设为1,允许对GPIOCAFSEL对应位的写操作  */
	GPIOCCR   = 0xFF;
    GPIOPadConfigSet(GPIO_PORTC_BASE, LED4|LED5, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD);                                /*  设置管脚为上拉驱动          */
    GPIODirModeSet(GPIO_PORTC_BASE, LED4|LED5, GPIO_DIR_MODE_OUT);      /*  设置管脚为输出              */
    GPIOCLOCK = 0x00;   
    
    GPIOPadConfigSet(GPIO_PORTB_BASE, KEY4, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD);                                /*  设置管脚为上拉驱动          */
    GPIODirModeSet(GPIO_PORTB_BASE, KEY4, GPIO_DIR_MODE_IN);    
    GPIOIntTypeSet(GPIO_PORTB_BASE, KEY4, GPIO_FALLING_EDGE);
    GPIOPinIntEnable(GPIO_PORTB_BASE, KEY4); 
    IntEnable(INT_GPIOB);
    IntMasterEnable();    
    while(1) {

        GPIOPinWrite(GPIO_PORTC_BASE, LED4, ~LED4);
        GPIOPinWrite(GPIO_PORTC_BASE, LED5, LED5);
        for(i = 0; i < 200000; i++);
        GPIOPinWrite(GPIO_PORTC_BASE, LED4, LED4);
        GPIOPinWrite(GPIO_PORTC_BASE, LED5, ~LED5);
        for(i = 0; i < 200000; i++);
    }


}
/*********************************************************************************************************
** Function name:           GPIO_Port_B_ISR 
**
** Descriptions:            PB5引起中断,用于恢复JTAG功能
**
** input parameters:        NONE
** output parameters:       NONE
**
** Returned value:          NONE
**
** Created by:              Zhao shimin
** Created Date:            2007/10/09
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void GPIO_Port_B_ISR (void)
{
  
   GPIOPinIntClear(GPIO_PORTB_BASE,KEY4);
   /*  
    * 恢复PB7,PC0-PC3的JTAG功能  
   */
   GPIOBLOCK = 0x1ACCE551;
   GPIOBCR   = 0xFF;
   GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_7,GPIO_DIR_MODE_HW);
   GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_7,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
   GPIOBCR   = 0x7F;
   GPIOBLOCK = 0x00;

   GPIOCLOCK = 0x1ACCE551;
   GPIOCCR   = 0xFF;
   GPIODirModeSet(GPIO_PORTC_BASE, JTAGC,GPIO_DIR_MODE_HW);
   GPIOPadConfigSet(GPIO_PORTC_BASE, JTAGC,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
   GPIOCCR   = 0xF0;
   GPIOCLOCK = 0x00;
   
}
/*********************************************************************************************************
  END FILE
*********************************************************************************************************/

⌨️ 快捷键说明

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