这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » USART接485发送+PROTESU仿真

共1条 1/1 1 跳转至

USART接485发送+PROTESU仿真

专家
2009-03-13 02:38:41     打赏
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);
}
}




关键词: USART     485发送     +PROTESU     仿真    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]