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 support@ccsinfo.com

LCD 16x2 interfacing with PIC18F4550

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



Joined: 04 Feb 2012
Posts: 20

View user's profile Send private message

LCD 16x2 interfacing with PIC18F4550
PostPosted: Sat Feb 04, 2012 1:58 am     Reply with quote

I'm new one here. Hope can obtain gurus help..
I intend to show character on the display on LCD 16x2. But I failed. I have read many regarding posts in this ccs forum, first time i just using lcd.c, but it seemed not to be worked. My LCD just showed all black boxes in first line, probably the initialization not going to work.

Then, i copy the code of flex.lcd.c in the ccs forum posts. I changed the pins for my board as follow:

Code:

#define LCD_DB1   PIN_D1
#define LCD_DB2   PIN_D2
#define LCD_DB3   PIN_D3
#define LCD_DB4   PIN_D4
#define LCD_DB5   PIN_D5
#define LCD_DB6   PIN_D6
#define LCD_DB7   PIN_D7

#define LCD_E     PIN_B5
#define LCD_RS    PIN_B4
#define USE_LCD_RW   1 
#define LCD_RW    USE_LCD_RW



the LCD_RW have been connected to ground. Is there any problems if I define so?

The following is the coding, just follow the previous ccs forum posts:


Code:

#include <18F4550.h>
#fuses NOWDT, HS, NOPROTECT, NOPUT
#use delay(clock=20M, crystal)
#include <stdlib.h>
#include "flex_lcd.c"

void main()
{
   lcd_init();
   lcd_putc("Hello World\n");
   lcd_putc("Line Number2");
   delay_ms(20);
   
   while(TRUE);
}


Although the black boxes in the first line have been disappeared, but my LCD is still unable to show out the message, it is just blank...>.<..Hope gurus here can help me.
Jent



Joined: 04 Feb 2012
Posts: 20

View user's profile Send private message

PostPosted: Sat Feb 04, 2012 2:19 am     Reply with quote

One more thing, i read the PIC18F4550 datasheet, it mentioned that PortB can be as analog pins or digital pins.

But at default they are analog pins. Since my PIC kit uses the RB4 for RS of LCD and RB5 for E of LCD...

If required to make these pins to digital, it has to disable PBADEN configuration bits.. Then how can be done in CCS C compiler?
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Sat Feb 04, 2012 3:02 am     Reply with quote

If you have LCD R/W tied to ground, you need to get _rid_ of the definitions:

#define USE_LCD_RW 1
#define LCD_RW USE_LCD_RW

The second is wrong anyway.
You #define 'USE_LCD_RW', if you are connecting the R/W pin. If not, don't define it.
Then if using a pin, LCD_RW, needs to be set to the pin number.
So with your line wired low, you must get rid of these lines.

Then in your fuses you need to add 'NOPBADEN' which says 'don't default to using the ADC on port B.

Best Wishes
Jent



Joined: 04 Feb 2012
Posts: 20

View user's profile Send private message

PostPosted: Sat Feb 04, 2012 3:34 am     Reply with quote

But if didn't define for #define LCD_RW, this may cause errors in flex.lcd.c
Sad

3 errors: Undefined identifier LCD>RW

no matter how i change and edit, still the same...black boxes disappeared, but without showing any characters, just blank..
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Sat Feb 04, 2012 3:46 am     Reply with quote

_Read_the text at the top of the flex_lcd driver.

If you get rid of the #define USE_LCD_RW, the code should not talk to the LCD R/W line at all.
Jent



Joined: 04 Feb 2012
Posts: 20

View user's profile Send private message

PostPosted: Sat Feb 04, 2012 4:03 am     Reply with quote

How to get rid? I don't too understand. Since there are some codings in flex_lcd.c are related to LCD_RW...if i didn't define it, errors appeared.
Jent



Joined: 04 Feb 2012
Posts: 20

View user's profile Send private message

PostPosted: Sat Feb 04, 2012 4:20 am     Reply with quote

Thanks so much. I just deleted the USE_LCD_RW. Finally I got the characters I want. Thank you so much...^.^
mateeb4u@gmail.com



Joined: 07 Feb 2012
Posts: 19
Location: pakistan

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

LCD Working Code
PostPosted: Mon Feb 20, 2012 7:15 am     Reply with quote

Code:

#include<18F452.h>
#use delay(clock = 4000000)
//#use I2C(MASTER, SDA=PIN_B1, SCL=PIN_B0,FAST=400000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#fuses NOWDT,NOPROTECT,NOLVP,XT
#define EN PIN_C7
#define RW PIN_C6
#define RS PIN_C5
unsigned char we[10]= "PIC LCD:";


void delay()
{
 long i;
for( i=0;i<=6555;i++)
{}
}

void interface()
{
 output_b(0x3c);
 
 output_bit(EN,1);
 output_bit(RS,0);
 output_bit(RW,0);
 delay();
 output_bit(EN,0);
}
void DISPLAY_CURSOR()
{
 output_b(0x08);
 output_bit(EN,1);
 output_bit(RS,0);
 output_bit(RW,0);
 delay();
 output_bit(EN,1);
}
void clear_display()
{
 output_b(0x01);
 output_bit(EN,1);
 output_bit(RS,0);
 output_bit(RW,0);
 delay();
 output_bit(EN,0);
}
void blink()
{
 output_b(0x0f);
 output_bit(EN,1);
 output_bit(RS,0);
 output_bit(RW,0);
 delay();
 output_bit(EN,0);
}
void home ()
{
 output_b(0x02);
 output_bit(EN,1);
 output_bit(RS,0);
 output_bit(RW,0);
 delay();
 output_bit(EN,0);
}


void lcd(unsigned char ch)
{
 output_b(ch);
 output_bit(RS,1);
 output_bit(RW,0);
 output_bit(EN,1);
 delay();
 output_bit(EN,0);
}




void main (void)
{
int i,j,count;
for(i=0;i<3;i++)
     {
     interface();
     delay();
     }
     DISPLAY_CURSOR();
     delay();
     clear_display();
     delay();
     blink();
     delay();
     home ();
     delay();
     for(j=0;j<10;j++)
     {
    
     lcd(we[j]);
//printf("char=%c",we[j]);
     delay();
     count=count+1;
     if(count==16)
     {
     clear_display();
     count=0;
     }
     }
   

}




   
   
   
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