PIC Microcontrollers: problem with LCD module (see below)

In summary: Turns out that in my code I was not initializing the display correctly. Once I fixed that it worked fine.
  • #1
thegreengineer
54
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: 526
Engineering news on Phys.org
  • #2
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.
 
  • #3
Do you have a scope you can analyze the data stream to the LCD?
 
  • #4
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 thegreengineer
  • #5
  • Like
Likes thegreengineer
  • #6
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 donpacino

1. How do I troubleshoot issues with my PIC microcontroller's LCD module?

First, check all connections between the PIC microcontroller and the LCD module to ensure they are secure and properly connected. Next, verify that the code being used to control the LCD module is correct and free of any errors. If the issue persists, try using a different LCD module or testing the module with a different microcontroller to determine if the problem is with the module or the microcontroller.

2. Why is my LCD module not displaying any text or characters?

There could be several reasons for this issue. Check that the power supply to the LCD module is stable and sufficient. Additionally, verify that the contrast and brightness settings of the LCD module are adjusted correctly. If these settings are correct, there may be an issue with the code or the connections between the microcontroller and the module.

3. Can I use any LCD module with my PIC microcontroller?

No, not all LCD modules are compatible with PIC microcontrollers. It is important to check the datasheet of the LCD module to ensure that it is compatible with the specific microcontroller you are using. Additionally, some modifications to the code may be necessary to make the module work with the microcontroller.

4. How can I display special characters or symbols on my LCD module using a PIC microcontroller?

To display special characters or symbols, you will need to use the custom character generation feature of the LCD module. This involves creating a custom character pattern in the microcontroller's memory and then sending the pattern to the LCD module to display. Consult the datasheet of your specific LCD module for instructions on how to generate custom characters.

5. My LCD module is displaying gibberish characters. What could be the problem?

This issue could be caused by incorrect initialization of the LCD module or incorrect configuration of the microcontroller's ports. Check that the code used to initialize the LCD module is correct and that the ports are configured properly. It is also important to ensure that the LCD module is receiving stable and sufficient power.

Similar threads

  • Electrical Engineering
Replies
2
Views
2K
  • Electrical Engineering
Replies
1
Views
2K
Replies
9
Views
2K
  • Electrical Engineering
Replies
10
Views
3K
  • Electrical Engineering
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Electrical Engineering
Replies
6
Views
1K
Back
Top