AVR ATTiny45, Beginner question

Discussion in 'Embedded Systems and Microcontrollers' started by bug13, Mar 25, 2012.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    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!

     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    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.)
     
  3. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    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?
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    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.
     
  5. bazis1

    New Member

    Mar 31, 2012
    2
    0
    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.
     
Loading...