Here's something you might find useful: struct time { char hours; char minutes; char seconds; } elapsed; int32 clock; // TIMER0 interrupt service routine. Update the elapsed // time counter. #int_rtcc void tmr0_int() { // This is part of the "zero-error" clock method proposed by // Roman Black on the PICList. We get a TIMER0 interrupt every // 8192 microseconds - 4MHz clock/4 = 1MHz T0 clock, with a /32 // prescaler, divided by 256 since we get an interrupt when T0 // overflows. Did you follow that? OK. So we load the clock // value with 1000000 (cycles per second), then on each interrupt // subtract 8192 (cycles per interrupt). If there is less than // 8192 left, we add one second and add 1000000 to the clock value. // That way any error in one second is compensated for in the // next - we can be off by 8191 uSec per second, but the // cumulative error over time should be zero, plus any inherent // clock frequency error (like 50ppm for a crystal, etc). clock -= 8192; restart_wdt(); if(clock < 8192) { elapsed.seconds++; clock += 1000000; } if(elapsed.seconds == 60) { elapsed.minutes++; elapsed.seconds = 0; } if(elapsed.minutes == 60) { elapsed.hours++; elapsed.minutes = 0; } } Now you have a struct you can go to when you want the elapsed time since you cleared it... elapsed.hour, elapsed.minutes, elapsed.seconds. You can of course expand this to include days, day of the week, whatever. To set it up to start just drop this into main(): setup_counters(RTCC_INTERNAL,RTCC_DIV_32); // This sets T0 interrupt rate clock = 1000000; // One second's worth of interrupts elapsed = 0; // Zero the elapsed time counter on reset enable_interrupts(INT_RTCC); enable_interrupts(global); Now your elapsed time struct ticks merrily away while your main program does something else, like measuring the temperature with an ADC and displaying time and temperature on an LCD! ;) This example is set up for a 4MHz crystal or internal 4MHz oscillator (I used it on a 16F628 based project), but all you have to do is change the clock= line to match whatever freq/4 is, and change the clock -= line to subtract however many cycles occur between interrupts. Hope this helps... Dale -- "Curiosity is the very basis of education and if you tell me that curiosity killed the cat, I say only the cat died nobly." - Arnold Edinborough On Thu, 14 Mar 2002, MATTHEWS, DEAN (D.) wrote: > I am fairly new to PICs but have undertaken a project using a > PIC16F877. I am programming in C and using the CCs compiler. I have > managed to get my A/D working and to output data on an LCD screen. > However my next step in the evolution of my PIC is to use interrupts, > just write a single program for one interrupt. Does anyone have any > idea where I should atart. I have read the example program in the CCS > manual without success. -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics