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) .. before I jump to my main program. So this is in the initialisation section of the program. The DIP switches are read ... the delay times are set ... and then the device runs the program until it is turned off, or an interrupt occurs ... which shouldn't happen unless there is a fault The switches shouldn't be changed while the device is running ... and if they are ... 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, Roger ----- 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=some value W=don't care carry bit=0 or 1 After the instruction: PORTB=unchanged W(bit 7)=carry bit value from before W(bits 6 through 0)=PORTB(bits 7 through 1) carry bit=PORTB(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