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.

[SOLVED] LCD 16x2 by using 18F4550

Status
Not open for further replies.

Jent CWH

Newbie level 6
Joined
Feb 1, 2012
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,389
Hi, I am new here. Hope can get help since i'm unable to interface the LCD with my PIC18F4550 by using CCS compiler. I'm not too familiar with the C programming, but i tried to write out a C code. Hope you guys can check and inform me any errors occured.

my connection for the LCD to the PIC18F4550:
RS----RB4
R/W--Gnd
E-----RB5
DB0 to DB7----RD0 to RD7

This is my code:

#include <18F4550.h>
#fuses NOLVP, NOWDT, XT
#use delay(clock=20M,crystal)
#include <lcd.c>

#define LCD_RS PIN_B4
#define LCD_E PIN_B5

void lcd_init(void);
void port_init(void);
void lcd_write(unsigned char c);
void lcd_goto(unsigned char c);

void port_init(void)
{
set_tris_d(0x00);
set_tris_b(0b00000011);
}

void lcd_init(byte)
{
lcd_write(0x38);
delay_ms(20);
lcd_write(0x01);
delay_ms(15);
lcd_write(0x06);
delay_ms(15);
lcd_write(0x0F);
delay_ms(15);
lcd_write(0x80);
delay_ms(15);

output_low(LCD_RS);
output_high(LCD_E);
delay_ms(20);
output_high(LCD_RS);
output_low(LCD_E);
}

void main()
{

printf(lcd_putc, "Hello");
lcd_gotoxy(1,2);

while(TRUE)
{

}
}

I'm able to compile, but my LCD existed with a full black boxes in first line. Can I know what the problems are? Thanks a lot..^.^
 

Have you tried adjusting the contrast on your LCD?
 

In PIC18F4550 PortB<4:0> pins are analog by default u have to convert them into digital...
Then it will will work...
Change your configuration bits..
See your Compiler manual how to do this...

---------- Post added at 21:51 ---------- Previous post was at 21:50 ----------

I am referring to the fuse bits...
configure it as Digital I/O pin "PBADEN" configuration bit..

Hope this helps you..
 
btbass: I have ever tried many times, but didn't work..

sharma: actually i'm first time to use PIC.. not really understand much about it...I've checked its datasheet, but if i have tris the portB, is there still require to change it to digital from analog? Can you teach me more in-depth? I also worry about my LCD initialization got any problems?
 

Hai

I didn't see the calling function for initializing the LCD or Port. Did you removed while post or forgot?
 

actually I am a beginner to use PIC with C programming... so I think there are many errors in my coding, do you mind to teach me the calling function?
 

actually I am a beginner to use PIC with C programming... so I think there are many errors in my coding, do you mind to teach me the calling function?

Visit to this site to understand the function

Functions in C - Cprogramming.com

**broken link removed**

HowStuffWorks "The Basics of C Programming"

Thanks

---------- Post added at 10:38 ---------- Previous post was at 10:32 ----------

Can you tell me whether the code which you have uploaded is complete code or just a part of code?
 

in my view you need to check couple of functions are present or not like lcd_write , lcd_goto,set_tris_d, output_high, output_low......did this are inbuld or you need to write the body of these functions or not.....

Good Luck
 

Karthikkrv85: actually i base on my understanding to write it...is there alot of important functions missing? i have written two new coding..but not work too..>.<

milind: I think these functions have been inbuild in ccs compiler..is not, it will be appearing errors..
 

Code:
void main()
{
port_init();
lcd_init();
printf(lcd_putc, "Hello");
lcd_gotoxy(1,2);

while(TRUE)
{

}
}

Hai i have not used CCS compiler. But please confirm the lcd_write , lcd_goto, set_tris_d, output_high, output_low are pre-defined function.. By the way I have added the calling function with the main(); Have you done the same for the other two code which you said?

---------- Post added at 12:18 ---------- Previous post was at 12:03 ----------

Hai..

Are you using flex_lcd.c driver?
 

Karthikkrv85: actually i base on my understanding to write it...is there alot of important functions missing? i have written two new coding..but not work too..>.<

milind: I think these functions have been inbuild in ccs compiler..is not, it will be appearing errors..

Yes I agree with you......Actually ......I should ask you .....did your code is getting build or not..... Actaully I had never used CCS complier....I uses SDCC compiler....and in SDCC complier one need to write all the basic functions too.....

Ok....If your code is getting compiled then those function may be inbuild....

Good Luck
 

You can't run your LCD by an ANALOG PORT...
Which Software u are using to Program(BURN) your code in to the Controller..

Then Disable the PBADEN bit PORTB A/D bits ..


I am saying this to you..
Because this is the same problem, which i was facing few months back..
 
Have a Look on these pics

I use WInPIC to Burn code in my Controller
Capture.PNG
Capture2.PNG

Just Disable the PBADEN bit
 
In Your Code You have Write

#fuses NOLVP, NOWDT, XT

Do you know the Meaning of this line

It means that you are using LOW VOLTAGE PROGRAMMING DISABLE
WATCH DOG TIMER DISABLE
XT means you are using a crystal of 4MHz or Less So First of all change this to HS Becasue you are using 20MHZ Crystal
Although it doesn't create any problem..
But still it is a Wrong Practice

Now Come One to what i want to say..
Have a Look on the PIN-OUT
PIC18F4550-pinout.jpg


PIN RB4,RB5,RB6, and RB7 are analog Pins as well as Digital too..
But by default they are Analog Pins TRISB registers will not affect this..
and
RS----RB4
R/W--Gnd
E-----RB5

Your LCD RS is Connected to RB4
and RB5 is Connected to EN

So to make these pins Digital you have to disable PBADEN Fuse/Configuration bit..
I don't know how to do this in your compiler..

My another suggestion is to connect EN to RB0 and RS to RB1

and
Change your code as follow:-
Code:
#define LCD_RS PIN_B4
#define LCD_E PIN_B5

//Change this to
#define LCD_RS PIN_B1
#define LCD_E PIN_B0

I am 100% sure you are facing the problem, which i am mentioning..
Correct it ... You LCD Will Run
 
Thanks alot Arun Sharma..I'm trying to edit..
one thing i m not able to change is that I'm using kit of PIC..so, the connection have been fixed...>.<...if i am able to change, i will follow ur advice too.. anyway..i will try best to disable the PBADEN fuse..

---------- Post added at 08:25 ---------- Previous post was at 08:24 ----------

Thanks alot Arun Sharma..I'm trying to edit..
one thing i m not able to change is that I'm using kit of PIC..so, the connection have been fixed...>.<...if i am able to change, i will follow ur advice too.. anyway..i will try best to disable the PBADEN fuse..
 

Thank so much...i finally can get it....i am able to disable the PBADEN fuse...i get my desired characters...thank you so much!!^.^
 

Its Okay
enjoy ...
Can you tell me how you disable PBADEN bit in your compiler..

---------- Post added at 21:36 ---------- Previous post was at 21:33 ----------

I am happy that it works for you..
:)
 
actually already inbuilt in the ccs compiler...i asked the ppl in ccs forum.. they said: #fuses NOPBADEN
haha, just so simple, but i never thought about it..^.^
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top