Uploaded by Alex H

3.+Ports 1

advertisement
ATMEGA16 PORTS
ATMEGA 16 PIN DIAGRAM
REGISTER ASSOCIATED WITH PORTS
Three 8-bit Registers
1. DDRx
2. PORTx
3. PINx
x will be replaced by ‘A’ or ‘B’ or ‘C’ or ‘D’
depending upon the port in use.
DDRX
 8-bit Data Direction Register
 Eg. DDRA
D7
D6
D5
D4
D3
D2
D1
D0
0
0
0
0
0
0
0
0
All Pins of PortA are
input
DDRA =
0x00;
1
1
1
1
1
1
1
1
All Pins of PortA are
Output
DDRA =
0xFF;
0
D7, D4, D1 – Output
D6, D5, D3, D2, D0 Input
DDRA =
0x92;
1
0
0
1
0
0
1
PORTX
 To Write data to Port, We use PORTx register
 Eg. Write data to PORTC
 PORTC = 0x30;
LED CONTROL WITH SWITCH
PORTX ROLE IN INPUTTING
DATA
 PORTX register of used to
enable (1) or Disable (0) the
PULL_UP registers
PINX ROLE IN INPUTTING DATA
 To read Data from Port, We use PINx register
 Eg. To read Port A
 int a_val = PINA
PORTS ALTERNATE FUNCTIONS
PORTS ALTERNATE FUNCTIONS
Download