PIC18 LCD Screen troublshooting

General discussion on mikroElektronika website & forums.
Post Reply
Author
Message
huakui
Posts: 1
Joined: 25 Oct 2017 10:10

PIC18 LCD Screen troublshooting

#1 Post by huakui » 25 Oct 2017 10:32

Hello,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);

}
Thanks

Post Reply

Return to “Website & Forums General Discussion”