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 out_offset = 0;
48 volatile uint8_t reset_pos = 0xFF;
49 uint8_t lcd_enabled = 0;
55 DDRD = 0x06; // 00000110
56 PORTD = 0xC0; // 11000000
57 DDRB = 0x20; // 00100000
58 PORTB = 0x1F; // 00011111
59 PCMSK2 = BIT(PCINT19) | BIT(PCINT21);
77 if(++i>=sizeof(input))
82 if(PINB&BIT(LCD_DISABLE))
99 lcd_write(hexdigit(input[9-i/2]>>(4-i%2*4)));
109 if(!serial_read_available())
126 offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
127 nibbles = (offset&3);
129 if(rx_fill>3+nibbles)
131 for(i=0; i<=nibbles; ++i)
133 uint16_t j = offset+nibbles-i;
134 uint8_t shift = 4*(j&1);
135 uint8_t bits = decode_hex(rx_buf[3+i]);
136 input[j/2] = (input[j/2]&~(0xF<<shift)) | (bits<<shift);
137 latch[j/2] = input[j/2];
142 lcd_gotoxy(19-offset-nibbles, 0);
143 for(i=0; i<=nibbles; ++i)
144 lcd_write(rx_buf[3+i]);
152 if(rx_fill<sizeof(rx_buf))
153 rx_buf[rx_fill++] = c;
160 lcd_gotoxy(log_col, 1+log_row);
169 lcd_gotoxy(log_col, 1+log_row);
175 uint8_t hexdigit(uint8_t n)
184 uint8_t decode_hex(uint8_t c)
188 else if(c>='A' && c<='F')
209 PORTD |= BIT(DATA_OUT);
211 PORTD &= ~BIT(DATA_OUT);
217 out_bits = latch[out_offset];