-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathports_simple1.cpp
More file actions
70 lines (53 loc) · 1.64 KB
/
ports_simple1.cpp
File metadata and controls
70 lines (53 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "ports.h"
using namespace ports;
int main(void) {
// «PORTS_DDR_PORT_PIN[^ *,]»
typedef PIN_C2 Pin_In; // Give PIN_C2 a meaningful name.
// Use your favorite way of setting DDR of pin C2:
Pin_In::DDR = 0; // PIN_C2::DDR = 0; would work as well.
Pin_In::DDR = ports::DataDirection::Read; // Use the (safer) provided enum.
Pin_In::setDD(ports::DataDirection::Read); // Equivalent to the previous line.
Pin_In::setToInput(ports::PullUp::HighZ); // Sets DDR and then PORT (pullup).
uint8_t i = Pin_In::PIN; // Read a value.
/*¤*/
// «PORTB[^ *,]»
PORTB &= ~(_BV(2));
/*¤*/
// «PIN_B2[^ *,]»
PIN_B2::DDR = 0;
/*¤*/
// «PIN_DDR_Ex1[^ *,]»
PIN_C3::DDR = DataDirection::Input;
/*¤*/
// «PIN_DDR_Ex2[^ *,]»
uint8_t currentDDR = PIN_C3::DDR;
/*¤*/
if (currentDDR == 0) currentDDR = 1;
// «PIN_DDR_Ex3[^ *,]»
enum DataDirection currentDDR2 = PIN_C3::DDR;
/*¤*/
if (currentDDR2 == DataDirection::Input) currentDDR2 = DataDirection::Output;
// «PIN_PORT_Ex1[^ *,]»
PIN_ADC4::PORT = 1;
/*¤*/
// «PIN_PORT_Ex2[^ *,]»
uint8_t currentPort = PIN_ADC4::PORT;
/*¤*/
if (currentPort == 1) currentPort = 0;
// «PIN_PORT_Ex3[^ *,]»
enum PullUp currentPullUp = PIN_ADC4::PORT;
/*¤*/
if (currentPullUp == PullUp::HighZ) currentPullUp = PullUp::Off;
// «PIN_PORT_Ex4[^ *,]»
PIN_C3::PORT = PullUp::HighZ;
/*¤*/
// «PIN_PIN_Ex1[^ *,]»
PIN_C3::PIN = 1; // equivalent to: PIN_C3::PORT = ! PIN_C3::PORT;
/*¤*/
// «PIN_PIN_Ex2[^ *,]»
uint8_t input = PIN_C3::PIN;
/*¤*/
if (input == 0) input = 1;
for (;;);
return i;
}