Test arduino code

Dependents:   DR14_4D7S_US

Fork of ArduinoHAL by René Bohne

Committer:
rbohne
Date:
Sat Jun 04 20:01:33 2011 +0000
Revision:
2:7e1ff33bc76a
Child:
4:40396527a068
added some basic wiring functions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rbohne 2:7e1ff33bc76a 1 /*
rbohne 2:7e1ff33bc76a 2 wiring.h - Partial implementation of the Wiring API for the ATmega8.
rbohne 2:7e1ff33bc76a 3 Part of Arduino - http://www.arduino.cc/
rbohne 2:7e1ff33bc76a 4
rbohne 2:7e1ff33bc76a 5 Copyright (c) 2005-2006 David A. Mellis
rbohne 2:7e1ff33bc76a 6
rbohne 2:7e1ff33bc76a 7 This library is free software; you can redistribute it and/or
rbohne 2:7e1ff33bc76a 8 modify it under the terms of the GNU Lesser General Public
rbohne 2:7e1ff33bc76a 9 License as published by the Free Software Foundation; either
rbohne 2:7e1ff33bc76a 10 version 2.1 of the License, or (at your option) any later version.
rbohne 2:7e1ff33bc76a 11
rbohne 2:7e1ff33bc76a 12 This library is distributed in the hope that it will be useful,
rbohne 2:7e1ff33bc76a 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
rbohne 2:7e1ff33bc76a 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
rbohne 2:7e1ff33bc76a 15 Lesser General Public License for more details.
rbohne 2:7e1ff33bc76a 16
rbohne 2:7e1ff33bc76a 17 You should have received a copy of the GNU Lesser General
rbohne 2:7e1ff33bc76a 18 Public License along with this library; if not, write to the
rbohne 2:7e1ff33bc76a 19 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
rbohne 2:7e1ff33bc76a 20 Boston, MA 02111-1307 USA
rbohne 2:7e1ff33bc76a 21
rbohne 2:7e1ff33bc76a 22 $Id$
rbohne 2:7e1ff33bc76a 23 */
rbohne 2:7e1ff33bc76a 24
rbohne 2:7e1ff33bc76a 25 #ifndef Wiring_h
rbohne 2:7e1ff33bc76a 26 #define Wiring_h
rbohne 2:7e1ff33bc76a 27
rbohne 2:7e1ff33bc76a 28 //#include <avr/io.h>
rbohne 2:7e1ff33bc76a 29 //#include <stdlib.h>
rbohne 2:7e1ff33bc76a 30 #include "binary.h"
rbohne 2:7e1ff33bc76a 31
rbohne 2:7e1ff33bc76a 32 #ifdef __cplusplus
rbohne 2:7e1ff33bc76a 33 extern "C"{
rbohne 2:7e1ff33bc76a 34 #endif
rbohne 2:7e1ff33bc76a 35
rbohne 2:7e1ff33bc76a 36 #define HIGH 0x1
rbohne 2:7e1ff33bc76a 37 #define LOW 0x0
rbohne 2:7e1ff33bc76a 38
rbohne 2:7e1ff33bc76a 39 #define INPUT 0x0
rbohne 2:7e1ff33bc76a 40 #define OUTPUT 0x1
rbohne 2:7e1ff33bc76a 41
rbohne 2:7e1ff33bc76a 42 #define true 0x1
rbohne 2:7e1ff33bc76a 43 #define false 0x0
rbohne 2:7e1ff33bc76a 44
rbohne 2:7e1ff33bc76a 45 #define PI 3.1415926535897932384626433832795
rbohne 2:7e1ff33bc76a 46 #define HALF_PI 1.5707963267948966192313216916398
rbohne 2:7e1ff33bc76a 47 #define TWO_PI 6.283185307179586476925286766559
rbohne 2:7e1ff33bc76a 48 #define DEG_TO_RAD 0.017453292519943295769236907684886
rbohne 2:7e1ff33bc76a 49 #define RAD_TO_DEG 57.295779513082320876798154814105
rbohne 2:7e1ff33bc76a 50
rbohne 2:7e1ff33bc76a 51 #define SERIAL 0x0
rbohne 2:7e1ff33bc76a 52 #define DISPLAY 0x1
rbohne 2:7e1ff33bc76a 53
rbohne 2:7e1ff33bc76a 54 #define LSBFIRST 0
rbohne 2:7e1ff33bc76a 55 #define MSBFIRST 1
rbohne 2:7e1ff33bc76a 56
rbohne 2:7e1ff33bc76a 57 #define CHANGE 1
rbohne 2:7e1ff33bc76a 58 #define FALLING 2
rbohne 2:7e1ff33bc76a 59 #define RISING 3
rbohne 2:7e1ff33bc76a 60
rbohne 2:7e1ff33bc76a 61 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
rbohne 2:7e1ff33bc76a 62 #define INTERNAL1V1 2
rbohne 2:7e1ff33bc76a 63 #define INTERNAL2V56 3
rbohne 2:7e1ff33bc76a 64 #else
rbohne 2:7e1ff33bc76a 65 #define INTERNAL 3
rbohne 2:7e1ff33bc76a 66 #endif
rbohne 2:7e1ff33bc76a 67 #define DEFAULT 1
rbohne 2:7e1ff33bc76a 68 #define EXTERNAL 0
rbohne 2:7e1ff33bc76a 69
rbohne 2:7e1ff33bc76a 70 // undefine stdlib's abs if encountered
rbohne 2:7e1ff33bc76a 71 #ifdef abs
rbohne 2:7e1ff33bc76a 72 #undef abs
rbohne 2:7e1ff33bc76a 73 #endif
rbohne 2:7e1ff33bc76a 74
rbohne 2:7e1ff33bc76a 75 #define min(a,b) ((a)<(b)?(a):(b))
rbohne 2:7e1ff33bc76a 76 #define max(a,b) ((a)>(b)?(a):(b))
rbohne 2:7e1ff33bc76a 77 #define abs(x) ((x)>0?(x):-(x))
rbohne 2:7e1ff33bc76a 78 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
rbohne 2:7e1ff33bc76a 79 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
rbohne 2:7e1ff33bc76a 80 #define radians(deg) ((deg)*DEG_TO_RAD)
rbohne 2:7e1ff33bc76a 81 #define degrees(rad) ((rad)*RAD_TO_DEG)
rbohne 2:7e1ff33bc76a 82 #define sq(x) ((x)*(x))
rbohne 2:7e1ff33bc76a 83
rbohne 2:7e1ff33bc76a 84 #define interrupts() sei()
rbohne 2:7e1ff33bc76a 85 #define noInterrupts() cli()
rbohne 2:7e1ff33bc76a 86
rbohne 2:7e1ff33bc76a 87 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
rbohne 2:7e1ff33bc76a 88 #define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
rbohne 2:7e1ff33bc76a 89 #define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
rbohne 2:7e1ff33bc76a 90
rbohne 2:7e1ff33bc76a 91 #define lowByte(w) ((uint8_t) ((w) & 0xff))
rbohne 2:7e1ff33bc76a 92 #define highByte(w) ((uint8_t) ((w) >> 8))
rbohne 2:7e1ff33bc76a 93
rbohne 2:7e1ff33bc76a 94 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
rbohne 2:7e1ff33bc76a 95 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
rbohne 2:7e1ff33bc76a 96 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
rbohne 2:7e1ff33bc76a 97 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
rbohne 2:7e1ff33bc76a 98
rbohne 2:7e1ff33bc76a 99
rbohne 2:7e1ff33bc76a 100 typedef unsigned int word;
rbohne 2:7e1ff33bc76a 101
rbohne 2:7e1ff33bc76a 102 #define bit(b) (1UL << (b))
rbohne 2:7e1ff33bc76a 103
rbohne 2:7e1ff33bc76a 104 #define uint8_t int
rbohne 2:7e1ff33bc76a 105
rbohne 2:7e1ff33bc76a 106 typedef uint8_t boolean;
rbohne 2:7e1ff33bc76a 107 typedef uint8_t byte;
rbohne 2:7e1ff33bc76a 108
rbohne 2:7e1ff33bc76a 109 void init(void);
rbohne 2:7e1ff33bc76a 110
rbohne 2:7e1ff33bc76a 111 void pinMode(uint8_t, uint8_t);
rbohne 2:7e1ff33bc76a 112 void digitalWrite(uint8_t, uint8_t);
rbohne 2:7e1ff33bc76a 113 int digitalRead(uint8_t);
rbohne 2:7e1ff33bc76a 114 int analogRead(uint8_t);
rbohne 2:7e1ff33bc76a 115 void analogReference(uint8_t mode);
rbohne 2:7e1ff33bc76a 116 void analogWrite(uint8_t, int);
rbohne 2:7e1ff33bc76a 117
rbohne 2:7e1ff33bc76a 118 unsigned long millis(void);
rbohne 2:7e1ff33bc76a 119 unsigned long micros(void);
rbohne 2:7e1ff33bc76a 120 void delay(unsigned long);
rbohne 2:7e1ff33bc76a 121 void delayMicroseconds(unsigned int us);
rbohne 2:7e1ff33bc76a 122 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
rbohne 2:7e1ff33bc76a 123
rbohne 2:7e1ff33bc76a 124 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
rbohne 2:7e1ff33bc76a 125 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
rbohne 2:7e1ff33bc76a 126
rbohne 2:7e1ff33bc76a 127 void attachInterrupt(uint8_t, void (*)(void), int mode);
rbohne 2:7e1ff33bc76a 128 void detachInterrupt(uint8_t);
rbohne 2:7e1ff33bc76a 129
rbohne 2:7e1ff33bc76a 130 void setup(void);
rbohne 2:7e1ff33bc76a 131 void loop(void);
rbohne 2:7e1ff33bc76a 132
rbohne 2:7e1ff33bc76a 133 #ifdef __cplusplus
rbohne 2:7e1ff33bc76a 134 } // extern "C"
rbohne 2:7e1ff33bc76a 135 #endif
rbohne 2:7e1ff33bc76a 136
rbohne 2:7e1ff33bc76a 137 #endif