![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
PIC18F4550 and LCD |
Posted: Sun Jan 06, 2008 3:14 am |
|
|
Hi All
I am tiring to get a LCD working on a PIC18F4550, but I can’t seem to get it to initialize. I am just using the stranded CCS lcd.c file, just changed the port and the tris statements as I want to use PORTD. Nothing fancy, done before, and works OK on other PICs. Also tried the FlexLCD driver, but get same problem, just black squares. Tried code on PIC16F877A with same LCD, and works without a problem.
I have a LED blinking to make sure that PIC is running, and it is OK on both PICs.
I also have tried to run a simulation in Proteus, but it will also not initialize. I did notice that the Enable pin will change from HIGH to LOW, but the RS and RW pin will always be LOW. The data pins also go show funny things. When I simulate a PIC16F877A, the data pins will never be floating, but in the F184550, they will quite often float. Not sure if this is just a simulation problem. Don’t have a DSO, so I can check.
I have had a look at the forum, and it looks like others have had the same problem, but no solutions have been suggested.
I am using CCS 3.249
Code: |
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOBROWNOUT
#use delay(clock=48000000)
#include <LCD420.c>
void main()
{
lcd_init();
while(1)
{
printf(lcd_putc,"Hello");
output_high(PIN_C0);
delay_ms(500);
output_low(PIN_C0);
delay_ms(500);
}
}
|
In LCD.c, all I change is “#byte lcd = 6” to “#byte lcd = 8” not sure if that is correct, but it seems to change the PORT to D. I also change all the tris statements to PORTD. I have tried to run a unmodified version of LCD.c on port B, but I get the same result.
I have checked my wiring, and it all looks good.
Anyone have any ideas??
Thanks, Mark |
|
![](templates/subSilver/images/spacer.gif) |
coast
Joined: 03 Jan 2008 Posts: 6 Location: WALDERSLADE, KENT,UK
|
pic4550 |
Posted: Sun Jan 06, 2008 8:24 am |
|
|
Ya need to read page 120 of the data sheet. The hidden subtlety is you need to explicitly ensure that the enhanced PWM is off and the streaming parallel port stuff. Don't just hope!! The former point also applies when using pic16f690 and probably a few other micros. It "had us going" for a while here too.
If you have any experience in converting pic18 c progs to ccs c....please reciprocate by posting a reply to my question on the forum. |
|
![](templates/subSilver/images/spacer.gif) |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Sun Jan 06, 2008 4:05 pm |
|
|
Hi Coast, I added the following line to my code
Code: |
SETUP_ADC_PORTS(NO_ANALOGS);
setup_psp(PSP_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
|
unfortunately, LCD still will not initialize. Is there anything else I should add to my code that I have missed??
Thanks, Mark |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 06, 2008 4:13 pm |
|
|
Quote: | #include <LCD420.c>
In LCD.c, all I change is “#byte lcd = 6” to “#byte lcd = 8” not sure if
that is correct, but it seems to change the PORT to D. I also change all
the tris statements to PORTD. I have tried to run a unmodified version of
LCD.c on port B, but I get the same result. |
Your code is using LCD420.c, which is for a 20x4 character LCD module.
But in your post, you continually refer to "LCD.c", which is for a 16x2 LCD.
Which LCD type is really installed on your board ?
2nd thing: You're using an 18F PIC. The register addresses are not
the same as in the 16F PICs. Download the 18F4550 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf
Look in this section of the data sheet, on page 68 in the Acrobat Reader:
Quote: | 5.3.5 SPECIAL FUNCTION REGISTERS |
There is a table that shows the addresses of all the registers. Find the
correct address for Port D and put it into the #byte statement, instead
of the "8" that you used for the 16F PIC. |
|
![](templates/subSilver/images/spacer.gif) |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Sun Jan 06, 2008 5:30 pm |
|
|
PCM, you really are a champ. It was simply that the port address is different in the PIC18 chips.
Funny thing is, I did not check it because when i changed “#byte lcd = 6” to “#byte lcd = 8”, the Proteus simulation did show that the output port was changing, eg if i had "byte lcd = 8", then PortD would be active. I guess this will teach me to look at the data sheet before starting the project.
Once again, Thank you very much
Mark |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|