Hello everybody. I am trying to interface my LCD to a 16F684. I am following the tutorial on this page: http://joshuagalloway.com/lcd.html
I wrote the program, but I can't get anything on the display. I am programming the chip using assembly.
I went step by step following the tutorial to write the code. I wrote a routine to write a command to the LCD (LCD_WriteC) and a routine to write data to the lcd (LCD_WriteD). Can anybody help me out to see why I can't get anything on the display?
I already checked my code with the instructions on how to initialize the lcd and how to write data/commands and according to me they do what the website says.
edit: forgot to mention that I am trying to interface using 4-bit mode
I wrote the program, but I can't get anything on the display. I am programming the chip using assembly.
I went step by step following the tutorial to write the code. I wrote a routine to write a command to the LCD (LCD_WriteC) and a routine to write data to the lcd (LCD_WriteD). Can anybody help me out to see why I can't get anything on the display?
I already checked my code with the instructions on how to initialize the lcd and how to write data/commands and according to me they do what the website says.
edit: forgot to mention that I am trying to interface using 4-bit mode
Rich (BB code):
list p=16F684
#include <p16F684.inc>
errorlevel -302
errorlevel -312
EXTERN delay10
;***** CONFIGURATION
; ext rest, no code protect, no brownout detect,
; no watchdog, power-up timer, int clock with I/O,
; no failsafe clock monitor, two-speed start-up disabled
__CONFIG _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOD_OFF & _WDT_OFF & _PWRTE_ON & _INTOSCIO & _FCMEN_OFF & _IESO_OFF
;***** PIN ASSIGNMENTS
#define LCD_EN PORTA,5 ; LCD enable pin
#define LCD_RS PORTA,4 ; LCD RS pin
;***** VARIABLE DEFINITIONS
CONTEXT UDATA_SHR ; variables for context saving
cs_W res 1
cs_STATUS res 1
SHADOW UDATA_SHR
sPORTA res 1 ; shadow registers
sPORTC res 1
GENVAR UDATA_SHR ; general variables
LCD_DATA res 1 ;variable to store data to be written to lcd
DELAY UDATA
counter res 1
;*******************************************************************
RESET CODE 0x0000 ; processor reset vector
pagesel Start
goto Start
;***** INTERRUPT SERVICE ROUTINE
ISR CODE 0x0004
; *** Save context
movwf cs_W ; save W
movf STATUS,w ; save STATUS
movwf cs_STATUS
; isr code goes here
isr_end
movf cs_STATUS,w ; restore STATUS
movwf STATUS
swapf cs_W,f ; restore W
swapf cs_W,w
retfie
;***** MAIN PROGRAM
MAIN CODE
;***** Initialization
Start ;configure ports
movlw b'00001111' ; set RC<3:0> as digital IO
banksel ANSEL
movwf ANSEL
banksel TRISA ; configure PORTA and PORTC
movlw b'110000' ; set RC<3:0> as outputs
movwf TRISC
movlw b'001111' ; set RC<5:4> as outputs
movwf TRISA
Initialize_LCD
call delay5ms ; wait 20ms for LCD to power up
call delay5ms
call delay5ms
call delay5ms
banksel PORTA
bcf LCD_RS
movlw 0x03
movwf PORTC ; write 0x03 with RS = 0
call delay5ms ; wait 5ms
movwf PORTC ; write 0x03 with RS = 0 again
call delay200us ; wait 200us
movwf PORTC ; write 0x03 with RS = 0 one more time
call delay200us ; wait 200us
movlw 0x02 ; write 0x02 to enable four-bit mode
movwf PORTC
call delay5ms ; wait 5ms
movlw 0x28 ; write command "Set interface"
movwf LCD_DATA
call LCD_WriteC
movlw 0x08 ; write command "Enable display/cursor"
movwf LCD_DATA
call LCD_WriteC
movlw 0x01 ; write command "Clear and Home"
movwf LCD_DATA
call LCD_WriteC
movlw 0x06 ; write comamand "Set cursor move direction (right)
movwf LCD_DATA
call LCD_WriteC
movlw 0x0C ; turn on display
movwf LCD_DATA
call LCD_WriteC
;***** Main loop
mainloop
call delay5ms
movlw 'A'
movwf LCD_DATA
call LCD_WriteD
goto $
LCD_WriteD
banksel PORTA
bcf LCD_EN ; clear LCD_EN (low)
nop
bsf LCD_RS ; set LCD_RS (data = 1)
swapf LCD_DATA,w ; put high nibble of data on d7-4
movwf PORTC
bsf LCD_EN ; set LCD_EN (high)
nop ; wait at least 450 ns
bcf LCD_EN ; clear LCD_EN (low)
call delay200us ; wait 200 us for data writes
movf LCD_DATA,w
movwf PORTC ; put the low nibble of data on d7-4
bcf LCD_EN ;clear LCD_EN
call delay200us ;wait 200us for data writes
return
LCD_WriteC
banksel PORTA
bcf LCD_EN ; clear LCD_EN (low)
nop
bcf LCD_RS ; clear LCD_RS (command = 0)
swapf LCD_DATA,w ; put high nibble of data on d7-4
movwf PORTC
bsf LCD_EN ; set LCD_EN (high)
nop ; wait at least 450 ns
bcf LCD_EN ; clear LCD_EN (low)
call delay5ms ; wait 5ms for command writes
movf LCD_DATA,w
movwf PORTC ; put the low nibble of data on d7-4
bcf LCD_EN ;clear LCD_EN
call delay5ms ;wait 5ms for command writes
return
delay5ms
clrf counter ; delay = 5.124 ms with 4Mhz clock
delayn goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
nop
decfsz counter
goto delayn
return
delay200us
movlw .67 ; delay = 206 us with 4Mhz clock
movwf counter
decc decfsz counter
goto decc
return
END
Last edited: