# How can i read 8 digit by use PortManipulation

Hi, i want to read 8 digit from TMI1640 ic driver for 7 segments i want use PORTD to make that but i don't know how ? this simple short code
note / ABCDEFG and DP in sequence pins 0,1,2,3,4,5,6,7 as inputs

``````void setup(){
DDRD = B00000000; // make all bin input
Serial.begin(9600);
}
void loop(){
if(PIND & B00000110){ // B00000000 == DP,G,F,E,D,C,B,A --> pin0 == A, pin1 == B, ... pin7== DP
Serial.println('1');
}
delay(100);
}
``````

any suggestion, thanks.

you code is most OK I should think!

the only bit I would change is here:

``````void setup(){
DDRD = B00000000; // make all bin input
Serial.begin(9600);
}
void loop(){
if((PIND & B00000110)==B00000110){ // <-- that way is statement will ONLY be true for B00000110. else it would be true for any non-zero value of the logical AND operation
Serial.println("1");
}
delay(100);
}
``````

this you use set the PORTD pins that have been set as OUTPUT. since there are all inputs, no real use here. If you want to drive another 7-seg then you would need to some other port that is available on you board. that would be B or C of a UNO

hope that helps....

On an UNO or NANO you can't use Pin 0 or Pin 1 for data if you are using Serial. You can only use the top 6 bits of PIND.

You need 8 inputs to detect when each digit is lit. Port B (pins 8-13) and Port C (A0-A5) are connected to 6 Arduino pins each. With Pin 0 and Pin 1 dedicated to Serial you have 18 pins to work with.

I would use pins 2 through 9 for data and 10-13+A0-A3 for the digits. Read PIND, PINB, and PINC. From the PINB and PINC values, figure out which digit is lit. Then store the top 6 of PIND and bottom 2 of PINB as the segment values. From the segment values, you can calculate the digit.

You could use Pin Change Interrupts on the Digit pins to detect the digit strobes. That would be a good time to sample the Segment pins.

excellent, the code is worked fine thank you for help

this is what i'm waiting for , thank you for response is very help

I used PORTD (2,3,4,5,6,7) and two pins from PORTB (8,9) also i used PORTC (A0,A1,A2,A3,A4) to know which GRID is LOW to active 7segment (7segment active HIGH) but when i compare the input register like this `((PINC & B000000) == B000000)` not excatly read i think the reason is speed of transfer data from IC TMI1640 to UNO they time of pulse is 580 us approximately and and time to rest is 180 us approximately between pulse and pulse what the appropriate code to read this with 16 bit send every segment (each segment send 16 bit because the display had 16 digit (GRID) and i used just five digit from that to read the weighing by arduino and display it as any thing displayed in computer) in simple i want the logic code to control speed of receiving data if time of the pulse received is 580 us if HIGH and in same time i receive data from 8 wires (7 for segments and 1 for DP) the data in each wire HIGH if GRID is LOW (because the display was common cathode) , i hope i transfered the picture is same is if there is no thing clearing tell me and thank you in advance.

That comparison is always 'true'. Anything & zero is always zero. Maybe if you show your code I could understand what is going wrong.

okay i will coding new one to fix the mistake if i need some thing i will tell you .

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.