Close

Input with tactile Push button.

A project log for AVR Programming with C.

Simple and fun projects with AVR-C

8teims8teims 08/26/2019 at 23:460 Comments

Today i decided to use tactile push button to get binary input unlike the arduino code i had to do math. Encountered my third AVR i/o avr register  PINx.

//This Code is a simple i/o using tactile switch button and a LED.
#define F_CPU 16000000L

#include <avr/io.h>
#include <util/delay.h>

int main(){
        DDRB = 0x01;//Setting PB0 as output
        PORTB = 0x02;//Activating internal pullups of PB1

        while(1){
                if(!(PINB & 0x02)){
                        PORTB |= 0x01;//Bitmask operation
                }
                else{
                        PORTB &= 0xFE;//Bitmask operation
                }
        }
}

Discussions