Lecture4
Lecture4
}
return (0);
}
DDRx (Data Direction Register for Port x={B, C, D})
Setting a bit to 1 corresponding pin of the given port as is set as OUTPUT pin
Setting a bit to 0 corresponding pin of the given port as is set as INPUT pin
Default configuration: Input
Header file io.h need to be included to access the registers by their name
DDRD = 0xFF; or
DDRD = 0b11111111; or
DDRD = 255;
PORTx (Data Register for Port x={B, C, D})
Used to set logic values (i.e. 0 or 1) on a port that has already been configured as output
port.
Read/writable
Setting a bit to 1 Logic 1 (i.e. Vcc) on corresponding output pin of the given port.
Setting a bit to 0 Logic 0 (i.e. ground) on corresponding output pin of the given port.
Default configuration: Logic 0
Header file io.h need to be included to access the registers by their name
Individual bits are given names of Pxn
PORTx (Data Register for Port x={B, C, D})
Example: Write C-statements to configure PORTC as ouput port and drive logic 1
on PC3 and PC6.
DDRC = 0xFF;
PORTC=0b01001000;
PINx (Port x ={B, C, D} input pins)
If a port is configured as input port, the input data is made available in PINx
register.
Only readable.
2. Write the value in the PORT register to make it available on pins of the port.
Build an AVR-microcntroller based circuit that
blinks 8 LEDs from right to left direction by
taking «two steps forward, one step backward».
Connect 8 LEDS with PORTD.
NOTE: Each LED need to be grounded using a
current limiting resistor (1K).
while(1) {