I am a fairly new user of PIC controllers. I am using a PIC 16C74B to flash a set of LEDs, located on PORTB, on and off at 5 second intervals. I know that there are several ways to accomplish this task; however, I have chosen to user Timer2 with PostScaler=10, PR=250, and PreScaler=4 using a 4Mhz clock yielding Internal clock rate of 1uS. By my calculation this produces an Interrupt every 10mS, which works fine. Needing a delay of 5 secs forced the implementation of a inner and outer loop, where the inner loop is executed 5 times and the outer loop is executed a 100 times. The problem is that when I simulate this in MPLAB and use the StopWatch to view the number cycles, my program locks up around 50ms -62ms. If load this code into the PIC, the LEDS come on and stay on. Is there is glitch in my program, MPLAB, or I just missing it. Thanks Ronald The code is shown Below: ORG 0x000 ; processor reset vector clrf PCLATH ; ensure page bits are claared goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register bcf STATUS,RP0 ; ensure file register bank set to 0 movwf status_temp ; save off contents of STATUS register movf DelayValue,w ; move status register into W register movwf DelayTemp ; save off current DelayValue contents btfsc PIR1,TMR2IF ; Handler for Timer2 call IntTimer2 ; Interrupt Handler for Timer2 bcf STATUS,RP0 ; ensure file register bank set to 0 movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents movf DelayTemp,W ; retrieve copy of delay register movwf DelayValue ; restore pre-isr DelayValue register swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt IntTimer2: bcf PIR1,TMR2IF ; Must Clear Int flag for Timer2 decf Counter,F ; Decrease Counter return main: bcf STATUS,RP0 ; movlw 0x04 ; movwf Counter ; movlw 0x63 movwf Outer call InitTimer2 ; movlw 0xc0 ; movwf INTCON ; movlw 0x49 ; Prescaler=16, PostScaler=16 movwf T2CON ; Since OSC = 4Mhz timer = 1uS bsf T2CON,TMR2ON ; Start Timer MainLoop: call DecOuter call LED goto MainLoop ;*************************************************************************** ****************** ;* Everything in this section represents either initialization code or * ;* helper functions. * ;* * ;* Ronald J.Cotton * ;* 02/02/2001 * ;*************************************************************************** ****************** DecOuter: decf Outer,F DecInner: btfss Counter,7 ; goto DecInner movlw 0x05 ; addwf Counter,F ; Put Counter back to 50 btfss Outer,7 goto DecOuter goto ReInit ReInit: movlw 0x64 addwf Outer,F return LED: comf PORTB,F ; Toggle PORTB return InitTimer2: bcf STATUS,RP0 ; Ensure Reg Bank 0 clrf T2CON ; Stop Timer2, Pre=1:1, Post=1:1 clrf TMR2 ; Clear Timer2 register clrf PIR1 ; Clear Interrupt Flag register bsf STATUS,RP0 ; Bank1 clrf PIE1 ; Disable all Peripheral Interrupts bsf PIE1,TMR2IE ; Enable only Timer2 movlw 0xf9 ; Timeout Value = 249 movwf PR2 ; clrf TRISB ; Make PortB output bcf STATUS,RP0 ; Back to Bank0 movlw 0xff ; All on movwf PORTB ; Initialize LEDS to be on return END ; directive 'end of program' -- 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