36 lines
1.2 KiB
C
36 lines
1.2 KiB
C
#include <avr/io.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 D1 0
|
|
#define D2 1
|
|
#define D3 2
|
|
#define D4 4
|
|
|
|
// 14.2 : registers :
|
|
// DDRx : (Data Direction Register) Controls whether each pin is an input or output
|
|
// - 1 = output (pull-up off)
|
|
// - 0 = input
|
|
// 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 (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 with only AVR registers (DDRX , PORTX, PINX)
|
|
int main()
|
|
{
|
|
// turns on led 1
|
|
SET(DDRB, D1); // make PB0 as OUTPUT (pullup is off)
|
|
SET(PORTB, D1); // make PB0 as HIGH (LED turns ON)
|
|
|
|
return 0;
|
|
} |