Im having a little problem with getting an LCD to work at all. I've been making myself a small development board just to play around with pic programming, as far as i can tell the LCD is connected correctly. The LCD is a N27AZ and states that it uses an HD44780 eqivalent driver.
The pic is an 16F872 and i've tried using it in both 4 bit and 8 bit modes (just in case) and the result was just black flashing blocks on the upper row of the display and a bit of gibberish from time to time.
I used the LCD demo program but with the following alterations to suit:
Update. Now I can consistently get gibberish, thinking as I wasnt sure the ports were being defined as outputs ive added that and a small delay so the program is now:
EDIT To above : i've still tried in 4 bit and 8 bit, in 4 bit i still just get black squares and in 8 bit i get a few bits of permanent gibberish still and nothing else
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well that's weird, the 16f872 is not getting initialized properly. GCBasic is forgetting to turn off the comparator module, maybe because its a midrange device with only one comparator? So change LCD_RW off PortC.2, to another pin. Or you can add this to your initialization code to turn off the comparator. Don't have the 16f872 datasheet downloaded, so you may have to check if this code will work.
movlw 7
movwf CCP1CON
Also, the lcd.h handles the port pin direction for you, and no real reason for the delay during the #defines.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Start:
PRINT "HELLO WORLD"
wait 2 s
cls
Goto Start
I've tried with/without the DIR PORTB / DIR PORTC as reading through other forum posts regarding LCD problems some have had success by trying this. However it doesnt seem so in this case. I've again tried this in 8 bit mode without success.
The board i've hooked up using RB0-7 connected to the LCD via a dip switch so i can disconnect/connect RB0-3 for 4 bit/8 bit. and the RS/RW/E are connected via port C (as you've probably noticed from the code anyway).
Cheers
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, just in case Ive tried connecting an LCD that i know definately works ok (tested on PC parallel port) and tried a different PIC 16F627 using this program:
yep i've used a pot and adjusted the contrast (on both displays) and get the same results, a few bits of odd gibberish or just black squares on the top row.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
EDIT: Again tried with different PIC & display, both in 4 or 8 bit modes, adjusted contrast in both modes with both displays and just black squares and nothing more, the second display is a different manufacturer and confirmed as working correctly, I've also tried downloading the update patch and installing to no avail and re-installing GCBASIC but with no success.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well there I go again. Going back to the 16f872, the data sheet says the CCP1CON register gets reset to '0' on power up and MCLR. So ignore the CLRF CCP1CON ; Turn CCP module off . Also not required for other processors.
Should use label and goto label in main program, like:
Start: ;or Main:
....
...
goto Start ;or goto Main
Have you got a simple flashing led going with your new board? It could be the external osc is not operating properly, do you have the required 20pf (approx.) caps to ground? Try the 16f627 4mhz internal osc with config INTRC_OSC_NOCLKOUT. Also check for any solder bridges, or shorts with DVM to adjacent pins.
Sometimes for me I have to do an MCLR reset on LCD setups, due to insufficient warmup, or some such thing. Tend to use the cls command very sparingly, because it needs 2 or 3 ms to perform this command, and will use the locate, and Print " " to format data instead.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had just written an entire essay, and had to delete it as it now works, I had checked and checked everything twice, only until I turned it over did I realise the problem...Thankyou to whoever it was to check the board, it is assembled on stripboard, a tiny piece of solder had got lodged the other side of the dip switch across 2 data lines...Doh
Thanks very much to everyone who has helped me out getting this working it has been greatly appreciated :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The weird thing is the one on the breadboard didnt work at all (even though I confirmed the display actually worked) only reason i can think of for that is that maybe the datasheet for it was wrong as the exact model was discontinued...live and learn I guess :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi there,
Im having a little problem with getting an LCD to work at all. I've been making myself a small development board just to play around with pic programming, as far as i can tell the LCD is connected correctly. The LCD is a N27AZ and states that it uses an HD44780 eqivalent driver.
Link to datasheet
http://www.maplin.co.uk/Media/PDFs/N27AZ.pdf
The pic is an 16F872 and i've tried using it in both 4 bit and 8 bit modes (just in case) and the result was just black flashing blocks on the upper row of the display and a bit of gibberish from time to time.
I used the LCD demo program but with the following alterations to suit:
'LCD connection settings
#define LCD_IO 8
#define LCD_DATA_PORT PORTB
#define LCD_RS PORTC.1
#define LCD_RW PORTC.2
#define LCD_Enable PORTC.3
the rest remains as is in the demo file.
Any help or advice would be greatly appreciated.
Thanks in advance
Update. Now I can consistently get gibberish, thinking as I wasnt sure the ports were being defined as outputs ive added that and a small delay so the program is now:
'General hardware configuration
#chip 16F872, 4
#config XT_OSC, WDT_OFF, LVP_OFF
DIR PORTB OUT
DIR PORTC OUT
wait 2 s
'LCD connection settings
#define LCD_IO 4
#define LCD_DB4 PORTB.4
#define LCD_DB5 PORTB.5
#define LCD_DB6 PORTB.6
#define LCD_DB7 PORTB.7
#define LCD_RS PORTC.1
#define LCD_RW PORTC.2
#define LCD_Enable PORTC.3
cls
Start:
wait 2 s
PRINT "HELLO"
Goto Start
EDIT To above : i've still tried in 4 bit and 8 bit, in 4 bit i still just get black squares and in 8 bit i get a few bits of permanent gibberish still and nothing else
Well that's weird, the 16f872 is not getting initialized properly. GCBasic is forgetting to turn off the comparator module, maybe because its a midrange device with only one comparator? So change LCD_RW off PortC.2, to another pin. Or you can add this to your initialization code to turn off the comparator. Don't have the 16f872 datasheet downloaded, so you may have to check if this code will work.
movlw 7
movwf CCP1CON
Also, the lcd.h handles the port pin direction for you, and no real reason for the delay during the #defines.
O.K. have the 16f872 data sheet downloaded over dialup connection. One would want to clear the CCP1CON, so previous advice was wrong. Use:
CLRF CCP1CON ; Turn CCP module off
thanks for helping me out kent twt4, its greatly appreciated by a pic newbie :)
Still a No-Go, using the program listed below I just get a full row of black squares on the top LCD row
'General hardware configuration
#chip 16F872, 4
#config XT_OSC, WDT_OFF, LVP_OFF
CLRF CCP1CON ; Turn CCP module off
wait 1 s
DIR PORTB OUT
DIR PORTC OUT
'LCD connection settings
#define LCD_IO 4
#define LCD_DB4 PORTB.4
#define LCD_DB5 PORTB.5
#define LCD_DB6 PORTB.6
#define LCD_DB7 PORTB.7
#define LCD_RS PORTC.1
#define LCD_RW PORTC.2
#define LCD_Enable PORTC.3
cls
Start:
PRINT "HELLO WORLD"
wait 2 s
cls
Goto Start
I've tried with/without the DIR PORTB / DIR PORTC as reading through other forum posts regarding LCD problems some have had success by trying this. However it doesnt seem so in this case. I've again tried this in 8 bit mode without success.
The board i've hooked up using RB0-7 connected to the LCD via a dip switch so i can disconnect/connect RB0-3 for 4 bit/8 bit. and the RS/RW/E are connected via port C (as you've probably noticed from the code anyway).
Cheers
Just to be sure...
Have you adjusted contrast level?
OK, just in case Ive tried connecting an LCD that i know definately works ok (tested on PC parallel port) and tried a different PIC 16F627 using this program:
#chip 16F627, 4
#config XT_OSC, WDT_OFF, LVP_OFF
CLRF CCP1CON ; Turn CCP module off 'General hardware configuration
'LCD connection settings
#define LCD_IO 4
#define LCD_DB4 PORTB.4
#define LCD_DB5 PORTB.5
#define LCD_DB6 PORTB.6
#define LCD_DB7 PORTB.7
#define LCD_RS PORTB.1
#define LCD_RW PORTB.2
#define LCD_Enable PORTB.3
cls
Start:
PRINT "HELLO WORLD"
wait 2 s
cls
Goto Start
It's still producing just black squares and nothing else, any suggestions?
yep i've used a pot and adjusted the contrast (on both displays) and get the same results, a few bits of odd gibberish or just black squares on the top row.
EDIT: Again tried with different PIC & display, both in 4 or 8 bit modes, adjusted contrast in both modes with both displays and just black squares and nothing more, the second display is a different manufacturer and confirmed as working correctly, I've also tried downloading the update patch and installing to no avail and re-installing GCBASIC but with no success.
Hi vitesse...
I didn't try the LCD functions in GCBasic, but i think they work for other people... the only thing i can suggest is try with higher clock speeds.
I remenber some examples that did it with 20 MHz clock... may be that with only 4 MHz there are timing problems... i don't know, but is a posiblity...
Would I be right in thinking though that the 16F627 and the 16F872 both have a 4mhz clock only?
OK, ive altered it thusly:
'General hardware configuration
#chip 16F627, 20
#config HS_OSC, WDT_OFF, LVP_OFF
CLRF CCP1CON ; Turn CCP module off
'LCD connection settings
#define LCD_IO 4
#define LCD_DB4 PORTB.4
#define LCD_DB5 PORTB.5
#define LCD_DB6 PORTB.6
#define LCD_DB7 PORTB.7
#define LCD_RS PORTB.1
#define LCD_RW PORTB.2
#define LCD_Enable PORTB.3
cls
Start:
PRINT "HELLO WORLD"
wait 2 s
cls
Still getting black blocks.
Just to confirm ive connected the display correctly ive got:
Vss -> GND
Vdd -> 5V
V0 -> Pot between 5V and 0V rails
RS -> RB1
RW -> RB2
E -> RB3
DB7 -> RB7
DB6 -> RB6
DB5 -> RB5
DB4 -> RB4
as best I can tell, its hooked up properly?
Actually...ignore the above, just read the datasheet :P
Hi vitesse, i tried your code but with a pic16f628a
It works perfectly for me with 4 and 20 MHZ external clock and 4MHz internal clock.
I think you should look for a hardware o wiring error...
Well there I go again. Going back to the 16f872, the data sheet says the CCP1CON register gets reset to '0' on power up and MCLR. So ignore the CLRF CCP1CON ; Turn CCP module off . Also not required for other processors.
Should use label and goto label in main program, like:
Start: ;or Main:
....
...
goto Start ;or goto Main
Have you got a simple flashing led going with your new board? It could be the external osc is not operating properly, do you have the required 20pf (approx.) caps to ground? Try the 16f627 4mhz internal osc with config INTRC_OSC_NOCLKOUT. Also check for any solder bridges, or shorts with DVM to adjacent pins.
Sometimes for me I have to do an MCLR reset on LCD setups, due to insufficient warmup, or some such thing. Tend to use the cls command very sparingly, because it needs 2 or 3 ms to perform this command, and will use the locate, and Print " " to format data instead.
I had just written an entire essay, and had to delete it as it now works, I had checked and checked everything twice, only until I turned it over did I realise the problem...Thankyou to whoever it was to check the board, it is assembled on stripboard, a tiny piece of solder had got lodged the other side of the dip switch across 2 data lines...Doh
Thanks very much to everyone who has helped me out getting this working it has been greatly appreciated :)
The weird thing is the one on the breadboard didnt work at all (even though I confirmed the display actually worked) only reason i can think of for that is that maybe the datasheet for it was wrong as the exact model was discontinued...live and learn I guess :)