;------------------------------------------------------------------------------- ; FILE: Character LCD ; AUTH: Ed's Projects ; DATE: 10/02/2017 ; DESC: Character LCD 4 x 20 ; ; PortD LCD data bus ; PortC, 3 enable, 2 RW, 1 RS ;------------------------------------------------------------------------------- LIST P=18F4520, R=DEC ; All numbers Decimal format unless otherwise stated. include ; Define configurations, registers, etc. CONFIG OSC = INTIO67 ; 8 MHz internal oscillator CONFIG FCMEN = OFF ; Failsafe clock monitor off CONFIG IESO = OFF ; Internal / External oscillator switchover off CONFIG PWRT = ON ; Power up timer on CONFIG BOREN = OFF ; Brown out reset off CONFIG WDT = OFF ; Watchdog timer off CONFIG MCLRE = OFF ; Master reset pin off CONFIG LPT1OSC = OFF ; Low power timer 1 off CONFIG PBADEN = OFF ; PortB 4 to 0 digital on reset CONFIG LVP = OFF ; Low voltage programming off CONFIG XINST = OFF ; Extended instruction set enabled ;------------------------------------------------------------------------------- ;-------------------------------- Variables ---------------------------------- ;------------------------------------------------------------------------------- cblock 0x000 b0_temp b0_temp2 b0_temp3 temp1 temp2 endc ;------------------------------------------------------------------------------- ;------------------------------ Define Symbols ------------------------------- ;------------------------------------------------------------------------------- #define LCDen LATC, 3, 1 #define LCDrw LATC, 2, 1 #define LCDrs LATC, 1, 1 ;------------------------------------------------------------------------------- ;------------------------------- Program Code -------------------------------- ;------------------------------------------------------------------------------- ORG 0x0 ; Reset Vector ORG 0x0008 ; High Priority Interrupt Vector ORG 0x0018 ; Low Priority Interrupt Vector ;------------------------------------------------------------------------------- ;-------------------------- Initialisation of Ports -------------------------- ;------------------------------------------------------------------------------- Init movlb d'15' ; Set BSR to bank 15 clrf ADCON0 ; Turn off analogue module movlw 00001111b movwf ADCON1 ; Configure all pins as digital movlw 00000111b movwf CMCON ; Turn off comparators clrf TRISA clrf TRISB clrf TRISC clrf TRISD ; Set all ports as outputs clrf TRISE movlw 01110000b movwf OSCCON ; 8MHz Internal oscillator movlw 01000000b movwf OSCTUNE ; Enable PLL ; 32MHz with PLL ;------------------------------------------------------------------------------- ;------------------------------- Main Program -------------------------------- ;------------------------------------------------------------------------------- Main call LCDinit movlw " " call LCDsend movlw " " call LCDsend movlw " " call LCDsend movlw "E" call LCDsend movlw "D" call LCDsend movlw "'" call LCDsend movlw "S" call LCDsend movlw " " call LCDsend movlw " " call LCDsend movlw "P" call LCDsend movlw "r" call LCDsend movlw "o" call LCDsend movlw "j" call LCDsend movlw "e" call LCDsend movlw "c" call LCDsend movlw "t" call LCDsend movlw "s" call LCDsend cat goto cat ;------------------------------------------------------------------------------- ;----------------------------- LCD Initialisation ---------------------------- ;------------------------------------------------------------------------------- LCDinit call d50ms ;Function Set movlw 00111000b ;8-bit mode, 2 lines, 5x7 matrix call LCDinst ;Display on / off movlw 00001100b ;Display on, Cursor off, Blink off call LCDinst ;Entry Mode Set movlw 00000110b ;Increment, Display shifted call LCDinst ;Cursor or display shift movlw 00010000b ;Display Shift call LCDinst ;Clear Screen movlw 00000001b ; Clear screen call LCDinst return ;------------------------------------------------------------------------------- ;----------------------------- LCD Character Send ---------------------------- ;------------------------------------------------------------------------------- LCDsend movlb d'15' ; Ensure BSR is FSR banking bsf LCDrs ; Data mode bcf LCDrw ; Write mode call sndt ; Send data return ;------------------------------------------------------------------------------- ;---------------------------- LCD Instruction Send --------------------------- ;------------------------------------------------------------------------------- LCDinst movlb d'15' ; Ensure BSR is FSR banking bcf LCDrs ; Instruction mode bcf LCDrw ; Write mode call sndt ; Send data call d50ms return ;------------------------------------------------------------------------------- ;--------------------------------- LCD Status ------------------------------- ;------------------------------------------------------------------------------- sndt movwf LATD, 1 ; Place into LCD bus nop bsf LCDen nop nop nop bcf LCDen goto micro100 ;------------------------------------------------------------------------------- ;------------------------------ Delay Routines ------------------------------- ;------------------------------------------------------------------------------- delay movlw d'100' ; 125ns 1 second delay movwf b0_temp3, 0 ; 125ns nop ; 125ns label_3 movlw d'40' ; 125ns movwf b0_temp2, 0 ; 125ns nop ; 125ns nop ; 125ns label_1 movlw d'249' ; 125ns movwf b0_temp, 0 ; 125ns nop ; 125ns nop ; 125ns label_2 nop ; 125ns nop ; 125ns nop ; 125ns nop ; 125ns nop ; 125ns decfsz b0_temp, f, 0 ; 125ns goto label_2 ; 250ns (1us total inner loop) ; 125ns decfsz b0_temp2, f, 0 ; 125ns goto label_1 ; 250ns ; 125ns decfsz b0_temp3, f, 0 ; 125ns goto label_3 ; 250ns return d50ms movlw d'1' ; 50ms delay movwf b0_temp3, 0 goto label_3 micro100 movlw d'100' ; 100us delay movwf b0_temp, 0 label_4 nop ; 125ns nop ; 125ns nop ; 125ns nop ; 125ns nop ; 125ns decfsz b0_temp, f, 0 ; 125ns goto label_4 ; 250ns (1us total inner loop) return end