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);
79 if(++i>=sizeof(input))
88 if(++i>=sizeof(input))
93 if(PINB&BIT(LCD_DISABLE))
102 else if(!lcd_enabled)
110 lcd_write(hexdigit(input[9-i/2]>>(4-i%2*4)));
120 if(!serial_read_available())
137 offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
138 nibbles = (offset&3);
140 if(rx_fill>3+nibbles)
142 for(i=0; i<=nibbles; ++i)
144 uint16_t j = offset+nibbles-i;
145 uint8_t shift = 4*(j&1);
146 uint8_t bits = decode_hex(rx_buf[3+i]);
147 input[j/2] = (input[j/2]&~(0xF<<shift)) | (bits<<shift);
148 latch[j/2] |= input[j/2];
153 lcd_gotoxy(19-offset-nibbles, 0);
154 for(i=0; i<=nibbles; ++i)
155 lcd_write(rx_buf[3+i]);
163 if(rx_fill<sizeof(rx_buf))
164 rx_buf[rx_fill++] = c;
171 lcd_gotoxy(log_col, 1+log_row);
180 lcd_gotoxy(log_col, 1+log_row);
186 uint8_t hexdigit(uint8_t n)
195 uint8_t decode_hex(uint8_t c)
199 else if(c>='A' && c<='F')
221 PORTD |= BIT(DATA_OUT);
223 PORTD &= ~BIT(DATA_OUT);
229 out_bits = output[out_offset];