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

📄 uart.c

📁 使用在cc1000芯片和avr128l处理器上的无线通讯新到监听程序,比较简单适合入门。
💻 C
字号:
#include "uart.h"
#include "type.h"

uint8_t buff[4];
uint8_t count;
void uart_init()
{

     // initialize UART
    * (volatile unsigned char *)0x90 = 0;		    /* UBRR0H = 0 */
	* (volatile unsigned char *)(0x09 + 0x20) = 15;	/* UBRR0L = 15 */	
	/* UCSR0A中的U2X0 = 1,即传输速率倍速 */
	* (volatile unsigned char *)(0x0B + 0x20) = 1 << 1;	
	/* UCSR0C中UCSZ1 = 1,UCSZ0 = 1,即传送或接收字符长为8bit */
	* (volatile unsigned char *)0x95 = (1 << 2) | (1 << 1);	
	/* UCSR0B中的RXCIE,TXCIE,RXEN和TXEN都置为1 */
    * (volatile unsigned char *)(0x0A + 0x20) = (((1 << 7) | (1 << 6)) | (1 << 4)) | (1 << 3);		 
}

/*************************************************************************
*功能描述:将rssi参数组合成一个有格式的包
*参数说明:rssi数据
*返回值:  
**************************************************************************/
void uart_txrssi(uint16_t rssidata){
    
    buff[0] = 0x8e;
	buff[1] = (rssidata>>8)&0xFF;
	buff[2] = rssidata&0xFF;
	buff[3] = 0x7e;
	* (volatile unsigned char *)(0x0C + 0x20) = buff[0];	// 将data写入数据寄存器UDR0 
	* (volatile unsigned char *)(0x0B + 0x20) |= 1 << 6;	// 向TXC位写逻辑1,从而清零该位
	count = 1;
}

/*************************************************************************
*功能描述:串口发送完成中断响应函数
*参数说明:无
*返回值:  
**************************************************************************/
void __attribute((signal))   __vector_20(void){

    if(count < 4){
	* (volatile unsigned char *)(0x0C + 0x20) = buff[count];	// 将data写入数据寄存器UDR0 
	* (volatile unsigned char *)(0x0B + 0x20) |= 1 << 6;	// 向TXC位写逻辑1,从而清零该位
	count++;
	}

}

⌨️ 快捷键说明

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