-
Notifications
You must be signed in to change notification settings - Fork 1
/
uno_def.h
202 lines (170 loc) · 3.34 KB
/
uno_def.h
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* uno_def.h
*
* Created: 11.06.2021 12:04:54
* Author: LD
*/
#ifndef UNO_DEF_H_
#define UNO_DEF_H_
#include "glob_def.h"
#include "stdint.h"
#include <util/setbaud.h>
// LED
#define LED P13
#define _LED _P13
#define __LED __P13
#define _LED_ _P13_
// Pins
#define A0 PORTC0
#define A1 PORTC1
#define A2 PORTC2
#define A3 PORTC3
#define A4 PORTC4
#define A5 PORTC5
#define P13 PORTB5
#define P12 PORTB4
#define P11 PORTB3
#define P10 PORTB2
#define P9 PORTB1
#define P8 PORTB0
#define P7 PORTD7
#define P6 PORTD6
#define P5 PORTD5
#define P4 PORTD4
#define P3 PORTD3
#define P2 PORTD2
#define P1 PORTD1
#define P0 PORTD0
// Port
#define _A0 PORTC
#define _A1 PORTC
#define _A2 PORTC
#define _A3 PORTC
#define _A4 PORTC
#define _A5 PORTC
#define _P13 PORTB
#define _P12 PORTB
#define _P11 PORTB
#define _P10 PORTB
#define _P9 PORTB
#define _P8 PORTB
#define _P7 PORTD
#define _P6 PORTD
#define _P5 PORTD
#define _P4 PORTD
#define _P3 PORTD
#define _P2 PORTD
#define _P1 PORTD
#define _P0 PORTD
// Pin
#define __A0 PINC
#define __A1 PINC
#define __A2 PINC
#define __A3 PINC
#define __A4 PINC
#define __A5 PINC
#define __P13 PINB
#define __P12 PINB
#define __P11 PINB
#define __P10 PINB
#define __P9 PINB
#define __P8 PINB
#define __P7 PIND
#define __P6 PIND
#define __P5 PIND
#define __P4 PIND
#define __P3 PIND
#define __P2 PIND
#define __P1 PIND
#define __P0 PIND
// DDR
#define _A0_ DDRC
#define _A1_ DDRC
#define _A2_ DDRC
#define _A3_ DDRC
#define _A4_ DDRC
#define _A5_ DDRC
#define _P13_ DDRB
#define _P12_ DDRB
#define _P11_ DDRB
#define _P10_ DDRB
#define _P9_ DDRB
#define _P8_ DDRB
#define _P7_ DDRD
#define _P6_ DDRD
#define _P5_ DDRD
#define _P4_ DDRD
#define _P3_ DDRD
#define _P2_ DDRD
#define _P1_ DDRD
#define _P0_ DDRD
#define USART_READY _GET(UCSR0A, UDRE0)
#define USART_RECIVE_COMPLETE _GET(UCSR0A, RXC0)
#define USART_TRANSMIT_COMPLETE _GET(UCSR0A, TXC0)
#define USART_RECIVE_ENABLE() _ON(UCSR0B, RXEN0)
#define USART_RECIVE_DISABLE() _OFF(UCSR0B, RXEN0)
#define USART_TRANSMIT_ENABLE() _ON(UCSR0B, TXEN0)
#define USART_TRANSMIT_DISABLE() _OFF(UCSR0B, TXEN0)
#define USART_ENABLE_INT_UDR() _ON(UCSR0B, UDRIE0)
#define USART_ENABLE_INT_RX() _ON(UCSR0B, RXCIE0)
#define USART_ENABLE_INT_TX() _ON(UCSR0B, TXCIE0)
typedef enum
{
DISABLED,
EVEN,
ODD
} USART_PARITY;
typedef enum
{
ONE = 0,
TWO = 1
} USART_STOP_BIT;
typedef enum
{
ASYNC = 0,
SYNC = 1
} USART_MODE;
typedef enum
{
BIT5,
BIT6,
BIT7,
BIT8,
BIT9
} USART_CHAR_SIZE;
typedef enum
{
BINARY = 2,
OCTAL = 7,
DECIMAL = 10,
HEXDECIMAL = 16
} BASE;
void usart_std_init();
void usart_init(USART_MODE _mode, USART_CHAR_SIZE _charsize, USART_STOP_BIT _stopbit, USART_PARITY _parity);
char usart_getc();
char usart_getc_ifready();
void usart_setc(char c);
void usart_setc_ifready(char c);
void usart_setstr(char *str);
void usart_setint(int i, BASE base);
void usart_win_cursor(bool onoff);
typedef enum
{
READ = 1,
WRITE = 0,
} I2C_RW;
typedef enum
{
ACK = 0,
NACK = 1,
} I2C_ACK;
void i2c_init(unsigned long clock, bool pullup);
void i2c_twi_start();
void i2c_twi_tx(uint8_t data, I2C_ACK ack);
void i2c_twi_tx16(uint16_t data, I2C_ACK ack);
uint8_t i2c_twi_rx(I2C_ACK ack);
void i2c_twi_stop();
void i2c_tx(uint8_t address, uint8_t data, I2C_ACK ack);
uint8_t i2c_rx(uint8_t address, I2C_ACK ack);
void i2c_tx16(uint8_t address, uint16_t data, I2C_ACK ack);
#endif /* UNO_DEF_H_ */