You can do the Main loop like this: main_loop banksel LED_TIMER ; Selects bank containing LED_TIMER movf LED_TIMER,f ; Check if register LED_TIMER is 0 btfss STATUS,Z goto main_loop ; Wait until LED_TIMER counter reaches zero times_up1 movlw .100 ; Re-initizalize LED_TIMER movwf LED_TIMER state1 ; This simplified State Machine only could have 2 states, ; you probably want to write a much better one banksel STATE btfsc STATE,0 goto state2 ; Not State 1, try State 2 bsf STATE,0 ; Change State banksel PORTA bsf PORTA,1 ; Turn LED on goto main_loop state2 bcf STATE,0 ; Change State banksel PORTA bcf PORTA,1 ; Turn LED off goto main_loop Tamas On 4 July 2013 08:07, Tamas Rudnai wrote: > Not sure if you got my previous e-mail about the color coded ISR? That on= e > helps you to understand the structure. Anyway, just a small modification = to > that that includes your LED_TIMER variable: > > ;************************ INTERRUPT ROUTINE > ********************************* > > org 0x0004 ; Interrupt vector > > pologue > > movwf w_temp ; Saves value in register W > > movf STATUS ; Saves value in register STATUS > > movwf status_temp > > movf PCLATH ; Saves value in register PCLATH > > movwf pclath_temp > > > > isr_case_TMR0 > > banksel INTCON ; Selects bank containing INTCON > > btfsc INTCON, TMR0IF ; Check if interrupt occurred by TMR0 > > goto isr_tmr0 ; Yes, go to it=92s ISR > > isr_default > > goto epilogue > > > > isr_tmr0 > > banksel LED_TIMER ; Selects bank containing LED_TIMER > > movf LED_TIMER,f ; Check if register LED_TIMER is 0 > > btfsc STATUS,Z ; Only when it is non-zero, it... > > decf LED_TIMER ; Decrements register COUNTER by 1 > > > > eoi_tmr0 > > banksel INTCON ; Selects bank containing INTCON > > bcf INTCON,TMR0IF ; Clears interrupt flag TMR0IF > > > > epilogue > > movf pclath_temp,w ; PCLATH is given its original content > > movwf PCLATH > > movf status_temp,w ; STATUS is given its original content > > movwf STATUS > > swapf w_temp,f ; W is given its original content > > swapf w_temp,w > > > > retfie ; Return from interrupt routine > > > Now in the main loop you check if LED_TIMER is zero. If it is, then turn > led on or off depending on the state plus set LED_TIMER to the designated > value. > > Tamas > > > > On 4 July 2013 06:15, Electronic Consultation < > electronic.consultation.au@gmail.com> wrote: > >> or : >> >> counting btfss INTCON,T0IF ;is timer0 interrupt flag true ? >> goto zero_status >> bcf INTCON,T0IF ;if T0IF=3Dfalse >> clear timer0 interrupt flag >> decf LedTimer,1 ;if T0IF=3Dtrue reduc= e >> the counter >> ;check if LedTimer =3D 0 ? >> zero_status btfsc STATUS, Z ;Z bit is set >> to 1 if W was 00 - skip next instruction if not 00 >> ;LedTimer=3D0 >> goto counting ;from btfsc if it's 1, go >> to next state >> ;LedTimer!=3D0 >> goto next_state ;from btfsc if it's >> 0 keep counting interrupt >> >> next_state incf LedState,1 ; if 00 increase >> the state, for the next state >> return >> -- >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist >> > > > > -- > int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; > printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", > q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } > --=20 int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .