PDA

View Full Version : PIC16F506 Problems



Aussie Barry
- 17th January 2011, 06:10
Hi All,

I am having some difficulties running anything on a PIC16F506.
The intended project was to display some information on a 16x2 LCD display but after I couldn't get that to work I went back to basics and tried a simple "Blink" program. I have tried the following code using an external (crystal) oscillator as well as the internal oscillator but get absolutely nothing happening on the LED. (the LED circtuit works perfectly when connected/driven manually)

Led var PORTC.0
TRISC=0
Again:
Led=1
Pause 1000
Led=0
Pause 1000
Goto Again
end

I am quite confused as to why this simple program will not work on the 16F506 when I can get it to work on others (eg 16F84A, 16F628A, 16F716 tec.)

Is there something peculiar about using the 16F506 that I am missing?

Any help would be greatly appreciated.

Cheers
Barry

mackrackit
- 17th January 2011, 06:35
That chip has comparators that need turned off when not using them.
Try adding near the top of your code
CM1CON0 = 0
CM2CON0 = 0

Aussie Barry
- 17th January 2011, 08:31
Thanks Dave - that seems to have solved my problem.

Now to move on to the LCD display section followed (hopefully) soon after by the A/D section.

Cheers
Barry

mackrackit
- 17th January 2011, 08:33
COOL!!!
Keep the data sheet handy :)

Aussie Barry
- 17th January 2011, 10:34
Things are progressing well with the extension of my project but I have hit a bit of a snag.
I have the the A/D working on PORTB.0 and I can do all the standard "Hello World" type stuff with the LCD. My problem occurs when I try to display the result of the A/D conversions.

The relevant code extract is as follows:

adval var byte ' Create adval to store result

ADCON0 = %11110001 ' Set clock divisor to INTOSC/4
' Set AN0, AN1 and AN2 as Analogue Input
' Turn on A/D converter
CM1CON0 = 0 ' Disable comparator
CM2CON0 = 0 ' Disable comparator
OPTION_REG.5 = 0 ' Set PORTC.5 as digital I/O port
TRISC = 0 ' Set PORTC as all outputs
TRISB = %00000111 ' Set PORTB.0, PORTB.1 and PORTB.3 as inputs

Pause 500 ' Wait .5 second

loop: ADCIN 0, adval ' Read channel 0 to adval

LCDOUT $fe, 1 ' Clear LCD
LCDOUT "Value: ", DEC adval ' Display the decimal value
Pause 100 ' Wait .1 second

Goto loop ' Do it forever
End

When I try to compile this program using MPLAB IDE I get the following error

Executing: "C:\PBP\PBPW.EXE" -ampasmwin -oq -z -p16F506 "ADCIN8 16F506.bas"
PICBASIC PRO(TM) Compiler 2.47, (c) 1998, 2006 microEngineering Labs, Inc.
All Rights Reserved.

ERROR: Macro LCDOUTCOUNT?C not found in macro file.
ERROR: Macro LCDOUTNUM?B not found in macro file.
ERROR: Macro LCDOUTDEC? not found in macro file.Halting build on first failure as requested.
BUILD FAILED: Mon Jan 17 21:22:24 2011

but when I change the LCDOUT statement to

LCDOUT "Value: ", #adval

everything works perfectly.
I was led to believe that the two statements are the same so why doesn't it work?
Frustratingly, LCDOUT "Value: ", DEC adval works perfectly when compiling fo 16F684 or 16F716 but not 16F506.

Can anyone shed some light on this?

The final program will use Darrel Taylor's Bargraph display and my initial compile resulted in a host of LCDOUT error statements (DEC, REP issues) so I need to get to the bottom of this problem. (BTW, I can get Darrel's bargraph working beautifully on 16F684, 16F716 etc).

Cheers
Barry

Bruce
- 17th January 2011, 13:50
SEROUT2 type modifiers aren't supported for 12-bit core device types.

Aussie Barry
- 17th January 2011, 23:09
WOW!
I don't ever remember seeing that documented anywhere.
Thanks Bruce.

I guess that kills it for the 16F506 on this project...

Cheers
Barry

Bruce
- 17th January 2011, 23:44
It's in the 2nd paragraph in the manual under LCDOUT, and in older versions of PBP new.txt docs.

12-bit core has very limited support due to limited resources on the PIC. If you're using these, it's best to keep it as simple as possible since these device types have very limited RAM and stack resources.

You can normally find a 14-bit core type really close to same price range.

Aussie Barry
- 18th January 2011, 02:50
Thanks Bruce,

I don't know how many times I have read the LCDOUT section of the manual without seeing that caveat (or at least have it sink into my brain). A valuable lesson learnt!.

I will change over to using a PIC16F684 - pin compatible, does what I need it to do and is less than a dollar more expensive.

Thank you to all who have assisted me in my endeavours.

Cheers
Barry