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 transmitter module
21 Inputs are pulled high by internal pull-up resistors. Connect to GND to
26 #include <avr/interrupt.h>
28 #define BIT(n) (1<<(n))
30 void send_state(void);
31 void write_serial(uint8_t);
32 uint8_t hexdigit(uint8_t);
34 volatile uint8_t state = 0;
38 DDRD = 0x02; // 00000010
39 PORTD = 0xFC; // 11111100
40 DDRB = 0x20; // 00100000
41 PORTB = 0x3F; // 00111111
46 UCSR0C = BIT(UCSZ00) | BIT(UCSZ01);
47 UCSR0B = BIT(RXEN0) | BIT(TXEN0);
49 // 0.5 Hz (CK/1024, TOP=31250)
51 TCCR1B = BIT(WGM12) | BIT(CS12) | BIT(CS10);
68 pins = ~((PIND>>2) | (PINB<<6));
71 valid &= ~(pins^input);
75 input |= state&~valid;
87 ISR(TIMER1_COMPA_vect)
95 write_serial(hexdigit(state>>4));
96 write_serial(hexdigit(state&0xF));
99 void write_serial(uint8_t c)
101 while(!(UCSR0A&(1<<UDRE0))) ;
105 uint8_t hexdigit(uint8_t n)