tests PIN register

This commit is contained in:
hugogogo
2025-03-04 13:09:57 +01:00
parent 8829366ff2
commit 5555310580
2 changed files with 54 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
#include <avr/io.h>
// #include <util/delay.h>
#define SET(REGISTER, BIT) REGISTER |= 1 << BIT
#define CLEAR(REGISTER, BIT) REGISTER &= ~(1 << BIT)
@@ -12,19 +13,22 @@
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)
// - 0 = input
// PORTx :
// if DDRx = 1 (output mode) :
// - 1 = HIGH (5V)
// - 0 = LOW (0V)
// if DDRx = 0 (input mode) :
// PORTx : (Port Data Register)
// if DDRx = 1 (output mode) : Controls the output state of a pin when it's configured as an output
// - 1 = HIGH (5V?) (VCC)
// - 0 = LOW (0V) (GND)
// if DDRx = 0 (input mode) : Controls the internal pull-up resistor when the pin is an input
// - 1 = pull-up on
// - 0 = pull-up off
// PINx :
// - 0 = pull-up off (pin floats)
// 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)
CLEAR(PORTB, D1); // make PB0 as HIGH (LED turns ON)
@@ -37,5 +41,45 @@ int main()
// CLEAR(DDRB, D4); // make PB4 as INPUT
// 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;
}