View previous topic :: View next topic |
Author |
Message |
fr3nsis
Joined: 13 May 2013 Posts: 10
|
Problem with lcd and 18f2550 |
Posted: Mon May 13, 2013 10:30 am |
|
|
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
|
|
Posted: Mon May 13, 2013 10:51 am |
|
|
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
|
|
Posted: Mon May 13, 2013 11:08 am |
|
|
Rw is connected to ground so must be
#define USE_LCD_RW 1
or i'm wrong? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon May 13, 2013 11:17 am |
|
|
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
|
|
Posted: Mon May 13, 2013 11:21 am |
|
|
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
|
|
Posted: Mon May 13, 2013 12:35 pm |
|
|
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.
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Mon May 13, 2013 2:39 pm |
|
|
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
|
|
Posted: Mon May 13, 2013 2:49 pm |
|
|
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
|
|
Posted: Tue May 14, 2013 1:12 am |
|
|
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
|
|
|
david_bur_91
Joined: 25 Jun 2013 Posts: 2
|
I have got the same problem |
Posted: Tue Jun 25, 2013 2:11 am |
|
|
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
|
solution |
Posted: Tue Jun 25, 2013 3:14 am |
|
|
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. |
|
|
|