Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Moving The bit value to array

Status
Not open for further replies.

nayakajit87

Member level 5
Joined
Aug 13, 2018
Messages
84
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
1,065
Dear all

I have digital IO which reads high(1) or LOW(0). I have created char buf which read the 1 byte of data thats 8 bits
Currently i am moving my data like this .Where i store the values like this

need simple code where i could able to move 0A into Buffer that buffer value to be move to ser_data[]
ser_data[3]=0X0A;
ser_data[4]=0XFF;
ser_data[5]=0XA0;
ser_data[6]=0XFF;

0A means -> 8 digital Io -> 0000 1010 this is value it read.This might change Io pin state changes. SImple code to move bit value to array to form byte
 

I don't understand your question. Do you mean you want to convert 8 bits arriving one at a time into a byte?
If that is what you want, either use a UART if there is one or you can construct a shift register in software to assemble the bits together.

Brian.
 

I have written simple code in arduino platform.

Here INF will store the digital status of Input configured. Now i wanted to move all 8 pin digital IO to ser_data[] buffer and print Ser_data to represent 8 bit

if all digital io read is FF means all input are 1 then

Ser_data= 0XFF where all bit represent like this

INPUT_T.INF1 = 1;
INPUT_T.INF2 = 1;
INPUT_T.INF3 = 1;
INPUT_T.INF4 = 1;
INPUT_T.INF5 = 1;
INPUT_T.INF6 = 1;
INPUT_T.INF7 = 1;
INPUT_T.INF8= 1;

Ser_data= 0X0A

INPUT_T.INF1 = 0;
INPUT_T.INF2 = 1;
INPUT_T.INF3 = 0;
INPUT_T.INF4 = 1;
INPUT_T.INF5 = 0;
INPUT_T.INF6 = 0;
INPUT_T.INF7 = 0;
INPUT_T.INF8= 0;




Code:
unsigned char ser_data[10];
#define LED D1

typedef union
{
  struct
  {
    unsigned INF1: 1;
    unsigned INF2: 1;
    unsigned INF3: 1;
    unsigned INF4: 1;
    unsigned INF5: 1;
    unsigned INF6: 1;
    unsigned INF7: 1;
    unsigned INF8: 1;
  };
  unsigned char INF1_9;
} INPUT_TYPE;

INPUT_TYPE INPUT_T;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  pinMode(0, OUTPUT);
  pinMode(D1, INPUT);

}

void loop()
{
  // put your main code here, to run repeatedly:

  if (digitalRead(0) == 1)
  {
    INPUT_T.INF1 = 1;

  } else
  {
    INPUT_T.INF1 = 0;
  }

  if (digitalRead(D1) == 1)
  {
    INPUT_T.INF2 = 1;
    Serial.println("Pin high");
  } else
  {
    INPUT_T.INF2 = 0;
    Serial.println("Pin LOW");
  }
  delay(1000);


}
 
Last edited by a moderator:

Hi,

I also don´t understand the question.
In my eyes you mix different problems.
1) to get a byte from 8 input pins (one complete 8 bit port)
2) to store a byte in an array
3) to trnsmit one byte of the array via UART

Please focus on one problem.

for 1):
Just reading whole port input state will give you the desired byte like 0x0A. No need to convert anything.

****
For further discussion: you should tell which microcontroller and which compiler you use.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top