InitLCD bsf b_LCD_CS1
bsf b_LCD_CS2
movlw 0x3f
call WriteCMD
movlw 0xc0
call WriteCMD
movlw 0x40
call WriteCMD
movlw 0xb8
call WriteCMD
return
WaitNotBusy call SetInput
bsf b_LCD_RW
bcf b_LCD_RS
btfss b_LCD_CS1
goto Skip_CS1
bcf b_CS2
btfsc b_LCD_CS2
bsf b_CS2
bcf b_LCD_CS2
WNB1_Loop bsf b_LCD_E
btfsc PORTB,7
goto WNB1_Loop
bcf b_LCD_E
btfsc b_CS2
bsf b_LCD_CS2
Skip_CS1 btfss b_LCD_CS2
goto Skip_CS2
bcf b_CS1
btfsc b_LCD_CS1
bsf b_CS1
bcf b_LCD_CS1
WNB2_Loop bsf b_LCD_E
btfsc PORTB,7
goto WNB2_Loop
bcf b_LCD_E
btfsc b_CS1
bsf b_LCD_CS1
Skip_CS2
SetOutput bsf STATUS,RP0
clrf TRISB
bcf STATUS,RP0
return
SetInput bsf STATUS,RP0
movlw 0xff
movwf TRISB
bcf STATUS,RP0
return
ReadLCD bsf b_LCD_E
movfw PORTB
bcf b_LCD_E
return
WriteCMD movwf LCDTemp
call WaitNotBusy
movfw LCDTemp
movwf PORTB
bcf b_LCD_RW
bcf b_LCD_RS
bsf b_LCD_E
bcf b_LCD_E
return
WriteData movwf LCDTemp
call WaitNotBusy
movfw LCDTemp
movwf PORTB
bcf b_LCD_RW
bsf b_LCD_RS ;rs=1 rw=0
bsf b_LCD_E
bcf b_LCD_E
return
Cls bsf b_LCD_CS1
bsf b_LCD_CS2
movlw 0x08
movwf ForI
ClsLoopI movlw 0x40
movwf ForJ
call WriteCMD
decf ForI,W
iorlw 0xb8
call WriteCMD
ClsLoopK movlw 0x00
call WriteData
decfsz ForJ,F
goto ClsLoopK
decfsz ForI,F
goto ClsLoopI
clrf XPos
clrf YPos
return