include "hwreg-p16f628.h" // 16f628 config // enable internal oscillator FOSC2,FOSC1,FOSC0 = 100 // disable watchdog WDT = 0 // enable power up timer PWRTE = 0 // use MCLR as RA5 MCLRE = 0 // disable brown-out detect BODEN = 0 // low voltage prog disabled LVP = 0 // data memory not protected CPD = 1 // code memory not protected CP1,CP0,CP1,CP0 = 1111 // // see section 14.1 of PIC16F26X ref manual // microchip document name 40300b.pdf pragma cpu_config 0x3F10 include "LIB/strlib.bas" include "LIB/lcd_lib.bas" include "LIB/fifo_lib.bas" FIFO switch_event_fifo[6] include "LIB/keypad_lib.bas" // NOTE: the use of the user defined character 7 // this is because the LCD uses the yen symbol in // place of where the ASCII backslash would normally // be const char spin = "|/-", 7 // *.... // .*... // .*... // ..*.. // ...*. // ...*. // ....* // ..... const ubyte backslash_glyph = 0x10, 0x08, 0x08, 0x04, 0x02, 0x02, 0x01, 0x00 //---------------------------------------------------------------------- //---------------------------------------------------------------------- proc task_1() keypad_init() while 1 do debounce_keypad_queue_service() task_wait 1 done endproc //---------------------------------------------------------------------- //---------------------------------------------------------------------- proc main() uint loop_cnt ubyte acc ubyte pos // set PORTA to digital I/O instead of analog CMCON = 7 task_start task_1 LCD_init() LCD_define_glyph_code(7, &backslash_glyph) LCD_cursor_off() loop_cnt = 0 pos = 0 while 1 do // wait for a switch event task_wait 5 while_empty switch_event_fifo int ch ch = fifo_read_inline(&switch_event_fifo) if ch >= 0 && (ch & 0x80) == 0 then // only update display on key press // not key release LCD_set_pos(pos, 0) LCD_write_char(ch & 0x7f) pos = (pos + 1) & 15 endif LCD_set_pos(0, 1) acc = (loop_cnt >> 2) & 0x03 LCD_write_char(spin[acc]) loop_cnt += 1 done endproc //---------------------------------------------------------------------- //---------------------------------------------------------------------- proc intserv() endproc