这个程序得好理解就是用中断接收把收到的字节在PARTC上显示一下:
在Atmel Studio6.2具体程序如下:
/*
* GccApplication18.c
*
* Created: 2014-9-10 20:20:00
* Author: Administrator
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#define uchar unsigned char
#define uint unsigned int
#define FE 4
#define PE 2
#define DOR 3
uchar LEDdisp;
ISR(USART_RXC_vect)//USART串行接收中断
{
uchar status,data;
status=UCSRA;
data=UDR;
if((status&((1<<FE)|(1<<PE)|(1<<DOR)))==0)
{
LEDdisp=data;
}
}
int main(void)
{
DDRC=0xFF;
PORTC=0xFF;
DDRD=0xFA;
PORTD=0xFF;
UCSRA=0x00;
UBRRH=0;
UBRRL=25; //系统时钟8MHz,波特率为9600bps
UCSRB=0x90;
UCSRC=0x86;
while(1)
{
PORTC=LEDdisp;
}
}
编译通过的截图:
|