-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdio.c
128 lines (118 loc) · 2 KB
/
dio.c
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
/*
* DIO.c
*
* Created on: Aug 17, 2019
* Author: Ahmed Hassan
*/
#include <avr/io.h>
#include "types.h"
#include "macros.h"
void dio_vid_set_port_direction (u8 portNumber, u8 direction) {
switch (portNumber) {
case 0:
DDRA = direction;
break;
case 1:
DDRB = direction;
break;
case 2:
DDRC = direction;
break;
case 3:
DDRD = direction;
break;
}
}
void dio_vid_set_port_value (u8 portNumber, u8 value) {
switch (portNumber) {
case 0:
PORTA = value;
break;
case 1:
PORTB = value;
break;
case 2:
PORTC = value;
break;
case 3:
PORTD = value;
break;
}
}
u8 dio_u8_read_port_value (u8 portNumber) {
switch (portNumber) {
case 0:
return PINA;
break;
case 1:
return PINB;
break;
case 2:
return PINC;
break;
case 3:
return PIND;
break;
}
return 0;
}
u8 dio_u8_read_pin_value (u8 portNumber, u8 index) {
u8 port = dio_u8_read_port_value(portNumber);
return getBit(port, index);
}
void dio_vid_set_pin_value (u8 portNumber, u8 index, u8 value) {
switch (portNumber) {
case 0:
if (value == 1)
setBit(PORTA, index);
else if (value == 0)
clrBit(PORTA, index);
break;
case 1:
if (value == 1)
setBit(PORTB, index);
else if (value == 0)
clrBit(PORTB, index);
break;
case 2:
if (value == 1)
setBit(PORTC, index);
else if (value == 0)
clrBit(PORTC, index);
break;
case 3:
if (value == 1)
setBit(PORTD, index);
else if (value == 0)
clrBit(PORTD, index);
break;
}
}
void dio_vid_set_pin_direction (u8 portNumber, u8 index, u8 direction) {
switch (portNumber) {
case 0:
if (direction == 1)
setBit(DDRA, index);
else if (direction == 0)
clrBit(DDRA, index);
break;
case 1:
if (direction == 1)
setBit(DDRB, index);
else if (direction == 0)
clrBit(DDRB, index);
break;
case 2:
if (direction == 1)
setBit(DDRC, index);
else if (direction == 0)
clrBit(DDRC, index);
break;
case 3:
if (direction == 1)
setBit(DDRD, index);
else if (direction == 0)
clrBit(DDRD, index);
break;
}
}