tests PIN register
This commit is contained in:
@@ -19,7 +19,7 @@ hex: $(TARGET).hex
|
|||||||
|
|
||||||
# https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
|
# https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
|
||||||
$(TARGET).bin: $(TARGET).c
|
$(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
|
# https://linux.die.net/man/1/avr-objcopy
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
// #include <util/delay.h>
|
||||||
|
|
||||||
#define SET(REGISTER, BIT) REGISTER |= 1 << BIT
|
#define SET(REGISTER, BIT) REGISTER |= 1 << BIT
|
||||||
#define CLEAR(REGISTER, BIT) REGISTER &= ~(1 << BIT)
|
#define CLEAR(REGISTER, BIT) REGISTER &= ~(1 << BIT)
|
||||||
@@ -12,19 +13,22 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// DDRx : select direction of the pin
|
// registers :
|
||||||
|
// DDRx : (Data Direction Register) Controls whether each pin is an input or output
|
||||||
// - 1 = output (pull-up off)
|
// - 1 = output (pull-up off)
|
||||||
// - 0 = input
|
// - 0 = input
|
||||||
// PORTx :
|
// PORTx : (Port Data Register)
|
||||||
// if DDRx = 1 (output mode) :
|
// if DDRx = 1 (output mode) : Controls the output state of a pin when it's configured as an output
|
||||||
// - 1 = HIGH (5V)
|
// - 1 = HIGH (5V?) (VCC)
|
||||||
// - 0 = LOW (0V)
|
// - 0 = LOW (0V) (GND)
|
||||||
// if DDRx = 0 (input mode) :
|
// if DDRx = 0 (input mode) : Controls the internal pull-up resistor when the pin is an input
|
||||||
// - 1 = pull-up on
|
// - 1 = pull-up on
|
||||||
// - 0 = pull-up off
|
// - 0 = pull-up off (pin floats)
|
||||||
// PINx :
|
// PINx : (Pin Input Register) Reads the current logical state of a pin
|
||||||
|
// Reflects the actual voltage on the pin
|
||||||
|
// Special feature: Writing 1 to PINxn toggles the corresponding PORTxn bit (regardless of DDRx)
|
||||||
|
|
||||||
|
// turns on led 1
|
||||||
SET(DDRB, D1); // make PB0 as OUTPUT (pullup is off)
|
SET(DDRB, D1); // make PB0 as OUTPUT (pullup is off)
|
||||||
CLEAR(PORTB, D1); // make PB0 as HIGH (LED turns ON)
|
CLEAR(PORTB, D1); // make PB0 as HIGH (LED turns ON)
|
||||||
|
|
||||||
@@ -37,5 +41,45 @@ int main()
|
|||||||
// CLEAR(DDRB, D4); // make PB4 as INPUT
|
// CLEAR(DDRB, D4); // make PB4 as INPUT
|
||||||
// CLEAR(PORTB, D4); // make PB4 pullup off
|
// CLEAR(PORTB, D4); // make PB4 pullup off
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// TEST weird behavior of PIN register :
|
||||||
|
// in initial tests, using PIN register to toggle ON two leds only worked for the second one
|
||||||
|
// after some tests, this behavior is not anymore
|
||||||
|
//
|
||||||
|
// test 1 : only led 3 turns on
|
||||||
|
// SET(DDRB, D1);
|
||||||
|
// CLEAR(PORTB, D1);
|
||||||
|
// SET(PINB, D1);
|
||||||
|
// SET(DDRB, D3);
|
||||||
|
// CLEAR(PORTB, D3);
|
||||||
|
// SET(PINB, D3);
|
||||||
|
//
|
||||||
|
// test 2 : only led 3 turns on
|
||||||
|
// SET(DDRB, D1);
|
||||||
|
// CLEAR(PORTB, D1);
|
||||||
|
// SET(DDRB, D3);
|
||||||
|
// CLEAR(PORTB, D3);
|
||||||
|
// SET(PINB, D1);
|
||||||
|
// SET(PINB, D3);
|
||||||
|
//
|
||||||
|
// test 3 : both leds turns on
|
||||||
|
// SET(DDRB, D1);
|
||||||
|
// CLEAR(PORTB, D1);
|
||||||
|
// SET(DDRB, D3);
|
||||||
|
// CLEAR(PORTB, D3);
|
||||||
|
// PINB = (1 << D1) | (1 << D3);
|
||||||
|
//
|
||||||
|
// test 4 : both leds turns on
|
||||||
|
// SET(DDRB, D1);
|
||||||
|
// CLEAR(PORTB, D1);
|
||||||
|
// SET(DDRB, D3);
|
||||||
|
// CLEAR(PORTB, D3);
|
||||||
|
// SET(PINB, D1);
|
||||||
|
// _delay_us(500);
|
||||||
|
// SET(PINB, D3);
|
||||||
|
//
|
||||||
|
////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user