-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.h
41 lines (29 loc) · 1017 Bytes
/
led.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef __LEDs_H
#define __LEDs_H
#include <avr/io.h> //gives us names for registers
#include <avr/interrupt.h>
#include <inttypes.h> //gives us uintX_t
#include <string.h>
/*
IO Port Information starts on pg 72 of the Atmega datasheet.
DDRn : data direction register
PORTn : write to port (when configured as output)
PINn : read from port (when configured as input)
LEDS should be on the following pins:
Yellow : Port A Pin 0
Green : Port D Pin 5 ( OC1A )
Red : Port A Pin 2
*/
// define the output ports by which you send signals to the LEDs
#define PORT_RED PORTA
#define PORT_YELLOW PORTA
#define PORT_GREEN PORTD
// define the bit-masks for each port that the LEDs are attached to
#define BIT_RED ( 1 << 2 )
#define BIT_YELLOW ( 1 << 0 )
#define BIT_GREEN ( 1 << 5 )
// define "function" calls for turning LEDs on and off
#define LED_ON(x) (PORT_##x |= BIT_##x)
#define LED_OFF(x) (PORT_##x &= ~(BIT_##x))
#define LED_TOGGLE(x) (PORT_##x ^= BIT_##x)
#endif