PDA

View Full Version : Erratic behavior with a PIC16F88 and an custom LCD Board



russman613
- 5th December 2006, 17:22
I am having trouble with a custom LCD controller board I am trying to build.

Here is the background information:

- Attached is the schematic: (LCD_PIC16F88_PCB.jpg).

- I am using a 20Mhz resonator from HobbyEngineering (http://www.hobbyengineering.com/H1471.html).

- On the bottom of the post is my code - it is based off the LCD.bas sample.

- The B R D on the board represent Ground, +5V and Data respectively using a standard servo cable.

- I am using MicroCode Studio version 2.3.0.0, melabs Programmer software version 4.01 and a USB2 Programmer (http://www.melabs.com/products/usbprog.htm).

- I am programming with PicBasic Pro version 2.46

- I am using the following 16x2 backlit LCD (http://www.jameco.com/Jameco/Products/ProdDS/365982.pdf)

- this is my first attempt at a custom carrier board for any PIC.



The problem is that sometimes the thing works and sometimes it does not. When I first power on the circuit, it will either work or just show the top row as all black. The all black just means that the unit is powered on but has not received any direction from the microcontroller yet. I can accomplish the same thing by just powering the circuit on with no microcontroller in place.

To make sure it is not the code or the LCD or the pic, I am also using a PicoProto 18L prototyping board (http://www.melabs.com/downloads/pp18l_06.pdf) which is using the same resonator I’ve mentioned above. The whole thing works flawlessly every time out of the gate on the PicProto board.

Given this much, I figured maybe a bad resonator or a bad power supply. I changed the resonator with another one I had and that did not fix the problem - still getting erratic behavior.

I have several in progress projects that have a regulated 5v power output and tried the circuit connected to three or more of those (including the power on the PicProto 18L). To no avail.

I checked the circuit for bad etched copper lines and solder, re soldered a few things, dremmeled a few lines that looked too close, etc. All to no avail.


I am sure I am missing something simple that will be bright and blinding to the eyes of experience. Right now, I only see shadows …

Any suggestions, observations, comments, complements or insults anyone may be able to tender to help out would be very much appreciated.

Thanks in advance ...

Russ




----- not so brilliant code here ... ----

' 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 PIC16F88, HS_OSC 'HS oscillator
@ DEVICE PIC16F88, WDT_ON 'Watchdog Time
' (http://www.hobbyprojects.com/pic_tutorials/tutorial13.html)
@ DEVICE PIC16F88, PWRT_ON '15.5 Power-Up Timer: Provides a fixed delay of
' 72 ms (nominal) on power-up only. It is designed to keep the
' part in RESET while the power supply stabilizes.
@ DEVICE PIC16F88, BOD_ON '15.7 Brown-Out Detect
@ DEVICE PIC16F88, MCLR_ON 'Master Clear Options set to Internal. RA5 unavail
@ DEVICE PIC16F88, LVP_OFF '15.18 Low Voltage Programming via ICSP.
@ DEVICE PIC16F88, CPD_OFF '15.1 bit 8 - Data EE Memory Code Protection bit
@ DEVICE PIC16F88, WRT_OFF '15.1 bit 10-9. FLASH Program Memory Write protection off
@ DEVICE PIC16F88, DEBUG_OFF '15.1 bit 11. DEBUG: In-Circuit Debugger Mode bit
' In-Circuit Debugger disabled, RB6 and RB7 are general
' purpose I/O pins
@ DEVICE PIC16F88, CCPMX_OFF '15.1 bit 12. CCPMX: CCP1 Pin Selection bit
' 1 = CCP1 function on RB0
' 0 = CCP1 function on RB3
@ DEVICE PIC16F88, PROTECT_OFF 'Code protection off

'Command Operation
'$FE, 1 Clear display
'$FE, 2 Return home (beginning of first line)
'$FE, $0C Cursor off
'$FE, $0E Underline cursor on
'$FE, $0F Blinking cursor on
'$FE, $10 Move cursor left one position
'$FE, $14 Move cursor right one position
'$FE, $80 Move cursor to position 0 (+offset to precisly posn)
'$FE, $C0 Move cursor to beginning of second line (+offset to precisly posn)
'$FE, $94 Move cursor to beginning of third line
'$FE, $D4 Move cursor to beginning of fourth line

define OSC 20
OSCCON=%01110000 ' pg 41. Setting bit 1-0: 00 = Oscillator mode defined by FOSC<2:0>
TRISB=%00000000 ' all portb to output
TRISA=%00000000 ' all porta to output
ANSEL=%00000000 ' set all analog pins to digital

pinLED var portb.4 ' blink and stuff to know we're alive
I var word

high pinLED

Pause 1500 ' Wait for LCD to startup


loop:
low pinLED

Lcdout $FE, 1, "Russ was here ..."
pause 1000
lcdout $FE, $C0, " or was he ..."
pause 4000 ' Give that some time to sink in.

lcdout $FE,1 ' Clear screen
lcdout $FE, $C0, "Second line ..."
pause 500
lcdout $FE, 2, "First line ..."
pause 500


lcdout $FE, 1 ' Clear the screen again - we love to clear screens.
pause 500

lcdout $FE, $80, "Dec:"
lcdout $FE, $C0, "Hex:"
for I = 0 to 199
lcdout $FE, $80+5, dec3 I
lcdout $FE, $C0+5, hex3 I
toggle pinLED
pause 200
next I
pause 1500 ' Alone done - take a quick breather.

Goto loop ' Start all over again.

sayzer
- 5th December 2006, 17:59
I suspect your "OSCCON=%01110000" setting but I could not figure it out for 20Mhz HS setting.


------------------------------

russman613
- 6th December 2006, 02:44
My understanding is that setting bits 1 and 0 to 0 make the rest of the OSCCON register meaningless. The value i have set there is left over from other messing around.

russ

Archangel
- 6th December 2006, 03:58
Wow, so many people are using and having problems with 16F88 PICs right now I thought I might have missed out on a give away :)
Point to remember about this chip is : it has ANSEL, ADCON0,ADCON1, CMCON, REGISTERS, neglect one and it's not happy. The data sheet says" On power on reset the pins PortA<4:0> are configured as analog inputs and read as 0."




' 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 PIC16F88, HS_OSC 'HS oscillator
@ DEVICE PIC16F88, WDT_ON 'Watchdog Time
' (http://www.hobbyprojects.com/pic_tut...utorial13.html)
@ DEVICE PIC16F88, PWRT_ON '15.5 Power-Up Timer: Provides a fixed delay of
' 72 ms (nominal) on power-up only. It is designed to keep the
' part in RESET while the power supply stabilizes.
@ DEVICE PIC16F88, BOD_ON '15.7 Brown-Out Detect
@ DEVICE PIC16F88, MCLR_ON 'Master Clear Options set to Internal. RA5 unavail
@ DEVICE PIC16F88, LVP_OFF '15.18 Low Voltage Programming via ICSP.
@ DEVICE PIC16F88, CPD_OFF '15.1 bit 8 - Data EE Memory Code Protection bit
@ DEVICE PIC16F88, WRT_OFF '15.1 bit 10-9. FLASH Program Memory Write protection off
@ DEVICE PIC16F88, DEBUG_OFF '15.1 bit 11. DEBUG: In-Circuit Debugger Mode bit
' In-Circuit Debugger disabled, RB6 and RB7 are general
' purpose I/O pins
@ DEVICE PIC16F88, CCPMX_OFF '15.1 bit 12. CCPMX: CCP1 Pin Selection bit
' 1 = CCP1 function on RB0
' 0 = CCP1 function on RB3
@ DEVICE PIC16F88, PROTECT_OFF 'Code protection off

'Command Operation
'$FE, 1 Clear display
'$FE, 2 Return home (beginning of first line)
'$FE, $0C Cursor off
'$FE, $0E Underline cursor on
'$FE, $0F Blinking cursor on
'$FE, $10 Move cursor left one position
'$FE, $14 Move cursor right one position
'$FE, $80 Move cursor to position 0 (+offset to precisly posn)
'$FE, $C0 Move cursor to beginning of second line (+offset to precisly posn)
'$FE, $94 Move cursor to beginning of third line
'$FE, $D4 Move cursor to beginning of fourth line

define OSC 20
OSCCON=%01110000 ' pg 41. Setting bit 1-0: 00 = Oscillator mode defined by FOSC<2:0>
TRISB=%00000000 ' all portb to output
TRISA=%00000000 ' all porta to output
ANSEL=%00000000 ' set all analog pins to digital
<font color=red> CMCON=7 ' turn off comparators
ADCON1 = 7 ' or ADCON1 = %00000111 'Disable A/D converter
</font color=red>
pinLED var portb.4 ' blink and stuff to know we're alive
I var word

high pinLED

Pause 1500 ' Wait for LCD to startup


loop:
low pinLED

Lcdout $FE, 1, "Russ was here ..."
pause 1000
lcdout $FE, $C0, " or was he ..."
pause 4000 ' Give that some time to sink in.

lcdout $FE,1 ' Clear screen
lcdout $FE, $C0, "Second line ..."
pause 500
lcdout $FE, 2, "First line ..."
pause 500


lcdout $FE, 1 ' Clear the screen again - we love to clear screens.
pause 500

lcdout $FE, $80, "Dec:"
lcdout $FE, $C0, "Hex:"
for I = 0 to 199
lcdout $FE, $80+5, dec3 I
lcdout $FE, $C0+5, hex3 I
toggle pinLED
pause 200
next I
pause 1500 ' Alone done - take a quick breather.

Goto loop ' Start all over again.

Anyway try this and see if it helps.
JS

russman613
- 6th December 2006, 15:41
Thanks for the response. Properly setting those registers did not seem to help my specific problem.

Additionally, I set the OSCCON to 0 and used HS in the HW programmer (with external 20Mhz resonator) and that did not make a difference - still seeing flakey bahaviour.

I set:

define OSC 8
OSCCON=%01110110

and it was still flakey.

I am starting to suspect that my board is just bad. I wired it on a breadboard and it was reliable without the resonator though i had to jiggle the wires around quite a bit to get it to work.

russ

mister_e
- 6th December 2006, 17:10
OK.. you're using an external OSC, BUT not the MCLR pin, so just make MCLR pin as I/O OR tie it to Vdd via 10K resistor... it should work Better.

If you're using an external OSC, the OSCCON stuff won't change anything. So i bet that..


@ DEVICE PIC16F88, HS_OSC 'HS oscillator
@ DEVICE PIC16F88, WDT_ON 'Watchdog Time
' (http://www.hobbyprojects.com/pic_tut...utorial13.html)
@ DEVICE PIC16F88, PWRT_ON '15.5 Power-Up Timer: Provides a fixed delay of
' 72 ms (nominal) on power-up only. It is designed to keep the
' part in RESET while the power supply stabilizes.
@ DEVICE PIC16F88, BOD_ON '15.7 Brown-Out Detect
@ DEVICE PIC16F88, MCLR_OFF 'Master Clear Options set to Internal. RA5 unavail
@ DEVICE PIC16F88, LVP_OFF '15.18 Low Voltage Programming via ICSP.
@ DEVICE PIC16F88, CPD_OFF '15.1 bit 8 - Data EE Memory Code Protection bit
@ DEVICE PIC16F88, WRT_OFF '15.1 bit 10-9. FLASH Program Memory Write protection off
@ DEVICE PIC16F88, DEBUG_OFF '15.1 bit 11. DEBUG: In-Circuit Debugger Mode bit
' In-Circuit Debugger disabled, RB6 and RB7 are general
' purpose I/O pins
@ DEVICE PIC16F88, CCPMX_OFF '15.1 bit 12. CCPMX: CCP1 Pin Selection bit
' 1 = CCP1 function on RB0
' 0 = CCP1 function on RB3
@ DEVICE PIC16F88, PROTECT_OFF 'Code protection off

could help

russman613
- 6th December 2006, 23:06
Whose the stud?? Steve aka mister_e, that's who!

Thx much for noticing my problem with the MCLR fuse setting.

I changed it to the correct value (MCLR_OFF since i don't have reset wired in my schematic) and voila - flowers and discount surplus parts rained from the sky to bring happiness to the masses - even though they were sober and balding ...

Very much appreciate the attention to detail. Thanks again for your assistance.

Russ

Archangel
- 7th December 2006, 08:46
CONGRATULATIONS russman613 and
<font color=red><h1> Hurray for mister_e !</h1></font color> the devil is always in the details! Nice catch Steve!

mister_e
- 7th December 2006, 16:42
http://www.mister-e.org/Pics/Devil.gif