PDA

View Full Version : 12F683 - Pin1 not working



ruijc
- 23rd January 2009, 21:49
Hi there,

i was planning on hacking a small static toy car from my son and place inside a pic and some leds to give it some life.

I have a couple of 12f683 pics around so i decided to use them for this.

I started with a simple combination of lights to check the effects and go from there but something stopped me.

I can explain why but GPIO.1 does not respond to commands.
I can put any of the pins to work except pin 1 ( turnsign ).

I tried both pics and both have the same behavior.

Maybe some wrong define or something i'm not seeing but it's killing my brain's out.

Here is the code:


'PINS

speaker var GPIO.5
stops var GPIO.4
BUT var GPIO.3
bottom var GPIO.2
turnsign var GPIO.1
headlights var GPIO.0

'************************************************* ****************************

OSCTUNE=%00000000 ' calibrated frequency
DEFINE OSC 8

'************************************************* ****************************

@ DEVICE pic12F683, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F683, WDT_OFF
@ DEVICE pic12F683, PWRT_OFF
@ DEVICE pic12F683, MCLR_OFF
@ DEVICE pic12F683, BOD_ON

'************************************************* ****************************
'HPWM
DEFINE CCP1_REG GPIO
DEFINE CCP1_BIT 2

'************************************************* ****************************

ADCON0=0
ANSEL=0
CMCON0=7 'only for 12F683 - comparator off
OPTION_REG.7=1 ;disable Pull-Ups
TRISIO=%001000 ;set GPIO3 as input
OSCCON=%01110111 ' 8mHz clock define
CCP1CON=0 ' 12F683 ccpm module off
INTCON=0 'interrupt control register
'WPU=0
'PIE1=0
'PIR1=0
'T1CON=0
'T2CON=0
GPIO=0

'************************************************* ****************************

va var byte
va2 var byte
km var word
mem1 var byte

value var word
steps VAR WORD

eep1 con $10


'************************************************* ****************************

sense:
if but=1 then
mem1=1
write eep1,mem1
goto all
endif


init:


high turnsign
sound gpio.5,[50,10]
pause 100
low turnsign
pause 150
high turnsign
sound gpio.5,[50,10]
pause 100
low turnsign
pause 500

inp:
if but=1 then
mem1=mem1+1
endif
if mem1>12 then
mem1=1
endif
write eep1,mem1
return

all:
high headlights
high stops
low turnsign
low bottom
sound gpio.5,[50,10]
pause 500
low headlights
low stops
high turnsign
high bottom
sound gpio.5,[50,10]
pause 500
goto all



Thanks

Bruce
- 24th January 2009, 17:17
inp:
if but=1 then
mem1=mem1+1
endif
if mem1>12 then
mem1=1
endif
write eep1,mem1
return <<--- return to where? Maybe GOTO Init?

RETURN should only be used when you GOSUB to get there.

Also this;


high stops
low turnsign
low bottom
May also lead to trouble. It can cause read-modify-write. Sometime it's best to write to the whole port at once instead of multiple high low statements together.

What happens if you place a PAUSE 500 after each line where you try to set or clear turnsign?

Sometimes there may be a little more capacitance on one output than others, and setting of clearing port bits one-after-another will cause read-modify-write. The value you expect on an output may not be what you expect since the 2nd bsf or bcf operation causes the previous pin to be read back (before it has changed) and written back to the pin.

dw_picbasic
- 8th February 2014, 15:50
Just one thought ruijc
Since your trying to troubleshoot the functionality of a pin to a particular device (perhaps an LED) , why not consider reducing down to the lowest level?
Create a program to control that one device and nothing more.
You can swap the code and wiring from gpio.0 to gpio.1 to see if the device is acting differently. That would allow you to verify if the issue is hardware vs code.
In some cases, I have had to sink a device rather than source it due to current limitations on the PIC. Hope that helps. :-]

Amoque
- 8th February 2014, 17:38
The original post is dated more than 5 years ago. I suspect his son is old enough to help figure out what is wrong by now. :)