Hi Roger, =A0 Do you even need to use RRF at all?=A0When you read Port B into W, bits 1 t= o=A04 contain the switch settings. AND the result with 1E to isolate the fo= ur bits you want, add this to the program counter. The resulting offsets wi= ll now be two addresses apart instead of adjacent, but this won't matter un= less you're short of program space. Use NOPs to fill the gaps. =A0 Hope this helps, =A0 John --- On Tue, 22/9/09, Roger Weichert wrote: From: Roger Weichert Subject: Re: Basic question on 'RRF' command To: "Microcontroller discussion list - Public." Date: Tuesday, 22 September, 2009, 12:50 AM Hi Sean, Thanks for the quick response and thanks for explaining the workings of the = command in this instance. Because I wasn't really sure how it was going to work, I added the 'andlw' = command to clear eveything but the four least significant bits. I figured that should then give me a 'clean' number between 1 - 16. The reason I used the addition to the program counter is because I need to = set the parameters for a delay (depending on the DIP switches)=A0 ..=A0 bef= ore I = jump to my main program. So this is in the initialisation section of the = program. The DIP switches are read=A0 ... the delay times are set=A0 ...=A0 and then= the = device runs the program until it is turned off, or an interrupt occurs=A0= =A0=A0... = which shouldn't happen unless there is a fault The switches shouldn't be changed while the device is running=A0 ...=A0 and= if = they are=A0 ...=A0 the program wont take any notice of them. That's the way= I = want it. I dont have a lot of experience writing programs so there may well be a far = better way of doing what I need. Regards,=A0=A0=A0Roger ----- Original Message ----- = From: "Sean Breheny" To: "Microcontroller discussion list - Public." Sent: Tuesday, September 22, 2009 8:45 AM Subject: Re: Basic question on 'RRF' command Hi Roger, RRF PORTB,W will not affect PORTB and will put the result into W. However, that result may not be exactly what you expect. RRF stands for Rotate Right File register. It is not the same as a right shift. The LSB gets placed into the carry bit (part of the status register) and the carry bit gets placed into the MSB of the result. So, in other words: Before the instruction: PORTB=3Dsome value W=3Ddon't care carry bit=3D0 or 1 After the instruction: PORTB=3Dunchanged W(bit 7)=3Dcarry bit value from before W(bits 6 through 0)=3DPORTB(bits 7 through 1) carry bit=3DPORTB(bit 0) Also, it seems a bit strange to me to perform an addition to the program counter like this. Do you really want to go to a unique piece of code for every single DIP switch setting? That's 16 different code snippets in this case. Sean On Mon, Sep 21, 2009 at 6:59 PM, Roger Weichert = wrote: > Hi Guys, > > I have a very basic question about the 'RRF' command, for a program using = > a 16F627. > > I am using RB1,2,3,4 to read a DIP switch to choose 1 of 16 different = > outcomes. (RB0 is being used as an external interrupt otherwise it = > wouldn't be a problem) > > I want to read the switch ... 'RRF' the result to scrub off the least = > significant bit ... then use that result (a number between 1 - 16 ) to = > offset the program counter etc. > > I'm not sure of what I can 'operate' on ... > > Can I use ... > > rrf portb,w ; remove the least sig bit > > ... or does that mess with portb as well ... which has actual switches on = > it. Then ... > > andlw b'00001111' ; only keep the 4 lowest bits > addwf pc,f ; add offset to prog counter > > > ... or do I have to read the port, move it into a seperate file register = > .. 'RRF' that ... then move the result into 'w' to offset the program = > counter ? > > ... or alternatively, can I 'RRF' 'W' and put the result in 'W' ? > > I would have assumed the last one would be possible, but I cant find any = > examples of it, so have been wondering. > > Thanks for any help. > > Regards, Roger > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist ---------------------------------------------------------------------------= ----- No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.5.409 / Virus Database: 270.13.110/2385 - Release Date: 09/20/09 = 17:51:00 -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist