uarttest1._c
来自「这是关于AVR单片机学习的初步开发」· _C 代码 · 共 73 行
_C
73 行
//ICC-AVR application builder : 2005-3-9 下午 11:22:18
// Target : M8
// Crystal: 11.0592Mhz
#include <iom8v.h>
#include <macros.h>
void port_init(void)
{
PORTB = 0xFF;
DDRB = 0x00;
PORTC = 0x7F; //m103 output only
DDRC = 0x00;
PORTD = 0xFF;
DDRD = 0x00;
}
//UART0 initialisation
// desired baud rate: 19200
// actual: baud rate:19200 (0.0%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = 0x86;
UBRRL = 0x23; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0xD8;
}
#pragma interrupt_handler uart0_rx_isr:12
void uart0_rx_isr(void)
{
//uart has received a character in UDR
char temp;
temp =UDR;
UDR = temp;
}
#pragma interrupt_handler uart0_tx_isr:14
void uart0_tx_isr(void)
{
//character has been transmitted
//UDR = 0x5a;
}
//call this routine to initialise 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 initialised
}
//
void main(void)
{
init_devices();
//insert your functional code here...
// UDR = 2;
while(1);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?