#include<avr/io.h>
#include<avr/interrupt.h>
#include<avr/pgmspace.h>
unsigned char rdata;
unsigned char biaozhi;
#define CRYSTAL 8000000 //系统时钟8MHZ
//发送函数
void USART_Transmit(unsigned int data)
{
UDR=data;
}
ISR(USART_RXC_vect)
{
rdata=UDR;
biaozhi=1;
}
void init(unsigned int BAUD)
{
unsigned char a;
a=CRYSTAL/16/BAUD-1;
UCSRC=0x86;
UCSRB=0x98;
UBRRH=a%256;
UBRRL=a/256;
sei();
}
int main()
{ DDRD=0x02;
init(9600);
while(1)
{ if(biaozhi)
biaozhi=0;
USART_Transmit(rdata);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>