;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;LCD Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;PortC0 = RS ;PortC1 = R/W ;PortC7 = E ;PortD = Data (8Bit) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCDInit: clrf PORTC, 0 clrf PORTD, 0 movlw 0x7C movwf TRISC, 0 clrf TRISD, 0 ;Function Set - 8Bit movlw 0x38 movwf PORTD, 0 bsf PORTC, 7, 0 nop nop bcf PORTC, 7, 0 nop nop call LCDDelay ;Display on, Cursor off, blinking off movlw 0x0C movwf PORTD, 0 bsf PORTC, 7, 0 nop nop bcf PORTC, 7, 0 nop nop call LCDDelay ;Clear Display movlw 0x01 movwf PORTD, 0 bsf PORTC, 7, 0 nop nop bcf PORTC, 7, 0 nop nop call LCDDelayLong ;Entry Mode Set movlw 0x06 movwf PORTD, 0 bsf PORTC, 7, 0 nop nop bcf PORTC, 7, 0 nop nop call LCDBusy return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCDBusy: decf TRISD, 0 bsf PORTC, 1, 0 LCDBusy_Loop: bsf PORTC, 7, 0 nop nop rlcf PORTD, 0, 0 bcf PORTC, 7, 0 nop nop bc LCDBusy_Loop bcf PORTC, 1, 0 clrf TRISD, 0 call LCDDelay return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCDHome: movlw 0x02 movwf PORTD, 0 bsf PORTC, 7, 0 nop nop bcf PORTC, 7, 0 nop nop call LCDBusy return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCDClear: movlw 0x01 movwf PORTD, 0 bsf PORTC, 7, 0 nop nop bcf PORTC, 7, 0 nop nop call LCDBusy return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCDShow: bsf PORTC, 0, 0 movwf PORTD, 0 bsf PORTC, 7, 0 nop nop bcf PORTC, 7, 0 nop nop call LCDBusy bcf PORTC, 0, 0 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCDDelay: ;Wait 50us movlw 0xA5 movwf LCDDelayVar1, 1 LCDDelay_0: decfsz LCDDelayVar1, 1, 1 goto LCDDelay_0 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCDDelayLong: ;Wait 1,7ms movlw 0x0E movwf LCDDelayVar2, 1 movlw 0x0F movwf LCDDelayVar3, 1 LCDDelayLong_0: decfsz LCDDelayVar2, 1, 1 goto LCDDelayLong_1 decfsz LCDDelayVar3, 1, 1 LCDDelayLong_1: goto LCDDelayLong_0 nop nop nop return