PDA

View Full Version : LCD showing mostly jibberish on 16F716



davewanna
- 26th May 2015, 12:53
I've had a break from PIC's for a little so I'm a bit rusty, but I don't recall having this many issues in the past.

Just trying to get an LCD to work first on my 16F716. I haven't used this pic before so might have some config wrong.

B4-B7 goto DB4-DB7 on my 2-line LCD
RW is held low VIA code, Enable and RS are on corresponding pins.

The issue is that I get mostly jibberish all over the screen changing constantly, with glimpses of the text I'm trying to put there. I've mostly used 4-line LCD's before so don't even know if I have the addressing right, I dont' have a datasheet for this exact LCD
I have tried fiddling the COMMANDUS and DATAUS values but they haven't had an effect, even without them there.




@ __CONFIG _WDT_ON & _RC_OSC & _PWRTE_ON

' Define LCD registers and bits
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_LINES 2

DEFINE LCD_COMMANDUS 1500 'defines the delay after LCDOUT statement
DEFINE LCD_DATAUS 44 'delay in micro seconds

TRISA = %11111
TRISB = %00000000

butdn var porta.4
butup var porta.3
butmode var porta.2
bail2 var porta.0
bail3 var porta.1

clutch var portb.0
lcdrw var portb.2

c var word
c = 0
lcdrw = 0

pause 150
lcdout $fe,1
pause 500
Start: '************************************************* *********************** START
c = c + 1
lcdout $fe,1
lcdout $fe,$00,"This is a test "
lcdout $fe,$40,DEC c
pause 500
if c > 100 then
c = 0
endif
GOTO start

HenrikOlsson
- 26th May 2015, 14:15
Hi,
I was going to suggest increasing the command and/or data delay considerably (say 5000us for command and 200 for data) just to see if it starts to work but perhaps you've already tried that while fiddling with the numbers?

Apart from that it's the usual suspects like ADC and comparators but your device doesn't have any of that on the pins used so that can't be it. So, I think it's either a slow controller or a hardware problem like one of the datalines not reaching the controller.

/Henrik.

davewanna
- 26th May 2015, 15:02
Thanks for thereply.

I haven't gone that high with the numbers so I'll try that in the morning. I made the pcb with a cnc machine, the socket is very close to the pic and the lcd is plugged straight into it. I don't think it's a connection problem but I will triple check. I put a 4 line lcd on and the same problem occurs.
I am using the internal oscillator, could that be a cause?

Scampy
- 26th May 2015, 15:31
If that's the full code, then should there not be an DEFINE OSC XX to let PBP know what frequency the PIC is running at.

Have a look at my last post in this thread http://www.picbasic.co.uk/forum/showthread.php?t=20024

You may need to change the config settings to match the chip you are using, but if it has an internal 4 Mhz clock then it should work without too much modifications

davewanna
- 26th May 2015, 15:36
A late night case of "I wonder if" has got me up. Set the command and data times up higher, still the same.
Not real happy with a couple of the SMD solder pads for the pic. The leg has solder, and the pad has solder, but not convinced they are soldered together. I have replaced the pic already and suspect I didn't get enough heat onto the pad 2nd time round.

Tomorrow I'll resolder at the workshop and cross my fingers.

Scampy
- 26th May 2015, 15:46
I don't have a 16F716 to play with, but the following code works with an 18F 4580 running at 4mhz from its internal clock. LCD is on port B




ASM
__CONFIG _CONFIG1H, _OSC_IRCIO7_1H ; _OSC_HSPLL_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM

DEFINE OSC 4
ADCON1 = $0F
clear

DEFINE LCD_DREG PORTB ' LCD Data port
DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4)
DEFINE LCD_EREG PORTB ' LCD Enable port
DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD)
DEFINE LCD_RSREG PORTB ' LCD Register Select port
DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD)
DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 4 ' number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us

LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD



TRISA = %11111
TRISB = %00000000

butdn var porta.4
butup var porta.3
butmode var porta.2
bail2 var porta.0
bail3 var porta.1

clutch var portb.0
lcdrw var portb.2

c var word
c = 0
lcdrw = 0

pause 150
lcdout $fe,1
pause 500
Start: '************************************************* *********************** START
c = c + 1
lcdout $fe,1
lcdout $fe,$00,"This is a test ",DEC c
pause 500
if c > 100 then
c = 0
endif
GOTO start


I'm using an EasyPIC5 board which has the LCD wired as shown below

http://micro-heli.co.uk/lcd.jpg

You could try breadboarding the circuit to confirm the code etc is working. If so then the issue may well be with your PCB

davewanna
- 26th May 2015, 15:46
Scampy,

That is interesting and a part of this PIC I don't fully understand. I've used PIC's with Internal OSC before, but quite a while ago and I don't remember being this confused about it.

It seems unclear to me in the datasheet what frequency the internal OSC runs at and if any external components are required. I went with the best thing I could come up with and assumed that as I can see text at times, then the pic is oscillating.
I did try DEFINE OSC 4 at the top earlier, but the problem still occurred.

Scampy
- 26th May 2015, 16:00
Obviously by using the internal oscillator you can omit the external crystal shown in the easyPIC5 diagram. Some of the config lines in the code might need removing as you are using a different family of PICs than the one I used for testing. When I tried your code it compiled OK, but you have one line missing which could be the cause



DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits)

davewanna
- 26th May 2015, 16:17
I noticed the LCD_BITS 4 line in your code. I've never used that line before and always used 4-bit LCDs. I added it anyway and no change. I also changed the LCD init line to same as yours, and outputted everything on one LCDOUT command like you. Same result.

I'm sure I recall using a specific command to use the internal osc in the past, whereas this datasheet indicates clearing option register bit 5 will turn it on?
To be honest I don't really know how to set the option register bits with the setup I am using now. I'm using the dos-based pickit2 so I don't get to choose the option bits before I hit program.

I feel stupid for claiming I've done this before but not knowing how to set option reg bits.

HenrikOlsson
- 26th May 2015, 16:28
Scampy,
Nice catch and something Worth a try but the manual does say that if not told otherwise PBP assumes 4-bit mode.

davewanna,
You say in your post that you're using the internal oscillator but as far as I can see the 16F716 doesn't have one. And you've got the config set to RC_OSC indicating external RC combination on the OSC1 pin. If that IS what you're using what values do you have for R and C and have you verified at what frequency the PIC is actually running?

If you don't DEFINE OSC xx PBP assumes 4MHz. If the actual speed is different, then all timings will be off.

/Henrik.

EDIT: OPTION_REG.5 Controls from where TMR0 gets its clock. OPTION_REG.5 = 0 will clear that bit but it's got nothing to do with the problem at hand.

davewanna
- 26th May 2015, 16:28
After reading more datasheet and looking at the PBP inc file for this chip, the best I came up with in my tired state is to change my first line to....

@ __CONFIG _WDT_ON & _RC_OSC & _PWRTE_ON & OPTION_REG = %11011000

Now I'm sure this is wrong, can anyone point me to the idiots guide to setting option regs?
Thanks

davewanna
- 26th May 2015, 16:31
Henrik,

That would explain why I can't find an easy way of turning it on and off. Having said that, in my circuit the OSC pins are left floating. How is it doing anything?

Edit: I think you're right Henrik, I've been trying to make it do something it isn't meant to do.
I will add a crystal osc tomorrow and change the osc source and see how I go.
Thanks

HenrikOlsson
- 26th May 2015, 17:23
Yeah, with the OSC pins floating it might be picking up noise and running off of that.
For that device you need an external crystal/resonator or an external R/C network - or an external clock signal for that matter. With both OSC pins floating you have neither.

/Henrik.

davewanna
- 26th May 2015, 23:30
You're exactly right Henrick.
I put a 4Mhz osc on it thismorning, works perfectly.

I'm surprised it worked at all with no external osc components.

Cheers

Scampy
- 27th May 2015, 15:04
I must admit I'm surprised that it doesn't have a built in oscillator. Thought that all pics had that ??

HenrikOlsson
- 27th May 2015, 16:20
Hi,
Actually, according to the product selector on Microchips website only 18 out of around 375 models (which are in production) is missing an internal oscillator of one type or another. They are:

PIC16F54
PIC16F57
PIC16F716
PIC16F59
PIC16F1454
PIC16F1455
PIC16F1459
PIC16HV540
PIC16F818
PIC16F819
PIC16F72
PIC16F73
PIC16F84A
PIC16F74
PIC16F76
PIC16F77
PIC18F6520
PIC18F8520

So it's close but not quite all ;-)

/Henrik.

mark_s
- 27th May 2015, 20:43
I have used both the pic16f818 and 819 which are in the list. Both have internal oscillators to 8mhz.
Microchip has one of the worst website/search engines out there.

HenrikOlsson
- 27th May 2015, 21:22
That's just weird, selecting No and None in the Internal Oscillator column of the product selector produced the above list. Checking the 16F818 does indeed show it's got internal oscillator.
Thanks for pointing that out Mark!

davewanna
- 28th May 2015, 02:39
I cut my teeth on the 16F877 and it is my understanding it does not have an internal oscillator. And it doesn't seem to be in your list Henrik.

HenrikOlsson
- 28th May 2015, 06:04
That seems correct.
Conclusion: The list is flawed and so is the data Microchip is using in their selector tool - which is what generated the list.

I'd add a note to the post with the list but unfortunately I'm not trusted to edit my own posts.

Sorry for the confusion.

/Henrik.

davewanna
- 28th May 2015, 12:53
All is good. I'm just glad I'm able to shift some of the blame from myself to Microchip in this instance.. haha

Thanks for all the help anyway circuit now working like it should, now back to finishing the code....

Ryan7777
- 29th May 2015, 18:34
Your open pins were probably acting like little antennas and picking up something nearby on occasion that just happened to be what the pic was expecting as an OSC frequency, hence the occasional flicker of life . Floating pins on PICs can do some pretty weird stuff, or on logic chips of any sort.

Glad you got it sorted!