added macro modes input and output

This commit is contained in:
hugogogo
2025-03-04 13:26:57 +01:00
parent 37325f2b16
commit 1a86e78984
2 changed files with 7 additions and 25 deletions

View File

@@ -19,7 +19,7 @@ hex: $(TARGET).hex
# https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
$(TARGET).bin: $(TARGET).c
$(CC) -mmcu=$(AVRGCC_MCU_TYPE) -D F_CPU=$(F_CPU) $(TARGET).c -o $(TARGET).bin
$(CC) -mmcu=$(AVRGCC_MCU_TYPE) -D F_CPU=$(F_CPU) $(TARGET).c -Os -o $(TARGET).bin
# https://linux.die.net/man/1/avr-objcopy

View File

@@ -1,10 +1,14 @@
#include <avr/io.h>
#include <util/delay.h>
#define SET(REGISTER, BIT) REGISTER |= 1 << BIT
#define CLEAR(REGISTER, BIT) REGISTER &= ~(1 << BIT)
#define TEST(REGISTER, BIT) REGISTER & 1 << BIT
#define TOGGLE(REGISTER, BIT) REGISTER ^= 1 << BIT
#define MODE_INPUT(BIT) CLEAR(DDRB, BIT)
#define MODE_OUTPUT(BIT) SET(DDRB, BIT)
#define D1 0
#define D2 1
#define D3 2
@@ -12,30 +16,8 @@
int main()
{
// DDRx : select direction of the pin
// - 1 = output (pull-up off)
// - 0 = input
// PORTx :
// if DDRx = 1 (output mode) :
// - 1 = HIGH (5V)
// - 0 = LOW (0V)
// if DDRx = 0 (input mode) :
// - 1 = pull-up on
// - 0 = pull-up off
// PINx :
SET(DDRB, D1); // make PB0 as OUTPUT (pullup is off)
CLEAR(PORTB, D1); // make PB0 as HIGH (LED turns ON)
// SET(DDRB, D2); // make PB1 as OUTPUT (pullup is off)
// CLEAR(PORTB, D2); // make PB1 as LOW (LED turns OFF)
// CLEAR(DDRB, D3); // make PB2 as INPUT
// SET(PORTB, D3); // make PB2 pullup on
// CLEAR(DDRB, D4); // make PB4 as INPUT
// CLEAR(PORTB, D4); // make PB4 pullup off
MODE_OUTPUT(D1);
SET(PORTB, D1);
return 0;
}