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.

Comparing digits in an array

Status
Not open for further replies.

innovationhut

Junior Member level 2
Joined
Mar 23, 2010
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,456
Hi,

I am currently writing a program in which I have to compare the value received from a pin (values read from the pin and stored in variable) with the numbers stored in an array.

For example:

Code:
const char com3[] = {0x0C, 0x0A, 0x0A, 0x0C}; // now compare them with the four variables. D0, D1, D2 and D3

D0 = 0C, D1 = 0X0A, D2 = 0X0A, D3 = 0X0C   //so that if they are all equal it should set PORTC high.

what kind of loop I can use to compare them, all variables and data stored should be equal to set PORTC HIGH, such that D0 should be equal to 0C, D1 to 0A and so on.
 

innovationhut said:
so that if they are all equal it should set PORTC high.
Well, this is probably the only sentence in your post that completely makes sense. It sounds like you want to compare 2 arrays with known equal length.

If that's all you need to do, than the algorithm is fairly simple. You will need a variable to act as a temporary flag. Before you enter a loop, set a flag to true. If the i-th elements are equal, set the flag to true. If they are not equal, set the flag to false and break out of the loop. After the loop check the flag. If it remains true after the loop is complete, then set PORTC high.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top