-
Notifications
You must be signed in to change notification settings - Fork 1
/
rele.c
107 lines (92 loc) · 2.52 KB
/
rele.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
#include "xpander.h"
#include "timer0.h"
#include "rele.h"
#define RELE_PORT PORTD
/**
* Đĺëĺ-burn2 â "0" ďîęŕ!
*/
static struct {
bool rele_pow;
bool rele_am;
bool rele_burn;
u8 rsvd;
} rele_status_struct;
/* Číčöčŕëčçŕöč˙ đĺëĺ */
void RELE_init(void)
{
/* Ńňŕâčě ďîđňű D íŕ âűőîä */
pin_set(RELEBURN_CS_PORT, RELEBURN_CS_PIN);
pin_set(RELEAM_CS_PORT, RELEAM_CS_PIN);
pin_set(RELEPOW_CS_PORT, RELEPOW_CS_PIN);
pin_clr(RELE_SET_PORT,RELE_SET_PIN);
pin_clr(RELE_CLR_PORT,RELE_CLR_PIN);
rele_status_struct.rele_pow = false;
rele_status_struct.rele_am = false;
rele_status_struct.rele_burn = false;
}
/**
* Âęëţ÷ĺíčĺ đĺëĺ, äîëćĺí áűňü ÓĆĹ âęëţ÷ĺí ňŕéěĺđ2 č číčöčŕëčçčđîâŕí XPANDER !
* ďŕđŕěĺňđ: Ęŕęîĺ đĺëĺ
* âîçâđŕň: óńďĺő čëč íĺň
*/
bool RELE_on(RELE_TYPE_ENUM rele)
{
u8 cs;
switch (rele) {
case RELEPOW:
cs = RELEPOW_CS_PIN;
rele_status_struct.rele_pow = true;
break;
case RELEAM:
cs = RELEAM_CS_PIN;
rele_status_struct.rele_am = true;
break;
case RELEBURN:
cs = RELEBURN_CS_PIN;
rele_status_struct.rele_burn = true;
break;
default:
return false;
}
pin_clr(RELE_SET_PORT, RELE_SET_PIN); /* Ńňŕâčě SET â 0 */
pin_set(RELE_CLR_PORT, RELE_CLR_PIN); /* Ńňŕâčě CLR â 1 */
pin_clr(RELE_PORT, cs); /* CS âíčç, âńĺ íŕ ďîđňĺ D */
delay_ms(15); /* Çŕäĺđćęŕ äë˙ ńđŕáŕňűâŕíč˙ ďîë˙đ đĺëĺ */
pin_set(RELE_PORT, cs); /* CS ââĺđő, âńĺ íŕ ďîđňĺ D */
pin_set(RELE_SET_PORT, RELE_SET_PIN); /* Set â 1 */
pin_set(RELE_CLR_PORT, RELE_CLR_PIN); /* Ńňŕâčě CLR â 1 */
return true;
}
/**
* Âűęëţ÷ĺíčĺ đĺëĺ, äîëćĺí áűňü ÓĆĹ âęëţ÷ĺí ňŕéěĺđ2 č číčöčŕëčçčđîâŕí XPANDER !
* ďŕđŕěĺňđ: Ęŕęîĺ đĺëĺ
* âîçâđŕň: óńďĺő čëč íĺň
*/
bool RELE_off(RELE_TYPE_ENUM rele)
{
u8 cs;
switch (rele) {
case RELEPOW:
cs = RELEPOW_CS_PIN;
rele_status_struct.rele_pow = false;
break;
case RELEAM:
cs = RELEAM_CS_PIN;
rele_status_struct.rele_am = false;
break;
case RELEBURN:
cs = RELEBURN_CS_PIN;
rele_status_struct.rele_burn = false;
break;
default:
return false;
}
pin_set(RELE_SET_PORT, RELE_SET_PIN); /* Set â 1 */
pin_clr(RELE_CLR_PORT, RELE_CLR_PIN); /* Ńňŕâčě CLR â 0 */
pin_clr(RELE_PORT, cs); /* CS âíčç */
delay_ms(15); /* Çŕäĺđćęŕ äë˙ ńđŕáŕňűâŕíč˙ ďîë˙đ đĺëĺ */
pin_set(RELE_PORT, cs); /* CS ââĺđő */
pin_set(RELE_CLR_PORT, RELE_CLR_PIN); /* Ńňŕâčě CLR â 1 */
pin_set(RELE_SET_PORT, RELE_SET_PIN); /* Set â 1 */
return true;
}