AVR ATTiny45, Beginner question

Thread Starter

bug13

Joined Feb 13, 2012
2,002
As the basic code show below, I can understand the C part, but I don't know where are "
DDRB" and "PORTB" from.

These codes are for AVR ATTiny45 uC

Can someone point me to the right direction, and let me know what I should be googling, thanks!

#include <avr/io.h>

int main(void)
{

// Set Port B pins as all outputs
DDRB = 0xff;
// Set all Port B pins as HIGH
PORTB = 0xff;

return 1;
}
 

MrChips

Joined Oct 2, 2009
30,824
Open the file io.h found in the directory avr and you will see all the io addresses defined as described in the manufacturer's data sheet for that specific micro (in this case ATiny45).

PORTB refers to the 8-bit output parallel port.
By default, all pins of I/O ports are defined as inputs. To enable a specific pin as output, set the corresponding bit in the Data Direction Register to 1.

In this example,

DDRB = 0xFF;

sets all bits of DDRB to 1 and hence all 8 pins of PORTB are enabled as outputs.

(Note that inputs use a different register, PINB.)
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
So I can pretty much find almost all those strange name from matching the address in the data sheet, and defined address in io.h?
 

MrChips

Joined Oct 2, 2009
30,824
Yes. All the manufacturer's names are define for you in io.h
If you don't like their names you can create your own.
 

bazis1

Joined Mar 31, 2012
2
Hi, simply right-click on PORTB/DDRB and select "go to definition". This will work if you are using Visual Studio or the latest AVR studio.
 
Top