Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how do you define ports of ATMEGA32?

Status
Not open for further replies.

unwrittennovel

New Member
hey there im new to ATMEGA programming( C language) so, i would like to kno how do you define ports in ATMEGA (like it was P2^1, P2^3 etc in 8051)....

thank you
 
That depends of Your C-Compiler.
In most Compilers will be used PORTx to access the output of a Port, or to activate the internal Pull Up's.
Where 'x' is the Port A,B,C.. and so on Example: PORTA.
There are 2 additional registers for each Port.
The first one is the DDRx register that selects if a Port is an Input or an Output.
The second is the PINx Register that shows the state of the Input Port of each Port.

Example:
DDRA=0x0F; //Select the lower nibble as Output and the higher Nibble as Input
PORTA=0x81; //Set the More significant bit Output as Pullup - It is a Input and Set the Low significant Bit to High - It's an Output.
A=PINA; //Readout the State of the Complete PORTA and store it into the variable A

Most Compilers support single bit access like "PORTA.0=1" - The PORTA - 0 = Low significant bit will be set to 1.

Be a little careful with the Port C. A few Ports of that will be used for the JTAG Interface and that is activated on a new Controller.
You must disable the JTAGen Fuse in the Fuse Setting to get full access to all Pins of Port C.
But the Controller Programming and Debugging via a JTAG Interface is not further possible until Change the State of the JTAGen Fuse.
But most people use ISP Programming and that doesn't depend of the JTAGEN.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top