3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
7 Firmware for wireless S88 receiver module
27 #include <avr/interrupt.h>
29 #define DATA_OUT PORTD2
34 #define BIT(n) (1<<(n))
36 uint8_t decode_hex(uint8_t);
38 volatile uint8_t rx_buf[3];
39 volatile uint8_t rx_fill = 0;
40 volatile uint8_t input = 0;
41 volatile uint8_t latch = 0;
45 uint8_t clock_high = 0;
48 DDRD = 0x06; // 00000110
49 PIND = 0xC0; // 11000000
50 DDRB = 0x20; // 00100000
51 PINB = 0x1F; // 00011111
56 UCSR0C = BIT(UCSZ00) | BIT(UCSZ01);
57 UCSR0B = BIT(RXEN0) | BIT(TXEN0) | BIT(RXCIE0);
77 PORTD |= BIT(DATA_OUT);
79 PORTD &= ~BIT(DATA_OUT);
98 rx_buf[rx_fill++] = c;
102 rx_buf[rx_fill++] = c;
103 if(rx_buf[0]==':' && rx_fill==3)
105 input = (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
112 uint8_t decode_hex(uint8_t c)
116 else if(c>='A' && c<='F')