// Example of using the BV4512 formally the BV4219 // with PIC32 Basic // constant LCDGADR 0x42 // initialise and check address function lcdg_init i2copen 400000 if i2ctest(LCDGADR) = 0 then print "Device not connected at address ";hex$(LCDGADR) endif endf // ----------- Text functions ---------------------- // // put character to display at current location // use: lcd20_putc('a') // lcd20_putc(97) function lcdg_putc(c) i2cwrite LCDGADR 0x20 c endf // prints a string to display at current position function lcdg_puts(s$) dim j for j = 1 to len(s$) lcdg_putc(asc(s$,j)) next endf // set line and current position, line is 0 or 7 snd // postion is 0 to 20 // use: lcd20_lp(1,5) function lcdg_lp(line,pos) i2cwrite LCDGADR 0x25 line pos // set line & pos endf // clear screen and home cursor function lcdg_cls i2cwrite LCDGADR 0x05 endf // -------------- Graphic Functions ---------------- // // Draw horizontal and vertical lines atarting at given // co-ordimates where // x: horixontal 0-127 // y: vertical 0-63 function lcdg_Hline(x,y, length) i2cwrite LCDGADR 0x12 x y length endf function lcdg_Vline(x,y, length) i2cwrite LCDGADR 0x14 x y length endf // // Draws a box N no fill F filled // x,y are the top left hand corner of the box and // xl, yl are the lengths of the sides function lcdg_Nbox(x,y,xl,yl) i2cwrite LCDGADR 0x16 x y xl yl endf function lcdg_Fbox(x,y,xl,yl) i2cwrite LCDGADR 0x18 x y xl yl endf // ---------- Sample voltage indicator ---------------- // // Initialise ADC and set up a clean display with // graticule function v_init openadc 30 0 lcdg_init lcdg_cls lcdg_puts("Volts") // graticule on line 2 lcdg_Vline(10,24,7) // 0v lcdg_Vline(45,24,7) // 1v lcdg_Vline(80,24,7) // 2v lcdg_Vline(115,24,7) // 3v // numbers on line 4 in pixel positions lcdg_lp(4,0) // correct line i2cwrite LCDGADR 7 8 lcdg_putc('0') i2cwrite LCDGADR 7 43 lcdg_putc('1') i2cwrite LCDGADR 7 78 lcdg_putc('2') i2cwrite LCDGADR 7 113 lcdg_putc('3') // box to put line in lcdg_Nbox(6,15,119,10) endf function v_bar(volts#) dim v#=(volts#*35)+10 lcdg_lp(2,1) lcdg_puts(" ") // clear lcdg_Vline(v#,16,6) lcdg_Vline(v#+1,16,8) lcdg_Vline(v#+2,16,6) endf // prints voltahe next to 'Volts' function v_vdisp(v#) dim j // clear last reading lcdg_lp(0,6) for j = 1 to 5 lcdg_putc(' ') next lcdg_lp(0,6) lcdg_puts(format$("#.###",v#)) endf // gets software smoothed out voltage // voltage is represented by 1023=3.3V so // voltage constant is 3.3/1023 = 0.0032258 function v_volts# dim av=0, j, v# for j=1 to 300 av=av+adc(0) next av=av/300 v#=av*0.0032258 result v# endf function go dim k=5, v# v_init while key?(2) = 0 v#=v_volts# v_vdisp(v#) v_bar(v#) wend endf