相应马老师的号召,我把cvavr中usart中断子程序注释了一下
相应马老师的号召,我把cvavr中usart中断子程序注释了一下,里面也有几句不懂的地方,希望高手帮我注释一下,谢谢/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.4a Standard
Automatic Program Generator
?Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
e-mail:office@hpinfotech.com
Project :
Version :
Date : 2005-10-19
Author: df
Company : dadf
Comments:
Chip type : ATmega8L
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size: 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
// USART Receiver buffer
#define RX_BUFFER_SIZE 8
char rx_buffer; //定义接受缓冲区8个char型变量组成的数组
#if RX_BUFFER_SIZE<256 //若缓冲区大于256个字节,定义为 int型数组
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif
// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow; //接受缓冲区溢出标志
// USART Receiver interrupt service routine //usart接受中断服务程序
interrupt void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;//读取数据寄存器
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0) //判断是否有错误标志
{
rx_buffer=data;// 填充接受缓冲区
if (++rx_wr_index == RX_BUFFER_SIZE) //判断接受缓冲区是否满
rx_wr_index=0; //如果满则下一个接受数据覆盖缓冲区的首字节
if (++rx_counter == RX_BUFFER_SIZE)//记录缓冲区还有多少个字节没有读取,如果超出了缓冲区容量,置位缓冲区溢出标志
{
rx_counter=0;
rx_buffer_overflow=1; //缓冲区溢出
};
};
}
#ifndef _DEBUG_TERMINAL_IO_ //?????????
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_ //?????????
#pragma used+ //?????????
char getchar(void)
{
char data;
while (rx_counter==0); //没有数据可以读取,等待。。。。。
data=rx_buffer; //读取缓冲区数据
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;//标记出读到哪里,如果读到缓冲区末尾,则从头开始读
#asm("cli")
--rx_counter; //未读数据个数减少1
#asm("sei")
return data;
}
#pragma used- //?????????
#endif
// Standard Input/Output functions
#include <stdio.h>
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=1 State4=1 State3=T State2=T State1=T State0=T
PORTB=0x30;
DDRB=0x30;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
};
} #ifndef _DEBUG_TERMINAL_IO_ //?????????
#define _ALTERNATE_GETCHAR_ //?????????
#pragma used+ //?????????
#pragma used- //?????????
高手,这几句是什么意思? 您一说高手,没人敢回答了:D
俺是低手,瞎说两句:那些都是编译指示,和具体程序关系不太大的。主要取决于编译器。 呵呵,谢谢,只要能当我老师,您就是高手:) 看了下中文的资料,上边也没有明确说明,不过有这样一段:
// 关闭编译时的warning
#pragma used+
// 库函数原型
int sum(int a, int b);
int mul(int a, int b);
#pragma used-
// #pragma 指示符告诉编译器从 mylib.lib 库中编译或连接函数
#pragma used+是关闭编译时的warning,那#pragma used-就是打开了。。。
不知道对不对,仅作参考! 注释好,看程序花的时间少。支持!!! #pragma used+
#pragma used-
应该是否提示警告信息,编译时如果定义后没使用会提示警告信息。我也是新手,跟大家学习,不知道理解是否正确。 高手哪去了?给个GCC的程序啊! 因为ICC默认的getchar()和putchar()是采用查询方式编写的.
此处是中断方式,所以要重新定义getchar()和普通char();
这些语句不是标准C编译器里有的,不用太在意. 一年半的旧贴了,把它翻出来做些解释。
下面是1楼的贴子,开了好头,但没有好的结尾,原因是......不说了。我在它的基础上画个句号吧。
=================================================================================
相应马老师的号召,我把cvavr中usart中断子程序注释了一下,里面也有几句不懂的地方,希望高手帮我注释一下,谢谢
#include <mega8.h>
#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
// USART Receiver buffer
#define RX_BUFFER_SIZE 8 // 接收缓冲区大小,可根据需要修改
char rx_buffer; // 接收缓冲区,为char型变量组成的数组,该数组构成环形对列,个数为RX_BUFFER_SIZE
// 定义接收缓冲区环形对列的控制指针:rx_wr_index为写指针,rx_rd_index为读指针,rx_counter为在队列中接收到的字符个数
#if RX_BUFFER_SIZE<256 // 若接收缓冲区小于256个字节,定义为环形队列的指针为char型变量
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else // 否则为int型变量
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif
// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow; //接收缓冲区溢出标志
// USART Receiver interrupt service routine //usart接受中断服务程序
interrupt void usart_rx_isr(void)
{
char status,data;
status=UCSRA;//读取接收状态标志位,必须先读,当读了UDR后,UCSRA便自动清零了
data=UDR; //读取USART数据寄存器,这句与上句位置不能颠倒的
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0) //判断本接收到的数据是否有数据帧、校验或数据溢出错误(此处指USART的硬件接收溢出)
{
rx_buffer=data;// 将数据填充到接收缓冲队列中
if (++rx_wr_index == RX_BUFFER_SIZE) //写指针指向下一个单元,并判断是否到了队列的尾部,(不表示接受缓冲区是否满!)
rx_wr_index=0; //到了尾部,则指向头部(构成环状)
if (++rx_counter == RX_BUFFER_SIZE)//队列中收到字符加1,并判断是否队列已满
{
rx_counter=0; // 队列满了,队列中收到字符个数为0,表示队列中所有以前的数据作废,因为最后的数据已经把最前边的数据覆盖了
rx_buffer_overflow=1; //置缓冲区溢出标志。在主程序中必要的地方需要判断该标志,以证明读到数据的完整性
};
};
}
#ifndef _DEBUG_TERMINAL_IO_ // 如果在主程序中没有定义 _DEBUG_TERMINAL_IO_ 则下面程序有效(注1)
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_ // 定义标示字 _ALTERNATE_GETCHAR_ ,该标示字在本程序中不起作用,主要应用于编写其他模块时告之系统的getchar()函数已经被本程序的Ggetchar()替换
#pragma used+ // CVAVR的伪指令,通知编译系统,编译到与系统提供的同名函数时,使用以下的代码
char getchar(void)
{
char data;
while (rx_counter==0); //接收数据队列中没有数据可以读取,等待......(注2)
data=rx_buffer; //读取缓冲队列中的数据
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;//读取指针指向下一个未读的数据,如果指到了队列尾部,则指回到队列头步
#asm("cli") // 关中断!非常重要
--rx_counter; //队列中未读数据个数减1。因为该变量在接收中断中要改变的,为了防止冲突,所以改动前临时关闭中断。程序相当可靠了。
#asm("sei") // 开中断
return data;
}
#pragma used- // CVAVR的伪指令,取消used+的作用
#endif
// Standard Input/Output functions
#include <stdio.h>
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=1 State4=1 State3=T State2=T State1=T State0=T
PORTB=0x30;
DDRB=0x30;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
};
}
====================================================================
在CVAVR系统提供的标准库函数stdio.h中,提供了getchar()函数,该函数是采用轮询方式从USART接收数据的,轮询方式不仅效率低,而且会丢失数据,不能实现多任务的并行处理。
CVAVR程序向导中给出的采用中断+缓冲的方式接受数据,同PC的串口接受数据的方法一样,充分利用了AVR的高速和RAM多的优点,体现出了如何才能充分发挥AVR的特点的程序设计思想,这种思路在32位系统中也是这样的。
使用AVR的话,对软件的设计能力要求更高了,否则根本不能发挥和体现AVR的特点。许多人有了一点C的基础,就认为采用C编写单片机程序没问题,很快就会掌握AVR了,对此我只能一笑了之。看看本站上众多的代码,再看看本贴的遭遇,能说什么呢?
回到本题:
注1:
如果在程序的开头部分加上语句
#define _DEBUG_TERMINAL_IO_
那么程序在编译时仍使用系统自己的getchar()函数,这样在软件模拟仿真时,可以从模拟的终端读取数据,便于在软件模拟环境中调试整个系统,而需要正式运行时,则把该句注释掉。
注2:
此处在正式应用中应根据实际情况做适当的修改。否则当主程序调用getchar()时,如果缓冲队列中没有数据,同时对方也没有发数据的情况时,程序会在此死循环。
比较简单的办法是将这句删掉,而在调用getchar()函数前先判断rx_counter的值,为0的话就不调用了。
或改为:
signed int getchar(void)
{
signed int data;
if (rx_counter == 0)
{
data = -1;
}
else
{
data=rx_buffer; //读取缓冲队列中的数据
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;//读取指针指向下一个未读的数据,如果指到了队列尾部,则指回到队列头步
#asm("cli") // 关中断!非常重要
--rx_counter; //队列中未读数据个数减1。因为该变量在接收中断中要改变的,为了防止冲突,所以改动前临时关闭中断。程序相当可靠了。
#asm("sei") // 开中断
}
return data;
}
注3:
有兴趣希望深入实在学习的网友,可将CVAVR生成的USART发送代码仔细分析以下。它的发送代码非常完美,可以马上使用。
#include <mega16.h>
#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
// USART Transmitter buffer
#define TX_BUFFER_SIZE 8
char tx_buffer;
#if TX_BUFFER_SIZE<256
unsigned char tx_wr_index,tx_rd_index,tx_counter;
#else
unsigned int tx_wr_index,tx_rd_index,tx_counter;
#endif
// USART Transmitter interrupt service routine
interrupt void usart_tx_isr(void)
{
if (tx_counter)
{
--tx_counter;
UDR=tx_buffer;
if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0;
};
}
#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter == TX_BUFFER_SIZE);
#asm("cli")
if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0))
{
tx_buffer=c;
if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
++tx_counter;
}
else
UDR=c;
#asm("sei")
}
#pragma used-
#endif
// Standard Input/Output functions
#include <stdio.h>
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x48;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x19;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
putchar(0x55);
};
}
思考分析:
我在主程序的循环里仅有一句不停的发0X55,问题是AVR的运行速度非常快,而USART串出的速度肯定明显的慢(按9600bps计算,需要1秒多时间才能送出1000个字符),那么,假定主程序循环了1000次,发送1000个0x55,请判断在UASRT口上能否正确的发出1000个0x55,有没有丢失或溢出现象存在?
-----此内容被machao于2007-03-12,02:11:58编辑过 ouravr推荐使用winavr 使用gcc的应该很多。高手们如能在繁忙的工作中挤点时间,为论坛造福。提供一个gcc的m16多机通讯实例,供大家学习用。非常感谢!
静思语:与朋友相处要多感恩、知足、善解、包容。 烦请斑竹把本贴移到我的讨论组里。它在这里有些不合适。谢谢了。 非常感谢~!前不久我用CVAVR系统生成了USART程序,有很多地方我也不明白.今天算是取到经了. 新发现的老帖子,对新手来说非常好,交作业了:
思考分析:
我在主程序的循环里仅有一句不停的发0X55,问题是AVR的运行速度非常快,而USART串出的速度肯定明显的慢(按9600bps计算,需要1秒多时间才能送出1000个字符),那么,假定主程序循环了1000次,发送1000个0x55,请判断在UASRT口上能否正确的发出1000个0x55,有
没有丢失或溢出现象存在?
答:不会。因为putchar()中有这句:
while (tx_counter == TX_BUFFER_SIZE);
表示如果缓冲满就等待。 GOOD 学习了 思考分析:
我在主程序的循环里仅有一句不停的发0X55,问题是AVR的运行速度非常快,而USART串出的速度肯定明显的慢(按9600bps计算,需要1秒多时间才能送出1000个字符),那么,假定主程序循环了1000次,发送1000个0x55,请判断在UASRT口上能否正确的发出1000个0x55,有没有丢失或溢出现象存在?
不能正确发出1000个,有丢失的现象,理由是:缓存有限. 各位好,我能不能问下关于USART发送和接收的问题。上面程序中如果我把中断那块去掉、同时保留putchar(getchar)与#include<stdio.h>中的一个,我的发送程学仍然可以。请问这中间的区别是什么阿?我刚开始学,请大家理解。 谢谢,学习了! xiexie 收藏了,正要学习使用串口 呵呵 这算啥呀我写的串口打印驱动早就用循环队列了 呵呵 学习一下 mark。 cvavr中,T/C1的比较匹配A的中断标号是什么? JH mark MARK mark Mark 谢谢莫站长给我们提供这么好的学习平台,更感谢那些高手大侠们在繁忙的工作之余穿梭于各个板块之间,参与讨论,给出解决方法,分享经验,上传资料。大大缩短了我学习的时间,在此致以深深的感谢,我也会尽快学有所成,参与其中。 mark ji 顶。 mark // USART Receiver interrupt service routine //usart接受中断服务程序
interrupt void usart_rx_isr(void)
{
char status,data;
status=UCSRA;//读取接收状态标志位,必须先读,当读了UDR后,UCSRA便自动清零了
data=UDR; //读取USART数据寄存器,这句与上句位置不能颠倒的
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0) //判断本接收到的数据是否有数据帧、校验或数据溢出错误(此处指USART的硬件接收溢出)
{
rx_buffer=data;// 将数据填充到接收缓冲队列中
if (++rx_wr_index == RX_BUFFER_SIZE) //写指针指向下一个单元,并判断是否到了队列的尾部,(不表示接受缓冲区是否满!)
rx_wr_index=0; //到了尾部,则指向头部(构成环状)
if (++rx_counter == RX_BUFFER_SIZE)//队列中收到字符加1,并判断是否队列已满/***********/
{
rx_counter=0; // 队列满了,队列中收到字符个数为0,表示队列中所有以前的数据作废,因为最后的数据已经把最前边的数据覆盖了
rx_buffer_overflow=1; //置缓冲区溢出标志。在主程序中必要的地方需要判断该标志,以证明读到数据的完整性
};
};
}
上面一段程序中后面带/********/中,不明白为什么(++rx_counter == RX_BUFFER_SIZE)时最后的数据已经把最前边的数据覆盖!我觉得缓存区刚满,应该是当(++rx_counter == (RX_BUFFER_SIZE+1))最后的数据才把最前边的数据覆盖.
高手不吝赐教! 学习了 尚未有人讨论中断保护的问题,用NAKED好像能提高效率。 好 mark 和35楼有相同的疑问,是不是应该写成 if (rx_counter++ == RX_BUFFER_SIZE)
高手指点。。。 记号. 向楼主致敬… mark mark 新手表示还木有看明白,明天再研究研究了··· 记一下 mark 再次看马老师的回复,受益匪浅 学习了 最近遇到的问题,看了看,还是有点迷惑啊 mark and thanks 做个记号!最近也在学这个! #ifndef _DEBUG_TERMINAL_IO_ //?????????
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_ //?????????
#pragma used+ //?????????
其实。我真的很关心这几句啊。。。。。。求解释。 请马潮老师给个正确答案,谢谢了! 好东西,顶一个 正在研究AVR的串口通信,谢谢各位了~ 学习了,这么好的帖子:) 真好{:smile:} 学习了 周末没事 mark优秀帖
页:
[1]