Main Menu
Home
AVR News
Atmel AVR
AVR Development Tools
Valuable Tools
WinAVR toolset
Makefile for WinAVR
AVR Virtual Simulators
Hardware for prototyping
GCC and AVR-GCC
Short introduction to C
AVR-GCC Tutorial
Example AVR Projects
AVR-GCC articles
WinAVR Site Map
Scienceprog FORUM
ScienceProg BLOG
Disclaimer
WinARM Tutorial
Latest comments
Programming AVR ADC module...
hi please send me example usart with...
More...

Measuring motor speed and...
main.c: In function...
More...

Running TX433 and RX433 RF...
(Hopefully this is not a re-post). I am...
More...

Running TX433 and RX433 RF...
I just bnought a pair of the RX/TX 433...
More...

Accessing AVR microcontroller...
You need to read PORTD 5th bit and...
More...

Friendly sites

Related Items:

Recommended sites


AVR GCC Structures PDF Print E-mail
Written by Administrator   
Tuesday, 05 September 2006
Last Updated ( Tuesday, 05 September 2006 )

Basically Structures are nothing more than collection of variables so called members. Structures allows to reference all members by single name. Variables within a structure doesn't have to be the same type. General structure declaration:

struct structure_tag_name{
	type member1;
	type member2;
	...
	type memberX
};

or

struct structure_tag_name{
	type member1;
	type member2;
	...
	type memberX
} structure_variable_name;

in second example we declared the variable name. Otherwise variables can be declared this way:

struct structure_tag_name var1, var2,var3[3];

Members of structure can be accessed by using member operator (.). The member operator connects the member name to the structure.

Lets take an example:

struct position{
	int x;
	int y;
}robot;

we can set robot position by using following sentence:

robot.x=10;
robot.y=15;

or simply

robot={10,15};

Structures can be nested:

struct status{
	int power;
		struct position coordinates;
} robotstatus;

to access robot x coordinate we have to write:

x=robotstatus.coordinates.x;

Actions can be taken with structures:

  • Copy;

  • Assign;

  • Take its address with &;

  • Access members.

Of course you can treat a structure like a variable type. So you can create an array of structures like:

struct status{
	int power;
	struct position coordinates;
} robotstatus[100];

Accessing 15th robot power would be like this:

pow=robotstatus[15].power;



Related Items:

   

Users' Comments  
 

Average user rating

 


Add your comment
Only registered users can comment an article. Please login or register.

No comment posted



mXcomment 1.0.6 © 2007-2008 - visualclinic.fr
License Creative Commons - Some rights reserved
< Prev   Next >

© 2008 WinAVR AVR-GCC Tutorial
Joomla! is Free Software released under the GNU/GPL License.