/**************************************************
文件名:test5.c
功能:串口通信程序,将发送给串口的字符串发还给串口
说明:时钟:7.3728MHz
*****************************************************/
#include <avr/io.h>
#include<avr/delay.h>
#define uchar unsigned char
#define uint unsigned int
/***************************************************
*名称putc()
*功能 向串口发送数据
*入口参数char c
*出口参数:无
*****************************************************/
void putc(uchar c)
{
while( !(UCSR0A & (1<<UDRE0)) );//数据发送已准备好
UDR0=c;
}
/***************************************************
*名称getc()
*功能 从串口接收数据
*入口参数:无
*出口参数:UDR
*****************************************************/
uchar getc(void)
{
while( !(UCSR0A & (1<<RXC0)) );//接收完成
return UDR0;
}
/***************************************************
*名称main()
*功能 串口通信
*入口参数:无
*出口参数:UDR
*****************************************************/
int main(void)
{
//uart 初始化
UBRR0L=7;//57.6k baud 7.3728MHz
UCSR0B=_BV(RXEN0)|_BV(TXEN0);//使能发送和接受允许
while(1)
putc(getc());//输出从串口接收的数据
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
使用查询方式实现AVR单片机的串口通信 开发平台 atmega128 包含程序 │Makefile 13.78 KB │test5-2.hex 360.03 KB │test5.c 1.15 KB │test5.eep 13 bytes │test5.elf 3.93 KB │test5.hex 713 bytes │test5.lss 5.13 KB │test5.lst 3.22 KB │test5.map 14.06 KB │test5.o 2.65 KB │test5.pnproj 60 bytes │test5.sym 1.59 KB │UCCmds32.cmf 2.36 KB
资源推荐
资源详情
资源评论
收起资源包目录
3.7.串口通信实验1.rar (15个子文件)
3.7.串口通信实验1
UCCmds32.cmf 2KB
test5.map 14KB
test5.sym 2KB
test5.c 1KB
test5.elf 4KB
test5.eep 13B
.dep
test5.o.d 930B
test5.c.bak 2KB
test5.lss 5KB
test5.o 3KB
test5-2.hex 360KB
test5.lst 3KB
test5.hex 713B
test5.pnproj 60B
Makefile 14KB
共 15 条
- 1
资源评论
- yanhengyanzhu2013-04-08使用了一下,是正确的
chensz08
- 粉丝: 2
- 资源: 27
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功