Maybe try using the TMR0 interrupt. You'll need to configure the TRIS and ANSEL registers to your specific peripherals. It's basically a clock that runs in the background. Every 60th of a second it goes to the dualcounter subroutine (or whatever subroutine you tell it to go to) without you having to call it so that you're free to write code to do other things. The last three bits of the OPTION_REG set up the prescaler which is what tells it how often to interrupt. I'm not exactly sure, but I think 1:64 is about 1/60th of a second. You may need to tweak that a bit though.
Code:#config __CONFIG _CP_OFF & _WDTE_OFF & _BOREN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _IOSCFS_8MHZ #endconfig ADCON0 = %00000000 ADCON1 = %00110000 ANSEL = %00000110 define ADC_SAMPLEUS 50 define ADC_BITS 8 DEFINE ADC_CLOCK 3 CM1CON0 = %00000000 CM2CON0 = %00000000 TRISA = %00001111 TRISC = %00000000 ' Set TMR0 interrupt prescaler to 1:64 OPTION_REG = %10000101 ' Set TMR0 configuration and enable PORTB pullups INTCON = %10100000 ' Enable TMR0 interrupts On Interrupt Goto dualcounter 1minutecounter var word 5minutecounter var word MAIN: ' insert main code here if 1minutecounter > 3600 then ' insert code to handle 1 minute timer here 1minutecounter = 0 ' clear counter endif if 5minutecounter > 18000 then ' insert code to hand 5 minute time here 5minutecounter = 0 'clear counter endif goto MAIN ''''''''''''''''''''''''''''''''''''''''''''''''''''''''INTERRUPT''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Disable ' Disable interrupts during interrupt handler dualcounter: ' Interrupt routine to handle each timer tick 1minutecounter = 1minutecounter + 1 ' add 1 on every interrupt 5minutecounter = 5minutecounter + 1 tiexit: INTCON.2 = 0 ' Reset timer interrupt flag Resume enable end




Bookmarks