串口调试助手收不到数据,程序如下,求解
时间:10-02
整理:3721RD
点击:
#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);
}
}
#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);
}
}