Here some code I started but i don't think it's handling interrupt's right
Code: Select all
Device = 18f2520
Clock = 8
Config osc = INTIO67
Include "utils.bas"
Include "HiLowVolts"
Event OnVoltChange()
If PIR2.bits(2) = 1 Then
PORTC.7 = 1
PIR2.bits(2) = 0
Else
PORTC.7 = 0
End If
End Event
Dim LedRed As PORTC.7
Dim LedGreen As PORTC.6
OSCCON=$72
SetAllDigital
Output(LedGreen)
Output(LedRed)
LedRed = 0
LedGreen = 0
HLVDCON =%00011011
While true
HiLowVolts.Initialize (OnVoltChange)
Toggle (LedGreen)
DelayMS(1000)
Wend
Code: Select all
Module HiLowVolts
// event handler type...
Type TEvent = Event()
// local and public variables...
Dim LowVolts As TEvent
// ISR routine...
Interrupt OnVoltChange()
LowVolts()
End Interrupt
// initialize...
Public Sub Initialize(pOnvoltEvent As TEvent)
LowVolts = pOnVoltEvent
PIR2.bits(2) = 0 //clear HLVD flag
PIE2.bits(2) = 1 //enables HLVD interupt
intcon.7 = 1 //enables HLVD interupt
Enable(OnVoltChange)
End Sub