clock_generator/firmware/src/main.c

679 lines
23 KiB
C
Raw Normal View History

#include <avr/eeprom.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <assert.h>
#include <stdbool.h>
#define SPI_PORT PORTB
#define SPI_DDR DDRB
#define SPI_SCK PB5
#define SPI_MOSI PB3
#define SPI_SS PB2
#define LCD_CD PB0
#define LCD_RST PB1
#define ENC_A (PINB & (1 << PB6))
#define ENC_B (PINB & (1 << PB7))
#define SYM_ENTRY(SYM) { SYM, sizeof(SYM) / 2 }
static uint8_t EEMEM eeprom_contrast = 8;
static uint8_t EEMEM eeprom_backlight = 1;
static const __flash uint8_t sacred_chao[] = { 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x80, 0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x03, 0xC3, 0xE3, 0x73, 0x37, 0x17, 0x07, 0x0F, 0x1E, 0x3C, 0xF0, 0x80,
0xFF, 0xFF, 0xFF, 0xE7, 0xC3, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0x30, 0x00, 0x00, 0xFF,
0x01, 0x0F, 0x3F, 0x4F, 0x9F, 0x3F, 0x3E, 0x3C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3E, 0x3E, 0x3E, 0x1F, 0x1F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x81, 0x40, 0x30, 0x0E, 0x01,
0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x08, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x40, 0x40, 0x20, 0x20, 0x10, 0x08, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00 };
static const __flash uint8_t onders_org[] = { 0xE0, 0x60, 0xE0, 0x00, 0x00, 0xE0, 0x60, 0xE0, 0x00, 0x00, 0xE0, 0x60, 0xF8, 0x00, 0x00, 0xE0, 0xA0, 0xE0, 0x00, 0x00, 0xE0, 0x20, 0x60, 0x00, 0x00, 0xE0, 0xA0, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x60, 0xE0, 0x00, 0x00, 0xE0, 0x20, 0x60, 0x00, 0x00, 0xE0, 0x60, 0xE0,
0x03, 0x02, 0x03, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x02, 0x03, 0x00, 0x00, 0x03, 0x02, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x02, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x0A, 0x0F};
static const __flash uint8_t sym_0[] = { 0xF8, 0xFC, 0x0C, 0xFC, 0xF8,
0x1F, 0x3F, 0x30, 0x3F, 0x1F };
static const __flash uint8_t sym_1[] = { 0x30, 0x30, 0xFC, 0xFC, 0x00,
0x30, 0x30, 0x3F, 0x3F, 0x30 };
static const __flash uint8_t sym_2[] = { 0x18, 0x1C, 0x8C, 0xFC, 0xF8,
0x38, 0x3E, 0x3F, 0x33, 0x30 };
static const __flash uint8_t sym_3[] = { 0x18, 0x9C, 0x8C, 0xFC, 0x78,
0x18, 0x39, 0x31, 0x3F, 0x1E };
static const __flash uint8_t sym_4[] = { 0x80, 0xE0, 0x78, 0xFC, 0xFC,
0x07, 0x07, 0x06, 0x3F, 0x3F };
static const __flash uint8_t sym_5[] = { 0xFC, 0xFC, 0x8C, 0x8C, 0x0C,
0x1C, 0x3D, 0x31, 0x3F, 0x1F };
static const __flash uint8_t sym_6[] = { 0xF8, 0xFC, 0x8C, 0xBC, 0x38,
0x1F, 0x3F, 0x31, 0x3F, 0x1F };
static const __flash uint8_t sym_7[] = { 0x0C, 0x0C, 0xEC, 0xFC, 0x1C,
0x00, 0x3E, 0x3F, 0x01, 0x00 };
static const __flash uint8_t sym_8[] = { 0x78, 0xFC, 0x8C, 0xFC, 0x78,
0x1E, 0x3F, 0x31, 0x3F, 0x1E };
static const __flash uint8_t sym_9[] = { 0xF8, 0xFC, 0x8C, 0xFC, 0xF8,
0x1C, 0x3D, 0x31, 0x3F, 0x1F };
static const __flash uint8_t sym_colon[] = { 0x30, 0x30,
0x0C, 0x0C };
static const __flash uint8_t sym_a[] = { 0xC0, 0xF0, 0x3C, 0x3C, 0xF0, 0xC0,
0x3F, 0x3F, 0x06, 0x06, 0x3F, 0x3F };
static const __flash uint8_t sym_b[] = { 0xFC, 0xFC, 0x8C, 0x8C, 0xFC, 0x78,
0x3F, 0x3F, 0x31, 0x31, 0x3F, 0x1E };
static const __flash uint8_t sym_c[] = { 0xF8, 0xFC, 0x0C, 0x1C, 0x18,
0x1F, 0x3F, 0x30, 0x38, 0x18 };
static const __flash uint8_t sym_e[] = { 0xFC, 0xFC, 0x8C, 0x8C, 0x0C,
0x3F, 0x3F, 0x31, 0x31, 0x30 };
static const __flash uint8_t sym_g[] = { 0xF8, 0xFC, 0x0C, 0x0C, 0x3C, 0x38,
0x1F, 0x3F, 0x30, 0x33, 0x3F, 0x1F };
static const __flash uint8_t sym_h[] = { 0xFC, 0xFC, 0x80, 0x80, 0xFC, 0xFC,
0x3F, 0x3F, 0x01, 0x01, 0x3F, 0x3F };
static const __flash uint8_t sym_i[] = { 0x0C, 0xFC, 0xFC, 0x0C,
0x30, 0x3F, 0x3F, 0x30 };
static const __flash uint8_t sym_k[] = { 0xFC, 0xFC, 0xC0, 0xF0, 0x7C, 0x1C,
0x3F, 0x3F, 0x03, 0x0F, 0x3E, 0x38 };
static const __flash uint8_t sym_l[] = { 0xFC, 0xFC, 0x00, 0x00, 0x00,
0x3F, 0x3F, 0x30, 0x30, 0x30 };
static const __flash uint8_t sym_n[] = { 0xFC, 0xFC, 0xF0, 0xC0, 0x00, 0xFC, 0xFC,
0x3F, 0x3F, 0x00, 0x03, 0x0F, 0x3F, 0x3F };
static const __flash uint8_t sym_o[] = { 0xF8, 0xFC, 0x0C, 0x0C, 0xFC, 0xF8,
0x1F, 0x3F, 0x30, 0x30, 0x3F, 0x1F };
static const __flash uint8_t sym_p[] = { 0xFC, 0xFC, 0x8C, 0x8C, 0xFC, 0xF8,
0x3F, 0x3F, 0x01, 0x01, 0x01, 0x00 };
static const __flash uint8_t sym_r[] = { 0xFC, 0xFC, 0x8C, 0x8C, 0xFC, 0xF8,
0x3F, 0x3F, 0x01, 0x03, 0x3F, 0x3E };
static const __flash uint8_t sym_s[] = { 0xF8, 0xFC, 0x8C, 0x8C, 0x9C, 0x18,
0x18, 0x39, 0x31, 0x31, 0x3F, 0x1F };
static const __flash uint8_t sym_t[] = { 0x0C, 0x0C, 0xFC, 0xFC, 0x0C, 0x0C,
0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00 };
static const __flash uint8_t sym_u[] = { 0xFC, 0xFC, 0x00, 0x00, 0xFC, 0xFC,
0x3F, 0x3F, 0x30, 0x30, 0x3F, 0x3F };
static const __flash uint8_t sym_none[] = { 0x00 };
struct symbol {
const __flash uint8_t* data;
const uint8_t length;
};
static const struct symbol symbol_table[] = { SYM_ENTRY(sym_0),
SYM_ENTRY(sym_1),
SYM_ENTRY(sym_2),
SYM_ENTRY(sym_3),
SYM_ENTRY(sym_4),
SYM_ENTRY(sym_5),
SYM_ENTRY(sym_6),
SYM_ENTRY(sym_7),
SYM_ENTRY(sym_8),
SYM_ENTRY(sym_9),
SYM_ENTRY(sym_colon),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_a),
SYM_ENTRY(sym_b),
SYM_ENTRY(sym_c),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_e),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_g),
SYM_ENTRY(sym_h),
SYM_ENTRY(sym_i),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_k),
SYM_ENTRY(sym_l),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_n),
SYM_ENTRY(sym_o),
SYM_ENTRY(sym_p),
SYM_ENTRY(sym_none),
SYM_ENTRY(sym_r),
SYM_ENTRY(sym_s),
SYM_ENTRY(sym_t),
SYM_ENTRY(sym_u) };
enum input { cw, ccw, click, hold };
static volatile enum state { home, ch1, ch2, ch3, setup } current_state = home;
static volatile enum state home_state = ch1;
static volatile enum setup_state { contrast, backlight, back, change_contrast, change_backlight } setup_state = contrast;
static volatile uint8_t enc = 0;
static volatile uint8_t value_contrast;
static volatile uint8_t value_backlight;
static void spi_init(void) {
SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS);
SPI_PORT |= (1 << SPI_SS);
SPCR = (1 << SPE) | (1 << MSTR);
SPSR = (1 << SPI2X);
}
static uint8_t spi_byte(const uint8_t data) {
SPDR = data;
while(!(SPSR & (1 << SPIF)));
return SPDR;
}
static void lcd_write(const uint8_t data) {
SPI_PORT &= ~(1 << SPI_SS);
spi_byte(data);
SPI_PORT |= (1 << SPI_SS);
}
static void lcd_init(void) {
SPI_DDR |= (1 << LCD_CD) | (1 << LCD_RST);
_delay_ms(1);
SPI_PORT |= (1 << LCD_RST);
_delay_ms(5);
lcd_write(0x40); // (6) Set Scroll Line: Display start line 0
lcd_write(0xA1); // (13) Set SEG direction: SEG reverse
lcd_write(0xC0); // (14) Set COM direction: Normal COM0 - COM63
lcd_write(0xA6); // (11) Set Inverse Display: Display inverse off
lcd_write(0xA2); // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65)
lcd_write(0x2F); // (5) Set Power Control: Booster, Regulator and Follower on
lcd_write(0x27); // (8) Set VLCD Resistor Ratio: Set Contrast
lcd_write(0x81); // (9) Set Electronic Volume: Set Contrast
lcd_write(value_contrast); // (9) Set Electronic Volume: Set Contrast
lcd_write(0xAF); // (12) Set Display Enable: Display on
}
static void lcd_update_contrast(void) {
SPI_PORT &= ~(1 << LCD_CD);
lcd_write(0x81); // (9) Set Electronic Volume: Set Contrast
lcd_write(value_contrast); // (9) Set Electronic Volume: Set Contrast
SPI_PORT |= (1 << LCD_CD);
}
static void lcd_update_backlight(void) {
switch (value_backlight) {
case 0:
DDRD &= (0 << PD5);
break;
default:
DDRD |= (1 << PD5);
OCR0B = value_backlight - 1;
break;
}
}
static void lcd_move_cursor(const uint8_t column, const uint8_t row) {
assert(row < 16);
SPI_PORT &= ~(1 << LCD_CD);
lcd_write(0x00 + (0x0F & column));
lcd_write(0x10 + (column >> 4));
lcd_write(0xB0 + row);
SPI_PORT |= (1 << LCD_CD);
}
static void lcd_fill(const uint8_t data) {
for (uint8_t i = 0; i < 8; i++) {
lcd_move_cursor(0, i);
for (uint8_t j = 0; j < 102; j++)
lcd_write(data);
}
}
static void lcd_write_kerning(const uint8_t length,
const bool invert) {
for (uint8_t i = 0; i < length; i++)
if (invert)
lcd_write(0xFF);
else
lcd_write(0x00);
}
static void lcd_write_symbol_page(const struct symbol* symbol,
const uint8_t page,
const bool invert) {
for (uint8_t i = 0; i < symbol->length; i++)
if (invert)
lcd_write(~symbol->data[page * symbol->length + i]);
else
lcd_write(symbol->data[page * symbol->length + i]);
}
static void lcd_write_digit_page(const uint8_t digit,
const uint8_t page,
const bool invert) {
lcd_write_symbol_page(&symbol_table[digit], page, invert);
}
static void lcd_write_character_page(const char character,
const uint8_t page,
const bool invert) {
lcd_write_symbol_page(&symbol_table[character - 48], page, invert);
}
static void lcd_write_string_page(const char* string,
const uint8_t page,
const bool invert) {
for (uint8_t i = 0; string[i] != 0; i++) {
lcd_write_kerning(2, invert);
lcd_write_character_page(string[i], page, invert);
}
}
static void lcd_write_integer_page(const uint8_t integer,
const uint8_t digits,
const uint8_t page,
const bool invert) {
if (digits != 0 || integer != 0) {
uint8_t input_digits = 0;
uint16_t comperator = 1;
for (; comperator <= integer; comperator *= 10, input_digits++);
for (int8_t i = digits - input_digits; i > 0; i--) {
lcd_write_kerning(2, invert);
lcd_write_digit_page(0, page, invert);
}
for (; comperator >= 10; comperator /= 10) {
lcd_write_kerning(2, invert);
lcd_write_digit_page((integer % comperator) / (comperator / 10),
page, invert);
}
}
}
static void lcd_splash(void) {
lcd_fill(0x00);
for (uint8_t i = 0; i < 5; i++) {
lcd_move_cursor(31, 1 + i);
for (uint8_t j = 0; j < 40; j++)
lcd_write(sacred_chao[i * 40 + j]);
}
for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(26, 6 + i);
for (uint8_t j = 0; j < 48; j++)
lcd_write(onders_org[i * 48 + j]);
}
}
static void lcd_home(void) {
lcd_fill(0x00);
bool ch1_selected = false;
bool ch2_selected = false;
bool ch3_selected = false;
bool setup_selected = false;
switch (home_state) {
case ch1:
ch1_selected = true;
break;
case ch2:
ch2_selected = true;
break;
case ch3:
ch3_selected = true;
break;
default: // setup
setup_selected = true;
break;
}
for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, i);
lcd_write_string_page("CH1\0", i, ch1_selected);
lcd_write_kerning(2, ch1_selected);
lcd_move_cursor(0, 2 + i);
lcd_write_string_page("CH2\0", i, ch2_selected);
lcd_write_kerning(2, ch2_selected);
lcd_move_cursor(0, 4 + i);
lcd_write_string_page("CH3\0", i, ch3_selected);
lcd_write_kerning(2, ch3_selected);
lcd_move_cursor(33, 6 + i);
lcd_write_string_page("SETUP\0", i, setup_selected);
lcd_write_kerning(2, setup_selected);
}
}
static void lcd_setup(void) {
lcd_fill(0x00);
bool contrast_selected = false;
bool backlight_selected = false;
bool back_selected = false;
bool change_contrast_selected = false;
bool change_backlight_selected = false;
switch (setup_state) {
case contrast:
contrast_selected = true;
break;
case backlight:
backlight_selected = true;
break;
case back:
back_selected = true;
break;
case change_contrast:
change_contrast_selected = true;
break;
case change_backlight:
change_backlight_selected = true;
break;
}
for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, i);
lcd_write_kerning(30, true);
lcd_write_string_page("SETUP\0", i, true);
lcd_write_kerning(33, true);
}
for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, 2 + i);
lcd_write_string_page("CONTRAST:\0", i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_kerning(16, false);
lcd_write_integer_page(value_contrast, 2, i, change_contrast_selected);
lcd_write_kerning(2, change_contrast_selected);
}
for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, 4 + i);
lcd_write_string_page("BACKLIGHT:\0", i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_kerning(5, false);
lcd_write_integer_page(value_backlight, 3, i, change_backlight_selected);
lcd_write_kerning(2, change_backlight_selected);
}
for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(33, 6 + i);
lcd_write_string_page("BACK:\0", i, back_selected);
lcd_write_kerning(2, back_selected);
}
}
static void change_state(const enum state new_state) {
switch (new_state) {
case home:
lcd_home();
current_state = home;
break;
case ch1:
break;
case ch2:
break;
case ch3:
break;
case setup:
setup_state = contrast;
lcd_setup();
current_state = setup;
break;
}
}
static void update_home(const enum input event) {
switch (event) {
case cw:
home_state++;
if (home_state > setup)
home_state = ch1;
lcd_home();
break;
case ccw:
home_state--;
if (home_state > setup)
home_state = setup;
lcd_home();
break;
case click:
change_state(home_state);
break;
case hold:
break;
}
}
static void update_setup(const enum input event) {
switch (event) {
case cw:
switch (setup_state) {
case contrast:
case backlight:
case back:
setup_state++;
if (setup_state > back)
setup_state = contrast;
break;
case change_contrast:
if (value_contrast < 63) {
value_contrast++;
lcd_update_contrast();
}
break;
case change_backlight:
if (value_backlight < 100) {
value_backlight++;
lcd_update_backlight();
}
break;
}
lcd_setup();
break;
case ccw:
switch (setup_state) {
case contrast:
case backlight:
case back:
setup_state--;
if (setup_state > back)
setup_state = back;
break;
case change_contrast:
if (value_contrast > 0) {
value_contrast--;
lcd_update_contrast();
}
break;
case change_backlight:
if (value_backlight > 0) {
value_backlight--;
lcd_update_backlight();
}
break;
}
lcd_setup();
break;
case click:
switch (setup_state) {
case contrast:
setup_state = change_contrast;
lcd_setup();
break;
case backlight:
setup_state = change_backlight;
lcd_setup();
break;
case back:
change_state(home);
break;
case change_contrast:
eeprom_update_byte(&eeprom_contrast, value_contrast);
setup_state = contrast;
lcd_setup();
break;
case change_backlight:
eeprom_update_byte(&eeprom_backlight, value_backlight);
setup_state = backlight;
lcd_setup();
break;
}
break;
case hold:
switch (setup_state) {
case contrast:
case backlight:
case back:
change_state(home);
break;
case change_contrast:
setup_state = contrast;
value_contrast = eeprom_read_byte(&eeprom_contrast);
lcd_update_contrast();
lcd_setup();
break;
case change_backlight:
setup_state = backlight;
value_backlight = eeprom_read_byte(&eeprom_backlight);
lcd_update_backlight();
lcd_setup();
break;
}
break;
}
}
static void update_state(const enum input event) {
switch (current_state) {
case home:
update_home(event);
break;
case ch1:
break;
case ch2:
break;
case ch3:
break;
case setup:
update_setup(event);
break;
}
}
// Encoder rotation interrupt
ISR(PCINT0_vect) {
cli();
switch (enc) {
case 0:
if (ENC_A && !ENC_B)
enc = 1;
else if (!ENC_A && ENC_B)
enc = 3;
break;
case 1:
if (ENC_A && ENC_B) {
enc = 2;
update_state(cw);
} else if (!ENC_A && !ENC_B) {
enc = 0;
update_state(ccw);
}
break;
case 2:
if (!ENC_A && ENC_B)
enc = 3;
else if (ENC_A && !ENC_B)
enc = 1;
break;
case 3:
if (!ENC_A && !ENC_B) {
enc = 0;
update_state(cw);
} else if (ENC_A && ENC_B) {
enc = 2;
update_state(ccw);
}
break;
}
// TODO: proper dechattering
_delay_us(100);
sei();
}
// encoder button interrupt
ISR(PCINT1_vect) {
cli();
if (PINC & (1 << PC0)) { // release
TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1
if (TCNT1 != 0) {
update_state(click); // Switch to selected state
TCNT1 = 0;
}
} else { // press
if (!(TCCR1B & (1 << CS10)))
TCCR1B |= (1 << CS11) | (1 << CS10); // Enable Timer/Counter1
}
// TODO: proper debouncing
_delay_us(70);
sei();
}
// Timer/Counter1 compare match A for back event
ISR(TIMER1_COMPA_vect) {
cli();
TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1
TCNT1 = 0;
update_state(hold);
sei();
}
int main(void) {
// Load contrast and backlight values from EEPROM
value_contrast = eeprom_read_byte(&eeprom_contrast);
value_backlight = eeprom_read_byte(&eeprom_backlight);
// Init backlight: FastPWM: 1.25kHz
// TODO: Try to get the backlit even more dim
TCCR0A |= (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
TCCR0B |= (1 << CS01) | (1 << WGM02); // prescaler = 8;
OCR0A = 100;
lcd_update_backlight();
// SPI setup
spi_init();
lcd_init();
// Encoder setup
PORTB |= (1 << PB6) | (1 << PB7);
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT6) | (1 << PCINT7);
// Encoder switch setup
PORTC |= (1 << PC0);
PCICR |= (1 << PCIE1);
PCMSK1 |= (1 << PCINT8);
// Timer1 setup to recognize held button
OCR1A = 8192;
TIMSK1 |= (1 << OCIE1A); // Enable match compare A
// Show splash screen and load the menu
lcd_splash();
_delay_ms(250);
change_state(current_state);
// Enable interrupts
sei();
// Run...
for (;;);
}