fbpx

AVR PROGRAMMING

AVR has four ports.

  • Port A, Port B, Port C, Port D.
  • AVR is a 8bit.
  • Port pins can be access by.
    1. Bit instruction.
    2. Byte instruction.

Bit Instruction

  • In bit instruction each port pins value assigned individually.
  • Example: In port0 3rd pin should keep high and 4th pin should keep low it can be done in this way.
    1. P0_3=1; (High) // Port0 3rd pin
    2. P0_4=0; (Low) // Port0 4th pin

Byte Instruction

  • In byte instruction we can access entire port pins.
  • Example
  • In port0 all pin should keep low.
    1. P0 = 0x00;
      0x0000|0000;
      0x 0 | 0 = 0x00.
    2. In port 0 MSB should keep high and LSB should keep low.
    3. P0=0xF0;
      0x1111|0000;
      0x F | 0 = 0xF0.

Binary Table

Byte Instruction

Accessing Pins

  • AVR Digital I/O ports is associated with three (3) I/O register.
  • They are.
    1. Data Direction Register (DDRx).
    2. Port X Input Pins Register (PINx).
    3. Port Register (PORTx).

Data Direction Register (DDRx)

  • DDRx is an 8-bit register.
  • It is used to set the pin as an input or output
    1. if DDRX is set to 1 it acts as an output pin,
    2. if DDRX is set to 0 it acts as an input pin,
    DDRA0=0
    Port A 0th pin act as input.

Port X Input Pins Register (PINx)

  • PINx is an 8-bit register.
  • It stores the logic value, the current state of the physical pins on Portx.
  • To read the values on the pins of Portx.
  • Must read the values that are in its PIN register.

Port Register (PORTx)

  • PORTx is an 8-bit register.
  • It stores the logic value, the current state of the Portx.

1 comment on “AVR PROGRAMMING

Leave a Reply

Your email address will not be published. Required fields are marked *