Spending too much time in the ISR
Don't use delays, write to slow peripherals like LCDs, write to EEPROM, or perform other time-consuming tasks in the ISR. If you have an interrupt that occurs more quickly than one of these tasks, your application never gets out of the ISR and your main code never runs.
Here one for the road
'xxxxxxxxxxxxxxxxxxxx
'interrupt
'xxxxxxxxxxxxxxxxxxxxx
Interrupt PORTB_Change()
Save(0) // Save the system variables
If RBIF = 1 Then // Check if the interrupt was a PORTB change
RBIF = 0
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
WhatTheHellButtonWasPressed = PORTB
// PORTB 7:4 has changed, do what you want here...
EndIf
Restore // Restore the system variables
End Interr
'xxxxxxxxxxxxxxxxxxxx
'interrupt
'xxxxxxxxxxxxxxxxxxxxx
Interrupt PORTB_Change()
Save(0) // Save the system variables
If RBIF = 1 Then // Check if the interrupt was a PORTB change
RBIF = 0
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
s2 = PORTB
// PORTB 7:4 has changed, do what you want here...
EndIf
Restore // Restore the system variables
End Interrupt
Sub PORTB_Interrupts(Control As Boolean) // Small routine to enable/disable PORTB Interrupts.
If Control = True Then
RBIE = 1 // interrupt enable bit
Enable(PORTB_Change)
Else
RBIE = 0 // port change interrupt enable bit
Disable(PORTB_Change) //
EndIf //
End Sub
While True // Infinite loop
PORTB_Interrupts(True) // Enable PORTB interrupts
If s2 = 0 Then
enable (portb_Change)
led0 = 0
DelayMS(2000)
Toggle(led0)
Else
led0=1
End If
Sleep // Put the PIC to sleep and wait for a change
// on PORTB 7:4
Wend
// your main would be like this
Start_ Interrupt // turns on the PORTB interrupt's
If change_Happened then // test for change
// what you want to do goes here
endif
If but_HV = 1 then // then test the battery
Test_Batt // sub is called here
endif
//If none of the above is happening
//I'm taking a nap
sleep // here
If change_Happened then
// wake me up
endif
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 1/2/2013 *
* Version : 1.0 *
* Notes : this one works 1/10/2013 *
* : *
*****************************************************************************
}
Device = 18F2420
Clock = 8
Config LVP = OFF, mclre = off
Include "InternalOscillator.bas"
Include "utils.bas"
Dim RBIF As INTCON.0 //port change interupt flag
Dim RBIE As INTCON.3 //port change interupt enable
Dim x As Byte
Dim TX_Enable As PORTC.0
Dim TX_pwr As PORTC.1
Dim GD_bat As PORTC.2
Dim led0 As PORTA.5 // blue
Dim LED1 As PORTC.4 //green
Dim led2 As PORTC.5 //red
Dim s1 As PORTB.6
Dim s2 As PORTB.5
Dim s3 As PORTB.4
Dim saveport As Byte
//Dim As PORTB.5
'xxxxxxxxxxxxxxxxxxxx
'interrupt
'xxxxxxxxxxxxxxxxxxxxx
Interrupt PORTB_Change()
Save(0) // Save the system variables
If RBIF = 1 Then // Check if the interrupt was a PORTB change
RBIF = 0
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
// PORTB 7:4 has changed, do what you want here...
saveport = PORTB
EndIf
Restore // Restore the system variables
End Interrupt
Sub PORTB_Interrupts(Control As Boolean) // Small routine to enable/disable PORTB Interrupts.
If Control = True Then
RBIE = 1 // interrupt enable bit
Enable(PORTB_Change)
Else
RBIE = 0 // port change interrupt enable bit
Disable(PORTB_Change) //
EndIf //
End Sub
Inline Sub Sleep()
Asm
Sleep
End Asm
End Sub
//sssssssssssssssssssssssssssssssssssssssssss
SetAllDigital
Input(s1)
Input(s2)
Input(s3)
Output(led0)
Output(LED1)
Output(led2)
Output(TX_Enable)
Output(TX_pwr)
Output(GD_bat)
saveport.bits(5)=1
HLVDCON = %00010111 // 3.12 volts
PIR2.bits(2)=0 // clear HLVD flag
PIE2.bits(2) = 1 //enable HLVD interrupt
// Start Of Program...
TRISB = %11110000 // Make PORTB7:4 all inputs
TRISC = %00000000 // Make PORTC all outputs
led0 = 1 // turn off all leds
LED1 = 0
led2 = 0
TX_Enable = 1
TX_pwr = 0
GD_bat=0
While True // Infinite loop
PORTB_Interrupts(True) // Enable PORTB interrupts
if saveport.bits(5) = 0 then
led0 = 0 // turn on led0
delayms(2000)
led0 = 1 // turn off led0
end if
Sleep // Put the PIC to sleep and wait for a change
// on PORTB 7:4
Wend
Device = 18F2420
Clock = 8
Config LVP = OFF, mclre = off
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 1/2/2013 *
* Version : 1.0 *
* Notes : this one works 1/10/2013 *
* : *
*****************************************************************************
}
Device = 18F2420
Clock = 8
Config LVP = Off
Include "InternalOscillator.bas"
Include "utils.bas"
Dim RBIF As INTCON.0 //port change interupt flag
Dim RBIE As INTCON.3 //port change interupt enable
Dim x As Byte
Dim TX_Enable As PORTC.0
Dim TX_pwr As PORTC.1
Dim GD_bat As PORTC.2
Dim led0 As PORTA.5 // blue
Dim LED1 As PORTC.4 //green
Dim led2 As PORTC.5 //red
Dim s1 As PORTB.6
Dim s2 As PORTB.5
Dim s3 As PORTB.4
Dim saveport As Byte
//Dim As PORTB.5
'xxxxxxxxxxxxxxxxxxxx
'interrupt
'xxxxxxxxxxxxxxxxxxxxx
Interrupt PORTB_Change()
Save(0) // Save the system variables
If RBIF = 1 Then // Check if the interrupt was a PORTB change
RBIF = 0
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
// PORTB 7:4 has changed, do what you want here...
saveport = PORTB
EndIf
Restore // Restore the system variables
End Interrupt
Sub PORTB_Interrupts(Control As Boolean) // Small routine to enable/disable PORTB Interrupts.
If Control = True Then
RBIE = 1 // interrupt enable bit
Enable(PORTB_Change)
Else
RBIE = 0 // port change interrupt enable bit
Disable(PORTB_Change) //
EndIf //
End Sub
Inline Sub Sleep()
Asm
Sleep
End Asm
End Sub
//sssssssssssssssssssssssssssssssssssssssssss
SetAllDigital
Input(s1)
Input(s2)
Input(s3)
Output(led0)
Output(LED1)
Output(led2)
Output(TX_Enable)
Output(TX_pwr)
Output(GD_bat)
saveport.bits(5)=1
HLVDCON = %00010111 // 3.12 volts
PIR2.bits(2)=0 // clear HLVD flag
PIE2.bits(2) = 1 //enable HLVD interrupt
// Start Of Program...
TRISB = %11110000 // Make PORTB7:4 all inputs
TRISC = %00000000 // Make PORTC all outputs
led0 = 1 // turn off all leds
LED1 = 0
led2 = 0
TX_Enable = 1
TX_pwr = 0
GD_bat=0
While True // Infinite loop
PORTB_Interrupts(True) // Enable PORTB interrupts
If saveport.bits(5) = 0 Then
led0 = 1 // turn on led0
DelayMS(4000)
led0 = 1 // turn off led0
RBIE = 1
End If
Sleep // Put the PIC to sleep and wait for a change
// on PORTB 7:4
Wend
...On the HLVD it appears to be working but after I get the code edited I will run it again to be sure. The code is in the same order that you posted with added bells n whistles.. I used LEDs to indicate when each statement enabled a certain pin...
' xxxxxxxxxxxxxxxxxxxxxxxxxx
Sub BATTERY_TEST()
'xxxxxxxxxxxxxxxxxxxxxxxxxxx
' BAD BATTERY
If PIR2.bits(2)=1 Then // check hlvd flag
TX_pwr = 1 //turn on transmitter
led0 = 1 //blue led next to green BI color in final plan
DelayMS(1000)
Toggle(led0)
End If
PIR2.bits(2)=0
' GOOD BATTERY
If PIR2.bits(2)=0 Then
GD_bat = 1 // green led next to blue GD_bat = good battery
DelayMS(1000)
Toggle( GD_bat)
DelayMS(1000)
TX_pwr = 0 //turn off transmitter
EndIf
// PIR2.bits(2)=0 // reset interrupt flag DO I REALLY NEED TO RESET?
// RBIF = 0 // Port change interrupt flag bit
End Sub
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 1/2/2013 *
* Version : 1.0 *
* Notes : this one works 1/10/2013 *
* : *
*****************************************************************************
}
Device = 18F2420
Clock = 8
Config LVP = Off
Include "InternalOscillator.bas"
Include "utils.bas"
Dim RBIF As INTCON.0 //port change interupt flag
Dim RBIE As INTCON.3 //port change interupt enable
Dim x As Byte
Dim TX_Enable As PORTC.0
Dim TX_pwr As PORTC.1
Dim GD_bat As PORTC.2
Dim led0 As PORTA.5 // blue
Dim LED1 As PORTC.4 //green
Dim led2 As PORTC.5 //red
Dim s1 As PORTB.6
Dim s2 As PORTB.5
Dim s3 As PORTB.4
Dim saveport As Byte
//Dim As PORTB.5
'xxxxxxxxxxxxxxxxxxxx
'interrupt
'xxxxxxxxxxxxxxxxxxxxx
Interrupt PORTB_Change()
Save(0) // Save the system variables
If RBIF = 1 Then // Check if the interrupt was a PORTB change
RBIF = 0
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
// PORTB 7:4 has changed, do what you want here...
saveport = PORTB
EndIf
Restore // Restore the system variables
End Interrupt
Sub PORTB_Interrupts(Control As Boolean) // Small routine to enable/disable PORTB Interrupts.
If Control = True Then
RBIE = 1 // interrupt enable bit
Enable(PORTB_Change)
Else
RBIE = 0 // port change interrupt enable bit
Disable(PORTB_Change) //
EndIf //
End Sub
Inline Sub Sleep()
Asm
Sleep
End Asm
End Sub
//sssssssssssssssssssssssssssssssssssssssssss
SetAllDigital
Input(s1)
Input(s2)
Input(s3)
Output(led0)
Output(LED1)
Output(led2)
Output(TX_Enable)
Output(TX_pwr)
Output(GD_bat)
saveport.bits(5)=1
HLVDCON = %00010111 // 3.12 volts
PIR2.bits(2)=0 // clear HLVD flag
PIE2.bits(2) = 1 //enable HLVD interrupt
// Start Of Program...
TRISB = %11110000 // Make PORTB7:4 all inputs
TRISC = %00000000 // Make PORTC all outputs
led0 = 1 // turn off all leds
LED1 = 0
led2 = 0
TX_Enable = 1
TX_pwr = 0
GD_bat=0
While True // Infinite loop
PORTB_Interrupts(True) // Enable PORTB interrupts
If saveport.bits(5) = 0 Then
led0 = 1 // turn on led0
DelayMS(4000)
led0 = 1 // turn off led0
RBIE = 1
End If
Sleep // Put the PIC to sleep and wait for a change
// on PORTB 7:4
Wend
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?