Hey Scott, Doesn't look right :) Your code will add 1 to the counter when it reaches 3 instead of clearing it. Here is another idea: incf File, w ;11->100 andlw 0x04 skpz clrf File ;11->00 Nikolai > Subject: Re: [PIC]: Modulo 3 code > From: Scott Dattalo (scott@DATTALO.COM) > Date: Sat Jun 15 2002 - 11:01:41 PDT > On Sat, 15 Jun 2002, Peter L. Peres wrote: >> Hi, >> >> I need to make a modulo 3 counter in a file. I've come up with this code: >> >> movlw 0x03 >> andwf File,w ; >> >> xorlw 0x03 ; 11 -> 00 >> btfss STATUS,Z >> xorlw 0x03 ; undo xorlw above >> >> movwf File >> >> I actually need the movwf at the end to be like this because I have to add >> in some flags. Surely there is a MUCH shorter way to do this ... >> >> Peter >> >> PS: The code has to be constant run time > how 'bout > rrf File,w > andwf File,w > andlw 1 > addwf File,f > Scott -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu