PDA

View Full Version : learning asm have a quick question



Vbriel
03-19-2012, 05:11 PM
I'm trying to work with I/O ports in assembly and I've run into a problem.

I can set single pins with 'or outa, myregister' no problems, but I need to change the direction of P8-P15 to output, place a byte on those pins, then after a delay turn the direction back to input only on P8-15

What I tried to do was:

mov dira, dbusout 'make P8-P15 output
or outa, #$55
nop
mov dira, dbusin 'change pins back to input

dbusout long $FF<<8
dbusin long $00<<8

I'm totally missing something. Also, I've read a few of the "beginning asm for the propeller tutorials" but I'm looking for something that can explain controlling the ports a little better. I've been using the ATmega chips and defined 8 bit ports. I just need a little nudge in the right direction on this.

Vince

JonnyMac
03-19-2012, 05:21 PM
There is a cool instruction called andn (AND NOT) that will and the destination field with the inverted (NOT) bits of your source field. This allows you to use the same mask to set bits (using or) or clear bits (using andn).

Note that by using or and andn you do not upset other pins -- this is a good habit to get into as your programs become more complex.


mov mask, #%1111_1111
shl mask, #8

mov mybits, #%1010_1010
shl mybits, #8

andn outa, mask ' clear old bits
or outa, mybits ' write new bits
or dira, mask ' make p8-15 outputs

' do stuff

andn dira, mask ' make p8-15 inputs


BTW, you should use the [ code ] and [ /code ] tags (sans spaces) around code you want to post.

Phil Pilgrim (PhiPi)
03-19-2012, 05:21 PM
Your or statement writes to P7-P0, not P15-P8. You will need to load your data into a register, then shift that register left by 8 before writing it to outa.

Also, take a look at the andn command. It will allow you to use the same mask for setting the pins to input as you used for setting them to output.

-Phil

Circuitsoft
03-19-2012, 05:22 PM
What you have looks like it should work, but it's probably fast enough that you just can't see it. Pins 8-15 will go low-impedance for 50ns, then will switch to $55 for 100ns, then go high-impedance again. Can you see a 0.1microsecond pulse with the measuring equipment you're using?

Vbriel
03-19-2012, 05:33 PM
Wow, thanks guys. Thanks Jon I forgot the syntax for the code command, long morning already. I missed the shl command and was sending the data to P0-P7. I'm thinking in 8 bit instead of longs. Gotta clear that out of my head.

I'm going to try the 'or' instead of the mov. I was changing direction on my other pins, duh. Great help guys. Let you know how it goes. Oh, I'm using a LA to see the results, so I can see ns results if I program the ports correctly.

Vince

Vbriel
03-19-2012, 05:44 PM
That worked! Thank you. I've really got to throw out the whole 8 bit thing and get longs into my head for this.