From 08ac0063eee2f1e5344f5f21637674efd0c3c321 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 12 Jan 2016 13:32:17 +0100 Subject: add scrolling support --- main.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 0529721..736671c 100644 --- a/main.c +++ b/main.c @@ -5,7 +5,7 @@ #include #include -volatile uint8_t disp[8]; +volatile uint8_t disp[16]; int main (void) { @@ -29,6 +29,14 @@ int main (void) disp[5] = 0x62; disp[6] = 0x04; disp[7] = 0x08; + disp[8] = 0x28; + disp[9] = 0x44; + disp[10] = 0x22; + disp[11] = 0x02; + disp[12] = 0x02; + disp[13] = 0x22; + disp[14] = 0x44; + disp[15] = 0x28; sei(); @@ -42,9 +50,26 @@ int main (void) ISR(TIMER0_OVF_vect) { static uint8_t active_col = 0; + static uint16_t scroll = 0; + static uint8_t disp_offset = 0; + uint8_t buffer_col; + + if (++scroll == 1024) { + scroll = 0; + if (++disp_offset == sizeof(disp)) { + disp_offset = 0; + } + } + + buffer_col = (disp_offset + active_col) % sizeof(disp); + + /* + * To avoid flickering, do not put any code (or expensive index + * calculations) between the following three lines. + */ PORTB = 0; - PORTD = ~disp[active_col]; + PORTD = ~disp[buffer_col]; PORTB = _BV(active_col); if (++active_col == 8) -- cgit v1.2.3