Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C18 codes to interface LCD with pic18f4550

Status
Not open for further replies.

hmrox

Junior Member level 1
Joined
Nov 27, 2011
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,508
Hi all..
I'm new to microcontroller programming and I'm trying to interface a LCD with p18f4550. I'm having some trouble with the configuration bits. Can anyone please post the complete codes in C (including the configuration bits) ? I'm using a 20MHz oscillator.
 

1. What type of LCD you are using?
2. Mainly 2 types of connection are popular i)8 wire ii) 4 wire
3. There are 2 ways to send commands/data to LCD. --(a) Call a time delay before sending next data/command to an LCD (b) To monitor the busy flag before issuing a command / data to the LCD.

Search Edaboard. Its full of LCD routine.

Assuming you are using JHD162A, here is a routinefrom Mazidi:---

D0 to D7 are connected to RD0 to RD7
RB0->RS
RB1->R/W
RB2->E
---------------------------------
#include <P18F4580.h>
#define ldata PORTD
#define rs PORTBbits.RB0
#define rw PORTBbits.RB1
#define en PORTBbits.RB2
void main()
{
TRISD = 0;
TRISB = 0;
en = 0;
MSDelay(250);
lcdcmd(0x38);
MSDelay(250);
lcdcmd(0x0E);
MSDelay(15);
lcdcmd(0x01);
MSDelay(15);
lcdcmd(0x06);
MSDelay(15);
lcdcmd(0x86);
MSDelay(15);
lcddata('M');
MSDelay(15);
lcddata('D');
MSDelay(15);
lcddata('E');
}
void lcdcmd(unsigned char value)
{
ldata = value;
rs = 0;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
}
void lcddata(unsigned char value)
{
ldata = value;
rs = 1;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
}
void MSDelay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<135;j++);
}
 
Last edited:

Thank you papunblg, for your immediate response. I'm using a 16X2 LCD (3.3V) in 8 wire mode. Can you please post the codes with configuration bit settings for p18f4550 as well.. I'm having a time setting them...
 

Mr. hmrox,

In my previous post above (post #2) you will find a tested code for PIC18F4550 with all setting (every possible details)
 

Interfacing LCD to any micocontroller is not a difficult task. you just have a routine to send LCD commands to initialize the LCD and the the Data to be displayed is sent after that which is simply displayed on LCD.

now Try to make the circuit as follows:



And write the following code: and burn it into your pic....

//LCD Control pins
#define rs LATA.F0
#define rw LATA.F1
#define en LATA.F2

//LCD Data pins
#define lcdport LATB

void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned int i=0;

void main(void)
{
TRISA=0; // Configure Port A as output port
LATA=0;
TRISB=0; // Configure Port B as output port
LATB=0;
lcd_ini(); // LCD initialization
lcddata('E'); // Print 'E'
Delay_ms(1000);
lcdcmd(0x85); // Position 1st Line, 6th Column
lcddata('G'); // Print 'G'

}
void lcd_ini()
{
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
lcdcmd(0x0C); // Display On and Cursor Off
lcdcmd(0x01); // Clear display screen
lcdcmd(0x06); // Increment cursor
lcdcmd(0x80); // Set cursor position to 1st line, 1st column
}

void lcdcmd(unsigned char cmdout)
{
lcdport=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
Delay_ms(10);
en=0;
}

void lcddata(unsigned char dataout)
{
lcdport=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(10);
en=0;
}

Check out the following link.

**broken link removed**

here you can get a complete Tutorial to work with PIC18F4550.

hope this helps.

Regards.
 

Mr.papunlg,

I tried building your code with the following configuration bits -

#pragma config PLLDIV = 5
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2
#pragma config FOSC = HSPLL_HS//48MHZ clock

But I'm receiving a syntax error at (pointed by the arrow) -

void MSDelay(unsigned int itime)
{
unsigned int i, j;
---> for(i=0;i<itime;i++)
for(j=0;j<135;j++);
}

I cant figure out what the problem is.. Thank you for your help....! :)
 

I dont know how! That was "<" (less than operator) but due to some formatting error has changed to "<"

for(i=0;i<itime;i++)
for(j=0;j<135;j++);
 

Mr. Qaisar Azeemi,

The circuit schematic you have given uses pins RB6 and RB7 for LCD data. But I'm doing onboard programming and these pins are also ( PGD and PGC ) which should be connected to the programmer at all times. I tried editing the codes to use PORT D as the LCD data output with no luck. I'm just getting the two rows of darked squares.

---------- Post added at 16:15 ---------- Previous post was at 16:04 ----------

Mr. Qaisar Azeemi,

The circuit schematic you have given uses pins RB6 and RB7 for LCD data. But I'm doing onboard programming and these pins are also ( PGD and PGC ) which should be connected to the programmer at all times. I tried editing the codes to use PORT D as the LCD data output with no luck. I'm just getting the two rows of darked squares.
 

You must give LCDs a certain amount of time before sending data/commands to them. Check datasheet
But in the code of Engineers Garage as given by Mr. Qaisar Azeemi, I cant see any such delay routine before sending data/commands to the LCD. Would you please explain?

---------- Post added at 14:01 ---------- Previous post was at 13:46 ----------



Mr. Hamrox,
Check here:
 

Yes you r quite right mr papunblg, delays are necessary between sending commands and data to the LCD. i just tried to give and idea of using LCD with PIC to beginner.

MR Hmrox:
I also faced the same problem of two dark square rows on LCD screen while developing a project in beginning .... just you have to do is to control the contrast of Your LCD screen using a variable resistor. you will see the data displaying on LCD Screen. :) Good Luck.

Thank you.
 

Mr. Papunblg,

Your code finally was built, but sadly Im still unable to get any kind of output from my LCD - still showing the squares..

However, I used a pic16F877A to successfully interface the LCD with the following code and display a message-

#include <pic.h>
__CONFIG (0x3F32);

#define sw1 RA4
#define sw2 RA5
#define green RA2
#define red RE0
#define orange RC3
#define buzzer RA1
#define RS RC4
#define E RC5
#define lcd_data PORTD




//Function Prototype
void delay (unsigned long i);
void E_clock(void);
void lcd_bus(unsigned char data);
void lcd_init(void);
void lcd_char(unsigned char character);
void lcd_goto(unsigned char address);
void lcd_string(const char *s);

// main program start here
void main (void)

{
TRISA= 0b11111001;
TRISC= 0b11000111;
TRISD= 0b00000000;
TRISE= 0b00000000;
PORTA= 0b00000000;
PORTD= 0b00000000;
PORTE= 0b00000000;
ADCON0= 0b10000000; //RA0 as ADC input
ADCON1= 0b00001110; //Left justified,FOsc/32,


lcd_init();
//lcd_char(0x41);
lcd_goto(0x00); //Jump to 2nd line
lcd_string("Welcome");

lcd_goto(0x40); //jump to 2nd line
lcd_string("Good Morning");


while(1)continue;//

while(1)
{
if (sw1==0)
{
buzzer=1;
green=0;
//red=1;
delay(50000);
buzzer=0;
green=1;
delay(50000);
}
else
{
buzzer=0;
green=1;
//red=0;
}
}
}

void delay(unsigned long i)
{
for (i=i; i>0; i--);

}

void E_clock(void)
{
E=1;
delay(100);
E=0;
delay(100);

}
void lcd_bus(unsigned char data)
{
lcd_data= data;
E_clock();

}
void lcd_init(void)
{
RS= 0;
delay(200);
lcd_bus(0b00111000); //0x38, 8 bits interface, 2 line display
lcd_bus(0b00000001); //0x01, clear LCD
lcd_bus(0b00000010); //0x02, Home position
lcd_bus(0b00001111); //0x0F, Display ON, curssor ON, Cursor Blink
lcd_bus(0b00000110); //0x06, Increase cursor after each character
}
void lcd_char(unsigned char character)
{
RS= 1;
delay(200);
lcd_bus(character);
}
void lcd_goto(unsigned char address)
{
RS=0;
delay(200);
lcd_bus(0x80+address);

}
void lcd_string(const char *s)
{
while(*s)
{
lcd_char(*s);
*s++;
}
}



But, I'm unable to edit it to run on the p18f4550... can you please help ?
 

I will surely try my level best to help you. I am now in office. Its now 4:40pm here. Tonight I will check in detals after returning home. Though at quick look I can say that - add a atleast 250ms delay loop before calling init(). It is absolutely necessary.

For a newbie this type of failure is perfectly common. I can remember my days with LCDs
 

Going through your code I have found the followings:-

1. LCD data pins are connected to portD and RS is connected to PORTC.4, Enable pin is connected to PORTC.5 but this pins are not set as output.So, in main(), initialize TRISC properly. (with 0 for those pins)
2. You are not using R/W. Connect that pin(pin 5 of LCD) to ground.
3. After poweron the LCD needs some time. Use the following loop before calling the LCD initialization routines.(

void ldelay(unsigned int itimes){
unsigned int i; unsigned int j;
for(i=0;i<itimes;i++)
for(j=0;j<165;j++);
}
////////////may need adjustment according to your Xtal value. Assuming 10MHz crystal

4. Your init() method contains some error. After initialization call main() like this:-

main(){

//// all initialization of registers
//////////////////////////////////////////////////////////
ldelay(250);
///////////////////////////////////Starting LCD initialization///////////////
lcd_bus(0b00111000); //0x38, 8 bits interface, 2 line display
ldelay(250);
lcd_bus(0b00001110); //0x0E, Display ON, curssor ON
ldelay(15);
lcd_bus(0b00000001); //0x01, clear LCD
lcd_bus(0b00000110); //0x06, Increase cursor after each character
ldelay(15);
lcd_bus(0b10000001); //line 1 position 1,hex 81
ldelay(15);
/////////////////////////////You may put the above code in a function also////////////
lcd_string("Welcome");
//////////////////////rest of the codes////////////////

}

4. Change the lcd_bus() as follows...
void lcd_bus(unsigned char data)
{
lcd_data= data;
RS=0
E_clock();

}

5. Change the E_clock() method as follows.............

void E_clock(void) //// to strobe the enable pin
{
E=1;
ldelay(1);
E=0;
ldelay(1);

}


Good luck........................
 

okay. I did the changes as mentioned in your post, but I got some errors when I built.

main.c:47:Warning [2066] type qualifier mismatch in assignment
main.c:84:Error [1105] symbol 'RC5' has not been defined
main.c:84:Error [1101] lvalue required
main.c:86:Error [1105] symbol 'RC5' has not been defined
main.c:86:Error [1101] lvalue required
main.c:94:Error [1105] symbol 'RC4' has not been defined
main.c:94:Error [1101] lvalue required
main.c:100:Error [1105] symbol 'RC4' has not been defined
main.c:100:Error [1101] lvalue required
main.c:110:Error [1105] symbol 'RC4' has not been defined
main.c:110:Error [1101] lvalue required
main.c:116:Error [1105] symbol 'RC4' has not been defined
main.c:116:Error [1101] lvalue required
Halting build on first failure as requested.


******(The places where the error occured is pointed by the arrows----> in the code below)


The code is -




#include "p18f4550.h"

#define RS RC4
#define E RC5
#define lcd_data PORTD

//Function Prototype
void delay (unsigned long i);
void E_clock(void);
void lcd_bus(unsigned char data);
void lcd_init(void);
void lcd_char(unsigned char character);
void lcd_goto(unsigned char address);
void lcd_string(const char *s);
void ldelay(unsigned int itimes);


// main program start here
void main (void)

{
TRISC= 0b11001111;
TRISD= 0b00000000;
PORTD= 0b00000000;

ldelay(250);
///////////////////////////////////Starting LCD initialization///////////////
lcd_bus(0b00111000); //0x38, 8 bits interface, 2 line display
ldelay(250);
lcd_bus(0b00001110); //0x0E, Display ON, curssor ON
ldelay(15);
lcd_bus(0b00000001); //0x01, clear LCD
lcd_bus(0b00000110); //0x06, Increase cursor after each character
ldelay(15);
lcd_bus(0b10000001); //line 1 position 1,hex 81
ldelay(15);
/////////////////////////////You may put the above code in a function also////////////

lcd_string("Welcome"); ----> main.c:43:Warning [2066] type qualifier mismatch in assignment

//lcd_goto(0x40); //jump to 2nd line
//lcd_string("Good morning");


while(1)continue;//

}

void delay(unsigned long i)
{
for (i=i; i>0; i--);

}

void E_clock(void) //// to strobe the enable pin
{
E=1; --->main.c:61:Error [1105] symbol 'RC5' has not been defined --->lvalue required
ldelay(1);
E=0;--->main.c:61:Error [1105] symbol 'RC5' has not been defined --->lvalue required
ldelay(1);

}

void lcd_bus(unsigned char data)
{
lcd_data= data;
RS=0;--->main.c:71:Error [1105] symbol 'RC4' has not been defined--->main.c:71:Error [1101] lvalue required

E_clock();

}
void lcd_init(void)
{
RS= 0;--->main.c:71:Error [1105] symbol 'RC4' has not been defined--->main.c:71:Error [1101] lvalue required

delay(200);
lcd_bus(0b00111000); //0x38, 8 bits interface, 2 line display
lcd_bus(0b00000001); //0x01, clear LCD
lcd_bus(0b00000010); //0x02, Home position
lcd_bus(0b00001111); //0x0F, Display ON, curssor ON, Cursor Blink
lcd_bus(0b00000110); //0x06, Increase cursor after each character
}
void lcd_char(unsigned char character)
{
RS= 1; --->main.c:71:Error [1105] symbol 'RC4' has not been defined--->main.c:71:Error [1101] lvalue required

delay(200);
lcd_bus(character);
}
void lcd_goto(unsigned char address)
{
RS=0; --->main.c:71:Error [1105] symbol 'RC4' has not been defined--->main.c:71:Error [1101] lvalue required

delay(200);
lcd_bus(0x80+address);

}
void lcd_string(const char *s)
{
while(*s)
{
lcd_char(*s);
*s++;
}
}

void ldelay(unsigned int itimes){
unsigned int i; unsigned int j;
for(i=0;i<itimes;i++)
for(j=0;j<165;j++);
}
 

#define RS PORTCbits.RC4 /* PORT for RS */
#define E PORTCbits.RC5 /* PORT for E */
#define lcd_data PORTD

---------- Post added at 10:17 ---------- Previous post was at 10:07 ----------

and
void lcd_string(unsigned char *s)
{
while(*s)
lcd_char(*s++);
}

Modify your code as above. In post no #2 above use of #define have been shown already
 
Last edited:

I still couldnt get any output. I cant figure out what the problem is. And I couldnt use the lcd_string function you gave, because I'm getting a argument mismatch error.

This was the final code I built

#pragma config PLLDIV = 5
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2
#pragma config FOSC = HSPLL_HS//48MHZ clock // CONFIG7H

#define RS PORTCbits.RC4 /* PORT for RS */
#define E PORTCbits.RC5 /* PORT for E */
#define lcd_data PORTD

#include "p18f4550.h"
//Function Prototype
void delay (unsigned long i);
void E_clock(void);
void lcd_bus(unsigned char data);
void lcd_init(void);
void lcd_char(unsigned char character);
void lcd_goto(unsigned char address);
void lcd_string(const char *s);
void ldelay(unsigned int itimes);


// main program start here
void main (void)

{
TRISC= 0b11001111;
TRISD= 0b00000000;
// PORTD= 0b00000000;

ldelay(250);
///////////////////////////////////Starting LCD initialization///////////////
lcd_bus(0b00111000); //0x38, 8 bits interface, 2 line display
ldelay(250);
lcd_bus(0b00001110); //0x0E, Display ON, curssor ON
ldelay(15);
lcd_bus(0b00000001); //0x01, clear LCD
lcd_bus(0b00000110); //0x06, Increase cursor after each character
ldelay(15);
lcd_bus(0b10000001); //line 1 position 1,hex 81
ldelay(15);
/////////////////////////////You may put the above code in a function also////////////
lcd_string("Welcome");

//lcd_goto(0x40); //jump to 2nd line
//lcd_string("Good morning");


while(1)continue;//

}

void delay(unsigned long i)
{
for (i=i; i>0; i--);

}

void E_clock(void) //// to strobe the enable pin
{
E=1;
ldelay(1);
E=0;
ldelay(1);

}

void lcd_bus(unsigned char data)
{
lcd_data= data;
RS=0;
E_clock();

}
void lcd_init(void)
{
RS= 0;
delay(200);
lcd_bus(0b00111000); //0x38, 8 bits interface, 2 line display
lcd_bus(0b00000001); //0x01, clear LCD
lcd_bus(0b00000010); //0x02, Home position
lcd_bus(0b00001111); //0x0F, Display ON, curssor ON, Cursor Blink
lcd_bus(0b00000110); //0x06, Increase cursor after each character
}
void lcd_char(unsigned char character)
{
RS= 1;
delay(200);
lcd_bus(character);
}
void lcd_goto(unsigned char address)
{
RS=0;
delay(200);
lcd_bus(0x80+address);

}
void lcd_string(const char *s)
{
while(*s)
{
lcd_char(*s);
*s++;
}
}

void ldelay(unsigned int itimes){
unsigned int i; unsigned int j;
for(i=0;i<itimes;i++)
for(j=0;j<165;j++);
}




I tried doubling the '165' in ldelay and halving it , because I am using a 20MHz oscillator. No output still...
 

In my previous post the lcd_string() has other type of parameter. You have not changed it.

It is compiling perfectly ok. Here is the hex file:- (Due to some error I could not attach the file)

:020000040000FA
:06000000A4EF01F0120064
:020006000000F8
:08000800CF0E946E956AFA0E0A
:10001000E66EE66AFFD8E552E552380EE66E78D80D
:10002000E552FA0EE66EE66AF5D8E552E5520E0E96
:10003000E66E6ED8E5520F0EE66EE66AEBD8E55234
:10004000E552010EE66E64D8E552060EE66E60D803
:10005000E5520F0EE66EE66ADDD8E552E552810EF6
:10006000E66E56D8E5520F0EE66EE66AD3D8E55234
:10007000E552640EE66E030EE66EA8D8E552E55230
:10008000FFD7FED71200D9CFE6FFE1CFD9FFD95075
:10009000FB0FE96EFF0EDA20EA6EFB0EEECFDBFF00
:1000A000FC0EEECFDBFFFD0EEECFDBFFFE0EEECF44
:1000B000DBFFD950FB0FE96EFF0EDA20EA6ED88025
:1000C000000EEE54000EEE54000EEE54000EEE54F0
:1000D0000CE2D950FB0FE96EFF0EDA20EA6EEE0655
:1000E000000EEE5AEE5AEE5AE4D7E552E7CFD9FFAA
:1000F0001200828A010EE66EE66A8CD8E552E5525D
:10010000829A010EE66EE66A85D8E552E552120043
:10011000D9CFE6FFE1CFD9FFFE0EDB50836E829888
:10012000E8DFE552E7CFD9FF12008298C80EE66EED
:10013000E66AE66AE66AA7DFE552E552E552E5526D
:10014000380EE66EE5DFE552010EE66EE1DFE552C0
:10015000020EE66EDDDFE5520F0EE66ED9DFE552E8
:10016000060EE66ED5DFE5521200D9CFE6FFE1CFED
:10017000D9FF8288C80EE66EE66AE66AE66A83DF21
:10018000E552E552E552E552FE0EDBCFE6FFC0DF59
:10019000E552E552E7CFD9FF1200D9CFE6FFE1CF14
:1001A000D9FF8298C80EE66EE66AE66AE66A6BDFF9
:1001B000E552E552E552E552FE0EDB50800FE66E49
:1001C000A7DFE552E552E7CFD9FF1200D9CFE6FF0E
:1001D000E1CFD9FFFD0EDBCFE9FFFE0EDBCFEAFF5B
:1001E000EF5014E0FD0EDBCFE9FFFE0EDBCFEAFFA0
:1001F000EF50E66EBADFE552FD0EDBCFE9FFDB2AFA
:10020000FE0EDBCFEAFF01E3DB2AE4D7E552E7CFBE
:10021000D9FF1200D9CFE6FFE1CFD9FF040EE126C6
:10022000DE6ADD6ADECF00F0DDCF01F0FD0EDBCF50
:1002300002F0FE0EDBCF03F00250005C03500158C9
:100240001AE2020EDB6A030EDB6A020EDBCF00F05D
:10025000030EDBCF01F0A50E005C000E015806E294
:10026000020EDB2A030E01E3DB2AEFD7DF2A010EA1
:1002700001E3DB2AD7D7040EE15C02E2E16AE55232
:0A028000E16EE552E7CFD9FF12004E
:06028A00060EF66E000EE8
:10029000F76E000EF86E00010900F550656F090059
:1002A000F550666F03E1656701D03DD00900F55058
:1002B000606F0900F550616F0900F550626F090029
:1002C0000900F550E96E0900F550EA6E09000900D1
:1002D0000900F550636F0900F550646F09000900CB
:1002E000F6CF67F0F7CF68F0F8CF69F060C0F6FF9F
:1002F00061C0F7FF62C0F8FF0001635302E164537D
:1003000007E00900F550EE6E6307F8E26407F9D7DD
:1003100067C0F6FF68C0F7FF69C0F8FF0001650716
:08032000000E665BBFD712005E
:08032800000EF36E00EE00F080
:10033000040E01D81200EA6002D0EE6AFCD7F35036
:08034000E9601200EE6AFCD72F
:0803480013EE00F023EE00F0BB
:10035000F86A059C45EC01F0B6EC01F004EC00F005
:04036000FBD71200B5
:0803640057656C636F6D6500C5
:02036C0012007D
:020000040030CA
:0100000024DB
:010001000EF0
:00000001FF
 
Last edited:

Mr.Papunblg,

When I used the lcd_string() you posted, my program failed to build, saying its some mismatch error. Then I tried using the previous function and it built successfully..
 

What? Did you forget to change the function prototype? I think so.
//Function Prototype
void delay (unsigned long i);
void E_clock(void);
void lcd_bus(unsigned char data);
void lcd_init(void);
void lcd_char(unsigned char character);
void lcd_goto(unsigned char address);
void lcd_string(const char *s); <------------------------Change here also
void ldelay(unsigned int itimes);
 

This is the final code I compiled- though it compiled successfully, I was getting a warning( marked in red). Will this be a problem ?

//CONFIGURATIONS
#pragma config FOSC = HSPLL_HS // Using 20 MHz crystal with PLL
#pragma config PLLDIV = 5 // Divide by 5 to provide the 96 MHz PLL with 4 MHz input
#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
#pragma config USBDIV = 2 // USB clock comes from 96 MHz PLL output / 2
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config VREGEN = ON // Use internal USB 3.3V voltage regulator
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (44-pin devices)
#pragma config CP0 = OFF // Disable code protection
// CONFIG7H

#define RS PORTAbits.RA0 /* PORT for RS */
#define E PORTAbits.RA2 /* PORT for E */
#define lcd_data PORTD

#include "p18f4550.h"
//Function Prototype
void delay (unsigned long i);
void E_clock(void);
void lcd_bus(unsigned char data);
void lcd_init(void);
void lcd_char(unsigned char character);
void lcd_goto(unsigned char address);
void lcd_string(unsigned char *s);
void ldelay(unsigned int itimes);


// main program start here
void main (void)

{
TRISA= 0b11111010;
TRISD= 0b00000000;
// PORTD= 0b00000000;

ldelay(250);
///////////////////////////////////Starting LCD initialization///////////////
lcd_bus(0b00111000); //0x38, 8 bits interface, 2 line display
ldelay(250);
lcd_bus(0b00001110); //0x0E, Display ON, curssor ON
ldelay(15);
lcd_bus(0b00000001); //0x01, clear LCD
lcd_bus(0b00000110); //0x06, Increase cursor after each character
ldelay(15);
lcd_bus(0b10000001); //line 1 position 1,hex 81
ldelay(15);
/////////////////////////////You may put the above code in a function also////////////
lcd_string("Welcome"); ---->LCD code.c:58:Warning [2054] suspicious pointer conversion

//lcd_goto(0x40); //jump to 2nd line
//lcd_string("Good morning");


while(1)continue;//

}

void delay(unsigned long i)
{
for (i=i; i>0; i--);

}

void E_clock(void) //// to strobe the enable pin
{
E=1;
ldelay(1);
E=0;
ldelay(1);

}

void lcd_bus(unsigned char data)
{
lcd_data= data;
RS=0;
E_clock();

}
void lcd_init(void)
{
RS= 0;
delay(200);
lcd_bus(0b00111000); //0x38, 8 bits interface, 2 line display
lcd_bus(0b00000001); //0x01, clear LCD
lcd_bus(0b00000010); //0x02, Home position
lcd_bus(0b00001111); //0x0F, Display ON, curssor ON, Cursor Blink
lcd_bus(0b00000110); //0x06, Increase cursor after each character
}
void lcd_char(unsigned char character)
{
RS= 1;
delay(200);
lcd_bus(character);
}
void lcd_goto(unsigned char address)
{
RS=0;
delay(200);
lcd_bus(0x80+address);

}
void lcd_string(unsigned char *s)
{
while(*s)
lcd_char(*s++);
}

void ldelay(unsigned int itimes){
unsigned int i; unsigned int j;
for(i=0;i<itimes;i++)
for(j=0;j<165;j++);
}


for the pins RS and E, when I used RA0 and RA2 instead of RC4 and RC5, I got the following output ( just the cursor at random places) . I didnt obtain any outputs when using pins RC4 and RC5.

IMG_0324.JPG
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top