MrDEB
Well-Known Member
interrupt 2x instead of 1x
Been hacking this for a day and a half trying to configure to get one interrupt to enable LED on portA.5 but getting two cycles through code instead of one.
When I started I was getting 3x.
I only need 1x
Also thinking I should get a lower current draw during SLEEP. Presently drawing 4,2ma during sleep.
Been hacking this for a day and a half trying to configure to get one interrupt to enable LED on portA.5 but getting two cycles through code instead of one.
When I started I was getting 3x.
I only need 1x
Also thinking I should get a lower current draw during SLEEP. Presently drawing 4,2ma during sleep.
Code:
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : Doug *
* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 1/4/2013 *
* Version : 1.0 *
* Notes : had 3x but now 2x. Only need 1x *
* : *
*****************************************************************************
}
Device = 18F2420
Clock = 8
Include "InternalOscillator.bas"
Dim RBIF As INTCON.0 //port change interupt flag
Dim RBIE As INTCON.3 //port change interupt enable
Dim LED1 As PORTA.5
Dim led2 As PORTA.3
'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
LED1 = 0
DelayMS(5000)
Toggle (LED1)
DelayMS(500)
EndIf
RBIF = 0 // clear flag this changed from 3x to 2x
// 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 //
Disable(PORTB_Change) //
EndIf //
End Sub
Inline Sub Sleep()
Asm
Sleep
End Asm
End Sub
// Start Of Program...
TRISB = %11110000 // Make PORTB7:4 all inputs
//TRISC = %00000000 // Make PORTC all outputs
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