- For example:
This will produce a compiler error...PORTB.1 is expecting a 1 or 0.
Code: Select all
PORTB.1 = STATUS.0
How About Transfer of Single Bit Values Between Registers
How About Transfer of Single Bit Values Between Registers
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]
[url=http://circuit-ed.com]CircuitED -[/url]
Re: How About Transfer of Single Bit Values Between Register
We will work on it.
-
- Posts: 137
- Joined: 10 Mar 2005 22:59
- Location: Cardiff, UK
- Contact:
Messenga wrote:If you want to work with single bits then what you must do is work with entire bytes and use logical operators and masks in order to select the individual bits you require.
I remember the code right now but i'll post it once I am home again tomorrow.
- I can do it with these methods. Actually it's not too difficult to do with a simple assembly routine inserted into mBasic. Here's how to shift bits and test:
Code: Select all
sub procedure Ser2Par(dim outbyte as byte)
dim bit as byte
For bit = 0 to 7
If TESTBIT(outbyte, bit) = 0 Then
PORTB.0 = 0
Else
PORTB.0 = 1
End If
- Now look at code that does the same with bit transfers:
Code: Select all
sub procedure Ser2Par(dim outbyte as byte)
dim bit as byte
dim temp as byte
For bit = 0 to 7
temp = outbyte >> bit
PORTB.1 = STATUS.0
Next bit
- This code is very efficient. You can shift out a Byte or Word variable, left or right, and serially clock out the bits by merely checking the CARRY bit.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]
[url=http://circuit-ed.com]CircuitED -[/url]
- A little correction on the "wishlist" mBasic code:
Code: Select all
sub procedure Ser2Par(dim outbyte as byte)
dim bit as byte
dim temp as byte
For bit = 1 to 8
temp = outbyte >> bit
PORTB.0 = STATUS.0
Next bit
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]
[url=http://circuit-ed.com]CircuitED -[/url]
Where did STATUS come from? Surely you mean PORTB.0 = temp.0 ?xor wrote:
- A little correction on the "wishlist" mBasic code:
Code: Select all
sub procedure Ser2Par(dim outbyte as byte) dim bit as byte dim temp as byte For bit = 1 to 8 temp = outbyte >> bit PORTB.0 = STATUS.0 Next bit
Messenga wrote:Where did STATUS come from? Surely you mean PORTB.0 = temp.0 ?
- STATUS.0 is the CARRY bit. When you shift a byte left or right, the bit that shifts out is moved to the CARRY bit. It permits you to do a very efficient parallel to serial transmission.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]
[url=http://circuit-ed.com]CircuitED -[/url]
Hi XOR,xor wrote:Messenga wrote:Where did STATUS come from? Surely you mean PORTB.0 = temp.0 ?
- STATUS.0 is the CARRY bit. When you shift a byte left or right, the bit that shifts out is moved to the CARRY bit. It permits you to do a very efficient parallel to serial transmission.
Excuse me for my stupidity. I am a little lost on your above statement.
If the byte your are shifting is equal to a binary zero and the shift operation is shifting "in" a zero value for the "new" bits and a zero is constantly being shifted into the carry bit, then how does the carry bit ever change ?
Second question is how does that achieve a very efficient parallel to serial transmission ?
First off "I hate serial data streams" as I could never get my head straight with them for some unknown reason. I guess I am not understanding how the carry bit test is utilized. Your indulgence would be appreciated.
Thank you,
Bill.....WB6BNQ
WB6BNQ wrote:If the byte your are shifting is equal to a binary zero and the shift operation is shifting "in" a zero value for the "new" bits and a zero is constantly being shifted into the carry bit, then how does the carry bit ever change ?
Second question is how does that achieve a very efficient parallel to serial transmission ?
First off "I hate serial data streams" as I could never get my head straight with them for some unknown reason. I guess I am not understanding how the carry bit test is utilized. Your indulgence would be appreciated.
- Bill,
This all goes back to some code I wrote for using the 74HC595. It allows you to use SPI with three pins to get an enormous amount of outputs, such as to drive an LED display, relays, or whatever. It accepts a serial stream of bits and then will latch them to a parallel output. By making a port pin equivalent to the Carry bit of the Status register after shifting a Byte or Word variable, left or right....LSBit or MSBit....you can accomplish the data output very easily. Otherwise there are a few extra coding steps to do the same thing now. Here's code that works now:Code: Select all
sub procedure Ser2Par(dim outbyte as byte) dim bit as byte For bit = 0 to 7 If TESTBIT(outbyte, bit) = 0 Then PORTB.0 = 0 Else PORTB.0 = 1 End If
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]
[url=http://circuit-ed.com]CircuitED -[/url]
Hi XOR,
I think I am following you in reference to the following routine :
Is that correct ?
However, that is not the same routine that I was referring to. Here is the routine that I was referring to relative to my original questions :
BUT the very first message in this thread is suggesting that the function “PORTB.0=STATUS.0" is not valid or not supported. Is that correct ? If so then your method around this is my first quoted routine above.
Do I have all that right ?
NOW, about the SPI thing. I was under the impression that the SPI was handled by a library routine. If that is true, why would you need the above process ?
Bill.....WB6BNQ
I think I am following you in reference to the following routine :
As you increment the variable “bit” (is it 0 to 7 or should it be 1 to 8 ?? ), you test the “outbyte” bit position and either output a zero or a one on port B bit zero.
sub procedure Ser2Par(dim outbyte as byte)
dim bit as byte
For bit = 0 to 7
If TESTBIT(outbyte, bit) = 0 Then
PORTB.0 = 0
Else
PORTB.0 = 1
End If
Is that correct ?
However, that is not the same routine that I was referring to. Here is the routine that I was referring to relative to my original questions :
IF I now understand correctly, the action is that the “PORTB.0=STATUS.0" is a means of moving the “carry bit” to the port output pin.
sub procedure Ser2Par(dim outbyte as byte)
dim bit as byte
dim temp as byte
For bit = 1 to 8
temp = outbyte >> bit
PORTB.0 = STATUS.0
Next bit
BUT the very first message in this thread is suggesting that the function “PORTB.0=STATUS.0" is not valid or not supported. Is that correct ? If so then your method around this is my first quoted routine above.
Do I have all that right ?
NOW, about the SPI thing. I was under the impression that the SPI was handled by a library routine. If that is true, why would you need the above process ?
Bill.....WB6BNQ
I think you understand it all fine. The second code you quoted doesn't presently work in mBasic. I'm putting it on the "WishList". I used the SPI code as the example which prompted my request but the single bit transfer has more potential I'm sure.
You are correct there are 2 mBasic libraries, one for the PIC module and the other is Software_SPI which can be implemented on a single port.
Since software SPI is easy to implement and use on any pins spread over all the ports, and I like coding that has assembler-like qualities and speed, I put my request in the suggestion box.
You are correct there are 2 mBasic libraries, one for the PIC module and the other is Software_SPI which can be implemented on a single port.
Since software SPI is easy to implement and use on any pins spread over all the ports, and I like coding that has assembler-like qualities and speed, I put my request in the suggestion box.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]
[url=http://circuit-ed.com]CircuitED -[/url]
Hi XOR,xor wrote: I think you understand it all fine.
Well, don't to be quick with that assumption. I am not a programmer. I am a hardware type, for the most part, forced to learn some programming. Fancy programming steps seem to escape my grasp most of the time.
I think your suggested request makes sense and hopefully ME can implement it.The second code you quoted doesn't presently work in mBasic. I'm putting it on the "WishList". I used the SPI code as the example which prompted my request but the single bit transfer has more potential I'm sure.
You are correct there are 2 mBasic libraries, one for the PIC module and the other is Software_SPI which can be implemented on a single port.
Since software SPI is easy to implement and use on any pins spread over all the ports, and I like coding that has assembler-like qualities and speed, I put my request in the suggestion box.
Again, thank you for your time.
Bill....WB6BNQ