PIC Microcontrollers: problem with LCD module (see below)

AI Thread 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: 608
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
Hi all I have some confusion about piezoelectrical sensors combination. If i have three acoustic piezoelectrical sensors (with same receive sensitivity in dB ref V/1uPa) placed at specific distance, these sensors receive acoustic signal from a sound source placed at far field distance (Plane Wave) and from broadside. I receive output of these sensors through individual preamplifiers, add them through hardware like summer circuit adder or in software after digitization and in this way got an...
I am not an electrical engineering student, but a lowly apprentice electrician. I learn both on the job and also take classes for my apprenticeship. I recently wired my first transformer and I understand that the neutral and ground are bonded together in the transformer or in the service. What I don't understand is, if the neutral is a current carrying conductor, which is then bonded to the ground conductor, why does current only flow back to its source and not on the ground path...
I have recently moved into a new (rather ancient) house and had a few trips of my Residual Current breaker. I dug out my old Socket tester which tell me the three pins are correct. But then the Red warning light tells me my socket(s) fail the loop test. I never had this before but my last house had an overhead supply with no Earth from the company. The tester said "get this checked" and the man said the (high but not ridiculous) earth resistance was acceptable. I stuck a new copper earth...
Back
Top