object01
Joined: 13 May 2004 Posts: 90 Location: Nashville, TN
|
Can't get LVD module to work in PIC18F2320 |
Posted: Sat Jul 24, 2004 2:36 pm |
|
|
I've written the following code, according to the instructions on PDF-page 236 of the PIC18F2320 data sheet:
Code: | int1 voltageTripwire = FALSE;
void main() {
unsigned int8 LVDCON;
unsigned int8 PIR2;
unsigned int8 newTripValue = 0b11111110; // Mask top 4 bits for ANDing with LVDCON
#locate LVDCON=0xFD2
#locate PIR2=0xFA1
while (TRUE) {
// Set trip value
LVDCON &= newTripValue--;
if ((newTripValue & 0b00001111) == 0) newTripValue |= 0b00001110;
fprintf(DEBUGGER, "New trip value: %u\n", newTripValue);
// Disable LVD interrupt or global interrupts
disable_interrupts(GLOBAL);
// Enable LVD module
bit_set(LVDCON, 4);
// Wait for LVD module to stabilize
while (!bit_test(LVDCON, 5)) {}
// Clear LVD interrupt flag
bit_clear(PIR2, 2);
// Enable interrupts
enable_interrupts(GLOBAL);
enable_interrupts(INT_LVD);
delay_ms(5000);
if (voltageTripwire) fprintf(DEBUGGER, "Trip!\n");
}
} |
My interrupt service routine looks like this:
Code: | #int_lvd
void lowVoltageTrip() {
voltageTripwire = TRUE;
} |
My program traces indicate that the trip value does cycle through the range of LVD ranges specified in the data sheet, but voltageTripwire is never set. What am I missing?
--
Jeff S. |
|