piLinux
3/19/2016 - 12:40 PM

Sample usage of PINx

Sample usage of PINx

/*
 * lab7.c
 *
 * Author : mahir
 */ 

#include <avr/io.h>

int main(void)
{
	uint8_t x;		// x is an 8-bit unsigned integer
	
    DDRB = 0xff;	// Set all Port B pins as outputs
    PORTD = 0xff;	// By default, all Port D pins are set as inputs. So here we just activated the pull-ups
	x = PIND;		// We read the input values of D-pins and save them to x
	
	while(1){
		if (x == 0xff)
			PORTB = 0b00000001;
		else
			PORTB = 0x00;
	}

    return 1;
}