PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
Learn
Examples
Protocols
Test Masks for SPI.c
1
/*
2
MMA7455 Test Z Axis with SPI.c
3
4
Demonstrates creating bit masks and using them to set and clear bits in
5
certain variables. Useful in SPI when a particular bit in a variable
6
has to be set or cleared for writing data to or reading data from the chip.
7
8
http://learn.parallax.com/propeller-c-simple-protocols/bit-masks-better-code
9
*/
10
11
#include "simpletools.h"
// Include simpletools header
12
13
const
int
MCTL = 0x16;
// = 0b0100101 // Control register address
14
const
int
ZOUT8 = 0x08;
// = 0b0001000 // 8-bit z register address
15
16
17
const
int
writeMask = 1 << 6;
// Write mask for setting bit 6
18
const
int
readMask = ~(1 << 6);
// Read mask for clearing bit 6
19
20
signed
char
z;
// Z-axis
21
22
int
cmd;
// Variable for storing command
23
24
int
main
()
// Main function
25
{
26
print(
"MCTL = %07b \n"
, MCTL);
// Display binary MCTL address
27
print(
"writeMask = %07b (OR)\n"
, writeMask);
// Display binary writeMask
28
29
cmd = MCTL | writeMask;
// MCTL OR writeMask to cmd
30
31
print(
"-------------------------\n"
);
// Draw line
32
print(
"cmd = %07b \n\n"
, cmd);
// Display cmd result
33
print(
"ZOUT8 = %07b \n"
, ZOUT8);
// Display binary ZOUT address
34
print(
"readMask = %07b (AND)\n"
,
// Display binary readMask
35
readMask & 0b1111111);
// Bits 31...7 -> 0 for display
36
37
cmd = ZOUT8 & readMask;
// ZOUT8 AND readMask to cmd
38
39
print(
"-------------------------\n"
);
// Draw line
40
print(
"cmd = %07b \n"
, cmd);
// Display cmd result
41
}
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12