please dont rip this site

PIC Microcontoller Math Method : Basic

Sections:

Increment / Decrement

General Purpose

; from David Cary: tested on PIC 16F877
; inc
	incf count0,f
	skpnz
	incf count1,f
	skpnz
	incf count2,f
	;... {repeat the last two lines for as wide a counter as is needed}
	; w is unchanged.
	; Status:Z is 1 if and only if counter is now all zeros.
	; rest of Status unchanged.
;from Dmitry Kiryashov
;inc
        movlw   1
        addwf   count0,F
        skpnc
        addwf   count1,F
;... {ed: repeat the last two lines for as wide a counter as is needed}
	; w is now 1
	; Status:Z and Status:C are 1 if and only if counter is now all zeros.

;dec
        movlw   1
        subwf   count0,F
        skpc
        subwf   count1,F
;... {ed: repeat the last two lines for as wide a counter as is needed}
	; w is now 1
	; Status:C is now 0 if and only if counter rolled over and is now all ones
	; Status:Z is set if the least significant byte of the counter is zero
	; (not necessarily all bytes !) and in certain other cases.

Wrap (modulus)

Often we have a value Y (like the index to a circular buffer) that normally increases by 1 each iteration, but that we want to make sure stays in the range 0 <= Y < End. by forcing Y back to zero when it runs off the end of its range.

; if( w <= Y ){ Y = 0; };
; Y is 8 bits
; by David Cary
; useful for circular buffers.
; Load the upper limit into w -- perhaps
; movlw End ; when End is a constant
; movfw End ; when End is a variable
  subwf Y,w
  skpnc
  clrf Y
; now 0 <= Y < End.

[FIXME: 16 bit version ?]

More sophisticated modulus routines are available (typically wrapped up in a routine that calculates both (A/B) and (A MOD B) at once).

Questions:


file: /Techref/microchip/math/incdec/gp.htm, 2KB, , updated: 2002/9/19 10:55, local time: 2024/3/28 02:30, owner: DAV-MP-E62a,
TOP NEW HELP FIND: 
44.213.80.203:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://www.sxlist.com/Techref/microchip/math/incdec/gp.htm"> PIC Math Increment / Decrement General Purpose</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to www.sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .