#ATTINY85 PORT REGISTERS CODE#
Write a code so that when button connected to PB0 is pressed LED in PB2 should turn ON and when button to PB1 is pressed LED should turn off. Assign PB2 as output with LED connected to it. The example programs should run on the ATtiny 13, ATtiny25, ATtiny45 or ATtiny85. The ATtiny13 runs at 1.2MHz ( 9.6MHz Oscillator divided by 8 ) with 1K of RAM. This chip has one ADC which can be used to read up to four inputs. Configure PB0 and PB1 as input with internal pull up resistors enabled and button that connects to ground when pressed. For this primer we use the AVR ATtiny13 for its simplicity & small number of pins.PORTB |= (1 << PB4) //write to PORTB register to set the LED state to HIGH The high-performance, low-power Microchip 8-bit AVR® RISC-based microcontroller combines 8 KB ISP Flash memory, 512B EEPROM, 512B SRAM, six general purpose I/O lines, 32 general purpose working registers, one 8-bit timer/counter with compare modes, one 8-bit high. PORTB &= ~(1 << PB4) //write to PORTB register to set the LED state to LOW PORTB |= (1 << PB3) //activate pull-up resistor for PB3ĭDRB |= (1 << DDRB4) //set PB4 as output If order of pin configuration is changed everything is OK. That happens if inside setup () analog input A1 (pin 7, PB2) is configured after digital output PB1. It seems that output has been configured to high impedance mode. LED connected to pin PB1 lights very dim when output is high. This register is generally used to set the output state of that pin high or low, but as we declare this pin as input, this will activate the internal pull up resistor.ĭDRB &= ~(1 << DDRB3) //set PB3 as input Simplified circuitry there is 2 LEDs and 1 analog input. So we need to activate the internal pull up resistor of this pin. PB3 is an Input pin, therefore we can not leave the pin floating when neither high nor low logic level are connected to it. Now that we have configured the pins, we need to read the logic input from the input pin PB3. Therefore the DDB4 register bit will be logic ‘high’ or 1.ĭDRB |= (1 << PB4) // Set the pin PB4 as outputĬircuits Library - 220+ practical circuits PORTB register: I can get the board to work when comes just input and output operations. So I tried using internal register names in the code rather than using Arduino in built functions. Similarly we need to define the pin 3 or PB4 as an output pin. I have bought a Digispark ATtiny85 board to learn about that microcontroller. The below piece of code will do that.ĭDRB &= ~(1 << PB3) // Set the pin PB3 as input In order to make it as an Input we need to write the DDB3 register bit as logic ‘low’ or 0 in the code.
Now according to the datasheet the pin 2 is PB3 of PORTB. At least 1 port, and up to 3 ports are used in the ATtiny. We are looking to use pin 2 of attiny85 as Input. Port registers allow for lower-level and faster manipulation of the i/o pins of the ATtiny. The configuration of ATtiny85 GPIO input pins starts with DDRB register, you can refer the datasheet here. The LED state will be toggled based on the button input. Here we will use a push button to feed signal to digital input pin and a LED as output.
#ATTINY85 PORT REGISTERS HOW TO#
The second part of this series where we will explain how to configure its GPIO pins as input and how to read status of input pin. In the previous tutorial of ATtiny MCU series we have covered how to get started with this 8 bit MCU, Attiny85 and how to use its GPIO pin as an output.