This is a multi-part message in MIME format. ------=_NextPart_000_0016_01C091B6.B1B3CD40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > 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. < There is no "glitch " in your program. It works fine in mplab and it ran ok on a pic16f627 I have, though I changed the comf portb,f instruction, and I would suggest you change the context saving at the start and end of the interrupt routine (see notes in attached file rjc3.asm). I set a break point at the movlw 0x05 in the DecInner: . It stopped there every 50ms. I set another break point at the goto ReInit instruction. It stopped there every 5 seconds (hint: use Debug>Execute>Conditional break for this, it is much quicker, but still painfully slow). In your code you did not set up the fuses. Unless you set them when you programmed the chip, the oscillator may not have worked (depending on your setup of course). James Hillman ------=_NextPart_000_0016_01C091B6.B1B3CD40 Content-Type: application/octet-stream; name="rjc3.asm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="rjc3.asm" #define pic16f627 LIST P =3D PIC16F627 INCLUDE ; P16F627 include file __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & = _LVP_OFF=20 w_temp equ 0x20 ;leave this location free in bank 1 status_temp equ 0x21 DelayValue equ 0x22 DelayTemp equ 0x23 Counter equ 0x24 Outer equ 0x25 FLAG equ 0x26 ORG 0x000 ; processor reset vector clrf PCLATH ; ensure page bits = areclaared goto main ; go to beginning of = program ORG 0x004 ; interrupt vector = location movwf w_temp ; save off current = Wregister contents movf STATUS,w ; move status register = intoW register bcf STATUS,RP0 ; ensure file register = bankset to 0 movwf status_temp ; save off contents = ofSTATUS register movf DelayValue,w ; move status register = intoW register movwf DelayTemp ; save off = currentDelayValue contents ;;Interrupt context saving better this way : ;;MOVWF w_temp ;save the W register (could be in bank 0 or 1) ;;SWAPF STATUS,w =09 ;;BCF STATUS,RP0 ;;MOVWF status_temp ;and Status register in bank 0 ;;movf DelayValue,w ; move status register intoW register ;;movwf DelayTemp ; save off currentDelayValue contents ;;btfsc PIR1,TMR2IF ; Handler for Timer2 ;;call IntTimer2 ; Interrupt Handler forTimer2 ;;MOVF DelayTemp,W ; retrieve copy of delayregister ;;MOVWF DelayValue ; restore pre-isr DelayValueregister ;;SWAPF status_temp,w ;;MOVWF STATUS=09 ;;SWAPF w_temp,f ;swap it into W register to avoid affecting the Z flag = (if MOVF was used) ;;SWAPF w_temp,w ;;RETFIE btfsc PIR1,TMR2IF ; Handler for Timer2 call IntTimer2 ; Interrupt Handler = forTimer2 bcf STATUS,RP0 ; ensure file register = bankset to 0 movf status_temp,w ; retrieve copy of = STATUSregister movwf STATUS ; restore pre-isr = STATUSregister contents movf DelayTemp,W ; retrieve copy of = delayregister movwf DelayValue ; restore pre-isr = DelayValueregister swapf w_temp,f swapf w_temp,w ; restore pre-isr W = registercontents retfie ; return from interrupt IntTimer2: bcf PIR1,TMR2IF ; Must Clear Int flag = forTimer2 decf Counter,F ; Decrease Counter return main: MOVLW 0x07 ;Turn comparators off and enable MOVWF CMCON ;pins for I/O function MOVLW b'11111111' ;port A all high impedance TRIS PORTA MOVLW b'11111111' ;B3 (Opto output/ADC CS) set MOVWF PORTB ;B2 (ADC clock /opto data) set MOVLW b'11111011' =09 TRIS PORTB ;All others high impedance inputs (B4 and B5 now go high = impedance) bcf STATUS,RP0 ; movlw 0x04 ; movwf Counter ; movlw 0x63 movwf Outer call InitTimer2 ; movlw 0xc0 ; movwf INTCON ; movlw 0x49 ; = Prescaler=3D16,PostScaler=3D16 movwf T2CON ; Since OSC =3D 4Mhz = timer =3D1uS 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 BTFSS FLAG,0 GOTO SetIt BCF PORTB,2 BCF FLAG,0 return SetIt BSF PORTB,2 BSF FLAG,0 return InitTimer2: bcf STATUS,RP0 ; Ensure Reg Bank 0 clrf T2CON ; Stop Timer2, = Pre=3D1:1,Post=3D1:1 clrf TMR2 ; Clear Timer2 register clrf PIR1 ; Clear Interrupt = Flagregister bsf STATUS,RP0 ; Bank1 clrf PIE1 ; Disable all = PeripheralInterrupts bsf PIE1,TMR2IE ; Enable only Timer2 movlw 0xf9 ; Timeout Value =3D 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' ------=_NextPart_000_0016_01C091B6.B1B3CD40-- -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.