sanguino/cores/arduino/wiring_shift.c

Thu, 07 Jul 2016 12:23:34 +0200

author
mbayer
date
Thu, 07 Jul 2016 12:23:34 +0200
changeset 2
b373b0288715
permissions
-rw-r--r--

added missing sanguino files

2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
1 /*
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
2 wiring_shift.c - shiftOut() function
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
3 Part of Arduino - http://www.arduino.cc/
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
5 Copyright (c) 2005-2006 David A. Mellis
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
6
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
7 This library is free software; you can redistribute it and/or
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
8 modify it under the terms of the GNU Lesser General Public
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
9 License as published by the Free Software Foundation; either
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
10 version 2.1 of the License, or (at your option) any later version.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
11
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
12 This library is distributed in the hope that it will be useful,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
15 Lesser General Public License for more details.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
16
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
17 You should have received a copy of the GNU Lesser General
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
18 Public License along with this library; if not, write to the
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
20 Boston, MA 02111-1307 USA
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
21
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
22 $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
23 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
24
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
25 #include "wiring_private.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
26
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
27 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
28 uint8_t value = 0;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
29 uint8_t i;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
30
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
31 for (i = 0; i < 8; ++i) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
32 digitalWrite(clockPin, HIGH);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
33 if (bitOrder == LSBFIRST)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
34 value |= digitalRead(dataPin) << i;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
35 else
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
36 value |= digitalRead(dataPin) << (7 - i);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
37 digitalWrite(clockPin, LOW);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
38 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
39 return value;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
40 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
41
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
42 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
43 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
44 uint8_t i;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
45
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
46 for (i = 0; i < 8; i++) {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
47 if (bitOrder == LSBFIRST)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
48 digitalWrite(dataPin, !!(val & (1 << i)));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
49 else
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
50 digitalWrite(dataPin, !!(val & (1 << (7 - i))));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
51
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
52 digitalWrite(clockPin, HIGH);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
53 digitalWrite(clockPin, LOW);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
54 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
55 }

mercurial