Skip to content

Instantly share code, notes, and snippets.

@pilinux
Created March 19, 2016 12:40
Show Gist options
  • Save pilinux/4d3ee2622f31c7f5af09 to your computer and use it in GitHub Desktop.
Save pilinux/4d3ee2622f31c7f5af09 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment