串行通信UART及PROTEUS仿真设计

嵌入式系统 时间:2010-06-26来源:网络

atmega64的程序:

两个文件,一个是将函数模块化,别一个是主函数,调用(- -!最近习惯将程序模块化。。。)

//------------------uart.c---------------------

//----这里将通信函数模块化------------

#include iom64v.h>

void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x33; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x18;
}


void uart0_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A (1UDRE0)) )
;
/* Copy ninth bit to TXB8 */
UCSR0B = ~(1TXB80);
//if ( data 0x0100 )
//UCSR0B |= (1TXB80);
/* Put data into buffer, sends the data */
UDR0 = data;
}

unsigned char uart0_Receive( void )
{
/* 等待接收数据*/
while ( !(UCSR0A (1RXC0)) )
;
/* 从缓冲器中获取并返回数据*/
return UDR0;
}

//--------------main.c-----------

//--------------------------------

#include iom64v.h>
#include spi.h
#define commun_symbol 0x31

//-----------send a commun_symbol-----
//-----------receive a commun_symbol--
// --no,continue receive||||||yes-->receive the data and send
void main()
{
unsigned char bybuff;
DDRB=0xff;
PORTB=0xff;
uart0_init();
{

do
{
bybuff=uart0_Receive();
}
while (bybuff!=commun_symbol);//commun_symbol);
while(1)
{

uart0_Transmit(bybuff);
bybuff=uart0_Receive();
PORTB=(0xff|bybuff);
}
}
}

ok,任务完成了,改天实验一下!

1 2

关键词: 仿真 设计 PROTEUS UART 通信 串行

加入微信
获取电子行业最新资讯
搜索微信公众号:EEPW

或用微信扫描左侧二维码

相关文章

查看电脑版