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.

unable to understand the code...

Status
Not open for further replies.

embed_v

Junior Member level 1
Joined
Aug 10, 2010
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,432
hiii

i have some code with structure, enum, fun plz tell me the flow of code
for understanding structure and like other stuff.
Code:
enum A_MODE{
	A = 0,
	B,
        C,
        D,
        E,	 
 };


typedef struct _a_mode
{
	unsigned int sen;
	unsigned int state;
	unsigned int last ;
	unsigned int thick;
	unsigned int count;
	unsigned int status;
} A_MODE;

A_MODE a_modes[MAX];


int Execute(void)
{
 (i am including only some part of this fun. )
	case BILL_PICKING:
				switch (a_mode[slot].sen)
				{
				case CASSETTE_A:
					sensor = SENSOR_A;
					break;

				case CASSETTE_B:
					sensor = SENSOR_B;
					break;
				}
				if (sensor)
				{
					 
					a_modes[slot].state = B;
					a_modes[slot].last= TimingCount;
				}
                                else
                                {}
                               }
}
 
Last edited:

seadolphine2000

Advanced Member level 3
Joined
Apr 12, 2005
Messages
881
Helped
122
Reputation
244
Reaction score
86
Trophy points
1,308
Activity points
7,374
enum A_MODE{
A = 0,
B,
C,
D,
E,
};
This is a definition for an enum template called "A_MODE". This enum has five values; A,B,C,D,E. The numerical value of A is 0, numerical value of B is 1 and so on.

typedef struct _a_mode
{
unsigned int sen;
unsigned int state;
unsigned int last ;
unsigned int thick;
unsigned int count;
unsigned int status;
} A_MODE;

A_MODE a_modes[MAX];
This is a definition of structure called "_a_mode" and you create an alias (nickname) for this template called "A_MODE". You then create an array of this structure, the array is called "a_modes" and the number of elements in this array is "MAX".

int Execute(void)
{
(i am including only some part of this fun. )
case BILL_PICKING:
switch (a_mode[slot].sen)
{
case CASSETTE_A:
sensor = SENSOR_A;
break;

case CASSETTE_B:
sensor = SENSOR_B;
break;
}
if (sensor)
{

a_modes[slot].state = B;
a_modes[slot].last= TimingCount;
}
else
{}
}
}

This is switch case statement that checks for the value of the property "sen" of the structure "A_MODE" (it should be "a_modes"), and according to the value of the "sen", a different decision will be taken.

Hope this helps.
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
Enumerations are listed constants

Code C - [expand]
1
2
3
4
5
6
7
enum A_MODE{
A = 0,
B,
C,
D,
E,
};


A with be 0 , B=1, C=2, D=3, E=4

Structures are used to group variables under one heading or name.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
typedef struct _a_mode
{
    unsigned int sen;
    unsigned int state;
    unsigned int last ;
    unsigned int thick;
    unsigned int count;
    unsigned int status;
} A_MODE;
 
//if you declare a variable of type A_MODE which represents the above structure
A_MODE mystracture;
 
// then you will have all the above members, each one is an individual unsigned int variable, they are just grouped under a variable name
mystracture.sen
mystracture.state
mystracture.last 
mystracture.thick
mystracture.count
mystracture.status



the next line

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
A_MODE a_modes[MAX]; // declares an array of the above structure
 
//then you will have: 
 a_modes[0].sen
 a_modes[0].state
 a_modes[0].last 
 a_modes[0].thick
 a_modes[0].count
 a_modes[0].status
 
 a_modes[1].sen
 a_modes[1].state
 a_modes[1].last 
 a_modes[1].thick
 a_modes[1].count
 a_modes[1].status
 
// up to MAX-1
 a_modes[MAX-1].sen
 a_modes[MAX-1].state
 a_modes[MAX-1].last 
 a_modes[MAX-1].thick
 a_modes[MAX-1].count
 a_modes[MAX-1].status



Alex
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top