You've lost me again. Did you read carefully my discussion on using flags as triggers for actions? I'm going to presume that the code below is in your interrupt service routine.=20 On Thu, Jul 04, 2013 at 09:07:47PM +0800, Electronic Consultation wrote: > Guys, >=20 > What should I do if T0IF =3D 0 ? nop ? You skip the section that deals with the timer 0 interrupt and move on to the next interrupt that could have triggered the interrupt service routine. Since it's an interrupt service routine, then at least one of the enabled interrupts caused it. They may not all be flagged. But at least one is on. Use that one as the trigger for the action. >=20 > counting btfss INTCON,T0IF ;is timer0 interrupt flag true ? > * nop** goto process_next_interrupt_flag > * bcf INTCON,T0IF ;if T0IF=3Dfalse=20 > clear timer0 interrupt flag > decf LedTimer,1 ;if T0IF=3Dtrue reduce= =20 ; Suggestion: Do not use 1 and 0 as the target. All PIC include files have ; the symbols W and F defined as targets. > the counter > ;check if LedTimer =3D 0 ? > btfsc STATUS, Z ;Z bit is set to 1= =20 The two instrutions above (decf, btfsc STATUS,Z) can be combined into a single DECFSZ. That's the purpose of the instruction. So combining the last two notes the above two lines should be: DECFSZ LedTimer,F > if W was 00 - skip next instruction if not 00 > ;LedTimer=3D0 > goto next_state ;from btfsc if it's 1,=20 If you use DECFSZ you reach the above goto if the LedTimer is not zero. Since this does not change the state. You should again leave the area processing the Timer 0 interrupt. So again: goto process_next_interrupt_flag > go to next state > ;LedTimer!=3D0 > goto counting ;from btfsc if it's 0 >= keep counting interrupt The above instruction should be removed. Again since this is an interrupt service routine, when you finish with a section, you move to the next section to process the next type of interrupt that is enabled. If all of them all done, then you do a RETFIE to leave the interrupt service routine. >=20 > next_state incf LedState,1 ; if 00 increase=20 > the state, for the next state This should makethe next interrupt flag to process: process_next_interrupt_flag: > return If it's an interrupt service routine, the return above should be a retfie. You're getting closer. Just remember to use the flags as triggers. So check the flag. If it's set, then clear it and do the action. If not, move on to the next section. Once you've checked all the flags, loop your main loop, or return from your interrupt if it's an interrupt service routine. BAJ >=20 > On 4/07/2013 7:36 AM, IVP wrote: > >> yes that's right I need the flag from my timer.asm, how can do that ? > > Many of my programs will use a register called 'flags', and I'll define > > each bit as an indicator that something needs attending to, eg > > > > #define motor_stalled flags,0 > > #define reverse flags,1 > > > > Just check with btfss etc and gotos for action, eg > > > > btfsc motor_stalled ;skip if motor running OK > > goto power_off ;else cut power > > > > Joe > > > > PS, please trim your posts by quoting only what you need to >=20 > --=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 --=20 Byron A. Jeff Chair: Department of Computer Science and Information Technology College of Information and Mathematical Sciences Clayton State University http://faculty.clayton.edu/bjeff --=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 .