// Copyright 2006 Yamane Akira // USART Sample Program // Target : M48 // Int RC Osc: 8.0000Mhz // USART setting: 19.2Kbaud stop data8 stop1 Parity N // Programmed by A.Yamane Aug.2005 #include #include char init_msg[] = "\n\r Pat1:1 Pat2:2 Pat3:3 Enter Pat# : "; void port_init(void) { PORTB = 0xFF; DDRB = 0xFF; PORTC = 0x7F; DDRC = 0x00; PORTD = 0xFF; DDRD = 0x00; } //UART0 initialize // desired baud rate: 19200 // actual: baud rate:19231 (0.2%) void uart0_init(void) { UCSR0B = 0x00; //disable while setting baud rate UCSR0A = 0x00; UCSR0C = 0x06; UBRR0L = 0x19; //set baud rate lo UBRR0H = 0x00; //set baud rate hi UCSR0B = 0x18; } //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; EICRA = 0x00; //extended ext ints EIMSK = 0x00; TIMSK0 = 0x00; //timer 0 interrupt sources TIMSK1 = 0x00; //timer 1 interrupt sources TIMSK2 = 0x00; //timer 2 interrupt sources PCMSK0 = 0x00; //pin change mask 0 PCMSK1 = 0x00; //pin change mask 1 PCMSK2 = 0x00; //pin change mask 2 PCICR = 0x00; //pin change enable PRR = 0x00; //power controller SEI(); //re-enable interrupts //all peripherals are now initialized } void USART_Tx(char tx_data) { while ( !(UCSR0A & (1<