{
*****************************************************************************
* 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 led0 As PORTC.3 // 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
'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 ' moved to end
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
// PORTB 7:4 has changed
If s1 = 0 Then
RBIF = 1
LED1 = 1
For x = 0 To 5
led2 = 0
led0 = 0
DelayMS(500)
Toggle (LED1)
DelayMS(500)
Toggle (LED1)
Next
LED1 = 0
End If
If s2 = 0 Then
RBIF = 1
led2 =1
For x = 0 To 5
LED1 = 0
led0 = 0
DelayMS(500)
Toggle (led2)
DelayMS(500)
Toggle (led2)
Next
led2 = 0
End If
if s3 = 0 and PIR2.bits(2)=1 Then // check hlvd flag
for x = 0 to 5
led0 = 1 //blue
DelayMS(500)
toggle(led0)
delayms(500)
next
pir2.bits(2)=0
EndIf
if pir2.bits(2)=0 then
led1 = 1
delayms(500)
toggle(led1)
endif
EndIf
RBIF = 0 // clear flag this changed from 3x to 2x
// Restore // Restore the system variables
// WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
Restore
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 //
Disable(PORTB_Change) //
EndIf //
End Sub
Inline Sub Sleep()
Asm
Sleep
End Asm
End Sub
SetAllDigital
Input(s1)
Input(s2)
Input(s3)
output(led0)
output(led1)
output(led2)
HLVDCON = %00011000 // 3.39 volts change bit 7 for testing the HLVD
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 = 0 // turn off all leds
LED1 = 0
led2 = 0
While True // Infinite loop
PORTB_Interrupts(True) // Enable PORTB interrupts
Sleep // Put the PIC to sleep and wait for a change
// on PORTB 7:4
Wend
'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 ' moved to end
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
// PORTB 7:4 has changed
If s1 = 0 Then
RBIF = 1
LED1 = 1
For x = 0 To 5
led2 = 0
led0 = 0
DelayMS(500)
Toggle (LED1)
DelayMS(500)
Toggle (LED1)
Next
LED1 = 0
End If
If s2 = 0 Then
RBIF = 1
led2 =1
For x = 0 To 5
LED1 = 0
led0 = 0
DelayMS(500)
Toggle (led2)
DelayMS(500)
Toggle (led2)
Next
led2 = 0
End If
if s3 = 0 and PIR2.bits(2)=1 Then // check hlvd flag
for x = 0 to 5
led0 = 1 //blue
DelayMS(500)
toggle(led0)
delayms(500)
next
pir2.bits(2)=0
EndIf
if pir2.bits(2)=0 then
led1 = 1
delayms(500)
toggle(led1)
endif
EndIf
RBIF = 0 // clear flag this changed from 3x to 2x
// Restore // Restore the system variables
// WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
Restore
End Interrupt
The processor responds by suspending its current activities, saving its state, and executing a small program called an interrupt handler (or interrupt service routine, ISR) to deal with the event.
Ok guess our on your own now.Weather its a good idea or not?
Like if PORTB not PORTB then find the change reset the interrupt jump to run needed code in main
Which while were here let's find a better bike light cause mine is broke the test battery switch don't work
and i can't tell if there dead. Why are they saying that is not battery tester for testing a battery?
How's yours work when there dead
If s1 = 0 Then
RBIF = 1
LED1 = 1
For x = 0 To 5
led2 = 0
led0 = 0
DelayMS(500)
Toggle (LED1)
DelayMS(500)
Toggle (LED1)
Next
LED1 = 0
End If
For I = 1 to 10
Toggle (LED1)
Delayms(500)
Next
LED1 = 0
processing in ISR, all other intterupts are disabled temporarily. For this same reason, you want to keep your ISR as short as possible (to avoid messing with the system clock itself
...and as Burt pointed out I have too many delays in the interrupt(3.5seconds? I need to look and find out how you figured that out. ...
Interrupt PORTB_Change()
Save(0) // Save the system variables
If RBIF = 1 Then // Check if the interrupt was a PORTB change
//RBIF = 0 ' moved to end
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
// PORTB 7:4 has changed
//************************************************************ First possible path
If s1 = 0 Then
RBIF = 1
LED1 = 1
For x = 0 To 5 //************************** five loops
led2 = 0
led0 = 0
DelayMS(500) //************************** 500 mS delay
Toggle (LED1)
DelayMS(500) //************************** 500 mS delay
Toggle (LED1)
Next // 5 loops * (500 mS + 500 mS) = 5 seconds!
LED1 = 0
End If
//************************************************************ Second possible path
If s2 = 0 Then
RBIF = 1
led2 =1
For x = 0 To 5 //************************** five loops
LED1 = 0
led0 = 0
DelayMS(500) //************************** 500 mS delay
Toggle (led2)
DelayMS(500) //************************** 500 mS delay
Toggle (led2)
Next
led2 = 0
End If
//************************************************************ third possible path
if s3 = 0 and PIR2.bits(2)=1 Then // check hlvd flag
for x = 0 to 5 //************************** five loops
led0 = 1 //blue
DelayMS(500) //************************** 500 mS delay
toggle(led0)
delayms(500) //************************** 500 mS delay
next // 5 loops * (500 mS + 500 mS) = 5 seconds!
pir2.bits(2)=0
EndIf
if pir2.bits(2)=0 then
led1 = 1
delayms(500)
toggle(led1)
endif
EndIf
RBIF = 0 // clear flag this changed from 3x to 2x
// Restore // Restore the system variables
// WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
Restore
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 //
Disable(PORTB_Change) //
EndIf //
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, 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 PORTC.3 // 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
'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 ' moved to end
WREG = PORTB // Be sure to read the contents of PORTB to
// clear the mismatch
// PORTB 7:4 has changed
'xxxxxxxxxxxxxxxxxxxxxxxxxxx
// TURN DETECTION
'xxxxxxxxxxxxxxxxxxxxxxxxxx
' LEFT
'--------------------
If s1 = 0 Then
RBIF = 1
LED1 = 1 // GREEN // NOTE I need to make ports LOW for transmission, HIGH for testing
led2 = 0
led0 = 0
TX_pwr = 1 // turn on transmitter
TX_Enable = 0 // enable encoder
DelayMS(500)
Toggle (LED1)
delayms(500)
LED1 = 0 // make sure its off
tx_pwr = 0
TX_Enable =1 // LOW for transmit
End If
'-------------------------
' RIGHT
'--------------------------
If s2 = 0 Then
RBIF = 1
led0 = 0
LED1 = 0
led2 = 1 // RED
TX_pwr = 1 // turn on transmitter
TX_Enable = 0 // enable encoder
DelayMS(500) // just enough to see for testing
Toggle (led2)
delayms(500)
led2 = 0 // make sure its off
tx_pwr = 0
TX_Enable =1 // LOW for transmit
End If
'xxxxxxxxxxxxxxxxxxxxxxxxxx
// BATTERY TEST
'xxxxxxxxxxxxxxxxxxxxxxxxxxx
' BAD BATTERY
if s3 = 0 and 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 s3 = 0 and 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?
EndIf
RBIF = 0 // Port change interrupt flag bit
Restore
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
SetAllDigital
Input(s1)
Input(s2)
Input(s3)
output(led0)
output(led1)
output(led2)
output(TX_Enable)
output(TX_pwr)
output(GD_bat)
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 = 0 // 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
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?