PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
shiftOut.c
1 /*
2  * @file shiftOut.c
3  *
4  * @author Andy Lindsay
5  *
6  * @version 0.85
7  *
8  * @copyright Copyright (C) Parallax, Inc. 2012. See end of file for
9  * terms of use (MIT License).
10  *
11  * @brief shiftOut function source, see simpletools.h for documentation.
12  *
13  * @detail Please submit bug reports, suggestions, and improvements to
14  * this code to editor@parallax.com.
15  */
16 
17 #include "simpletools.h" // simpletools function prototypes
18 
19 void shift_out(int pinDat, int pinClk, int mode, int bits, int value)
20 {
21  int vi, vf, inc;
22  set_direction(pinDat, 1);
23  if(mode == LSBFIRST)
24  {
25  vi = 0;
26  vf = bits;
27  inc = 1;
28  }
29  else
30  {
31  vi = bits - 1;
32  vf = -1;
33  inc = -1;
34  }
35  low(pinClk);
36  int i;
37  for(i = vi; i != vf; i += inc)
38  {
39  set_output(pinDat, (value >> i) & 1);
40  toggle(pinClk);
41  toggle(pinClk);
42  }
43 }
44 
shift_out
void shift_out(int pinDat, int pinClk, int mode, int bits, int value)
Send data to a synchronous serial device.
Definition: shiftOut.c:19
LSBFIRST
#define LSBFIRST
For use with shift_out. Stands for least significant bit first.
Definition: simpletools.h:410
low
void low(int pin)
Set an I/O pin to output-low.
Definition: low.c:19
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
set_direction
void set_direction(int pin, int direction)
Set an I/O pin to a given direction.
Definition: setDirection.c:19
toggle
unsigned int toggle(int pin)
Toggle the output state of the I/O pin.
Definition: toggle.c:19
set_output
void set_output(int pin, int state)
Set I/O pin output register bit to either 1 or 0.
Definition: setOutput.c:19