- #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:
This is my circuit in PROTEUS.
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.
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
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.