create ex02
This commit is contained in:
41
module00/ex02/main.c
Normal file
41
module00/ex02/main.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#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
|
||||
|
||||
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
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user