0
\$\begingroup\$

I am trying to initialize a 4x20 LCD using a PIC18 in 8bit serial interface. This is an LCD I found lying around in the lab and I cant find a datasheet for this exact one.

I am struggling to get it to work as all I ever achieve are blocks on the LCD. I have spent countless hours with no sign of success. Is there something in the code that I am missing?

All help is appreciated.

LCD.c

#define DataBus PORTA      //Data is set to 8 pins on port A
#define RS PORTCbits.RC0   
#define RW PORTCbits.RC1 
#define Enable PORTCbits.RC2 


void LCD_CmdWrite(int Cmd){
DataBus = Cmd;   //Sets command on Port A pins
Enable = 0;
RS = 0;
RW = 0;
Enable = 1;
__delay_ms(20);  //Delay for LCD
Enable = 0;

__delay_ms(10);

}

void LCD_intialize(){
RW = 0;
__delay_ms(20);

LCD_CmdWrite(0x38);  //LCD 8 bit mode
LCD_CmdWrite(0x01);  //Clears LCD
LCD_CmdWrite(0x06);  
LCD_CmdWrite(0x0F);  //Display on, cursor on, blink on
LCD_CmdWrite(0x80);

__delay_ms(2); 
}

main.c

#include <xc.h>  //Allows access to device specific features like TRIS etc.
#include <stdio.h>  //Allows access to input/output pins
#include <stdlib.h>  //Memory management and text conversion

#include "LCD.h" //Includes LCD Display functions

void main(void) {
OSCEN = 0b01000000;
OSCCON1 = 0b01100000;  
OSCCON2 = 0b01100000;
OSCFRQ = 0b000101;   //Sets clock at 16MHZ


TRISC = 0x00; //Sets PORT C as Output
TRISA = 0x00;//Sets PORT A as Output
PORTC = 0;
PORTA = 0;

__delay_us(200);  
LCD_intialize();  //Initializes LCD

__delay_us(200);
LCD_clear();  //Clears LCD again

while(1);

}
\$\endgroup\$
  • \$\begingroup\$ "This is an LCD I found lying around in the lab and I cant find a datasheet for this exact one. " So... yeah. \$\endgroup\$ – Harry Svensson Jul 30 '17 at 8:54
  • \$\begingroup\$ Which PIC18 MCU? \$\endgroup\$ – Bruce Abbott Jul 31 '17 at 5:39
0
\$\begingroup\$

Figure out what the LCD is. One way to do it is to power it up without initialization and adjust the contrast to see if you see a line of black boxes in the top row. If you do, it is the good old 44780. Find a data sheet and code to it.

If not, well, it will be a lot harder. But focus on finding a data sheet.

\$\endgroup\$
  • \$\begingroup\$ I get two bars, one the 1st and 3rd row. Does that means its a 44780? thank you for you reply! \$\endgroup\$ – DigiJockforLife Jul 30 '17 at 18:03
0
\$\begingroup\$

If the LCD is a 44780 then you could be Lucky. A company with the name of Extreme Electronics (India) produced a downloadable library complete with setup etc. I myself used the lib for pic1618877,pic16F648A and pic16F877A. The lib is small and can be adapted to your personal needs. For the pic16F18877 I needed to modify the use of the registers.

Here is the link http://extremeelectronics.co.in/pic16f877a-tutorials/setup-and-use-of-lcd-library-for-pic/

Looking at the comment it looks like a 44780. The described error can happen after a programming and restart cycle.. In that case power off and restart.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.