Loading...
Pages: [1]   Go Down
Author Topic: how to get digital 8bits data in the same and group the data in a digital value  (Read 664 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i uses HCTL-2020 for decoding the INCREMENTAL ROTARY encoder signal . it has 8 pins to provide a 8 bits data. i don't know how to get the data in the same time and group the data in a DEC value
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 98
Posts: 6389
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int dataPins[8] = {2,3,4,5,6,7,8,9};

void setup()
    {
    for (int i = 0; i< 8; i++)
         pinMode(dataPins[i], INPUT);
   }

void loop()
   {
   int value = 0;

   for (int i=0; i<8; i++)
       {
       value <<= 1;  // shift value left one bit
       value |= digitalRead(dataPins[i]);  // get a bit from a data pin
      }

// Do something with value
   }
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

johnwasser thx for your help . i found the result was 1111111 which was not the correct value from the decoder IC output. is it the shift occurred any problem?  My latest program is following: is it have any problem?

int dataPins[8] = {30,31,32,33,34,35,36,37};
int SELPin = 38; //set SEL pin
int OEPin = 39; //set OE pin
int value;
int valuelow ;
int valuehigh ;
void setup()
    {
      pinMode (SELPin, OUTPUT); //set SEL is output to control the decoder ic
   pinMode (OEPin, OUTPUT); // set OE做is output to control the decoder ic

    for (int i = 30; i<= 37; i++)
         pinMode(dataPins, INPUT);
         Serial.begin (9600);
   }

void loop()
   {
     digitalWrite(SELPin, HIGH); // SEL = 1    when SEL and OE are 1 that means tell the ic ready to give data
   digitalWrite(OEPin, HIGH); // OE = 1

   digitalWrite(SELPin, LOW); // SEL = 0   when SEL and OE are 0 that means tell the ic send the low 8 bits data
   digitalWrite(OEPin, LOW); // OE = 0

   valuelow=0;
   valuehigh=0;

   for (int i=30; i<=37; i++)
       {
       valuelow << 1;  // shift value left one bit
       valuelow |= digitalRead(dataPins);  // get a bit from a data pin
       }
/*     digitalWrite(SELPin, HIGH); // SEL = 1     when SEL is 1 and OE are 0 that means tell the ic send the high 8 bits data
   digitalWrite(OEPin, LOW); // OE = 0
     
      for (int i=30; i<=37; i++)
      {
        valuehigh <<= 1;  // shift value left one bit
       valuehigh |= digitalRead(dataPins);  // get a bit from a data pin
    }
   // value=(valuehigh*128)+valuelow;       */
    Serial.println(valuelow,BIN);
   }
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 98
Posts: 6389
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are you using to provide the clock to the HCTL-2020?
Logged

Pages: [1]   Go Up
Print
 
Jump to: