How About Transfer of Single Bit Values Between Registers

Post your requests and ideas on the future development of mikroBasic.
Post Reply
Author
Message
xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

How About Transfer of Single Bit Values Between Registers

#1 Post by xor » 02 Nov 2005 04:41

  • For example:

    Code: Select all

    PORTB.1 = STATUS.0
    This will produce a compiler error...PORTB.1 is expecting a 1 or 0.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: How About Transfer of Single Bit Values Between Register

#2 Post by zristic » 02 Nov 2005 08:12

We will work on it.

Messenga
Posts: 177
Joined: 18 Jan 2005 20:21

#3 Post by Messenga » 04 Nov 2005 14:16

Xor;

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.

ralphrmartin
Posts: 137
Joined: 10 Mar 2005 22:59
Location: Cardiff, UK
Contact:

#4 Post by ralphrmartin » 04 Nov 2005 16:53

Its perfectly reasonable to request that the compiler should generate the necessary code. That's what compilers are for :-)

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#5 Post by xor » 04 Nov 2005 21:37

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]

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#6 Post by xor » 05 Nov 2005 06:20

  • 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]

Messenga
Posts: 177
Joined: 18 Jan 2005 20:21

#7 Post by Messenga » 06 Nov 2005 22:22

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
Where did STATUS come from? Surely you mean PORTB.0 = temp.0 ?

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#8 Post by xor » 07 Nov 2005 02:44

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]

Messenga
Posts: 177
Joined: 18 Jan 2005 20:21

#9 Post by Messenga » 07 Nov 2005 03:17

ahh, I understand now. That is actually rather clever stuff :D

WB6BNQ
Posts: 228
Joined: 12 Jun 2005 21:02
Location: SAN DIEGO, CA - USA

#10 Post by WB6BNQ » 07 Nov 2005 04:37

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.
Hi XOR,

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

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#11 Post by xor » 07 Nov 2005 05:05

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]

WB6BNQ
Posts: 228
Joined: 12 Jun 2005 21:02
Location: SAN DIEGO, CA - USA

#12 Post by WB6BNQ » 07 Nov 2005 09:00

Hi XOR,

I think I am following you in reference to the following routine :

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

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.

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 :

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

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.

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

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#13 Post by xor » 07 Nov 2005 12:37

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.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

WB6BNQ
Posts: 228
Joined: 12 Jun 2005 21:02
Location: SAN DIEGO, CA - USA

#14 Post by WB6BNQ » 07 Nov 2005 19:18

xor wrote: I think you understand it all fine.
Hi XOR,

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.
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.
I think your suggested request makes sense and hopefully ME can implement it.

Again, thank you for your time.

Bill....WB6BNQ

Post Reply

Return to “mikroBasic Wish List”