Dear All can any one explain to me How to build a clock using Microcontroller timer?? Do you use external crystal oscillator or you use the Microcontroller timer to do the time keeping?? Thanks for your help Sam Sam, Below are some timing routines that I reuse frequently in my PIC coding. (Attention Code Police and Piclister's, please check the readability and math). Building a clock is simply a matter of gluing these type of routines together with a few counters to keep track of minutes, hours, etc, and some kind of display mechanism. Another method of doing the timing (with a PIC device that supports interrupts) would be to set up TMR0 and the prescaler to fire on known intervals and increment your counters in the interrupt service routine. An external crystal or ceramic oscillator is essential, whether or not the PIC you are using has an internal RC oscillator. (The 16C84 has NO internal clock, while the lowly 12C508's and 9's have an internal RC, go figure). The problem with the internal RC (or any RC network unless you use very expensive components) is it's limited accuracy (+-10%) and the fact that the accuracy varies depending on temperature. The accuracy variance may also vary between 2 identical PIC devices making it difficult or impossible to calibrate your clock if you are producing multiple units. Hope this gives you a start... Adam ;************************************************************************* ; TIMER ROUTINES ;************************************************************************* ;this routine implements a 1/2 second timing loop ;Delay calculation is as follows: ; .500420 - by calling the 25ms loop 20 times. ; .000100 - delay of this loops loop housekeeping ; .500520 - subtotal ; .000005 - delay for this loops setup ; .500525 - total delay for this loop delay500 MOVLW 20 MOVWF longcount CALL delay25 DECFSZ longcount,1 GOTO $ - 2 RETLW 0 ;this routine implements a 25ms timing loop. ;Delay calculation is as follows: ; .023836 - by calling the 1/10ms loop 236 times. ; .001180 - delay of this loops loop housekeeping ; .025016 - subtotal ; .000005 - delay for this loops setup ; .025021 - total delay for this loop delay25 MOVLW 236 MOVWF count CALL delay1_10 DECFSZ count,1 GOTO $ - 2 RETLW 0 ;this routine implements a 1/10 millisecond timing loop ;Delay calculation is as follows: ; .000096 - 4 cycle loop 24 times. ; .000005 - delay for this loops setup ; .000101 - total delay for this loop delay1_10 movlw d'24' movwf qmcount nop ;needed to make the loop a nice even 4 cycles decfsz qmcount,1 goto $ - 2 retlw 0