EDN首页   博客首页 用户登陆  |  注册

日志档案

发表于 2009/3/12 19:20:09

3

标签: 485,AVR,PROTESU,仿真  

USART接485发送+PROTESU仿真

仿真截图

点击开大图

//ICC-AVR application builder : 2007-11-30 20:29:49
//串口+485发送程序
// Target : M16
// Crystal: 8.0000Mhz
//编制:孙可

#include <iom16v.h>
#include <macros.h>
void x_print(unsigned char c) //发送采用查询方式
{
while( !(UCSRA & (1<<UDRE)) );
UDR=c;
}




void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x40;
DDRD = 0x40;
}

//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x0E;
UBRRL = 0x33; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x98;
}

#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr(void)
{
//uart has received a character in UDR
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
uart0_init();

MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices();
while(1)
{
unsigned int i="0x55";
unsigned int j="0xaa";
x_print(i);
x_print(j);
}
}

rar仿真+程序包

系统分类: 单片机   |   用户分类: AVR   |   来源: 原创   |   【推荐给朋友】   |   【添加到收藏夹】

该用户于2009/3/12 19:20:20编辑过该文章

阅读(1169)  |  评论(2)  |  收藏(3)  |  举报  

投一票您将和博主都有获奖机会!

最新评论

  • lxhf546

    2009/3/13 12:28:12

    会用这个软件啊,拿来学习学习,向楼主致敬。

  • tengjingshu

    2009/3/12 23:40:02

    受用了:)什么时候有时间也用用protesu:)