PIC18F25K22 & 2 x 20 LCD

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
Hi.

Has anybody seen this on their LCD display?

I'm working through the Hi Tech C PIC18 sample files, and trying to display some text. But all I get is this. :(

lcd.txt = lcd.c
lcd-h.txt = lcd.h

MPLAB 8.63
Hi tech C PIC18 (lite mode) V9.80
PIC 18F25K22
 

Attachments

spinnaker

Joined Oct 29, 2009
7,830
Usually means not initialized correctly.

Have you confirmed all of your connections by stepping through the code and confirming the correct data is arriving at the LCD?

Also could be your timing delays are not correct.
 

be80be

Joined Jul 5, 2008
2,072
How did you set up the oscillator
you have a #define _XTAL_FREQ 4000000

If your using PLL it's not set up in code
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
Usually means not initialized correctly.

Have you confirmed all of your connections by stepping through the code and confirming the correct data is arriving at the LCD?

Also could be your timing delays are not correct.
As far as I can see, all the EN, RS and R/W's are connected correct, same goes for datalines. But I can always check again. :)

How did you set up the oscillator
you have a #define _XTAL_FREQ 4000000

If your using PLL it's not set up in code
I know the best practice is to have the Configuration Bits set in code, but here they are in MPLAB. I've used internal oscillator.

On a later stage, they will end up in the code.
 

be80be

Joined Jul 5, 2008
2,072
Like I said you defined 40mhz
I've used internal oscillator
That's not happening with that chip Pll is times 4

So you set the osccon to one of these
16 x4 = 64mhz
8 x 4 = 32mhz
4 x 4 = 16 mhz
You get the idea it goes lower

There is no 40 mhz and the OSC will not run with out you setting the OSCCON in code
now if you where to use a 10mhz crystal you can get 40mhz

Put this in your code
Rich (BB code):
#define _XTAL_FREQ 6400000
OSCCON = 0x73  'for 16mhz intosc
 
Last edited:

t06afre

Joined May 11, 2009
5,934
Jens From your code it looks like you are writing the nibbles in wrong order. As the example is made for using the 4 lower bits of the port. try this instead
Rich (BB code):
/* send data to the LCD */
void
lcd_data(unsigned char c) {
 LCD_WAIT; // may check LCD busy flag, or just delay a little, depending on lcd.h
 LCD_DATA = 0;
 LCD_RS = 1;
 if (fourbit) {
   LCD_DATA = c &0xF0; 
   LCD_STROBE();
   LCD_DATA = ( ( c << 4 ) & 0xF0 );      
   LCD_STROBE();
 } else {
  LCD_DATA = c;
  LCD_STROBE();
 }
 LCD_RS = 0;
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
Jens From your code it looks like you are writing the nibbles in wrong order. As the example is made for using the 4 lower bits of the port. try this instead
Now it looks like this:

Did I miss a 0 sorry but it's still the same if you don't set the OSCCON the chips oscillator will not run

Been there and done that. There is no default setting like some chips have

And I ask if you where using PLL
I've added the 64000000 and the OSCON. It looks like in the picture...
PLL? No, I don't think so...
 

Attachments

be80be

Joined Jul 5, 2008
2,072
I'll test your code on hardware when I get home and see whats going on here

You have to turn pll on in the configure word PLLCFG: 4 x PLL Enable bit
and the osccon setting I posted should work at 64 mhz with pll and you Lcd should work
You used the standard LCD library that came with Hi-Tech
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
I'll test your code on hardware when I get home and see whats going on here

You have to turn pll on in the configure word PLLCFG: 4 x PLL Enable bit
and the osccon setting I posted should work at 64 mhz with pll and you Lcd should work
You used the standard LCD library that came with Hi-Tech
I found the setting you were talking about just now. It was on "Oscillator used directly".

I'll change it and try again.

Yes, it is a pretty std LCD, and the LCD code found in the Hi Tech sample folder under PIC18.

Thanks.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
With this:

Rich (BB code):
OSCCON = 0x73
I cannot compile the program. I get an error message referring to the file PIC18F25K22.h, line 5894.

Executing: "C:\Programfiler\HI-TECH Software\PICC-18\9.80\bin\picc18.exe" --pass1 "example.c" -q --chip=18F25K22 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Warning [374] example.c; 16.8 missing basic type; int assumed
Error [984] example.c; 16.8 type redeclared
Error [1098] example.c; 16.8 conflicting declarations for variable "OSCCON" (C:\Programfiler\HI-TECH Software\PICC-18\9.80\include\pic18f25k22.h:5894)
Error [195] example.c; 20.1 expression syntax
Error [194] example.c; 23.10 ")" expected
Error [984] example.c; 23.32 type redeclared
Error [1098] example.c; 23.32 conflicting declarations for variable "lcd_puts" (C:\users\jens\Skrivebord\Delt Mappe\18F25K22\LCD\lcd.c:122)
Error [285] example.c; 25.1 no identifier in declaration
Warning [374] example.c; 25.1 missing basic type; int assumed
Error [314] example.c; 25.1 ";" expected
Error [285] example.c; 25.8 no identifier in declaration
Warning [374] example.c; 25.8 missing basic type; int assumed
Error [314] example.c; 25.8 ";" expected
Error [285] example.c; 26.1 no identifier in declaration
Warning [374] example.c; 26.1 missing basic type; int assumed
Error [314] example.c; 26.1 ";" expected
file pic18f25k22 line 5894. (Extern volatile is line 5894)
extern volatile unsigned char OSCCON @ 0xFD3;
#ifndef _LIB_BUILD
asm("OSCCON equ 0FD3h");
#endif
// bitfield definitions
extern volatile union {
struct {
unsigned SCS :2;
unsigned HFIOFS :1;
unsigned OSTS :1;
unsigned IRCF :3;
unsigned IDLEN :1;
};
struct {
unsigned SCS0 :1;
unsigned SCS1 :1;
unsigned IOFS :1;
unsigned :1;
unsigned IRCF0 :1;
unsigned IRCF1 :1;
unsigned IRCF2 :1;
};
} OSCCONbits @ 0xFD3;
Further more I get an error on lcd.c line 122, the lcd_puts function..

I've checked the box in the Configuration Bits window that says: "Configuration Bits set in code."
And I've added this line:

Rich (BB code):
#pragma config IESO = OFF, FOSC = INTIO67, PRICLKEN = OFF, PLLCFG = ON
But still nothing.
 

be80be

Joined Jul 5, 2008
2,072
Are you using a boot loader? for get this part

And start here
Here the whole thing it should work out of the box unzip it and open with MPLAB
if you put it on C/ that's where I built it

I set the configure in MPLAB to use 4mhz OSC no pll
 

Attachments

Last edited:

spinnaker

Joined Oct 29, 2009
7,830
My advice is first make sure you are getting what you are getting with your OSC settings.

You can do this pretty easily with the simulation mode and the stop watch utility and a test program using your delay functions.

Once you have that nailed down, create a small test program that toggles each bit one at a time (RS, E, D4-D7 etc). Use a scope, logic analyzer, logic probe whatever to verify each bit.
 

spinnaker

Joined Oct 29, 2009
7,830
With this:

Rich (BB code):
OSCCON = 0x73
I cannot compile the program. I get an error message referring to the file PIC18F25K22.h, line 5894.



file pic18f25k22 line 5894. (Extern volatile is line 5894)


Further more I get an error on lcd.c line 122, the lcd_puts function..

I've checked the box in the Configuration Bits window that says: "Configuration Bits set in code."
And I've added this line:

Rich (BB code):
#pragma config IESO = OFF, FOSC = INTIO67, PRICLKEN = OFF, PLLCFG = ON
But still nothing.
What line is 5894? Which is 122? And you have a lot more errors that that, it looks like.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
Are you using a boot loader? for get this part

And start here
Here the whole thing it should work out of the box unzip it and open with MPLAB
if you put it on C/ that's where I built it

I set the configure in MPLAB to use 4mhz OSC no pll
Thanks. I do not use a boot loader. Is that the problem?
I'll try the code when I get home from work.

What line is 5894? Which is 122? And you have a lot more errors that that, it looks like.
This is line 5894:

Rich (BB code):
extern volatile unsigned char OSCCON @ 0xFD3;
The rest of the errors are coming from the OSCCON error initially.
Line 122 in LCD.C is the start on the lcd_puts function.

He left the LCD.C file out is why he got the errors
I tried with and without
Rich (BB code):
#include "lcd.c"
Thanks guys, I'll try the code, setup later today, and I'll go over the wiring for the n'th time. :)
 

be80be

Joined Jul 5, 2008
2,072
Well your not alone I tried it on hardware I'm getting the samething I've used Hi-Tech for the 10-12-16F chips and the LCD Library worked fine.

And I no what it takes to use the 18f25k22 I use Swordfish for the 18f chips and have set the OSC up to run at any speed.

It's not using the delay code
 
Thread starter Similar threads Forum Replies Date
nerdegutta Microcontrollers 4
Similar threads
PIC18F25K22 & ADC problem
Top