PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
getDirections.c
1 /*
2  * @file getstates.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 getStates 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 unsigned int get_directions(int endPin,
20  int startPin) // getStates function definition
21 {
22  unsigned int pattern = DIRA; // Copy INA
23  if(endPin < startPin) // Handle reverse pin size
24  {
25  int temp = startPin;
26  startPin = endPin;
27  endPin = temp;
28  }
29  pattern <<= (31 - endPin); // Remove zeros to left
30  pattern >>= (31 - endPin + startPin); // Right justify & return
31  return pattern ; // Right justify & return
32 }
33 
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
get_directions
unsigned int get_directions(int endPin, int startPin)
Get directions for a contiguous group of I/O pins.
Definition: getDirections.c:19
DIRA
#define DIRA
Use to set pins to input (0) or output (1).
Definition: propeller1.h:161