-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
106 lines (92 loc) · 3.16 KB
/
main.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "AVRpp11/mapping/arduinoUno.h"
//#include "AVRpp11/mapping/atmega328p.h"
#include "AVRpp11/avrpp11.h"
#include "AVRpp11/lib/Printer.hpp"
int main()
{
//Logic operator
volatile logic l1 = High || False;
volatile logic l2 = High && False;
volatile logic l3 = !True;
//Bits value
volatile byte v1 = bits::value<byte>(bits::Bit2);
volatile byte v2 = bits::value<byte>(bits::Bit1, bits::Bit2);
volatile byte v3 = bits::value<byte>(bits::Bit1, ~bits::Bit2);
volatile byte iv1 = bits::valueInv<byte>(bits::Bit2);
volatile byte iv2 = bits::valueInv<byte>(~bits::Bit1, ~bits::Bit2);
volatile byte iv3 = bits::valueInv<byte>(bits::Bit1, ~bits::Bit2);
//Bits manipulation
bits::assign(DDRB, bits::Bit2);
bits::assign(DDRB, bits::Bit2, bits::Bit3);
bits::add(DDRB, bits::Bit2);
bits::add(DDRB, ~bits::Bit2);
bits::add(DDRB, ~bits::Bit2, bits::Bit1, bits::Bit3, ~bits::Bit4);
volatile logic l4 = bits::get(DDRB, bits::Bit1);
bits::set(DDRB, bits::Bit2, High);
bits::toggle(DDRB, bits::Bit2);
//Global interruptions
isr::enable();
isr::disable();
volatile logic l5 = isr::getState();
isr::setState(l5);
//Gpio
gpio::D3.setMode(gpio::Output);
gpio::D3.write(High);
gpio::D2.setMode(gpio::Input);
volatile logic l6 = gpio::D2.read();
volatile logic l7 = gpio::D3.readOutput();
gpio::D3.toggle();
//Usart
isr::disable();
usart::Usart0.setMode(usart::Write);
usart::Usart0.setBitStop(usart::BitStop1);
usart::Usart0.setParity(usart::ParityDisable);
usart::Usart0.setBaudrate(usart::BaudRate9600);
while (!usart::Usart0.isWriteReady());
usart::Usart0.write('a');
while (!usart::Usart0.isDataSent());
usart::Usart0.onWriteReady([](HandlerArg(usart::Usart0) u){
u.write('b');
});
isr::enable();
//Spi
isr::disable();
spi::Spi.setMode(spi::Master);
spi::Spi.setBitOrder(spi::MSBFirst);
spi::Spi.setClockIdle(spi::ClockHigh);
spi::Spi.setClockEdge(spi::ClockLeading);
spi::Spi.setClockDivider(spi::ClockDiv2);
isr::enable();
//Timer0 8 bits
isr::disable();
gpio::D13.setMode(gpio::Output);
timer::Timer0.setCounterMode(timer::WaveNormalTopNormal);
timer::Timer0.setPinModeA(timer::PinDisable);
timer::Timer0.setPinModeB(timer::PinDisable);
timer::Timer0.setClock(timer::ClockDiv1024);
timer::Timer0.onOverflow([](HandlerArg(timer::Timer0) t) {
gpio::D13.toggle();
});
isr::enable();
//Timer1 16 bits
isr::disable();
gpio::D13.setMode(gpio::Output);
timer::Timer1.setCounterMode(timer::WaveNormalTopCompareA);
timer::Timer1.setPinModeA(timer::PinDisable);
timer::Timer1.setPinModeB(timer::PinDisable);
timer::Timer1.setClock(timer::ClockDiv1024);
timer::Timer1.writeCompareA(15625);
timer::Timer1.onMatchA([](HandlerArg(timer::Timer1) t) {
gpio::D13.toggle();
});
isr::enable();
//Printer
Printer::init(usart::BaudRate9600);
Printer::write("> example ");
Printer::write(404);
Printer::write(" and ");
Printer::write(-23456);
Printer::endl();
while (1);
return 0;
}