3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
7 Firmware for wireless S88 receiver module
27 #include <avr/interrupt.h>
32 #define DATA_OUT PORTD2
37 #define LCD_DISABLE PINB4
39 #define BIT(n) (1<<(n))
41 void receive(uint8_t);
42 uint8_t hexdigit(uint8_t);
43 uint8_t decode_hex(uint8_t);
45 volatile uint8_t rx_buf[7];
46 volatile uint8_t rx_fill = 0xFF;
47 volatile uint8_t input[128] = { 0 };
48 volatile uint8_t latch[128] = { 0 };
49 volatile uint8_t lcd_enabled = 0;
55 uint8_t clock_high = 0;
61 DDRD = 0x06; // 00000110
62 PORTD = 0xC0; // 11000000
63 DDRB = 0x20; // 00100000
64 PORTB = 0x1F; // 00011111
73 uint8_t b_pins, d_pins;
100 PORTD |= BIT(DATA_OUT);
102 PORTD &= ~BIT(DATA_OUT);
110 if(d_pins&BIT(RESET))
117 if(b_pins&BIT(LCD_DISABLE))
126 else if(!lcd_enabled)
134 lcd_write(hexdigit(input[9-i/2]>>(4-i%2*4)));
141 void receive(uint8_t c)
156 offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
157 nibbles = (offset&3);
159 if(rx_fill>3+nibbles)
161 for(i=0; i<=nibbles; ++i)
163 uint16_t j = offset+nibbles-i;
164 uint8_t shift = 4*(j&1);
165 uint8_t bits = decode_hex(rx_buf[3+i]);
166 input[j/2] = (input[j/2]&~(0xF<<shift)) | (bits<<shift);
167 latch[j/2] = input[j/2];
172 lcd_gotoxy(19-offset-nibbles, 0);
173 for(i=0; i<=nibbles; ++i)
174 lcd_write(rx_buf[3+i]);
182 if(rx_fill<sizeof(rx_buf))
183 rx_buf[rx_fill++] = c;
190 lcd_gotoxy(log_col, 1+log_row);
199 lcd_gotoxy(log_col, 1+log_row);
205 SERIAL_SET_CALLBACK(receive)
207 uint8_t hexdigit(uint8_t n)
216 uint8_t decode_hex(uint8_t c)
220 else if(c>='A' && c<='F')