'******************************************************** '* * '* LCD 16x2 LIBRARY FOR USE WITH BOOST BASIC * '* * '* WRITTEN BY : PUNERJOT SINGH MANGAT * '* COUNTRY : INDIA * '* CITY : PATIALA * '* WEB PAGE : www.rackeys.com/punerjot * '* EMAIL : punerjot@rackeys.com * '* SOURCEBOOST ID : c58_4311 * '* RELEASE DATE : March 03, 2006 * '* REVISED DATE : May 24, 2006 * '* * '******************************************************** ' ' ' ' commandas are ' lcd_putch(ASCII value of char to be printed) ' lcd_clear() ' lcd_line1() ' lcd_line2() ' lcd_init() ' ' any 16x2 alphanumeric lcd can be used as far as it uses hd44780 compatible chipset ' ' Pin connections of pic16f877A to lcd ' PIC PINS LCD PINS ' -------- -------- ' RB2 6 ' RB3 4 ' RB4 11 ' RB5 12 ' RB6 13 ' RB7 14 ' 1 gnd ' 2 +5V ' 3 contrast (typicaly connected to gnd via 2.2 k resistor) ' 5 +5V ' ' ' RB0 and RB1 of this PORTB are free ' ' '******************************* delay routines for the LCD ************************** sub wait_us() DIM wait_count as byte asm { MOVLW d'45' MOVWF _wait_count LOOP_LCD: DECFSZ _wait_count, F GOTO LOOP_LCD return } end sub '******************************* delay routines for the LCD ends ************************** sub lcd_strobe() portb.2 = 1 portb.2 = 0 end sub sub lcd_byte(c as byte) portb = (portb & 0x0f) portb = (portb | (c & 0xf0)) call lcd_strobe() portb = (portb & 0x0f) portb = (portb | (c << 4)) call lcd_strobe() call wait_us() end sub '************************ Procedure to output char to lcd ***************************** sub lcd_putch(c as byte) portb.3 = 1 'pin 3 of prt b as high call lcd_byte(c) end sub '************************ Procedure to output char to lcd ends ************************ '************************ Procedure to give commands to lcd ***************************** sub lcd_putcmd(c as byte) portb.3 = 0 call lcd_byte(c) end sub '************************ Procedure to give commands to lcd ends ************************ '************************ LCD Initializing routines ***************************** sub lcd_init() trisb = ( 00000000b ) 'pin(0) and pin(1) of this PORTB are free so it can be used for RS232 portb.3 = 0 call delay_ms(50) portb = (portb & 0x0f) portb = (portb | 0x30) call lcd_strobe() call delay_ms(5) call lcd_strobe() call wait_us() call lcd_strobe() call delay_ms(5) portb = (portb & 0x0f) portb = (portb | 0x20) call lcd_strobe() call wait_us() call lcd_putcmd(0x28) call lcd_putcmd(0x08) call lcd_putcmd(0x0C) call lcd_putcmd(0x06) end sub '************************ LCD Initializing routines ends ************************ '************************ Procedure to clear the lcd ***************************** sub lcd_clear() call lcd_putcmd(0x01) call delay_ms(2) end sub '************************ Procedure to clear the lcd ends ************************ '******************** Procedure to goto the begning of line1 of the lcd ***************** sub lcd_line1() call lcd_putcmd(0x02) 'start of first line end sub '******************** Procedure to goto the begning of line1 of the lcd ends ************ '******************** Procedure to goto the begning of line2 of the lcd ***************** sub lcd_line2() call lcd_putcmd(0x80+40) 'start of second line end sub '******************** Procedure to goto the begning of line2 of the lcd ends ************
Copyright © 2006 SourceBoost Technologies