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))
36 void receive(uint8_t);
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;
95 PORTD |= BIT(DATA_OUT);
97 PORTD &= ~BIT(DATA_OUT);
105 if(d_pins&BIT(RESET))
112 if(b_pins&BIT(LCD_DISABLE))
121 else if(!lcd_enabled)
129 lcd_write(hexdigit(input[9-i/2]>>(4-i%2*4)));
136 void receive(uint8_t c)
151 offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
152 nibbles = (offset&3);
154 if(rx_fill>3+nibbles)
156 for(i=0; i<=nibbles; ++i)
158 uint16_t j = offset+nibbles-i;
159 uint8_t shift = 4*(j&1);
160 uint8_t bits = decode_hex(rx_buf[3+i]);
161 input[j/2] = (input[j/2]&~(0xF<<shift)) | (bits<<shift);
162 latch[j/2] = input[j/2];
167 lcd_gotoxy(19-offset-nibbles, 0);
168 for(i=0; i<=nibbles; ++i)
169 lcd_write(rx_buf[3+i]);
177 if(rx_fill<sizeof(rx_buf))
178 rx_buf[rx_fill++] = c;
185 lcd_gotoxy(log_col, 1+log_row);
194 lcd_gotoxy(log_col, 1+log_row);
200 SERIAL_SET_CALLBACK(receive)
202 uint8_t hexdigit(uint8_t n)
211 uint8_t decode_hex(uint8_t c)
215 else if(c>='A' && c<='F')