Shifting pins?
cavelamb
Posts: 720
I've been away from the Propeller for a while and have been reading through the old projects to try to get up to speed on SPIN again.
Came across this in the TFT display code:
'pin definitions from tft.h. The pin manipulation
'macros have been converted to PRI functions.
CS_BIT = $04 << 8
RS_BIT = $08 << 8
WR_BIT = $10 << 8
RD_BIT = $20 << 8
Ok, so the pin assignments are shifted left 8 bits?
CS_BIT = $12
RS_BIT = $16
WR_BIT = $18
RD_BIT = $28
My question - what the advantage of specifying pin assignments with the shift operators?
Came across this in the TFT display code:
'pin definitions from tft.h. The pin manipulation
'macros have been converted to PRI functions.
CS_BIT = $04 << 8
RS_BIT = $08 << 8
WR_BIT = $10 << 8
RD_BIT = $20 << 8
Ok, so the pin assignments are shifted left 8 bits?
CS_BIT = $12
RS_BIT = $16
WR_BIT = $18
RD_BIT = $28
My question - what the advantage of specifying pin assignments with the shift operators?
Comments
pub pushData(data)
all_pin_low
outa |= (data << 2) ' bitwise OR (data shifted left two bits) ???
Bitwise OR what with what?
In the second post of yours, the data is shifted left two bits, then OR'd with OUTA because the I/O pins involved start with pin # 2 and go up from there (3, 4, ...). When the bits of OUTA are changed, the I/O pins change as well ... at least those that are configured as outputs.
Pre-computing the read / write versions of that value makes the code a little faster, but just storing them as raw values makes the correlation with the datasheet value harder, so they're often written with the shifts included. It's easy to see that ($3C<<1) is related to the address $3C from the datasheet, but $78 and $79 don't look anything like it.
Related to video, the Propeller output registers are arranged in groups of 8 pins. If the author of the TFT device code is using the video hardware to shift out data, he might have specified the pins as indices within the 8, then shifted them up to the correct pin group.
I can't guarantee that's what is happening in this case, but it's often the reason things are done this way.
It's from Local Roger's work on the TFT display.
I'm trying to figure out two things right now:
How the program communicated with (and controls) the display.
How the mailbox system works.
Here is the whole thing: except the whole thing doesnt fit in a message.
Currently runs on Martin Hodge' ASC board with the Radio Shack TFT display installed.
but I'm nowhere near able to code PASM yet.
How would that be written?
Which brings me back to the beginning question about how the pins are defined?
You already have all parts figured out, but just do not see it because it is so simple.
So first the thing with the pins.
Each 1 is the pin used in these masks. 0-31, the position of the 1 in the mask correspond to the pin used for CS,RS,WR,RD
Same with the all_ masks, each 1 represents the affected pins.
To use different pins you need to move the 1 around in the masks.
Then you have this in the code:
not sure why written like that, but this is basically the same as CS/RS/WR/RD_BIT_MASK, a long value with one bit set, the bit corresponding to the pin used.
So both definitions define each exactly the same value with different name and different way of notation. But both define a pin by setting the corresponding bit of the long.
so
CS_BIT_MASK long %0000_0100_0000_0000 is exactly the same as CS_BIT = $04 << 8, it is the value $0400.
here you are wrong. The pins are not written at the same time, they are changed bit by bit on each instruction.
the first three lines set some pins and the last two lines basically toggle pin defined by wr_bit_mask.
the spin instructions do basically the same.
a |= b will do an OR and then write the result to the left hand variable, so a = a OR b. Bitwise. and not affect the other bits of outa.
a &= b will do an AND and then write the result to the left hand variable, so a = a AND b. Bitwise. Since we want CS low we need to do a
a &= ! b, so a = a and (not b). Bitwise. To just clear the bit defined in cs_bit or cs_bit_mask, (since they are the same) and not affect the other bits of outa.
Have fun!
Mike
ANDN is one PASM instruction I really like. @chip has made a nice instruction set. Sometimes you wonder about some of them. I still want to try out that multi long add/subtract thing. Have no time for it but it is interesting. 512 bit integer? longlong's? Anyone?
Need to sleep.
Mike
My questions are probably confusing because I'm confused.
Seems to work that way a lot.
I guess I'm confused because I thought that these bit masks were defined as longs.
And thought that the entire bit mask long was being set here...
andn outa,cs_bit_mask
and the selected bit in the mask was the one that's being wigggled?
Or is that the only bit being manipulated?
(edit)
No, I get it.
That's the only bit being set or cleared.
Thanks
would translate to -
or outa,cs_bit_mask ' to set CS_BIT high
and
would be -
andn outa,cs_bit_mask ' to set CS_Bit low
Anywhere near close?
CS_BIT_MASK long %0000_0101_0000_0000
This will affect I/O pins 8 and 10 simultaneously (using CS_HIGH or CS_LOW or the equivalent PASM)
Good to hear from you!
Just trying to speed up the display writes.
Those CD_whatever routines get used a lot and look like potential.
Thank you for confirming the PASM instructions.
I'm on really shaky ground here, so maybe just one change at a time?
Is it shifting the control signals into the high byte of the lower word of that long?
Still not sure what pins are being used for data.
Might be that lower byte?
It is a wonderful Assembler language, like SPIN with some quirks attached, but easy to use.
And a lot of SPIN actually translate easy to PASM as seen in your examples. Just dive in. You might really like it.
Enjoy!
Mike
Most likely the lower byte is for the data. They are what I have seen used for a parallel data bus and used myself.
Sorry to intrude...
that's why I'm here asking confusing questions...
http://forums.parallax.com/discussion/132966/propeller-assembly-for-beginners#latest
I don't know if more copies are available, try contacting the author Harpit Singh Sandhu. I have a copy of the book and it does have a number of good tips/examples.
I've attached a PDF copy of the book's front/back covers.