--_003_51D8E1522080401gmailcom_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Here's the complete files, so make you guys easier to understand what I want to do... On 7/07/2013 9:15 AM, Byron Jeff wrote: > On Sun, Jul 07, 2013 at 07:03:26AM +0800, Electronic Consultation wrote: >> is it : >> LedTimer RES 1 >> movlw .10 >> movwf LedTimer >> >> >> ;counting >> >> check_counter >> btfss INTCON,T0IF >> goto check_counter > I'm going to keep repeating that I believe that the above is a poor desig= n > 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 syste= m > will not be able to do any other activity until that timer flag is raise= d. > > 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 wa= s > another interrupt you planned to process. You really need to structure yo= ur > code in the second form, so that when it's time to add more tasks, the > framework to do so is already in place. > >> >> sublw .1 >> btfss STATUS, Z ;Is the result 0, clear C= OUNT > 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 > >> >> goto check_counter ;if false check the COUNT= ER again > No. Move on to checking the next flag after this code. > >> goto next_state ;if true g= o to this statement > No. This goto is unnecessary because next_state is at the same address. > >> >> next_state >> clrf LedTimer ;if false go to this s= tatement > Redundant. You can only get here if LedTimer is zero. There is no need to > clear it. > >> incf LedState,1 ; if 00 = increase the state, for the next state >> >> 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. > > 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 decima= l >>> 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 inter= rupt 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, cl= ear COUNT >>>>>> >>>>>> >>>>>> goto check_counter ;if false check the COUNTER a= gain >>>>>> goto next_state ;if true go to thi= s statement >>>>>> >>>>>> >>>>>> >>>>>> next_state >>>>>> clrf COUNT ;if false go to th= is >>>>>> statement >>>>>> incf LedState,1 ; if 00 increa= se the >>>>>> state, for the next state >>>>>> >>>>>> return[/CODE] >>>>>> -- >>>>>> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >>>>>> View/change your membership options at >>>>>> http://mailman.mit.edu/mailman/listinfo/piclist >>>> -- >>>> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >>>> View/change your membership options at >>>> http://mailman.mit.edu/mailman/listinfo/piclist >> -- >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist --_003_51D8E1522080401gmailcom_ Content-Type: application/octet-stream; name="LED.rar" Content-Description: LED.rar Content-Disposition: attachment; filename="LED.rar"; size=3905; creation-date="Sun, 07 Jul 2013 03:46:17 GMT"; modification-date="Sun, 07 Jul 2013 03:46:17 GMT" Content-Transfer-Encoding: base64 UmFyIRoHAM+QcwAADQAAAAAAAADu3XQgkC0A7QMAABwKAAACsvTuIi+E5UIdMwgAIAAAAGluaXQu YXNtAPADlBMMHQzMzRPNwVvZ6Bvwc8O8L42brc27LvbA+Acld0QdbHNccG93lwbjUlY1xuBtPpd+ 98Ocl6xtOFJ/xL0k69eA30VtgtKwlYcxfxfjRROHCSikSD+KKBRWYvJet1JLBA8V5t96NvxoYA0Q uyPk9fquo+0hjlS0qqXM1y38Fhgfi9BlfkdIGmqH7NZsxnfhcMdHTGHIugTvKSKCYwihkLsgkYF7 jWA3FOzbCTydEPSGSeEnmntG1DCGatf84Ew8E2fhkMTLHyTSvsdS4kT79XfBTQ2MIQ94pTwEt8UU JdJmFOHQbjqVwSwrwYhfm/LDBOjPJFS51wmeeoikhwzeTV3J9uNjI0HxBn9QyRtxFx4NFo1GmQtg dRWa8mNZnXuSWUgtNRH2OksBtqtf01LyzgxtLNL2CPcrgZxfRkAlMTH0XZNdtgiRIcX91gPQqjM7 F+rXA/HGE98sGFv4TP9ldIFo3l9aXKPfnQAx19esH5/dlf55F5gNph8ofpVg9re0BXizOV1rxqgk DvKFQE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DRKWUCYiBrX/04lBCh9SZ96z8Cbxklm5/GmXVTD w0pz1N8HBqIiRZSI943xONVFJcYfQEhno2WwLJ2thrCox9RV0h10oQHWhinldA4rbyr84AeVYpvx etWcDqFy2uI6M8EcYFvoLmytdSbBHYNqQ+c640Hezimf5Ro/lFME1lhsP1wYPAtZ3LDdLW31Wmuc JMCDBFhiJa8yQM5MO5+0xD17AEAHAA== --_003_51D8E1522080401gmailcom_ Content-Type: text/plain; name="ATT00001.txt" Content-Description: ATT00001.txt Content-Disposition: attachment; filename="ATT00001.txt"; size=224; creation-date="Sun, 07 Jul 2013 03:46:17 GMT"; modification-date="Sun, 07 Jul 2013 03:46:17 GMT" Content-Transfer-Encoding: base64 LS0gDQpodHRwOi8vd3d3LnBpY2xpc3QuY29tL3RlY2hyZWYvcGljbGlzdCBQSUMvU1ggRkFRICYg bGlzdCBhcmNoaXZlDQpWaWV3L2NoYW5nZSB5b3VyIG1lbWJlcnNoaXAgb3B0aW9ucyBhdA0KaHR0 cDovL21haWxtYW4ubWl0LmVkdS9tYWlsbWFuL2xpc3RpbmZvL3BpY2xpc3QNCg== --_003_51D8E1522080401gmailcom_-- .