diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2008-11-01 22:06:13 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2008-11-01 22:06:13 +0000 |
commit | de4710abc813016d8a2bddcc2fb1a19be43c01de (patch) | |
tree | fa2dc220559eb9d577e2f2354c0ec02660d6ab6b /cores/arduino/wiring_serial.c | |
parent | e42b8d7ef811df7f552582c57cda66a275670fe4 (diff) |
Switching tests for __AVR_ATmega168__ to tests for __AVR_ATmega8__ so that less changes are needed to support other processors.
Diffstat (limited to 'cores/arduino/wiring_serial.c')
-rwxr-xr-x | cores/arduino/wiring_serial.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/cores/arduino/wiring_serial.c b/cores/arduino/wiring_serial.c index 4cac891..2dd242b 100755 --- a/cores/arduino/wiring_serial.c +++ b/cores/arduino/wiring_serial.c @@ -37,17 +37,7 @@ int rx_buffer_tail = 0; void beginSerial(long baud) { -#if defined(__AVR_ATmega168__) - UBRR0H = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8; - UBRR0L = ((F_CPU / 16 + baud / 2) / baud - 1); - - // enable rx and tx - sbi(UCSR0B, RXEN0); - sbi(UCSR0B, TXEN0); - - // enable interrupt on complete reception of a byte - sbi(UCSR0B, RXCIE0); -#else +#if defined(__AVR_ATmega8__) UBRRH = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8; UBRRL = ((F_CPU / 16 + baud / 2) / baud - 1); @@ -57,6 +47,16 @@ void beginSerial(long baud) // enable interrupt on complete reception of a byte sbi(UCSRB, RXCIE); +#else + UBRR0H = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8; + UBRR0L = ((F_CPU / 16 + baud / 2) / baud - 1); + + // enable rx and tx + sbi(UCSR0B, RXEN0); + sbi(UCSR0B, TXEN0); + + // enable interrupt on complete reception of a byte + sbi(UCSR0B, RXCIE0); #endif // defaults to 8-bit, no parity, 1 stop bit @@ -64,16 +64,16 @@ void beginSerial(long baud) void serialWrite(unsigned char c) { -#if defined(__AVR_ATmega168__) - while (!(UCSR0A & (1 << UDRE0))) +#if defined(__AVR_ATmega8__) + while (!(UCSRA & (1 << UDRE))) ; - UDR0 = c; + UDR = c; #else - while (!(UCSRA & (1 << UDRE))) + while (!(UCSR0A & (1 << UDRE0))) ; - UDR = c; + UDR0 = c; #endif } @@ -104,16 +104,16 @@ void serialFlush() rx_buffer_head = rx_buffer_tail; } -#if defined(__AVR_ATmega168__) -SIGNAL(SIG_USART_RECV) -#else +#if defined(__AVR_ATmega8__) SIGNAL(SIG_UART_RECV) +#else +SIGNAL(SIG_USART_RECV) #endif { -#if defined(__AVR_ATmega168__) - unsigned char c = UDR0; -#else +#if defined(__AVR_ATmega8__) unsigned char c = UDR; +#else + unsigned char c = UDR0; #endif int i = (rx_buffer_head + 1) % RX_BUFFER_SIZE; |