I am helping him privately. He is using 20MHz clock. The interrupt rate is 1 mS and internal time=20 delay loop was increased to 200 mS to do the decrement of the "LedTimer". So to switch on the LED for 200 mS, a count of 1 was used and for the=20 LED to be off for 30 seconds, a count of 150 was used. There was no need to use 16 bits register. Everything was solved using a=20 8 bits register. Just sent him the code. Cheers Ravi Byron Jeff wrote: > Since it's a count, you really do not need to store the value 300 in bina= ry > in a pair of 8 bit memory locations. Since it's a count you only need to > store two values whose product is 300 and whose values are each less than > 255. Examples are 150x2, 100x3, 75x4, 60x5, 30x10, 20x15. > > Once that is done you can then build a nested loop where the outer loop i= s > decremented once for each timeout of the inner loop. Here is a complete > example using 10 and 30 for the inner and outer loops: > > wait300: > movlw .10 > movwf outer > movlw .30 > movwf inner > loop300: > decfsz inner > goto not_done_yet ; Loop has not timed out. keep waiting > decfsz outer > goto reset_inner ; Outer loop not timed out. Reset inner loop > goto timed_out ; Loop has timed out. Do what you need > reset_inner: > movlw .30 ; Reset the inner timer count > movwf inner > not_done_yet: ; Do something else when no timeout > goto loop300 ; And loop after that > > timed_out: ; Do code when you time out > goto wait300 ; Reset the total count for next interation > > Of course you need to fill in the areas of not_done_yet and timed_out wit= h > waht you want done if the timer has not timed out and when it does. That = is > application dependent. > > Of course this loop still works if you store the binary 300 (1 in outer, = 44 > in inner) and you remove the reset_inner code. This counts down 44 the > first time, and then the inner loop is 256 the second time. This also giv= es > a total of 300 counts. But the structure of the inner and outer loops sta= y > the same. BTW you can extend this to as many bytes as you need. 4 bytes > could give you counting loops up to 4.2 billion counts, which at a 5 Mhz > tick count can delay up to 14 minutes. > > BAJ > > =09 > On Fri, Jul 12, 2013 at 08:06:16PM +0800, electronic.consultation.au@gmai= l.com wrote: >> I see, and then how can I reduce them ? >> >> could it be like this ? >> >> *movlw LOW .300 >> movwf LedTimer >> movlw HIGH .300 >> movwf LedTimer+1 >> >> counter* * >> Global counter ;Decrementing Sec's >> BANKSEL LedTimer ;timer value >> movf LedTimer,w ;for every counts >> btfss STATUS,Z >> decf LedTimer+1,f >> return* >> >> Thank you >> On 12/07/2013 7:36 PM, IVP wrote: >>> Tag added >>> >>>> how can I enter .300 into LedTimer ? >>> You might assign two registers, LedTimer_lo and LedTimer_hi >>> >>> The low( ) and high( ) operators do the division/remainder for you >>> >>> movlw low(.300) ;loads LedTimer_lo with 44 >>> movwf LedTimer_lo >>> >>> movlw high(.300) ;loads LedTimer_hi with 1 >>> movwf LedTimer_hi >>> >>> For 24-bit numbers this can be extended to >>> >>> movlw upper(.300) >>> movwf LedTime_up ;if LedTimer_up is also present >>> >>> If the 300 is defined as a constant, this makes it easier to change >>> in the following line rather than in the code >>> >>> LedTimer =3D .300 >>> >>> movlw low(LedTimer) >>> movwf LedTimer_lo >>> >>> movlw high(LedTimer) >>> movwf LedTimer_hi >>> >>> A register LedTimer can also be addressed as LedTimer+0, the next >>> in memory as LedTimer+1 and so on, if that suits you better >>> >>> Joe >> >> -- >> 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 .