Searching \ for 'Polling PortA' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/ios.htm?key=port
Search entire site for: 'Polling PortA'.

Truncated match.
PICList Thread
'Polling PortA'
1999\10\19@211740 by spamdogg

flavicon
face
I want to use portA to read two switches for one project and four
switches for another.  How do I make each bit rotate through the carry
flag consecutivly.  I have been using the following code, but it only
reads the first bit. I am using a 16c56


            movlw         0x0F
            tris              PORTA
            movlw         0x00
            tris              PORTB

input      bcf              STATUS, C
            rrf               PORTA, W
            btfsc            STATUS, C
            goto             code_1
            rrf               PORTA, W
            btfsc            STATUS, C
            goto             code_2
            goto             input

I was able to write the rest of this program and simulate it with
success and I have been stareing at this part for four hours with no
luck.

Scott

1999\10\19@214926 by Tony Nixon

flavicon
picon face
Scott wrote:
{Quote hidden}

Try this

input   movf portA,w
       movwf Temp
       rrf Temp
       btfsc status,C
       goto code_1
       rrf Temp
       btfsc status,C
       goto code_2

       etc....
       goto input

You don't need to preclear the carry bit because it will be overwritten
on the first rrf instruction anyway.

--
Best regards

Tony

http://www.picnpoke.com
Email spam_OUTsalesTakeThisOuTspampicnpoke.com

1999\10\19@220826 by spamdogg

flavicon
face
Tony

       I did not expect to get a response so fast, thanks.  However the
code that you supplied executed in exactly the same way as my original
code.  It seems that when I rrf the a register the first bit is sent to the
carry.  When the instruction comes around a second time it again shifts the
first bit into the carry instead of the second bit.

Scott

Tony Nixon wrote:

{Quote hidden}

1999\10\19@222048 by spamdogg

flavicon
face
Tony

       Ignore that last reply, the code worked tanks alot.  apparently
portA can't be rotated.

Scott

Tony Nixon wrote:

{Quote hidden}

1999\10\19@223123 by Tony Nixon

flavicon
picon face
Scott wrote:
>
> Tony
>
>         I did not expect to get a response so fast, thanks.  However the
> code that you supplied executed in exactly the same way as my original
> code.  It seems that when I rrf the a register the first bit is sent to the
> carry.  When the instruction comes around a second time it again shifts the
> first bit into the carry instead of the second bit.
>

Yes, that would be correct because you read PortA again and reloaded
'Temp' with this data.

However, if any switches are set, then the appropriate 'code_x' routine
will have executed before returning to the loop. I guess you have
appropriate code in these routines to handle debouncing, use switch once
and discard, or repeat, and to detect when it releases.

It is best to read the port once to get the switch information, rather
than to use the 'rrf' instruction on it repeatedly.

--
Best regards

Tony

http://www.picnpoke.com
Email .....salesKILLspamspam.....picnpoke.com

1999\10\19@231501 by Mitchell D. Miller

picon face
Scott,

The problem here is that every time you 'RRF PORTA', the entire port it
read, and the first bit is rotated into the C bit.  Rather than rotating the
port each time, you need to read the port into memory first, then rotate
that data.  Example: (sorry for the mixed Parallax & Microchip mnemonics)

   movw  porta
   movf   myvar, w
   rrf       myvar
   btfsc   status, c
   goto    code1
   rrf       myvar
   btfsc   status, c
   goto    code2
   .
   .
   .

Only problem this creates is that any changes in portA during processing are
not recognized until next time through this code.

Mitch Miller
Omaha, NE
EraseMEmdmiller2spam_OUTspamTakeThisOuThome.com



{Original Message removed}

1999\10\20@022404 by Ravi Pailoor

flavicon
face
part 0 2943 bytes content-type:text/x-vcard; charset=us-ascii; (decoded 7bit)

why not try this

readkey         btfss porta,0
               goto key1_press
               btfss porta,1
               goto key2_press
               retlw 00

key1_press      call debounce
               btfsc porta,0
               retlw 00h
               retlw 01h

key2_press      call debounce
               btfsc porta,1
               retlw 00h
               retlw 02h

Regards

Pailoor


"Mitchell D. Miller" wrote:
{Quote hidden}

> {Original Message removed}

1999\10\20@042859 by Quentin

flavicon
face
Here is your problem:
When you rotate the Temp reg, you store the result in W, this is wrong.
You should store it back into the Temp register. If you store it in W
the value in Temp does not change, that's why you are reading the same
bit.

Quentin

1999\10\20@064201 by Quentin

flavicon
face
Sorry, got the two examples mixed up. Tony's example does return the
value to the register. (Not used to not showing a destination)
Quentin

Quentin wrote:
>
> Here is your problem:
> When you rotate the Temp reg, you store the result in W, this is wrong.
> You should store it back into the Temp register. If you store it in W
> the value in Temp does not change, that's why you are reading the same
> bit.
>
> Quentin

1999\10\20@083127 by Dr. Imre Bartfai

flavicon
face
On Tue, 19 Oct 1999, Scott wrote:

> Tony
>
>         Ignore that last reply, the code worked tanks alot.  apparently
> portA can't be rotated.
Correct.
And - besides - if you rotate something into W, the original will remain
unchanged. If you repeat, you get the same result again. (That is why
Scott's code does not "exactly the same" as Tony's.)

Regards,
Imre

{Quote hidden}

1999\10\20@113234 by spamdogg

flavicon
face
It seems to be working pretty well now, however when I use the rlf instruction
the data is rolled into the high nibble of the variable temp and the carry never
sees is.  How can I make the temp variable four bits wide?    Thanks for having
mercy on such a newbi.

Scott

Tony Nixon wrote:

{Quote hidden}

1999\10\20@142753 by Byron A Jeff

face picon face
>
> I want to use portA to read two switches for one project and four
> switches for another.  How do I make each bit rotate through the carry
> flag consecutivly.  I have been using the following code, but it only
> reads the first bit. I am using a 16c56
>
>
>              movlw         0x0F
>              tris              PORTA
>              movlw         0x00
>              tris              PORTB
>
> input      bcf              STATUS, C
>              rrf               PORTA, W

This is a problem right here. Since you are sending the result to W, only
bit 0 of port A will be transferred to the carry bit.

{Quote hidden}

Two ways to solve it:

1. Copy portA to a temp register, then rotate that.

2. Skip the rotate completely and simply poll each bit with a bit test. The
reason that a lot of uControllers used rotate for this type of operation
ius simply because they couldn't test a bit directly. PIC's can so why not
use it.

3. You can mask out the bits in port A you're interested in and loop until
a switch is actually pressed. Then do a bit test to figure out which switch
was pressed.

Just a couple of thoughts. I think PIC's code set has other ways of solving
the problem.

BAJ

1999\10\20@191121 by Tony Nixon

flavicon
picon face
Scott wrote:
>
> It seems to be working pretty well now, however when I use the rlf instruction
> the data is rolled into the high nibble of the variable temp and the carry nev
er
> sees is.  How can I make the temp variable four bits wide?    Thanks for havin
g
> mercy on such a newbi.

I think someone sneezed on the wafer before they cut it up and wrapped
the bits in prickly plastic. It's given your chip an extra instruction
:-)

The carry is always changed after a 'rrf' or rlf' instruction. It may
not appear to get changed, because the new data bit may be the same as
the old.

if PortA = 00000010, then

       movf porta,w
       movwf temp

temp = 00000010
carry could be 0 or 1 - it doesn't matter

       rrf temp

temp = 00000001 - [note: bit 7 is the original carry bit value and could
be 1]
carry = 0       - carry = original value of temp bit 0

carry = 0 -> key #1 not pressed, loop back and rotate again

       rrf temp

temp = 00000000 - bit 7 = the carry bit value
carry = 1       - carry = original value of temp bit 0

carry = 1 -> key #2 is pressed, service the key routine

Just looking over your message again, you mentioned "rlf" not "rrf". If
you changed this by accident that could be causing your problem.

Try using 55h or 0xAA in a register and rotate that left or right to see
the effect on the register and the carry bit.

--
Best regards

Tony

http://www.picnpoke.com
Email RemoveMEsalesTakeThisOuTspampicnpoke.com

1999\10\20@231313 by spamdogg

flavicon
face
Tony

       I solved the problem by using portb for input and porta for output.  tha
t way
I can rrf for the first bit and rlf for the other three.  AAAchzoooo!  Damn ther
e goes
the level one environment!!!

Scott

Tony Nixon wrote:

> Scott wrote:
> >
> > It seems to be working pretty well now, however when I use the rlf instructi
on
> > the data is rolled into the high nibble of the variable temp and the carry n
ever
> > sees is.  How can I make the temp variable four bits wide?    Thanks for hav
ing
{Quote hidden}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...