Last active
February 24, 2020 20:49
-
-
Save liamkinne/d5790010d15743bfe6f0f337cfb889e6 to your computer and use it in GitHub Desktop.
AVR port manipulation using bit-fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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