PIC Microcontrollers: problem with LCD module (see below)

Click For Summary
The discussion centers on programming a PIC16F877A microcontroller to interface with a 16x2 LM016 LCD display using assembly language. The user successfully initialized the LCD but faced issues displaying characters, despite following the command structure. Key advice included ensuring the correct sequence for the Enable bit and using the proper command to turn on the display. The suggestion to analyze working libraries and check the data stream with an oscilloscope was also made. Ultimately, the user found a solution that resolved their issue.
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: 617
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.
 
Do you have a scope you can analyze the data stream to the LCD?
 
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
  • Like
Likes 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 donpacino
I am trying to understand how transferring electric from the powerplant to my house is more effective using high voltage. The suggested explanation that the current is equal to the power supply divided by the voltage, and hence higher voltage leads to lower current and as a result to a lower power loss on the conductives is very confusing me. I know that the current is determined by the voltage and the resistance, and not by a power capability - which defines a limit to the allowable...

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K