Anda di halaman 1dari 2

c  


February 8, 2009 at 23:36 (microcontroller)

OVERVIEW:

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.

Features:

`| 16/32 Kb In-System Self-Programmable Flash


`| 1024 Bytes EEPROM
`| Ñwo 8-bit Ñimer/Counters with Separate Prescalers and Compare Modes
`| One 16-bit Ñimer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
`| Four PWM Channels
`| Programmable Serial USARÑ
`| Internal Calibrated RC Oscillator
`| Power-on Reset and Programmable Brown-out Detection
`| 32 Programmable I/O Lines

and many more«

PROGRAMMING:

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.Ñhese three registers are

`| DDRx(data direction register)


`| PINx
`| PORÑx

x -A,B,C,D

    
  :

Ñhis 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 Ño make all pins of port D as input pins

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

DDRC=0b00001111

K 
 

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

e.g Ño read data from portA

DDRA=0b00000000

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

K 
 

PORÑx is used for two purpose-

1.| ÑO O/P DAÑA: when port is configured as output.when corresponding bits in DDR is set
1.
DDRA=0b11111111x=0b10101010PORÑA=x // now content of port a will be AA
2.| Ño activate or deactivate pull up registers: Ñhis 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.

e.g

`| Ño make portA as i/p with pull-up enableDDRA=0b00000000


PORÑA=0b11111111
y=PINA

`| Ño make portA as tri-stated i/p


DDRA=0b00000000
PORÑA=0b00000000

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

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

Anda mungkin juga menyukai