PDA

View Full Version : Simple program - Strange problem!



Megahertz
- 11th December 2009, 11:49
Hi

PIC used: 12F635

In my code:
GP 0,1,2 are outputs
GP 5,4,3 are inputs.
Two outputs are latching (GP 0,1 ) and third one (GP2) stays on for 5 seconds only

The problem
The latching part is not working fine. When GP5 is pressed, GP0 goes high but it doesn't go low when GP5 is pressed again - instead it goes low when GP4 is pressed ! GP4 - GP1 pair work fine by themself- when GP4 is pressed once GP1goes high and when GP4 if pressed again - GP1 goes low.

My code is attached - Please help if you can:

Bruce
- 11th December 2009, 15:09
Break up your delays into shorter PAUSE times so it can react to each interrupt faster, and
don't mess with INTCON.7 when using ON INTERRUPT.

PBP places a RETURN at location 4 (hardware interrupt vector), so INTCON.7 gets left clear
and this lets PBP know an interrupt needs to be serviced.

INTCON.7 is automatically set on return from your interrupt handler. If you set INTCON.7 in
your code, after ON INTERRUPT is used, PBP assumes the interrupt has already been
serviced.

See if this helps;


DEFINE NO_CLRWDT 1
DEFINE OSC 4
Include "modedefs.bas"
led VAR gpio.1
i VAR BYTE
X VAR WORD

@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _BOD_ON & _CPD_ON & _IESO_OFF & _FCMEN_ON & _WUREN_OFF
main:
' Initialize the processor
TRISIO = %111000
GPIO = 0
CMCON0 = 7
INTCON=128
OPTION_REG =%10000111 ' RAPU = off, PS 1:256 to TMR0 (overflows in 256*256*1uS) 65.536 mS
pcon.5=0
pie1=0
t1con.0=0
i=0

ON INTERRUPT GOTO start

pause 50

check:
if gpio.5=1 then ' Takes GP0 high BUT not low
toggle gpio.0
'pause 300 ' TMR0 will overflow long before this PAUSE is finished
FOR X = 1 TO 300 ' 300mS PAUSE in 1mS increments
PAUSE 1
NEXT X
while gpio.5
pause 1
wend
endif

if gpio.4=1 then ' Independently working fine BUT also takes low gp.0 if it's high only
toggle gpio.1
'pause 300 ' TMR0 will overflow long before this PAUSE is finished
FOR X = 1 TO 300 ' 300mS PAUSE in 1mS increments
PAUSE 1
NEXT X
while gpio.4
pause 1
wend
endif

if gpio.3=1 then
gpio.2=1
'pause 100 ' TMR0 will overflow long before this PAUSE is finished
FOR X = 1 TO 100 ' 100mS PAUSE in 1mS increments
PAUSE 1
NEXT X
while gpio.3
pause 1
wend
TMR0=0
INTCON.5 = 1 ' enable TMR0 overflow interrupt
endif

goto check

disable
start:
i=i+1
INTCON.2=0 ' clear TMR0 overflow interrupt flag bit
if i=77 then
gpio.2=0
i=0
' INTCON=128 ' INTCON.7 gets set on return from here
endif
resume

Megahertz
- 11th December 2009, 18:15
Hey Bruce, Now if GP1 is high, and gp0 is activated via gp4, it gets high and goes low after 2 seconds appx.
If GP1 is LOW, activating GP0 via gp4 makes it high but not low.

Bruce
- 11th December 2009, 18:39
Where is GPIO.0 activated by GPIO.4?

Megahertz
- 11th December 2009, 18:43
So Sorry, My Mistake, need a redbull. I will correct my sentence:
" If GP1 is high, and gp0 is activated via gp5, it gets high and goes low after 2 seconds appx.
If GP1 is LOW, activating GP0 via gp5 makes it high but not low"

Bruce
- 11th December 2009, 22:40
Can't say what would cause that. Programmed a 12F635 here, and it works just as
expected per the code example above.

LEDs on GPIO.0, 1 and 2, and buttons on GPIO.3, 4 and 5 with pull-down resistors, and
button presses taking inputs high.

Megahertz
- 19th December 2009, 22:52
Thanks Bruce. It was the PCB track getting short. It's working fine now.