仿真截图
//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);
}
}
https://static.assets-stash.eet-china.com/album/old-resources/2009/3/12/5cf6b8db-08a5-4995-9f2b-292ae6105ccb.rar仿真+程序包
用户191889 2009-3-13 12:28
tengjingshu_112148725 2009-3-12 23:40