资源简介
马潮老师 AVR串口例程代码 Atmega16
代码片段和文件信息
/*****************************************************
File name : demo_14_1.c
Chip type : ATmega16L
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include
#define UART_BEGIN_STX 0xBB
#define UART_END_STX 0xEE
#define FRAMING_ERROR (1< #define PARITY_ERROR (1< #define DATA_OVERRUN (1< #define DATA_REGISTER_EMPTY (1< #define RX_COMPLETE (1<
#define TX_BUFFER_SIZE 5
unsigned char tx_buffer[TX_BUFFER_SIZE]; // USART Transmitter buffer
unsigned char tx_wr_indextx_rd_indextx_counter;
// USART Transmitter interrupt service routine
interrupt [USART_TXC] void usart_tx_isr(void)
{
if (tx_counter)
{
--tx_counter;
UDR=tx_buffer[tx_rd_index];
if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0;
}
}
void putchar(unsigned char c)
{
while (tx_counter == TX_BUFFER_SIZE);
#asm(“cli“)
if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0))
{
tx_buffer[tx_wr_index]=c;
if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
++tx_counter;
}
else
UDR=c;
#asm(“sei“)
}
#define RX_BUFFER_SIZE 5
unsigned char rx_buffer[RX_BUFFER_SIZE]; // USART Receiver buffer
unsigned char rx_counter;
bit Uart_RecvFlag;
// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
unsigned char statusdata;
status = UCSRA;
data = UDR;
if (!Uart_RecvFlag) // 判断是否允许接收一个新的数据包
{
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
{
rx_buffer[rx_counter] = data;
rx_counter++;
switch (rx_counter)
{
case 1: // 检验起始字符
- 上一篇:ztree模糊搜索demo
- 下一篇:GLAS数据提取高程,IDL
相关资源
- 基于AVR的NRF24L01跳频通信程序
- AVR_GCC程序设计基础
- 自制AVR ATmega16 JTAG2008
- AVR多功能实验箱DS1302时钟实验源码资
- GY-291 ADXL345模块资料 例程
- LED屏无线控制器的设计方案
- 最全蓝牙协议规范-HFP/A2DP/AVRCP/PBAP/M
- AVR fighter win10 64位 好用版本 亲测好用
- ICCAVR v6.31a破解版+注册工具
- 蓝牙AVRCP1.6协议规范
- AVR单片机嵌入式系统原理与应用实践
- ATmega16(L) 中文数据手册.pdf
- STM32L051C8T6_USART1.zip
- 超声波测距 基于51 pic avr单片机
- ICCAVR7.0破解版
- ATMEL USB ISP
- avr—usb应用,vc上位机读avr数据,程序
- 电子血压计原理图和代码
- ICCAVR7.22直接安装不需要注册
- ENC28J60最全资料,含51AVRLPCSTM32程序源
- avr官方中文版技术手册
- DYP-ME007超声波模块资料以及驱动程序
- AVR单片机与CPLD_FPGA综合应用入门
- iccavr7.22.rar
- AVR单片机原理及应用
- AVR单片机嵌入式系统原理与应用实践
- AVR单片机嵌入式系统原理与应用实践
- AVR高压编程器制作的全部资料(原理
- BASCOM-AVR的例程
- Atmeg16学习笔记
评论
共有 条评论