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
Propeller GCC Demos
toggle
c++_toggle
toggle.cc
1
/*
2
This shows an example for creating an LMM program and Makefile.
3
It simply toggles the pins at 1Hz rate.
4
5
Copyright (c) 2011 Parallax, Inc.
6
MIT Licensed.
7
8
+--------------------------------------------------------------------
9
| TERMS OF USE: MIT License
10
+--------------------------------------------------------------------
11
Permission is hereby granted, free of charge, to any person obtaining
12
a copy of this software and associated documentation files
13
(the "Software"), to deal in the Software without restriction,
14
including without limitation the rights to use, copy, modify, merge,
15
publish, distribute, sublicense, and/or sell copies of the Software,
16
and to permit persons to whom the Software is furnished to do so,
17
subject to the following conditions:
18
19
The above copyright notice and this permission notice shall be
20
included in all copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+--------------------------------------------------------------------
30
*/
31
32
#include "propeller.h"
33
34
// this is a bit more elaborate than required, but
35
// it shows usage of a basic C++ class
36
class
pinset
{
37
private
:
38
// these variables are not accessible outside the class
39
unsigned
int
mask;
// which pins are in this set
40
unsigned
int
freq;
// the frequency at which to toggle them
41
public
:
42
// here are the public variables and methods
43
44
// the basic constructor
45
pinset
(
unsigned
int
m,
unsigned
int
f) {
46
mask = m;
47
freq = f;
48
DIRA |= m;
49
}
50
51
// the run loop
52
void
run(
void
) {
53
for
(;;) {
54
OUTA ^= mask;
55
waitcnt(freq+CNT);
56
}
57
}
58
};
59
60
int
main
(
void
)
61
{
62
// create a set of pins to toggle at 2Hz
63
pinset
allpins(0x3fffffff, CLKFREQ>>1);
64
65
// now go and toggle them, forever
66
allpins.run();
67
}
68
main
int main(void)
Definition:
GraphicsTest.c:20
pinset
Definition:
toggle.cc:36
Generated on Sat Aug 27 2016 00:58:10 for PropWare by
1.8.12