PDA

View Full Version : Problem with Timer Interrupt, PortB5-7 gets disabled



jamshid.dastur
- 6th April 2010, 18:50
Dear fellows, I'm trying to implement a timer which would get enabled on a specific action perfor a specific task ones the time is reached.

I've achieved the timer thing using interrupts and breaking it down furthur and keeping a check on it. But achieving so i've came accross a number of problems

1. Serin/Serout data started to messup...so used disable/enable before and after to run serial communication smoothly...

2. Data read using names symbols on PortB failed so again disable/enable and used directly like PORTB instead of variable...this solved problem with Porb.0-Portb.4

3. Now the actual problem being: I'm unable to deal with my inputs at Portb.5-Portb.7...

I'm using 18F452 with a 4MHz XTAL

The code for my interrupt and all is:


'''''''''''''''''''''DEFINING and ENABLING INTERRUPT'''''''''''''''
T0CON = %11000111
INTCON = %00100000

On Interrupt GoTo SwitchOff

GoTo ProgramInitializationCont

Disable
SwitchOff:

If CountIntTimer < TimerInSMS Then
CountIntTimer = CountIntTimer + 1
INTCON.2 = 0
ElseIf CountIntTimer = TimerInSMS Then
CountIntTimer = CountIntTimer + 1
Power = 1 'Power Off
Else
Resume
EndIf
Resume
Enable

''''''''''''''''''''''DEFINING and ENABLING INTERRUPT FINISHED'''''''''''''''


TimeInSMS = 100

ProgramInitializationCont:

If PortA.0 = 1 then
CountIntTimer = 0
INTCON.2 = 0
endif
if PortB.7 = 1 then 'I'M NOT ABLE TO READ PORTB.5-7
'Some other action
endif

end

''''''''''''''''''END OF CODE'''''''''''''''''''''''''''''''''

An urgent solution in timers implementation and PortB reuse would be appreciated

Best Regards
JD

PS: Although the code functions well on the OshonSoft PIC18 Simulator but am NOT ABLE TO READ MY PORTB IN PHYSICAL :(

jamshid.dastur
- 8th April 2010, 03:20
Instead of using the interrupts and blocking my port and all... i inserted the counter section into my main loops and making it count as it was in the interrupt, and without even enabling or disabling everything works fine and as had to... the section for timer now is


timerin =1333333 ' The value depends on the program length, for my program length this value represents 1Minute or 60Seconds

Main:

'TIMER ROUTINE
If TimerOn = 1 Then
CountIntTimer = CountIntTimer + 1
If CountIntTimer = TimerIn Then
Power = 1 'Power Off
TimerOn = 0
EndIf
EndIf

if PortB.0 = 1 Then
countinttimer = 0
power = 0
endif

goto main

end