2 Firmware for wireless S88 receiver module
22 #include <avr/interrupt.h>
27 #define DATA_OUT PORTD2
32 #define LCD_DISABLE PINB4
34 #define BIT(n) (1<<(n))
37 uint8_t hexdigit(uint8_t);
38 uint8_t decode_hex(uint8_t);
40 volatile uint8_t rx_buf[7];
41 volatile uint8_t rx_fill = 0xFF;
42 volatile uint8_t input[128] = { 0 };
43 volatile uint8_t latch[128] = { 0 };
44 volatile uint8_t lcd_enabled = 0;
50 uint8_t clock_high = 0;
56 DDRD = 0x06; // 00000110
57 PORTD = 0xC0; // 11000000
58 DDRB = 0x20; // 00100000
59 PORTB = 0x1F; // 00011111
68 uint8_t b_pins, d_pins;
97 PORTD |= BIT(DATA_OUT);
99 PORTD &= ~BIT(DATA_OUT);
107 if(d_pins&BIT(RESET))
114 if(b_pins&BIT(LCD_DISABLE))
123 else if(!lcd_enabled)
131 lcd_write(hexdigit(input[9-i/2]>>(4-i%2*4)));
141 if(!serial_read_available())
158 offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
159 nibbles = (offset&3);
161 if(rx_fill>3+nibbles)
163 for(i=0; i<=nibbles; ++i)
165 uint16_t j = offset+nibbles-i;
166 uint8_t shift = 4*(j&1);
167 uint8_t bits = decode_hex(rx_buf[3+i]);
168 input[j/2] = (input[j/2]&~(0xF<<shift)) | (bits<<shift);
169 latch[j/2] = input[j/2];
174 lcd_gotoxy(19-offset-nibbles, 0);
175 for(i=0; i<=nibbles; ++i)
176 lcd_write(rx_buf[3+i]);
184 if(rx_fill<sizeof(rx_buf))
185 rx_buf[rx_fill++] = c;
192 lcd_gotoxy(log_col, 1+log_row);
201 lcd_gotoxy(log_col, 1+log_row);
207 uint8_t hexdigit(uint8_t n)
216 uint8_t decode_hex(uint8_t c)
220 else if(c>='A' && c<='F')