//---------------------------------------------------------------------- //---------------------------------------------------------------------- // user interface test program // // This program uses 2 switches for user inputs and an LCD for user // output // // one switch is designated as the increment key and the other switch is // designated as the decrement key. // // A control value is displayed on the LCD. When the increment key is // pressed the control value is incremented. When the decrement key is // pressed the control value is decremented. when the control value // changes, the new value is displayed on the LCD // // // this program uses 2 tasks. Task 1 debounces the switches in the // background, while task 2 performs the user interaction. //---------------------------------------------------------------------- //---------------------------------------------------------------------- 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 "strlib.bas" include "lcdlib.bas" include "fifo_lib.bas" FIFO switch_event_fifo[6] include "debounce.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() debounce_init(0xC0, 0x00, &switch_event_fifo) while 1 do debounce_queue_service() task_wait 1 done endproc //---------------------------------------------------------------------- //---------------------------------------------------------------------- proc main() char buff[10] int val, last_val ubyte acc, loop_cnt // set PORTA to digital I/O instead of analog CMCON = 7 LCD_init() val = 0 LCD_define_glyph_code(7, &backslash_glyph) LCD_cursor_off() task_start task_1 loop_cnt = 0 while 1 do last_val = val acc = read_switch(6) if acc != 0 then val -= 1 endif acc = read_switch(7) if acc != 0 then val += 1 endif if last_val != val then int_to_str(&buff, val) strcat_code(&buff, " ") LCD_set_pos(0, 0) LCD_write_str(&buff) endif LCD_set_pos(0, 1) acc = (loop_cnt >> 7) & 0x03 LCD_write_char(spin[acc]) acc = (loop_cnt >> 6) & 0x03 LCD_write_char(spin[acc]) acc = (loop_cnt >> 5) & 0x03 LCD_write_char(spin[acc]) loop_cnt += 1 task_yield done endproc //---------------------------------------------------------------------- //---------------------------------------------------------------------- proc intserv() endproc