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

Problem with lcd and 18f2550

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



Joined: 13 May 2013
Posts: 10

View user's profile Send private message

Problem with lcd and 18f2550
PostPosted: Mon May 13, 2013 10:30 am     Reply with quote

I'm going to crazy! Please help me guys!
I have an 1602 lcd connected to 18f2550 pic with this pinout:
pic is connect to 20mhz crystal


test di fr3nsis, su Flickr

gnd
5v
vo to 10k trimmer
rs to Ra5
r/w to gnd
e to Ra4 (that have 10k pull up resistor)
db0-1-2-3 to gnd
db4 to ra3
db5 to ra2
db6 to ra1
db7 to ra0

Without lcd code board work fine, with it stop to work.
I try also to connect e and rs ro portb but no luck.

This is my code using flex_lcd.c:
Code:

void main()
{

setup_timer_1 ( T1_DISABLED );
setup_vref(FALSE);

SETUP_SPI(SPI_DISABLED);
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_ccp1 (CCP_OFF);
setup_ccp2 (CCP_OFF);
setup_comparator(NC_NC_NC_NC);
lcd_init();
lcd_putc("\fCREDITI  INSUFF.");

   while(TRUE)
   {
     output_high(PIN_C1);
     delay_ms(2000);
     output_low(PIN_C1);
      delay_ms(2000);
   }

}



Code:
// flex_lcd.c

// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver.  Change these
// pins to fit your own board.

#define LCD_DB4   PIN_a3
#define LCD_DB5   PIN_a2
#define LCD_DB6   PIN_a1
#define LCD_DB7   PIN_a0

#define LCD_E     PIN_a4
#define LCD_RS    PIN_a5
#define LCD_RW    PIN_A2

// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.

#define USE_LCD_RW   1
.........


Code:
#include <18LF2550.h>
#device adc=16

#fuses HSPLL,NOMCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN


#use delay(crystal=48000000)
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon May 13, 2013 10:51 am     Reply with quote

Have you read what this says?....
Code:

// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.

//#define USE_LCD_RW   1


Note the change.

Best Wishes
fr3nsis



Joined: 13 May 2013
Posts: 10

View user's profile Send private message

PostPosted: Mon May 13, 2013 11:08 am     Reply with quote

Rw is connected to ground so must be
#define USE_LCD_RW 1
or i'm wrong?
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon May 13, 2013 11:17 am     Reply with quote

You are wrong. Read what it says...
You must _comment out the following line_.
Unless the line is commented out, the code tries to use R/W, and since it is not connected, it'll wait forever.

Best Wishes
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon May 13, 2013 11:21 am     Reply with quote

Note that the LCD's are funny creatures and you may need to play with the "init" a bit. Usually, you need a delay before init (after coming out of reset) then you need a delay after init before you can send data to it or it simply ignores you. Check the spec sheet for your display for the delay times (I have also found that sometimes the needed delay is even longer than specified for surplus parts).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
fr3nsis



Joined: 13 May 2013
Posts: 10

View user's profile Send private message

PostPosted: Mon May 13, 2013 12:35 pm     Reply with quote

Connecting e and rs to portb led blinks but no char on lcd.
Connecting e and rs to porta like before led wont blink.
I don't understand why...
I have also added 5 seconds before and after lcd_init.
Confused
temtronic



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

View user's profile Send private message

PostPosted: Mon May 13, 2013 2:39 pm     Reply with quote

hmmm...LCD db0...3 are grounded ?(in original post).

I've always just let them 'float'(ie: no connection).

I know the flex_lcd driver works.....
...squares on LCD is a good sign..

Maybe post your current version of program, maybe 'something' got edited by mistake.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon May 13, 2013 2:49 pm     Reply with quote

You are not disabling Timer0, so RA4 will be the timer0 clock input (this is the default on power on). You don't need a pull up on RA4, on this chip the pin can pull up as well as down.
The clock statement should really say _clock=48000000_, not crystal. Your crystal is (hopefully) 20Mhz.
Are you sure you have got the DB4 to DB7 lines reversed as you show?.
Where did you get the define 'SPI_DISABLED' from?. It is not a standard one for the compiler. The normal syntax is:

setup_spi(FALSE);

If you have re-labelled the SPI_SS_DISABLED define, this turns the SPI _on_.....

Best Wishes
fr3nsis



Joined: 13 May 2013
Posts: 10

View user's profile Send private message

PostPosted: Tue May 14, 2013 1:12 am     Reply with quote

Ttelmah wrote:
You are not disabling Timer0, so RA4 will be the timer0 clock input (this is the default on power on). You don't need a pull up on RA4, on this chip the pin can pull up as well as down.
The clock statement should really say _clock=48000000_, not crystal. Your crystal is (hopefully) 20Mhz.
Are you sure you have got the DB4 to DB7 lines reversed as you show?.
Where did you get the define 'SPI_DISABLED' from?. It is not a standard one for the compiler. The normal syntax is:

setup_spi(FALSE);

If you have re-labelled the SPI_SS_DISABLED define, this turns the SPI _on_.....

Best Wishes


thank so much


test ok di fr3nsis, su Flickr

Very Happy
david_bur_91



Joined: 25 Jun 2013
Posts: 2

View user's profile Send private message

I have got the same problem
PostPosted: Tue Jun 25, 2013 2:11 am     Reply with quote

here is my code:
Code:

#include <18F2550.h>
#device adc=10

#FUSES NOWDT,HS,NOPROTECT,NOBROWNOUT,PUT,NOCPD,STVREN,NODEBUG,NOLVP
#FUSES NOWRT,NOWRTD,IESO,FCMEN,PBADEN,NOWRTC,NOWRTB,NOEBTR,NOEBTRB,NOCPB,MCLR

#USE delay(clock=20000000)
#USE rtos(timer=0,minor_cycle=1ms)
#USE fast_io(b)
#INCLUDE <flex_lcd.c>
#INCLUDE <string.h>

void main()
{
   setup_spi(FALSE); 

   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   delay_ms(10000);
   lcd_init();
   set_tris_b(0xF0);
   delay_ms(10000);
}
david_bur_91



Joined: 25 Jun 2013
Posts: 2

View user's profile Send private message

solution
PostPosted: Tue Jun 25, 2013 3:14 am     Reply with quote

I have just found the solution.

I had conect lcd to pins RC4 and RC5.
I read in another post that canĀ“t be used as outputs or something like that, so I tried to change them to ports RC0 and RC1 and now works ok!!

delays before and after init of LCD was not the problem, it works correctly with a delay of 100 ms.

hope your answer.
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