• tags: #C Programming #Embedded programming ProgrammingArduino
  • Resources
  • AVR programmers communicate with SPI, which is MISO, MOSI, SCK interface.
  • If you look at the data sheet there are PC,PD,PB ports. Eg PB7, Port B 7, Each port is a byte of data and each of these numbers correspond to a bit in the byte that is the port.
  • The register is a specific portion in the memory that serves a function in the micro controller.
  • Registers
    • Registers are a collection bits which represent the current state.
    • DDRx
      • Direction register that sets the port as the input or the output.
    • PORTx
      • PORTx sets the state of the pin, either on or off
      • Eg - Turning PB0 on and off
        • PB0 is the zeroth bit in the B port, ie DDRB 0000001 sets PB0 as output PORTB 00000001 turns the pin high.
        • In Hexadecimal DDRB 0x01, PORTB 0x01
    • PINx
      • These are input registers are dynamically updated, it will receive values based on the state of all the pins in the register.
      • When pulling the state of a single bit of the PIN register, we need a Mask variable. Its a variable of the same size as the number of bits you are comparing it to. Do an AND operation with the Mask.
      • Why use a mask variable?
        • If we want to check the state of a pin, but don’t know the condition of all the other pins, then we can’t find an exact match if we just do a Boolean operation to compare the state of the the pin. So we mask out all other pins and the output would just return the state of the pin we are interested in.
  • Bit Shifting
    • Bit shifting is an easy method to put values into the registers
  • Normally if you write a value to an output PORT it will turn the pin ON/OFF. But if you write a vlaue to the Input PORT, you will turn ON/OFF the internal pullups.

  • tags: #AVR C Hexadecimal

  • tags: #AVR C

  • AVR C

Notes mentioning this note

Here are all the notes in this garden, along with their links, visualized as a graph.