新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > AVR的uart串口通信程序

AVR的uart串口通信程序

作者:时间:2018-09-14来源:网络收藏

//1、使用ICC的终端调试窗口(Terminal),进行通信调试。
//2、对ICC的终端调试窗口进行设置,设置串口为com1或com2
//通信波特率为19200(Tools->EnvironmentOptions...)。
//3、将PC屏幕光标定位于调试窗口中。
#include
#definefosc8000000//晶振8MHZ
#definebaud19200//波特率
#defineosc_address0x1ff0
externunsignedcharread_flash(unsignedintadd);

voidputchar(unsignedcharc)
{
while(!(UCSRA(1UDR=c;
}

unsignedchargetchar(void)
{
while(!(UCSRA(1returnUDR;
}

intputs(char*s)
{
while(*s)
{
putchar(*s);
s++;
}
putchar(0x0a);//回车换行
putchar(0x0d);
return1;
}

voidputstr(char*s)
{
while(*s)
{
putchar(*s);
s++;
}
}

void_init(void)
{
OSCCAL=read_flash(osc_address);
UCSRB=(1UBRRL=(fosc/16/(baud+1))%6;
UBRRH=(fosc/16/(baud+1))/256;
UCSRC=(1}

voidmain(void)
{
unsignedchari;
_init();
puts(广州天河双龙电子公司RS232通信演示程序);
puts(HTTP://WWW.SL.COM.CN);
puts(MAILTsllg@sl.com.cn);
while(1)
{
i=getchar();
if(i!=0)//按PC键盘开始测试
{
putstr(当前按键是:);
putchar(i);
putchar(0x0a);
putchar(0x0d);
puts(广州天河双龙电子公司RS232通信演示程序);
puts(HTTP://WWW.SL.COM.CN);
puts(MAILTsllg@sl.com.cn);
putchar(0x0a);
putchar(0x0d);
}
}
}

本文引用地址:http://www.amcfsurvey.com/article/201809/389164.htm


关键词: AVR uart 串口通信

评论


相关推荐

技术专区

关闭