PIC Microcontrollers: problem with LCD module (see below)

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 3K views
thegreengineer
Messages
54
Reaction score
3
Good morning people. Recently I started programming in assembly language my PIC16F877A. Success. Now I wanted to work with a LCD display (more specifically a 16x2 LM016 display). At first I did not know the commands until I saw a datasheet and this page:

http://www.8051projects.net/lcd-interfacing/commands.php

I want to set my LCD in 8 bit (1 byte) mode. So I created a .INC file using Notepad with basic instructions:
Code:
 #DEFINE DB PORTD
 #DEFINE E PORTB,RB3
 #DEFINE RW PORTB,RB2
 #DEFINE RS PORTB,RB1

 lcd_set ;8 bit, 2 row 5x7 dots size of characters
 bcf RS
 bcf RW
 movlw D'56'
 call lcd_escribe
 return

 lcd_off ;Turns off the LCD, turns off cursor and turns off blinking
 bcf RS
 bcf RW 
 movlw D'8'
 call lcd_escribe
 return

 lcd_borra ;Erases LCD content as well as the DDRAM content
 bcf RS
 bcf RW
 movlw D'1'
 call lcd_escribe
 return

 lcd_incrementa ;Entry mode
 bcf RS
 bcf RW
 movlw D'6'
 call lcd_escribe
 return

 lcd_escribe ;This writes the data from PORTD to the Data Bus of the LCD in form of 1 byte (8 bits)
 bsf E
 movwf DB
 bcf E
 call retardo_100ms
 return

 lcd_inicializa ;Initialize the LCD
 bcf E
 bcf RW
 bcf RS
 call retardo_20ms
 call lcd_set
 call retardo_5ms
 call lcd_set
 call retardo_150us
 call lcd_set
 call retardo_5ms
 call lcd_set
 call retardo_60us
 call lcd_off
 call retardo_60us
 call lcd_borra
 call retardo_60us
 call lcd_incrementa
 return

 lcd_caracter ;Writing a character in the LCD
 bsf RS
 bcf RW
 call lcd_escribe
 return
This is my circuit in PROTEUS.

22688792_1981809168770284_2622245964249564251_n.jpg

I first initialized the LCD module by calling the instruction "lcd_inicializa", then I erase my LCD module and test it by sending a character into the LCD (such as 'M'). In MPLAB X I declared TRISD and TRISB as 0 since they will be outputs to control my LCD. MPLAB code would be like this:
call lcd_inicializa

call lcd_borra

movlw 'M'

call lcd_caracter
However after building up and placing the hex file in PROTEUS it does not work. The LCD turns on but it will not show any character (or do anything at all). So I wanted to know where my mistake is because I've tried to find it but I don't know where I'm wrong in my code. Also when I write a command (if it is an instruction then RS=0, and if its a character then RS=1) I set the Enable bit (i.e. E=1) and then clear it (i.e. E=0), however what I don't know is that if the Enable bit should go to 0 before the 8 bit command is sent or after it. I appreciate your answers and feedback. Thanks.
 

Attachments

  • 22688792_1981809168770284_2622245964249564251_n.jpg
    22688792_1981809168770284_2622245964249564251_n.jpg
    48.8 KB · Views: 645
Engineering news on Phys.org
No idea what is the problem (and my only experience is related to using LCD with ATmega, not PIC), but in general I would start analyzing some working library (I bet there are ready ones written in some language like C). That should give you a good starting point.
 
Its been a while since I did assembly... but

if D'56' means decimal 56, which I think it does, then it is equivalent to x38

I don't see you once turn the LED display on
to do that you need to write

x0C, if you want to turn just the display on

b000011XX. with X being if you want blinking stuff
 
  • Like
Likes   Reactions: thegreengineer
donpacino said:
Its been a while since I did assembly... but

if D'56' means decimal 56, which I think it does, then it is equivalent to x38

I don't see you once turn the LED display on
to do that you need to write

x0C, if you want to turn just the display on

b000011XX. with X being if you want blinking stuff
Hey, sorry for answering late man. Thanks for the answer, it actually worked.
 
  • Like
Likes   Reactions: donpacino