Having problems again,
Decided in the end it was best to stick with the KS0108 LCD, i was using a 16f877 for my project but have filled the chip and need loads more space.
So i decided to go for the 18f4685 loads of room in the same 40pin DIL package.
I changed the PIC in the Chip, Target menu to the 18f4685, just to make sure everything was ok i programmed my chip and tried it, to my dissapointment it didnt work as expected.
it looks like jargon on the screen, random pixels. Also its copied twice.
Just to make sure its not me i tried the LCD speed test, it displays and flashes on/off, but again i have a copy of the x creating a diamond shape in the middle of the LCD.
Using the 16f877 with all the same code (just configured for 877) it works no problem, but with the 4685 it refuses to.
I have tried looking in the config menu and the only thing i can see to affect it is the ADC on port B, which i set to I/O as my LCD data lines are on that port, instruction lines are on port D.
Have i missed something here??
Help with pic18f4685 + LCD
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Help with pic18f4685 + LCD
Have you got the config set up with the correct clocking options? This is a common issue with 18F devices.
Writing a simple LED-flasher program will allow you to be certain that your config options are correct.
Writing a simple LED-flasher program will allow you to be certain that your config options are correct.
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: Help with pic18f4685 + LCD
Hi Steve
Thanks for your reply, The timing options appear to be ok, in that the program is running and doing as it should (sort of) i have it set as HS with 20mhz xtal.
is there a particular part of the config i should be paying attention to??
Thanks for your reply, The timing options appear to be ok, in that the program is running and doing as it should (sort of) i have it set as HS with 20mhz xtal.
is there a particular part of the config i should be paying attention to??
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Help with pic18f4685 + LCD
Hello,
Are you using the beta custom component or are you trying to use the Flowcode LCD component? If you are trying to use the standard LCD component then this will only work with alphanumeric type LCDs. The custom component for the KS0108 LCD is available from here.
http://www.matrixmultimedia.com/Flowcode_Components.php
Seeing that youve had this working on a 877 is seems that you must be using the custom component.
Try entering the following C code into a C icon at the start of main and see if this helps at all.
adcon0 = 0x3C;
adcon1 = 0x0F;
cmcon = 0x07;
If these don't help then can you try changing ports or are your connections hard wired? Maybe worth creating a basic program to toggle the I/O and ensure that all the pins are toggling as expected. Eg if you find the CAN pins or other pins are not toggling then the peripheral may be active or the pin may be blown etc.
A few config settings to try,
Extended CPU - Disabled
Watchdog Timer - Disabled
LVP - Disabled
Are you using the beta custom component or are you trying to use the Flowcode LCD component? If you are trying to use the standard LCD component then this will only work with alphanumeric type LCDs. The custom component for the KS0108 LCD is available from here.
http://www.matrixmultimedia.com/Flowcode_Components.php
Seeing that youve had this working on a 877 is seems that you must be using the custom component.
Try entering the following C code into a C icon at the start of main and see if this helps at all.
adcon0 = 0x3C;
adcon1 = 0x0F;
cmcon = 0x07;
If these don't help then can you try changing ports or are your connections hard wired? Maybe worth creating a basic program to toggle the I/O and ensure that all the pins are toggling as expected. Eg if you find the CAN pins or other pins are not toggling then the peripheral may be active or the pin may be blown etc.
A few config settings to try,
Extended CPU - Disabled
Watchdog Timer - Disabled
LVP - Disabled
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: Help with pic18f4685 + LCD
Hi Benj
What do these do exactly???
adcon0 = 0x3C;
adcon1 = 0x0F;
cmcon = 0x07;
i added them in as you said and it works a treat, im am now a happy person.
What do these do exactly???
adcon0 = 0x3C;
adcon1 = 0x0F;
cmcon = 0x07;
i added them in as you said and it works a treat, im am now a happy person.
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: Help with pic18f4685 + LCD
ok narrowed this down a bit more, learning more and more every day.
this is what i think these mean...
adcon0 = 0x3C; (set all ADC to unassigned)
adcon1 = 0x0F; (set all pins to Digital I/O
cmcon = 0x07; ( turn off comparator)
just to see which was causing the problem i deleted them one by one from the c box, the only one to cause a problem being removed is "cmcon = 0x07" how does this cause problems??? and how does turning it off fix the problem??
this is what i think these mean...
adcon0 = 0x3C; (set all ADC to unassigned)
adcon1 = 0x0F; (set all pins to Digital I/O
cmcon = 0x07; ( turn off comparator)
just to see which was causing the problem i deleted them one by one from the c box, the only one to cause a problem being removed is "cmcon = 0x07" how does this cause problems??? and how does turning it off fix the problem??
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Help with pic18f4685 + LCD
Hello,
Great thanks for letting me know its working for you now. I thought it was a bit of a long shot as the current FCDs should call the cmcon line of code automatically in the background. Maybe you are using a slightly older version. Which version of Flowcode are you running?
Basically when the chip resets the comparitor pins are automatically set to analogue mode meaning the digital I/O functionality is disabled. Calling the line of code turns off the comparitor and sets the associated I/O back to standard digital functionality.
Great thanks for letting me know its working for you now. I thought it was a bit of a long shot as the current FCDs should call the cmcon line of code automatically in the background. Maybe you are using a slightly older version. Which version of Flowcode are you running?
Basically when the chip resets the comparitor pins are automatically set to analogue mode meaning the digital I/O functionality is disabled. Calling the line of code turns off the comparitor and sets the associated I/O back to standard digital functionality.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: Help with pic18f4685 + LCD
Hi Benj,
The image might be a bit more than i can do at the moment. Think ill just draw the image using line command.
I am having another tiny problem, when creating variables to make a number increase or decrease, the number displays ok, but when it gets to 10 it just displays a 1 and for 100 it displays a 10 all other for 1000 you get 100, havnt been any further than that.
Is there a reason for this to happen??
Im using the KS0108 file from your website if you need to look at the file im using
The image might be a bit more than i can do at the moment. Think ill just draw the image using line command.
I am having another tiny problem, when creating variables to make a number increase or decrease, the number displays ok, but when it gets to 10 it just displays a 1 and for 100 it displays a 10 all other for 1000 you get 100, havnt been any further than that.
Is there a reason for this to happen??
Im using the KS0108 file from your website if you need to look at the file im using
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: Help with pic18f4685 + LCD
dont worry i figured it out, in the custom.c file im using it says the following:
/*Macro_LCD_Print_Number_Start*/
char string_length;
if (Number < -10000 )
string_length = 6;
else if(Number > 10000 || Number < -1000)
string_length = 5;
else if(Number > 1000 || Number < -100)
string_length = 4;
else if(Number > 100 || Number < -10)
string_length = 3;
else if(Number > 10 || Number < -1)
string_length = 2;
else
string_length = 1;
char temp_str[6];
you IF commands are stating that the string only increases in length AFTER the number has passed 10,100,100,10000
i changed all these to 9,99,999,9999 and it now works spot on. i guess you could also use >= to solve the problem too.
/*Macro_LCD_Print_Number_Start*/
char string_length;
if (Number < -10000 )
string_length = 6;
else if(Number > 10000 || Number < -1000)
string_length = 5;
else if(Number > 1000 || Number < -100)
string_length = 4;
else if(Number > 100 || Number < -10)
string_length = 3;
else if(Number > 10 || Number < -1)
string_length = 2;
else
string_length = 1;
char temp_str[6];
you IF commands are stating that the string only increases in length AFTER the number has passed 10,100,100,10000
i changed all these to 9,99,999,9999 and it now works spot on. i guess you could also use >= to solve the problem too.