📄 uart1_rx
字号:
//ICC-AVR application builder : 2006-5-29 10:32:11
// Target : M128
// Crystal: 8.0000Mhz
#include <iom128v.h>
#include <macros.h>
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
PORTE = 0x00;
DDRE = 0x00;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x00;
DDRG = 0x00;
}
//Watchdog initialize
// prescale: 16K
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
WDTCR = 0x08; //WATCHDOG ENABLED - dont forget to issue WDRs
}
//UART1 initialize
// desired baud rate:2400
// actual baud rate:2404 (0.2%)
// char size: 8 bit
// parity: Odd
void uart1_init(void)
{
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x36;
UBRR1L = 0xCF; //set baud rate lo
UBRR1H = 0x00; //set baud rate hi
UCSR1B = 0x90;
}
#pragma interrupt_handler uart1_rx_isr:31
void uart1_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
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
watchdog_init();
uart1_init();
MCUCR = 0x80;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -