PC和ATMEGA128串口通信
#include
#define RXEN0 4
#define TXEN0 3
#define RXCIE0 7
#define UDRE0 5
#define UCSZ00 1
#define UCSZ01 2
#define UCSZ02 2
#define RXC0 7
char str[20];
unsigned char in;
void Uar_init(void);
void COM_send(void);
interrupt[19] void uart0(void)
{
bit flag=1;
str[in]=UDR0;
if(str[in]==$) //$为停止标志
{
UCSR0B&=~(1<
COM_send(); //发送接受的字符串
in=0;
flag=0;
UCSR0B|=(1<
if(flag)
in++;
}
void Uar_init(void)
{
in=0;
UCSR0B=(1<
UBRR0H=0x00;
UCSR0C=(1<
}
void COM_send(void)
{
unsigned char point=0;
while(str[point]!= )
{
while(!(UCSR0A&(1<
point++;
}
}
void main(void)
{
Uar_init();
#asm("sei");//全局中断开启
while(1);
}
评论