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

📄 iar-

📁 IAR_example_EasyARM8962.zip
💻
字号:
/****************************************Copyright (c)****************************************************
**                               Guangzhou ZHIYUAN electronics Co.,LTD.
**                                     
**                                 http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name:               uart.c
** Last modified Date:      2007.09.28 
** Last Version:            v1.0
** Description:             Stellaris系列单片机串口接收数据例程。UART将被配置为 9600波特率, 8-n-1模式
**                          字符将利用中断的方式通过UART接收。
**                          上位机发送"U",下位机就中断接收并判断数据,LED5或LED6将循环点亮,来显示发送
**                          接收数据的状态。
** 
**--------------------------------------------------------------------------------------------------------
** Created By:              zha jinzhong
** Created date:            2006.11.15 
** Version:                 v1.0
** Descriptions:       
**
**--------------------------------------------------------------------------------------------------------
** Modified by:             Kang qinhua 
** Modified date:           2008.01.13
** Version:                 v1.1
** Description:             
**
*********************************************************************************************************/
#include "hw_memmap.h"
#include "hw_types.h"
#include "hw_ints.h"
#include "gpio.h"
#include "uart.h"
#include "sysctl.h"
#include "interrupt.h"

/*********************************************************************************************************
  定义LED5、LED6,两者用来示意数据接收的状态
*********************************************************************************************************/
#define READ_TEST_LED  GPIO_PIN_4                                       
#define READ_TEST_LED1  GPIO_PIN_5

/*********************************************************************************************************
** Function name:           delay
** Descriptions:            延时函数
** input parameters:        d
** output parameters:       无
** Returned value:          无
** Created By:              zha jinzhong
** Created date:            2006.11.15 
**--------------------------------------------------------------------------------------------------------
** Modified by:              
** Modified date:           
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void delay (int  d)
{    
    for (; d; --d) {
        ;
    }
}

/*********************************************************************************************************
** Function name:           UART0_ISR
** Descriptions:            UART0中断服务函数,工作在串口的接收中断和超时中断下,
**                          接收上位机的数据并对数据进行判断:是否为“U”,是则翻转PA4,反之翻转PA5。
**                          用KEIL软件时,在Startup.S中添加该中断函数名
** input parameters:        无
** output parameters:       无
** Returned value:          无
** Created By:              zha jinzhong
** Created date:            2006.11.15 
**--------------------------------------------------------------------------------------------------------
** Modified by:            
** Modified date:           
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void UART0_ISR (void)
{
    UARTIntClear(UART0_BASE, UART_INT_RX | UART_INT_RT);
    if (UARTCharGet(UART0_BASE) == 0x55 ) {                             /*  判断接收到的数据是否为"U"   */
         GPIOPinWrite(GPIO_PORTA_BASE, READ_TEST_LED,
                      GPIOPinRead(GPIO_PORTA_BASE, READ_TEST_LED) ^ READ_TEST_LED);
    } else {                                                            /*  如果为"U"则翻转PA4          */
        GPIOPinWrite(GPIO_PORTA_BASE, READ_TEST_LED1,
                     GPIOPinRead(GPIO_PORTA_BASE, READ_TEST_LED1) ^ READ_TEST_LED1);
   }                                                                    /*  如果为"U"则翻转PA5          */
}

/*********************************************************************************************************
** Function name:           main	   
** Descriptions:            该范例程序演示了通过串口从上位机接收数据并对数据进行判断:是否为“U”,
**                          是则翻转LED5,反翻转LED6。
**                          UART将被配置为 9600波特率,8-n-1模式。	
** input parameters:        无
** output parameters:       无      
** Returned value:          无	 
** Created By:              zha jinzhong
** Created date:            2006.11.15 
**--------------------------------------------------------------------------------------------------------
** Modified by:             
** Modified date:           
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int main (void)
{
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC |
                   SYSCTL_OSC_MAIN |SYSCTL_XTAL_6MHZ);                  /*  设定晶振为时钟源            */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);                        /*  使能UART0外设               */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);                        /*  使能GPIOA外设               */

    IntMasterEnable();                                                  /*  开总中断                    */

    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
                                                                        /*  配置UART0的功能管脚         */
    GPIODirModeSet(GPIO_PORTA_BASE, READ_TEST_LED | READ_TEST_LED1, GPIO_DIR_MODE_OUT);
                                                                        /*  设置 GPIOA4、GPIOA5为输出口 */
    GPIOPadConfigSet(GPIO_PORTA_BASE, READ_TEST_LED | READ_TEST_LED1,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);             /*  配置端口类型                */

    GPIOPinWrite(GPIO_PORTA_BASE, READ_TEST_LED | READ_TEST_LED1, 0);   /* 初始化IO口                   */
    UARTConfigSet(UART0_BASE, 9600, (UART_CONFIG_WLEN_8 |
                                     UART_CONFIG_STOP_ONE |
                                     UART_CONFIG_PAR_NONE));            /*  配置UART0的波特率及端口参数 */                                                                        
    /*
     *  设置UART0接收中断及接收超时中断
     */ 
    HWREG(0X4000C034) = 1 << 3;
    IntEnable(INT_UART0);                                                
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);                                                                                   
    UARTEnable(UART0_BASE);                                             /*  使能UART0                   */
    while (1) {
        ;
    }
}

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

⌨️ 快捷键说明

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