Basics of atmega16/32

February 8, 2009 at 23:36 (microcontroller)


Atmega16/32 is atmel product. they are of megaAVR series , they have 16Kb and 32Kb Flash memory resp. like other AVR uc they are ISP(in system programmable ) i.e u can program it without taking it out of the system.


  • 16/32 Kb In-System Self-Programmable Flash
  • 1024 Bytes EEPROM
  • Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
  • One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
  • Four PWM Channels
  • Programmable Serial USART
  • Internal Calibrated RC Oscillator
  • Power-on Reset and Programmable Brown-out Detection
  • 32 Programmable I/O Lines

and many more…


As mentioned above it has 32 I/O lines that means it has 4 I/O ports(A,B,C,D).Every i/o port has 3 registers associated with each ports.These three registers are

  • DDRx(data direction register)
  • PINx
  • PORTx

x -A,B,C,D


This register configures data direction of port pins , means by using this register microcontroller decides whether this port will be used as input port or output port. In 8051 if we will declare any port as FF it becomes input port but in atmega it is opposite if we declare FF it becomes output port .

e.g To make all pins of  port D as input pins


If we want to make first 4 pins of portc as input and remaining 4 as output then


PINx register:

PIN(port IN) used to read data from port pins

e.g To read data from portA


Y=PINA  // data from port A will be stored in variable Y

PORTx register:

PORTx is used for two purpose-

  1. TO O/P DATA: when port is configured as output.when corresponding bits in DDR is set 1.
    DDRA=0b11111111x=0b10101010PORTA=x  // now content of port a will be AA
  2. To activate or deactivate pull up registers: This when u configure a port as input port. In input mode , when pull up is enabled , defaulted as 1. So, even if you dont connect anything to the pin and if you try to read it , it will read as 1. Now , when you drive pin to zero , only then it  will read as 0.


  • To make portA as i/p with pull-up enableDDRA=0b00000000
  • To make portA as tri-stated i/p

Using this basic knowledge we can easily write a program(I/O) for atmega.

u can also view this post on


………………….if you found this tutorial helpful or have any suggestions … do leave a comment.



  1. kt said,

    Please see my comment in your previous entry.
    This tutorial was helpful for a quick brush up.

  2. Sushanta Kumar Sahu said,

    Thanks man, I had been looking for a tutorial to program my avr. Now you have given a basis to understand further. But I feel you need to teach us more. There are not many guys accessible to dissipate their knowledge. Thanks for your help.

  3. sanket said,

    thanks for such a good, clear explanation of these basics.
    but i also wanted some tips on how to choose a particular microprocessor for a particular application and how to interface the Atmega 16/32 with the PC for loading the program onto the microcontroller. it would be wonderful if you could give some information regarding these.
    thanking you.

  4. Interface the Atmega 16/32 with the PC « Praveendb’s Weblog said,

    […] ATMEGA32 is a 8-bit AVR microcontroller with 32K Bytes In-system Programmable Flash. In Atmega32pins pin no.14 and 15 are RxD and TxD resp. For basics of atmega32 click here […]

  5. Mahi said,

    Really a clear explanation u have given ,thanx man

  6. scott said,

    mate, awesome, have been looking for something clean and simple all day


  7. hawk said,

    its really helpful man…
    thanx a lot

  8. Abhinav said,

    Thank u very much dude !!!
    This help me alot to understand …
    Keep up the nice work …

  9. Shagec said,

    Thanks man.teach the information that u know,is a great job.

  10. santosh said,

    nice material, keep it up

  11. rama brahmam said,

    it is absolutely nice for the basic is so nice if u add some more information about programming

  12. vadiraj said,

    its good information..thank you..

  13. GODLESS said,

    Very helpful information..thanks a lot

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: