Permalink
Find file
a86f877 Jun 24, 2013
211 lines (189 sloc) 4.33 KB
/**
pins_arduino.h - Pin definition functions for Arduino for ATmega 16
Based on the code from the following places
- Alternate core - http://www.avr-developers.com/corefiles/index.html
- Arduino - http://www.arduino.cc/
@author: Sudar <http://hardwarefun.com>
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define NUM_DIGITAL_PINS 32
#define NUM_ANALOG_INPUTS 8
#define analogInputToDigitalPin(p) ((p < 8) ? (p) + 24 : -1)
#define digitalPinHasPWM(p) ((p) == 4 || (p) == 5 || (p) == 7 || (p) == 11)
static const uint8_t SS = 12;
static const uint8_t MOSI = 13;
static const uint8_t MISO = 14;
static const uint8_t SCK = 15;
static const uint8_t SDA = 17;
static const uint8_t SCL = 16;
static const uint8_t LED_BUILTIN = 13; // We don't have a built-in LED, but still ..
static const uint8_t A0 = 24;
static const uint8_t A1 = 25;
static const uint8_t A2 = 26;
static const uint8_t A3 = 27;
static const uint8_t A4 = 28;
static const uint8_t A5 = 29;
static const uint8_t A6 = 30;
static const uint8_t A7 = 31;
//TODO: these are not assigned properly. Need to test more
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 32) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
#ifdef ARDUINO_MAIN
// digital pins are also used for the analog output (software PWM).
// Analog input pins are a separate set.
// ATMEL ATMEGA16 & 16A
//
// +-\/-+
// (D 8) PB0 1| |40 PA0 (AI 0)
// (D 9) PB1 2| |39 PA1 (AI 1)
// (D 10) PB2 3| |38 PA2 (AI 2)
// PWM (D 11) PB3 4| |37 PA3 (AI 3)
// (D 12) PB4 5| |36 PA4 (AI 4)
// (D 13) PB5 6| |35 PA5 (AI 5)
// (D 14) PB6 7| |34 PA6 (AI 6)
// (D 15) PB7 8| |33 PA7 (AI 7)
// RESET 9| |32 AREF
// VCC 10| |31 GND
// GND 11| |30 AVCC
// XTAL2 12| |29 PB7 (D 23)
// XTAL1 13| |28 PC6 (D 22)
// (D 0) PD0 14| |27 PC5 (D 21)
// (D 1) PD1 15| |26 PC4 (D 20)
// (D 2) PD2 16| |25 PC3 (D 19)
// (D 3) PD3 17| |24 PC2 (D 18)
// PWM (D 4) PD4 18| |23 PC1 (D 17)
// PWM (D 5) PD5 19| |22 PC0 (D 16)
// (D 6) PD6 20| |21 PD7 (D 7) PWM
// +----+
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
(uint16_t) &DDRA,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
(uint16_t) &PORTA,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PIN,
(uint16_t) &PINA,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /* 8 */
PB,
PB,
PB,
PB,
PB,
PB,
PB,
PC, /* 16 */
PC,
PC,
PC,
PC,
PC,
PC,
PC,
PA, /* 24 */
PA,
PA,
PA,
PA,
PA,
PA,
PA,
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 16, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 24, port A */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER, /* 0 - port D */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER1B,
TIMER1A,
NOT_ON_TIMER,
TIMER2,
NOT_ON_TIMER, /* 8 - port B */
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER0A, /* TODO: Need to verify it */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 16 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 24 - port A */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
#endif
#endif