On Sun, Jul 07, 2013 at 07:03:26AM +0800, Electronic Consultation wrote: > is it : > LedTimer RES 1 > movlw .10 > movwf LedTimer >=20 >=20 > ;counting >=20 > check_counter > btfss INTCON,T0IF > goto check_counter I'm going to keep repeating that I believe that the above is a poor design unless you have a system that specifically only has a single task to do. If you are spinning on checking the timer interrupt flag, then your system will not be able to do any other activity until that timer flag is raised. Your design is in the form: check_flag: btfss TARGET,FLAG1 ; see if the flag is raised goto check_flag ; wait until the flag is raised My suggestion is: main_loop: check_flag1: btfss TARGET,FLAG1 ; Check the first flag goto check_flag2 ;; Code to process flag 1 ... check_flag2 btfss TARGET,FLAG2 ; Check the next flag goto check_flag3 ;; Code to process flag 2 check_flag3 btfss TARGEt,FLAG3 ; Check the next flag goto check_last_flag ;; Code to process flag 3 check_last_flag: btfss TARGET,LAST_FLAG ; Check the last flag goto end_main_loop ;; Code to process last flag end_main_loop: goto main_loop Note that if you have only one flag, that the two pieces of code are essentially the same. However, You specifically said before that there was another interrupt you planned to process. You really need to structure your code in the second form, so that when it's time to add more tasks, the framework to do so is already in place. =20 >=20 >=20 > sublw .1 > btfss STATUS, Z ;Is the result 0, clear COU= NT I wouldn't do this for a few reasons. First it's bad design to separate the load of W with the count and the subtraction. Second SUBLW does not operate the way you think it does. Literally it subtracts the value of W from the constant. It's 1-W, not W-1. Finally the DECFSZ instruction in specifically designed to handle this sequence. Replace the whole thing with: decfsz LedTimer,F >=20 >=20 > goto check_counter ;if false check the COUNTER= again No. Move on to checking the next flag after this code. > goto next_state ;if true go = to this statement No. This goto is unnecessary because next_state is at the same address. >=20 >=20 > next_state > clrf LedTimer ;if false go to this sta= tement Redundant. You can only get here if LedTimer is zero. There is no need to clear it. > incf LedState,1 ; if 00 in= crease the state, for the next state >=20 > return Return to where? If this is a subroutine, then there should be no flag check. If it is not, then there should be no return.=20 BAJ > ? > On 7/07/2013 12:16 AM, Byron Jeff wrote: > > On Sat, Jul 06, 2013 at 10:03:27PM +0800, Electronic Consultation wrote= : > >> after > >> LedTimer RES 1 > >> > >> How can I set it to 20 decimal ? > > Exactly the same way you did it with COUNT: > > > > MOVLW .20 ; Note I normally change my default Radix to decimal > > MOVWF LedTimer > > > >> thanks > >> On 6/07/2013 9:42 PM, Byron Jeff wrote: > >>> On Sat, Jul 06, 2013 at 07:08:16PM +0800, Electronic Consultation wro= te: > >>>> Guys, > >>>> > >>>> I want to reduce LedTimer after interrupt but it returned to 20 agai= n > >>>> after interrupt, > >>>> Do you have idea how handle it ? > >>> The Equate (EQU) you have below fixes the value of LedTimer to 20. Si= nce > >>> you were moving it to COUNT, I figured you wanted a constant 20 count= s to > >>> count down in COUNT (which I do not see a definition for). > >>> > >>> Your code uses the RES directive to declare variables. If you want Le= dTimer > >>> to change, then it needs to be a variable too. > >>> > >>> BAJ > >>> > >>>> thanks > >>>> [CODE]LedTimer EQU .20 ;10 decimal (for content of the counter to ge= t 100ms) > >>>> > >>>> led_state_1 > >>>> bcf INTCON,T0IF ;clear the interr= upt flag > >>>> bsf PORTB, POWERLED ;Turn on LED > >>>> movlw LedTimer > >>>> movwf COUNT > >>>> > >>>> > >>>> ;counting > >>>> > >>>> check_counter > >>>> btfss INTCON,T0IF > >>>> goto check_counter > >>>> > >>>> > >>>> sublw .1 > >>>> btfss STATUS, Z ;Is the result 0, cle= ar COUNT > >>>> > >>>> > >>>> goto check_counter ;if false check the COUNTER ag= ain > >>>> goto next_state ;if true go to this= statement > >>>> > >>>> > >>>> > >>>> next_state > >>>> clrf COUNT ;if false go to thi= s > >>>> statement > >>>> incf LedState,1 ; if 00 increas= e the > >>>> state, for the next state > >>>> > >>>> return[/CODE] > >>>> --=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 > >> 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 > --=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 .