## status input pin shift in to a byte

7 posts / 0 new
Author
Message

hallo,

i think it is not a big problem, but i just don't see how to fix it.

i have 2 pins: 1 input and 1 output:

pinc3 = input serieel data comes in (90000 bits)

pinc4 = output clock pulse to synchronize

the speed is very slow something like 375 bytes/sec.

when 8 bits are in (a byte) i write it away in a externe RAM.

i like to do this with the shift instructions, so on the moment the clock = 1, i ask the status of pc3 (serieel in) and the result

i wanna gonna shit in to a byte.

but can i directly shift the status of a input pin in a byte, ore do i need a conversion ?

Last Edited: Tue. Aug 6, 2019 - 09:10 PM

C or assembler?

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

byte<<=1;
If (pin)
{
byte|=1;
}

Do you want most significant bit first or leadt significant bit first?

Kartman wrote:
Do you want most significant bit first or leadt significant bit first?
The alternative being:

byte>>=1;
If (pin)
{
byte|=0x80;
}

its in C

if i'am correct:

byte<<=1  is the same as  byte=byte<<1

and

byte|=1  is the same as  byte=byte|1

so:

byte=byte<<1     // here the byte is shift 1 pos. to the left

if(pin)                 // here i gonna ask if the serieel pin = "1"

{

byte=byte|1       // if serieel pin = "1"  the "1" is gonna place at the LSB

}

but wat i have to do when the serieel input pin = "0" ?

Last Edited: Wed. Aug 7, 2019 - 05:55 PM

trixo wrote:

its in C

if i'am correct:

byte<<=1  is the same as  byte=byte<<1

and

byte|=1  is the same as  byte=byte|1

so:

byte=byte<<1     // here the byte is shift 1 pos. to the left

if(pin)                 // here i gonna ask if the serieel pin = "1"

{

byte=byte|1       // if serieel pin = "1"  the "1" is gonna place at the LSB

}

but wat i have to do when the serieel input pin = "0" ?

the first shift above (byte = byte<<1;) shifts in a zero so nothing else needs to happen, but...

if the pin ==1, then the (byte = byte|1;) changes the zero to a one!

Jim