Skip to content

Instantly share code, notes, and snippets.

@liamkinne
Last active February 24, 2020 20:49
Show Gist options
  • Save liamkinne/d5790010d15743bfe6f0f337cfb889e6 to your computer and use it in GitHub Desktop.
Save liamkinne/d5790010d15743bfe6f0f337cfb889e6 to your computer and use it in GitHub Desktop.
AVR port manipulation using bit-fields
#include <avr/io.h>
#include <util/delay.h>
typedef struct {
bool BIT0 : 1;
bool BIT1 : 1;
bool BIT2 : 1;
bool BIT3 : 1;
bool BIT4 : 1;
bool BIT5 : 1;
bool BIT6 : 1;
bool BIT7 : 1;
} Port;
int main()
{
Port * ddrB = (Port *) &DDRB;
Port * portB = (Port *) &PORTB;
ddrB->BIT7 = true;
while(true)
{
portB->BIT7 = true;
_delay_ms(100);
portB->BIT7 = false;
_delay_ms(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment