-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDIO_program.c
144 lines (133 loc) · 2.23 KB
/
DIO_program.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* DIO_program.c
*
* Created: 12/13/2023 2:50:06 AM
* Author: mosta
*/
#include "DIO_Private.h"
#include "STBD_TYPES.h"
#include "BIT_MATH.h"
#include "DIO_interface.h"
void DIO_voidSetPinDir(u8 Port, u8 Pin, u8 Direction)
{
switch(Port)
{
case DIO_U8_PORTA:
if(Direction == DIO_U8_INPUT)
{
CLEAR_BIT(DDRA,Pin);
}
else if(Direction == DIO_U8_OUTPUT)
{
SET_BIT(DDRA,Pin);
}
break;
case DIO_U8_PORTB:
if(Direction == DIO_U8_INPUT)
{
CLEAR_BIT(DDRB,Pin);
}
else if(Direction == DIO_U8_OUTPUT)
{
SET_BIT(DDRB,Pin);
}
break;
case DIO_U8_PORTC:
if(Direction == DIO_U8_INPUT)
{
CLEAR_BIT(DDRC,Pin);
}
else if(Direction == DIO_U8_OUTPUT)
{
SET_BIT(DDRC,Pin);
}
break;
case DIO_U8_PORTD:
if(Direction == DIO_U8_INPUT)
{
CLEAR_BIT(DDRD,Pin);
}
else if(Direction == DIO_U8_OUTPUT)
{
SET_BIT(DDRD,Pin);
}
break;
}
}
void DIO_voidSetPinVal(u8 Port, u8 Pin, u8 Value)
{
switch(Port)
{
case DIO_U8_PORTA:
if(Value == DIO_U8_LOW)
{
CLEAR_BIT(PORTA,Pin);
}
else if(Value == DIO_U8_HIGH)
{
SET_BIT(PORTA,Pin);
}
break;
case DIO_U8_PORTB:
if(Value == DIO_U8_LOW)
{
CLEAR_BIT(PORTB,Pin);
}
else if(Value == DIO_U8_HIGH)
{
SET_BIT(PORTB,Pin);
}
break;
case DIO_U8_PORTC:
if(Value == DIO_U8_LOW)
{
CLEAR_BIT(PORTC,Pin);
}
else if(Value == DIO_U8_HIGH)
{
SET_BIT(PORTC,Pin);
}
break;
case DIO_U8_PORTD:
if(Value == DIO_U8_LOW)
{
CLEAR_BIT(PORTD,Pin);
}
else if(Value == DIO_U8_HIGH)
{
SET_BIT(PORTD,Pin);
}
break;
}
}
u8 DIO_u8GetPinVal(u8 Port, u8 Pin)
{
u8 LOCAL_u8Result = 0;
switch(Port)
{
case DIO_U8_PORTA: LOCAL_u8Result = GET_BIT(PINA,Pin); break;
case DIO_U8_PORTB: LOCAL_u8Result = GET_BIT(PINB,Pin); break;
case DIO_U8_PORTC: LOCAL_u8Result = GET_BIT(PINC,Pin); break;
case DIO_U8_PORTD: LOCAL_u8Result = GET_BIT(PIND,Pin); break;
}
return LOCAL_u8Result;
}
void DIO_voidSetPortValue(u8 DIO_u8Port, u8 DIO_u8Value)
{
if(DIO_u8Port == DIO_U8_PORTA)
{
PORTA = DIO_u8Value;
}
else if(DIO_u8Port == DIO_U8_PORTB)
{
PORTB = DIO_u8Value;
}
else if(DIO_u8Port == DIO_U8_PORTC)
{
PORTC = DIO_u8Value;
}
else if(DIO_u8Port == DIO_U8_PORTD)
{
PORTD = DIO_u8Value;
}
}