|
现在的程序只能发送接收单个字符,如果通过串口发送一个字符串 返回一个字符串 应该怎样修改 新手求指教 谢谢
# include <iom16v.h>
# include <macros.h>
#pragma interrupt_handler isr:12
# define uchar unsigned char
# define uint unsigned int
# define fosc 8000000
uchar rdata, flag;
void uart_init(uint baud)
{
uint a;
UCSRC = 0x86;
a = fosc/16/baud-1;
UBRRL = a%256;
UBRRH = a/256;
UCSRB = 0x98;
SREG |= BIT(7);
}
void isr()
{
UCSRB &= ~BIT(7);
rdata = UDR;
flag = 1;
UCSRB|= BIT(7);
}
void uart_send(uchar data)
{
while (!(UCSRA&BIT(5)));
UDR = data;
while (!(UCSRA&BIT(6)));
UCSRA |= BIT(6);
}
void main()
{
DDRD |= 0x02;
uart_init(9600);
while (1)
{
if (flag)
{
uart_send(rdata);
flag = 0;
}
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|