Port is the edge of data transportation, so that you can send you data through them . Atmega16 has 4 8-bit ports _ PortA , PortB , PortC , PortD _ you can configure them as output or input .
application :
for blinking an LED : you first configure them as output
if you connect them a "button" you will configure them as Input
Ports has three function registers :
( Registers are a place of SRAM , used to configure system)
///////////////////////////////////////////////////////////
DDRX (X means A or B or C or D):
if DDRX=0xff ( 0xff is a hexadecimal number with prefix 0x)
PORTX is configured as output
if DDRX=0x00
PORTX is configured as input (you should set PORTX = 0xff)
//////////////////////////////////////////////////////////
PORTX (X means A or B or C or D)
if PORTX=0xff for output configuration
You send 0xff to PORTX
if PORTX =0xff for input configuration
you used a pullup resistor for input(pullup resistor is a resistor that prevents noise from effecting you input . you should use pullup resistor)
if PORTX=0x00 for input configuration
hi-z state for input
if PORTX=0xff for output configuration
output is 0x00
////////////////////////////////////////////////////////
PINX (X means A or B or C or D)
if you want to get a value from PORT . you should use PINX
//////
notice:
if you configure input as tri-state , your input is like Op-amp inputs with high impedance, so that a small static charge can change the state of input, so you cants predict input
in the future lesson, we will introduce the programming structure
more texts: