CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

LCD failure to display content with 18f4550

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
colesha



Joined: 09 Jan 2012
Posts: 45

View user's profile Send private message Send e-mail

LCD failure to display content with 18f4550
PostPosted: Sat Nov 28, 2020 3:11 pm     Reply with quote

Hello,
am failing to display contents on the lcd using the 18f4550. The other programs run well like, if i want to blink a led, push buttons, all work fine. The two LCDs work fine with the audrino , but can not work on my pic. Where could i hve gone wrong?

here is a sample code and my LCD configuration

Code:

// Interfacing PIC18F4550 with LCD display CCS C code
 
//LCD module connections
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_ENABLE_PIN PIN_D2
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
//End LCD module connections
 
#include <18F4550.h>
#fuses NOMCLR INTRC_IO
#use delay(clock=8000000)
#include <lcd.c>
 
char i;
void main(){
  setup_oscillator(OSC_8MHZ);       // Setup internal oscillator @ 8MHz
  lcd_init();                       // Initialize LCD module
  lcd_gotoxy(2, 1);                 // Go to column 2 row 1
  lcd_putc("PIC18F4550");
  lcd_gotoxy(1, 2);                 // Go to column 1 row 2
  lcd_putc("LCD example");
  for(i = 0; i < 2; i++){           // Shift display right 2 times
    delay_ms(200);
    lcd_send_byte(0,0x1E);
    }
    OUTPUT_HIGH(PIN_C5);
  delay_ms(5000);
  for(i = 0; i < 14; i++){           // Shift display right 14 times
    delay_ms(200);
    lcd_send_byte(0,0x1E);
    }
  lcd_putc('f');                    // LCD clear
  lcd_gotoxy(18, 1);                 // Go to column 18 row 1
  lcd_putc("Hello world!");
  lcd_gotoxy(17, 2);                 // Go to column 17 row 2
  lcd_putc("Have a nice day");
  for(i = 0; i < 15; i++){           // Shift display left 15 times
    delay_ms(200);
    lcd_send_byte(0,0x18);
    }
  delay_ms(5000);
  lcd_putc('f');                    // LCD clear
  lcd_gotoxy(3, 1);                  // Go to column 3 row 1
  lcd_putc("Hello world!");
  i = 0;
  while(TRUE){
    if(input(PIN_C0) == 0){
      i++;
      if(i > 100)
        i = 0;
      lcd_gotoxy(7, 2);              // Go to column 7 row 2
      printf(lcd_putc,"%3u",i);      // Write i with 3 numbers max
      delay_ms(200);
      }
    }
}


I have spent some time on this, could anyone please help out?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 28, 2020 3:32 pm     Reply with quote

Had a quick look at the datasheet...
it's been years since I used it...
just a guess... as nothing obvious jumps out..

Those pins are also used with the 'Streaming Parallel Port', so you may have to disable that peripheral first.

I haven't used 'lcd.c' in years either, prefer the 'flex_lcd.c' version of the driver.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 28, 2020 7:04 pm     Reply with quote

One obvious mistake is this:
Quote:
lcd_putc('f');

The lcd.c file says this at the top:
Quote:

lcd_putc(c) Will display c on the next position of the LCD.

\a Set cursor position to upper left
\f Clear display, set cursor to upper left
\n Go to start of second line
\b Move back one position

If you want to clear the screen, do it like this, with a backlash f:
Code:
lcd_putc('\f');
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 29, 2020 6:13 am     Reply with quote

You may need to add a delay_ms(500); just after the lcd_init(); to allow the LCD module to properly reconfigure into 4bit mode and be 'ready'.
I don't know if lcd_init() of the lcd.c driver does wait before returning to main(). I 'think' flex_lcd.c does but since dayone I've always had a delay_ms(500); after the lcd_init() call... old habits die hard I suppose...


Also reduce code to a simple 'hello World'... get it working THEN add more messages...
makes it easier to debug !!
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Sun Nov 29, 2020 8:10 am     Reply with quote

Actually the delay needs to be before lcd_init.

It is common to need a delay here. There are two separate 'issues'. First,
the standard Hitachi chip needs 90mSec after power is applied before it
can accept commands. Most of the drivers do include this delay, but a lot
of the 'clone' controllers need more delay than this. The second reason,
is that the PIC often starts when the voltage is well below the voltage
needed to start the LCD's, so again more delay is needed.
colesha



Joined: 09 Jan 2012
Posts: 45

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 29, 2020 3:31 pm     Reply with quote

temtronic wrote:
Had a quick look at the datasheet...
it's been years since I used it...
just a guess... as nothing obvious jumps out..

Those pins are also used with the 'Streaming Parallel Port', so you may have to disable that peripheral first.

I haven't used 'lcd.c' in years either, prefer the 'flex_lcd.c' version of the driver.

Jay


Thanks, How do u disable SSP?
i have tried using the flec lcd too and a simple hello. but all in vane
colesha



Joined: 09 Jan 2012
Posts: 45

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 29, 2020 3:40 pm     Reply with quote

Ttelmah wrote:
Actually the delay needs to be before lcd_init.

It is common to need a delay here. There are two separate 'issues'. First,
the standard Hitachi chip needs 90mSec after power is applied before it
can accept commands. Most of the drivers do include this delay, but a lot
of the 'clone' controllers need more delay than this. The second reason,
is that the PIC often starts when the voltage is well below the voltage
needed to start the LCD's, so again more delay is needed.


I will do that in the morning, add a delay and use the flex lcd driver. Also i witl try out other ports and a standby Pic.
colesha



Joined: 09 Jan 2012
Posts: 45

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 29, 2020 3:42 pm     Reply with quote

PCM programmer wrote:
One obvious mistake is this:
Quote:
lcd_putc('f');

The lcd.c file says this at the top:
Quote:

lcd_putc(c) Will display c on the next position of the LCD.

\a Set cursor position to upper left
\f Clear display, set cursor to upper left
\n Go to start of second line
\b Move back one position

If you want to clear the screen, do it like this, with a backlash f:
Code:
lcd_putc('\f');


Thanks PCM,

Let me try with a simple code.

Is there any special way i should configure the PIC before using it, liking setting fuses etc?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 29, 2020 3:53 pm     Reply with quote

from the 4550 device header file...

// PSP Functions: SETUP_PSP, PSP_INPUT_FULL(), PSP_OUTPUT_FULL(),
// PSP_OVERFLOW(), INPUT_D(), OUTPUT_D()
// PSP Variables: PSP_DATA
// Constants used in SETUP_PSP() are:
#define PSP_ENABLED 0x10
#define PSP_DISABLED 0

#byte PSP_DATA= 0xF83

so something like ....

...
setup_psp(PSP_DISABLED);
...

..might work
however according to the datasheet, the default state is disabled. That doesn't mean that CCS' 'default' state is disabled, so better to be sure !

Jay
also the CCP uses some of that port, so try disabling it as well.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 29, 2020 5:27 pm     Reply with quote

CCS doesn't touch the streaming parallel port. So it's disabled on powerup
and it stays that way.
colesha



Joined: 09 Jan 2012
Posts: 45

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 30, 2020 5:05 am     Reply with quote

Hello,
For sure all not working, it's like the PIC is not communicating to the LCD. I am doing this on the breadboard. I am supplying both the VDD with 5V and both the VSS to ground. Pin MCLR through a resistor send 10k. I have chance the Flex lcd driver to use port B, tried a simple hello world program, but not displaying still.
Is my hardware connection fine? The connections are really firm on the breadboard.

I have used another new PIC as well.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 5:26 am     Reply with quote

hmm, post your 'hello World' program. I have a 46k22 running at 64MHz using the internal oscillator on a 20+year old breadboard with a 20x4 LCD , RTCEEP, DS18B20 as well as a USBTTL module plus a blinking 'I'm running' LED..so I KNOW it works....

Jay
colesha



Joined: 09 Jan 2012
Posts: 45

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 30, 2020 10:55 am     Reply with quote

temtronic wrote:
hmm, post your 'hello World' program. I have a 46k22 running at 64MHz using the internal oscillator on a 20+year old breadboard with a 20x4 LCD , RTCEEP, DS18B20 as well as a USBTTL module plus a blinking 'I'm running' LED..so I KNOW it works....

Jay


Hello, thanks for the response, here it is. I have also got a 20x4 LCD but yet to test it, when i reach home. This is for the 20x4 lcd:
Code:


//LCD Module Connections
#define LCD_RS_PIN      PIN_B1                                   
#define LCD_RW_PIN      PIN_B2
#define LCD_ENABLE_PIN  PIN_B0
#define LCD_DATA4       PIN_B4                                   
#define LCD_DATA5       PIN_B5                                   
#define LCD_DATA6       PIN_B6                           
#define LCD_DATA7       PIN_B7
//End LCD Module Connections

#include <18F4550.h>
#fuses NOMCLR NOBROWNOUT NOLVP INTRC_IO
#use delay (clock=8000000)
#include <lcd420.c>


void main()
{
   lcd_init();
   setup_oscillator(OSC_8MHZ);                    // Set the internal oscillator to 8MHz
   Delay_ms(500);
 
     lcd_putc('\f'); //Clear Display
     lcd_gotoxy(1,1);
     lcd_putc("Hello World");
     lcd_gotoxy(1,2);
     lcd_putc("Welcome To");
     lcd_gotoxy(1,3);
     lcd_putc("LCD Library");
   while(TRUE)
   { 
   }
}


for the pic, do i have to connect the LCD RW pin to ground? same for D0-D3? Is it mandatory?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 30, 2020 11:28 am     Reply with quote

1) connect the LCD_RW pin to the PIC B2 pin, as shown in the LCD module connections at the top of your program. This connection allows the PIC to both write to the LCD as well as read from it. The 'driver' may allow for the option of 'write only', however the actual update of LCD will be slower as the 'ready' bit isn't polled so fixed delays are usually used.

2) regarding D0...D3, that depends upon the make/model of the LCD module. The ones I use, I can leave 'floating' or not connected. The LCD module datasheet should explain the required connection for 4bit mode vs 8bit mode.

3) There is a 'contrast' pin, usually pin 3 of the LCD module and it is critical that it's properly connected. Typically it needs about 0.5v, though, again, check the datasheet. Some pre-made modules have a pot to allow you to adjust the voltage for best 'contrast'.
colesha



Joined: 09 Jan 2012
Posts: 45

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 01, 2020 1:45 am     Reply with quote

Thanks Temtronic,

It has really worked, the issue was the LCD RW and Contrast pins. I had to connect the RW pin to the PIC instead of connecting it to the ground. I also connected the contrast through a 10K variable resistor.

Am now Happy.

Thanks for your support always.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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