PDA

View Full Version : LCD problem with 16F628



ngeronikolos
- 13th February 2006, 09:22
Good morning to everybody,

I have a problem with my code.LCD--->16F628

Please check my code!!!
Thnks


' PicBasic program to demonstrate operation of an LCD in 4-bit mode
'
' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect
@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT ' system clock options
@ DEVICE pic16F628, WDT_ON ' watchdog timer
@ DEVICE pic16F628, PWRT_ON ' power-on timer
@ DEVICE pic16F628, MCLR_OFF ' master clear options (internal)
@ DEVICE pic16F628, BOD_ON ' brown-out detect
@ DEVICE pic16F628, LVP_OFF ' low-voltage programming
@ DEVICE pic16F628, CPD_OFF ' data memory code Protect
@ DEVICE pic16F628, PROTECT_OFF ' program code protection


Define LCD_BITS 4 ' 4-bit interface
Define LCD_LINES 2 ' 2 line LCD

' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
Define LCD_DREG PORTA
Define LCD_DBIT 0

' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
Define LCD_RSREG PORTA
Define LCD_RSBIT 4

' E PortB.3
Define LCD_EREG PORTB
Define LCD_EBIT 3

' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (wire wiper to Vo, adjust for contrast)
' DB0-3 No connect

Define LCD_COMMANDUS 2000 ' Adjust for slower LCD modules
Define LCD_DATAUS 50

INCLUDE "MODEDEFS.BAS"
INTCON = 0 ' Disable interrupts
CMCON = 7
Pause 500 ' Wait for LCD to startup

loop: Lcdout $fe, 1 ' Clear LCD screen
Lcdout "By:Geronikolos" ' Display Hello
Pause 500 ' Wait .5 second

Lcdout $fe,$c0,"World" ' Clear LCD screen
Pause 500 ' Wait .5 second

Lcdout $fe,$c0,"Hello" ' Clear LCD screen
Pause 500 ' Wait .5 second

Goto loop ' Do it forever

Melanie
- 13th February 2006, 10:26
You might want to try these two things...

1. Ground D0-D3 on the LCD

Don't leave those lines not connected and floating - it's bad practice.

2. Increase the inital Pause 500 to Pause 1000

Pause 500 may be insufficient for your LCD to initialise at power-on.

Why don't you want to use A.5 for E-Bit? That way the whole of PORTB is free for your applications use. If you used A.6 for the RS Bit, you wouldn't need that Resistor either.

Additionally, although this has nothing to do with the LCD... INTCON = 0 is unnescessary as Interrupts are disabled by default.

ngeronikolos
- 13th February 2006, 11:16
Melanie,

Thanks for your advice but nothing.I ground D0-D3 on the LCD and I change the inital Pause to 1000 and 1500.

I saw on my lcd all first line with black blocks.

Please advice

Melanie
- 13th February 2006, 11:28
1. Check the SPELLING of your LCD Defines... they must be EXACT because the compiler will not flag errors if have made a mistake there.

2. Check that you have not mistakenly swapped your E or RS bits and connected them the wrong way around...

3. Turn down your contrast... if it's too high then you might be swamping any displayed data with black blocks.

4. Finally, double-check your hardware connections against your DEFINES.

There are no problems or issues connecting LCDs to a 16F628 on internal oscillator with internal MCLR therefore it must be something in your connection...

ngeronikolos
- 13th February 2006, 11:36
The compiler is OK.No errors.

May my programmer cause the problem?
Because the circuit and the program was working in the past.

Thanks

ngeronikolos
- 13th February 2006, 15:30
Melanie,

I check my circuit and it seems ok.
That is the diargam of it.

Please have a look.

Melanie
- 13th February 2006, 16:39
Well, let's make sure your PIC is working...

Got an LED? Connect it say between PortB.0 with a series Resistor (anything between 220R and 470R) and Vss (0v).

After your LCD define put...

LED var PORTB.0

In your main loop, anywhere put...

Toggle LED

When the PIC runs, your LED should blink...

ngeronikolos
- 14th February 2006, 12:48
Dear Melanie,

You are right. My PIC is not working but I can not understand why?
I try to blink a led but nothing.Where is the problem with my code?

I attach my code and the hex file.

PLEASE HELP MEEEEEEEEEEEEEEEEEEEEEEE.

ngeronikolos
- 14th February 2006, 12:51
IS ALL THAT OK TO RUN MY PIC WITH INTERNAL OSC?
I have to write DEFINE OSC 4?

@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT ' system clock options
@ DEVICE pic16F628, WDT_ON ' watchdog timer
@ DEVICE pic16F628, PWRT_ON ' power-on timer
@ DEVICE pic16F628, MCLR_OFF ' master clear options (internal)
@ DEVICE pic16F628, BOD_ON ' brown-out detect
@ DEVICE pic16F628, LVP_OFF ' low-voltage programming
@ DEVICE pic16F628, CPD_OFF ' data memory code Protect
@ DEVICE pic16F628, PROTECT_OFF ' program code protection

Melanie
- 14th February 2006, 13:21
There is no attachment... nail it to your posting and I will check it...

ngeronikolos
- 14th February 2006, 13:30
HERE IT IS!!!


Thanks Melanie

Melanie
- 15th February 2006, 07:29
Little busy this morning, but I'll breadboard a 16F628 later in the day with your code and let you know...

n0oxv
- 16th February 2006, 05:16
Melanie,
You are tooo good !

Melanie
- 16th February 2006, 09:33
>"Melanie, You are tooo good !"

Yup, that's what all the boys say!


You may or may not like what I'll report...

1. Taking your posted LCD_HEX file and burning a PIC16F628 with it produces all Black Squares just as you say. So here I confirm the same result. I do notice one anomaly - your HEX of the same program is twice the size of mine.

2. But, taking your posted LCD_BAS file, renamed it LCD1, compiled it (with absolutely NO changes) with PBP2.46, burned the same PIC and it WORKS!!!! See appended picture. Try it with my HEX which I named LCD1.HEX.

I used the compile line...

PBP -p16F628 LCD1 -v

Therefore, either...

1. Your posted HEX file is not a true compilation of the posted BAS file...
2. You are using a very old compiler which may have problems...
3. Your compiler is corrupt...
4. You are using some external IDE (such as MCS) which is causing you a problem.
5. If you are compiling using Microchips MPASM the version you have may be old or corrupt.
6. Or any other reason such as alien invasion of your neighbourhood...

ngeronikolos
- 17th February 2006, 11:13
Thanks Thanks....Thanks Melanie,

I do not have words to thank you...

I will try it and I will inform you.

CuriousOne
- 5th September 2016, 14:52
Bumping an 10 year old tread.... :)

I also have problems with 16F628A and 1602 LCD



PCON=%00001011 'set intosc to 4mhz
DEFINE OSC 4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44
pause 500

LCDOUT $FE, "SACDELI "
PAUSE 5000
END


PORTB.0 - PORTB.1 are connected to D4-D7 pins of LCD
PORTB.5 is connected to RS pin
PORTB.6 is connected to E pin.

All hardware 100% verified and working. But still no display.

HenrikOlsson
- 5th September 2016, 17:06
Your code says RS is PortB.4 while you say it's PortB.5.
Your code says E us PortB.5 while you say it's PortB.6.

/Henrik.

CuriousOne
- 6th September 2016, 09:36
Thanks, fixed that, but still does not works...

mehmetOzdemir
- 6th September 2016, 09:39
can you share your config settings?

CuriousOne
- 6th September 2016, 09:52
;----[16F628A Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "16F628A"
#DEFINE MCU_FOUND 1
#CONFIG
cfg = _INTOSC_OSC_NOCLKOUT ; INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
cfg&= _WDT_ON ; WDT enabled
cfg&= _PWRTE_OFF ; PWRT disabled
cfg&= _MCLRE_OFF ; RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD
cfg&= _BODEN_ON ; BOD enabled
cfg&= _LVP_OFF ; RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming
cfg&= DATA_CP_OFF ; Data memory code protection off
cfg&= _CP_OFF ; Code protection off
__CONFIG cfg

#ENDCONFIG

#ENDIF

;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF

Include "Modedefs.bas"
PCON=%00001011 'set intosc to 4mhz
DEFINE OSC 4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44
pause 500

LCDOUT $FE, "SACDELI "
PAUSE 5000
END

richard
- 6th September 2016, 12:32
not suprised , it's certainly an odd use of the lcdout 254 directive

HenrikOlsson
- 6th September 2016, 13:10
Nice one Richard, don't know how I missed that!

CuriousOne
- 6th September 2016, 14:21
Haha thanks!
Fixed it. But there were other issues too, MCU itself was also defective, replaced it, and everything works now just fine.

HenrikOlsson
- 6th September 2016, 15:05
All hardware 100% verified and working. But still no display
I guess not then :-)

/Henrik.

CuriousOne
- 6th September 2016, 16:51
It was working, but at certain moment, when swapping LCDs, I've applied power to MCU in reverse polarity :D LCD survived ,MCU - not.

technotronix
- 19th September 2016, 08:28
Please see below thread discussion. This may help you.
https://www.ccsinfo.com/forum/viewtopic.php?t=42284