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 uint8_t clock_high = 0;
42 uint8_t rx_fill = 0xFF;
43 uint8_t input[128] = { 0 };
44 uint8_t latch[128] = { 0 };
45 uint8_t output[128] = { 0 };
46 uint8_t out_offset = 0;
49 volatile uint8_t load_pos = 0xFF;
50 volatile uint8_t reset_pos = 0xFF;
51 uint8_t lcd_enabled = 0;
57 DDRD = 0x06; // 00000110
58 PORTD = 0xC0; // 11000000
59 DDRB = 0x20; // 00100000
60 PORTB = 0x1F; // 00011111
61 PCMSK2 = BIT(PCINT19) | BIT(PCINT21);
77 if(++i>=sizeof(input))
86 if(++i>=sizeof(input))
91 if(PINB&BIT(LCD_DISABLE))
100 else if(!lcd_enabled)
108 lcd_write(hexdigit(input[9-i/2]>>(4-i%2*4)));
117 if(!serial_read_available())
120 uint8_t c = serial_read();
130 uint8_t offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
131 uint8_t nibbles = (offset&3);
133 if(rx_fill>3+nibbles)
135 for(uint8_t i=0; i<=nibbles; ++i)
137 uint16_t j = offset+nibbles-i;
138 uint8_t shift = 4*(j&1);
139 uint8_t bits = decode_hex(rx_buf[3+i]);
140 input[j/2] = (input[j/2]&~(0xF<<shift)) | (bits<<shift);
141 latch[j/2] |= input[j/2];
146 lcd_gotoxy(19-offset-nibbles, 0);
147 for(uint8_t i=0; i<=nibbles; ++i)
148 lcd_write(rx_buf[3+i]);
156 if(rx_fill<sizeof(rx_buf))
157 rx_buf[rx_fill++] = c;
164 lcd_gotoxy(log_col, 1+log_row);
173 lcd_gotoxy(log_col, 1+log_row);
179 uint8_t hexdigit(uint8_t n)
188 uint8_t decode_hex(uint8_t c)
192 else if(c>='A' && c<='F')
214 PORTD |= BIT(DATA_OUT);
216 PORTD &= ~BIT(DATA_OUT);
222 out_bits = output[out_offset];