PDA

View Full Version : 16F684 Basic Functionality



munromh
- 25th September 2009, 15:41
Having a few problems getting some basic functions to work properly on a 16F684, not sure if I can see the forest through the trees now. Basically I can't get the toggle function to work, works fine if I set a pin to 1 then 0. Also, if I have a SEROUT pin on the same Port as a Pin I'm manually toggling the SEROUT works but the toggle doesn't, move the SEROUT to a different port and all's fine:



'16f684

DEFINE OSC 8 'Oscillator speed in MHz

OSCCON = %01110111 'Page 20

ANSEL = %00000000

TRISA = %00000000
TRISC = %00000000

PortA = %00000000
PortC = %00000000

WPUA = %00000000

CMCON0 = %00000000

ADCON0 = %00000000
ADCON1 = %00000000

Heart_Beat_LED Var portC.1 'Output pin to LED for Heart Beat indication, Low is on.
Heart_Beat_LED = 0

Terminal_TX var PortC.2 'Output pin to the dumb terminal or PC program on port C

Start:

'Uncomment subroutine 1, 2, or 3

'Goto Subroutine_1
'Goto Subroutine_2
'Goto Subroutine_3

goto Start


Subroutine_1: 'This works.

Heart_Beat_LED = 1
Pause 1000
Heart_Beat_LED = 0
Pause 1000
Goto Start


Subroutine_2: 'Pin is "low" and can be seen cycling between 125mV and 75mV on a scope.
'both serial out's seen on terminal.
'If I move the Terminal_TX to PortA it works.

Heart_Beat_LED = 1
serout Terminal_TX,6,["1-Heart_Beat_LED",13,10]
Pause 1000

Heart_Beat_LED = 0
serout Terminal_TX,6,["2-Heart_Beat_LED",13,10]
Pause 1000
Goto Start


Subroutine_3: 'Doesn't work

Toggle Heart_Beat_LED
Pause 1000
Goto Start

Kamikaze47
- 25th September 2009, 16:48
Strange. I have seen toggle do strange things before but cant remember what the problem was.

Out of interest, does it work if you use the following instead of toggle:

IF Heart_Beat_LED=0 THEN
Heart_Beat_LED=1
ELSE
Heart_Beat_LED=0
ENDIF

PAUSE 1000

Archangel
- 25th September 2009, 18:57
cmcon0 = 7 'Comparators off. CxIN pins are configured as<b> digital I/O</b>
cmcon0 = 0'Comparators off. CxIN pins are configured as analog

munromh
- 25th September 2009, 19:02
Strange. I have seen toggle do strange things before but cant remember what the problem was.

Me too.



IF Heart_Beat_LED=0 THEN
Heart_Beat_LED=1
ELSE
Heart_Beat_LED=0
ENDIF

PAUSE 1000

Nada, doesn't work. Pin stays high, don't see any change with a scope. It always sees Heart_Beat_LED = 0.

Interestingly enough, which I left off the earlier post, if I write:


serout Terminal_TX,6,["1-Heart_Beat_LED = ",#Heart_Beat_LED,13,10]
serout Terminal_TX,6,["2-Heart_Beat_LED = ",#Heart_Beat_LED,13,10]

The value remains zero in each SEROUT.

munromh
- 28th September 2009, 11:15
cmcon0 = 7 'Comparators off. CxIN pins are configured as<b> digital I/O</b>

Thanks Joe S., I should know better. All is fine now.

mike1939
- 30th September 2009, 16:54
Can't quite find the right place to ask this but anyway.....please bear with me..........
Have scoured the 306 pages of the data sheet and still can't make my
PIC16F690 oscillate at 12MHz. In PBP how do I configure it for ext crystal?
Desperate, why do I find it so difficult? I'm only 70 yrs old.
Cheers

Melanie
- 30th September 2009, 20:28
External Oscillator selection is performed from the CONFIGURATION BITS of this PIC.

See section 14 of the Datasheet (and section 3 if you're really bored)... mine's only got 304 pages, so you must have the 'Professionals' copy.

Use your programmer to select HS OSC manually at program time if you are connecting a 12MHz Xtal.

Alternatively, embed the appropriate device CONFIG into your program... see for example...

http://www.picbasic.co.uk/forum/showthread.php?t=543

Finally, don't forget to include DEFINE OSC 12 somewhere at the top of your program to tell PBP that you're running at 12MHz, otherwise it will continue to think you're at 4MHz (the default).