CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Can't get LVD module to work in PIC18F2320

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

Can't get LVD module to work in PIC18F2320
PostPosted: Sat Jul 24, 2004 2:36 pm     Reply with quote

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.
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

Re: Can't get LVD module to work in PIC18F2320
PostPosted: Sat Jul 24, 2004 3:42 pm     Reply with quote

Nevermind. Bogus bitwise logic.

--
Jeff S.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group