Tissy
- 10th April 2005, 14:40
As i am using the MCLR PORT as an input pin and also have an Interrupt Switch on RB.0. I would however, still like the option of having a Reset. I'm thinking of using the Interrupt switch as this option. At the moment it works as a menu selection type switch, push it once, it jumps to the next sequence, push it again, another sequence etc etc. I'm thinking that if the button is held down for 5 seconds then a RESET occurs.
The code i have is as follows:
' register and interrupt definition
'
CMCON = 7 ' Disable analog comparator on PORTA... not needed as now
OPTION_REG=0 ' enable pull-up resistor on PORTb
' Interrupt on falling edge of RB0
INTCON = %10010000 ' Enable RB0 interrupt
On Interrupt Goto ProcedureSwitcher
SoftwareReset:
Clear
@ clrf PCLATH
@ Goto 0
Return
ProcedureSwitcher:
Low PORTB.1 ' reset output to PORTB
Low PORTB.2
Low PORTB.3
Low PORTB.4
Low PORTB.5
DelayLoop=Delay ' to exit the delay loop
GetOut = 1 ' to get out of the entire PWM loops
PushHowManytimes=PushHowManytimes+1 ' Changing task
If PushHowManytimes=19 Then PushHowManytimes=1
InterruptHandler:
While ModeSwitch = 0 ' waiting until
wend ' push-button is release
pause 100 ' debounce time
If ModeSwitch=0 Then InterruptHandler
INTCON.1=0 ' reset RB0 interrupt flag
Resume ' Return to main program
Enable ' Enable interrupts after
' handler
Obviously thats not all of it, just the bits i think is relevant. The Interrupt Switch is known as ModeSwitch. I've tried putting this 5 second 'Button Held Down' Routine in the code, but having all sorts of problems. This is what i have come up with for the 5 Second Button Down Routine.
TimeOut VAR Byte
While Timeout < 100
While ModeSwicth = 0:Wend
Else
TimeOut = TimeOut + 1
Pause 50
EndIf
If TimeOut = 5000 Then Softwarereset
Wend
Am i right in thinking the code to do this needs to go in the InterruptHandler Routine, also have i got the 5 second pause bit right. I'm thinking not though !! I only want it to do the 5 second pause if the button is HELD down, if it is a single switch action then it performs normally.
Many Thanks,
Steve
The code i have is as follows:
' register and interrupt definition
'
CMCON = 7 ' Disable analog comparator on PORTA... not needed as now
OPTION_REG=0 ' enable pull-up resistor on PORTb
' Interrupt on falling edge of RB0
INTCON = %10010000 ' Enable RB0 interrupt
On Interrupt Goto ProcedureSwitcher
SoftwareReset:
Clear
@ clrf PCLATH
@ Goto 0
Return
ProcedureSwitcher:
Low PORTB.1 ' reset output to PORTB
Low PORTB.2
Low PORTB.3
Low PORTB.4
Low PORTB.5
DelayLoop=Delay ' to exit the delay loop
GetOut = 1 ' to get out of the entire PWM loops
PushHowManytimes=PushHowManytimes+1 ' Changing task
If PushHowManytimes=19 Then PushHowManytimes=1
InterruptHandler:
While ModeSwitch = 0 ' waiting until
wend ' push-button is release
pause 100 ' debounce time
If ModeSwitch=0 Then InterruptHandler
INTCON.1=0 ' reset RB0 interrupt flag
Resume ' Return to main program
Enable ' Enable interrupts after
' handler
Obviously thats not all of it, just the bits i think is relevant. The Interrupt Switch is known as ModeSwitch. I've tried putting this 5 second 'Button Held Down' Routine in the code, but having all sorts of problems. This is what i have come up with for the 5 Second Button Down Routine.
TimeOut VAR Byte
While Timeout < 100
While ModeSwicth = 0:Wend
Else
TimeOut = TimeOut + 1
Pause 50
EndIf
If TimeOut = 5000 Then Softwarereset
Wend
Am i right in thinking the code to do this needs to go in the InterruptHandler Routine, also have i got the 5 second pause bit right. I'm thinking not though !! I only want it to do the 5 second pause if the button is HELD down, if it is a single switch action then it performs normally.
Many Thanks,
Steve