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

📄 uart.c

📁 TI的CC1110、CC2510、CC2430射频SOC的驱动程序
💻 C
字号:
/**************************************/

#include "hal.h"


uint8 Byte;
uint8 RFSendFlg;
uint8 RXOTFlg;          //串口接收数据超时标志
uint8 RXOTCnt;          //串口接收数据超时计数器
uint8 UartReceiveLen;
byte  UartReceive_Buf[68];
/***************************************/


/**************************************
函数名:UART_Init()
功能:初始化串口,使用timer2
入口参数:无
出口参数:无
***************************************/
void UART0_Init (void)
{
    U0CSR = 0xC0;
    U0UCR = 0x00;

    U0BAUD = 131;
    U0GCR = 0x08;      // Sclk=26Hz,BAUD=9600 bps

    URX0IE = 1;


}
/**************************************
函数名:UART0_SendData()
功能:串口发送,扫描方式
入口参数:数据缓冲区首地址
出口参数:无
***************************************/
void UART0_SendData (byte *buff,uint8 len)
{
    uint8 uart_sentcnt;
    U0CSR = 0x80;       //diable uart receive
    for(uart_sentcnt=1;uart_sentcnt<(len-1);uart_sentcnt++)
    {
        UTX0IF=0;
        U0DBUF = buff[uart_sentcnt];
      //  while ((UTX0IF==1));
         while (!(U0CSR==0x82));
    }
    U0CSR = 0xC0;       //enble uart receive
    URX0IE = 1;

}
void UART0_SendDataTest (void)
{
    U0CSR = 0x80;       //diable uart receive
    UTX0IF=0;
    U0DBUF = 0x16;
    while (!(U0CSR==0x82));
    U0CSR = 0xC0;       //enble uart receive
    URX0IE = 1;
}
/**************************************
函数名: UART0RX_Interrupt()
功能: 串口中断服务函数
入口参数:无
出口参数:接收到的数据UART_RECEIVEBuffer[]
***************************************/
#pragma vector = URX0_VECTOR
__interrupt void UART0RX_Interrupt (void)
{

      	URX0IF = 0;                           // Clear interrupt flag

      	Byte = U0DBUF;                      // Read a character from UART

      	if (UartReceiveLen < 64)
      	{
               	UartReceive_Buf[UartReceiveLen] = Byte; // Store in array

             	UartReceiveLen++;             // Update array's size

		RFSendFlg=1;					// Set falg
      	}


}

⌨️ 快捷键说明

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