diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | font.h | 130 | ||||
-rw-r--r-- | main.c | 45 |
3 files changed, 163 insertions, 15 deletions
@@ -26,7 +26,8 @@ AVRFLAGS += -U flash:w:main.hex main.elf: main.c ${AVRCC} ${CFLAGS} -o $@ ${@:.elf=.c} -Wl,-Map=main.map,--cref - avr-size -d $@ + @echo + @avr-size --format=avr --mcu=${MCU} $@ program: main.hex #main.eep ${AVRFLASH} -p ${MCU} -c ${AVRDUDE_PROGRAMMER} ${AVRFLAGS} @@ -3,6 +3,8 @@ #include <avr/pgmspace.h> +typedef const unsigned char* glyph_t; + const unsigned char PROGMEM chr_001[] = {0x08, 0x00, 0x20, 0x44, 0x40, 0x44, 0x20, 0x00, 0x00}; // happy smiley const unsigned char PROGMEM chr_002[] = {0x08, 0x00, 0x40, 0x24, 0x20, 0x24, 0x40, 0x00, 0x00}; // sad smiley const unsigned char PROGMEM chr_003[] = {0x05, 0x18, 0xEC, 0x5C, 0xEC, 0x18}; // skull @@ -130,5 +132,133 @@ const unsigned char PROGMEM chr_124[] = {0x01, 0xFF}; // | const unsigned char PROGMEM chr_125[] = {0x03, 0x82, 0x6C, 0x10}; // } const unsigned char PROGMEM chr_126[] = {0x05, 0x10, 0x08, 0x10, 0x20, 0x10}; // ~ +const glyph_t font[] PROGMEM = { + chr_001, + chr_002, + chr_003, + chr_004, + chr_005, + chr_006, + chr_007, + chr_008, + chr_009, + chr_010, + chr_011, + chr_012, + chr_013, + chr_014, + chr_015, + chr_016, + chr_017, + chr_018, + chr_019, + chr_020, + chr_021, + chr_022, + chr_023, + chr_024, + chr_025, + chr_026, + chr_027, + chr_028, + chr_029, + chr_030, + chr_031, + chr_032, + chr_033, + chr_034, + chr_035, + chr_036, + chr_037, + chr_038, + chr_039, + chr_040, + chr_041, + chr_042, + chr_043, + chr_044, + chr_045, + chr_046, + chr_047, + chr_048, + chr_049, + chr_050, + chr_051, + chr_052, + chr_053, + chr_054, + chr_055, + chr_056, + chr_057, + chr_058, + chr_059, + chr_060, + chr_061, + chr_062, + chr_063, + chr_064, + chr_065, + chr_066, + chr_067, + chr_068, + chr_069, + chr_070, + chr_071, + chr_072, + chr_073, + chr_074, + chr_075, + chr_076, + chr_077, + chr_078, + chr_079, + chr_080, + chr_081, + chr_082, + chr_083, + chr_084, + chr_085, + chr_086, + chr_087, + chr_088, + chr_089, + chr_090, + chr_091, + chr_092, + chr_093, + chr_094, + chr_095, + chr_096, + chr_097, + chr_098, + chr_099, + chr_100, + chr_101, + chr_102, + chr_103, + chr_104, + chr_105, + chr_106, + chr_107, + chr_108, + chr_109, + chr_110, + chr_111, + chr_112, + chr_113, + chr_114, + chr_115, + chr_116, + chr_117, + chr_118, + chr_119, + chr_120, + chr_121, + chr_122, + chr_123, + chr_124, + chr_125, + chr_126 +}; #endif /* FONT_H_ */ @@ -4,9 +4,11 @@ #include <util/delay.h> #include <stdlib.h> +#include "font.h" + #define SHUTDOWN_THRESHOLD 2048 -volatile uint8_t disp[32]; +volatile uint8_t disp[8]; int main (void) { @@ -32,6 +34,16 @@ int main (void) // raise timer interrupt on counter overflow (-> interrupt frequency = ~4kHz) TIMSK0 = _BV(TOIE0); + disp[0] = font[0][1]; + disp[1] = font[0][2]; + disp[2] = font[0][3]; + disp[3] = font[0][4]; + disp[4] = font[0][5]; + disp[5] = font[0][6]; + disp[6] = font[0][7]; + disp[7] = font[0][8]; + +#if 0 // smile! disp[0] = 0x08; disp[1] = 0x04; @@ -57,14 +69,15 @@ int main (void) disp[21] = 0x22; disp[22] = 0x44; disp[23] = 0x28; - disp[24] = 0xFF; - disp[25] = 0xFF; - disp[26] = 0xFF; - disp[27] = 0xFF; - disp[28] = 0xFF; - disp[29] = 0xFF; - disp[30] = 0xFF; - disp[31] = 0xFF; + disp[24] = 0x00; + disp[25] = 0x00; + disp[26] = 0x00; + disp[27] = 0x00; + disp[28] = 0x00; + disp[29] = 0x00; + disp[30] = 0x00; + disp[31] = 0x00; +#endif sei(); @@ -130,23 +143,27 @@ ISR(TIMER0_OVF_vect) static uint16_t scroll = 0; static uint8_t disp_offset = 0; - uint8_t buffer_col; + static uint8_t display[8]; + + uint8_t i; - if (++scroll == 256) { + if (++scroll == 512) { scroll = 0; if (++disp_offset == sizeof(disp)) { disp_offset = 0; } - } - buffer_col = (disp_offset + active_col) % sizeof(disp); + for (i = 0; i < 8; i++) { + display[i] = ~disp[(disp_offset + i) % sizeof(disp)]; + } + } /* * To avoid flickering, do not put any code (or expensive index * calculations) between the following three lines. */ PORTB = 0; - PORTD = ~disp[buffer_col]; + PORTD = display[active_col]; PORTB = _BV(active_col); if (++active_col == 8) |