-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISR_Founctions.h
124 lines (111 loc) · 3.55 KB
/
ISR_Founctions.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
#ifndef ISR_Founctions_H
#define ISR_Founctions_H
volatile uint16_t pinValues = 0; // Variable to store pin states for pins 0 to 13 and A0
void ISR_init()
{
sei();
// Enable pin change interrupt for pins 0 to 7 (PCINT16-23)
PCMSK2 |= 0xFF; // Enable interrupts for pins D0-D7 (PCINT16-23)
PCICR |= (1 << PCIE2); // Enable Pin Change Interrupt for PCINT16-23
// Enable pin change interrupt for pins 8 to 13 (PCINT0-5)
PCMSK0 |= 0x3F; // Enable interrupts for pins D8-D13 (PCINT0-5)
PCICR |= (1 << PCIE0); // Enable Pin Change Interrupt for PCINT0-5
// Enable pin change interrupt for A0 (PCINT14)
PCMSK1 |= (1 << PCINT8); // Enable interrupt for A0 (PCINT14)
PCICR |= (1 << PCIE1); // Enable Pin Change Interrupt for PCINT8-14
// Set pins 0 to 14 as inputs
for (int i = 0; i <= 14; i++)
{
pinMode(i, INPUT); // Set pins as input
}
}
/************** interrupt for pins 0 to 7 ***************************/
// Interrupt service routine for pin change interrupt group PCINT16-23
ISR(PCINT2_vect)
{
if(!digitalRead(0) || !digitalRead(1) || !digitalRead(2))
{
//Stop the motors
Motor1_off();
Motor2_off();
}
if(!digitalRead(0)) D0_SW_Alarm = HIGH;
else D0_SW_Alarm = LOW ;
if(!digitalRead(1)) D1_FlowSW_Alarm = HIGH;
if(!digitalRead(2)) D2_PhaseSq_Alarm = HIGH;
if(!digitalRead(3) || !digitalRead(4) || !digitalRead(5) || !digitalRead(6) || !digitalRead(7))
{
Motor1_off();
}
if(!digitalRead(3)) D3_HighPressure1_Alarm = HIGH;
if(!digitalRead(4)) D4_LowPressure1_Alarm = HIGH;
if(!digitalRead(5)) D5_OverLoadComperssor1_Alarm = HIGH;
if(!digitalRead(6)) D6_OverLoadCFM1_Alarm = HIGH;
if(!digitalRead(7)) D7_MotorProtector1_Alarm = HIGH;
/*
pinValues = (PIND & 0xFF); // Read pins D0-D7
// Perform actions based on pinValues for pins D0-D7
// Example:
if (pinValues & (1 << 3))
{
// D3 changed to HIGH
}
else
{
// D3 changed to LOW
}
*/
// Add conditions for other pins if needed
}
/************** interrupt for pins 8 to 13 *************************/
// Interrupt service routine for pin change interrupt group PCINT0-5
ISR(PCINT0_vect)
{
if(!digitalRead(8))
{
D8_OilPressure1_Alarm = HIGH;
Motor1_off(); //Stop the motors
}
if(!digitalRead(9) || !digitalRead(10) || !digitalRead(11) || !digitalRead(12) || !digitalRead(13))
{
Motor2_off();
}
if(!digitalRead(9)) D9_HighPressure2_Alarm = HIGH;
if(!digitalRead(10)) D10_LowPressure2_Alarm = HIGH;
if(!digitalRead(11)) D11_OverLoadComperssor2_Alarm = HIGH;
if(!digitalRead(12)) D12_OverLoadCFM2_Alarm = HIGH;
if(!digitalRead(13)) D13_MotorProtector2_Alarm = HIGH;
/*
pinValues = (PINB & 0x3F); // Read pins D8-D13
// Perform actions based on pinValues for pins D8-D13
// Example:
if (pinValues & (1 << 11))
{
// D11 changed to HIGH
}
else
{
// D11 changed to LOW
}
*/
// Add conditions for other pins if needed
}
/********************** interrupt for A0 *************************/
// Interrupt service routine for pin change interrupt group PCINT8-14 (A0)
ISR(PCINT1_vect)
{
pinValues = (PINC & 0x01); // Read pin A0 (PCINT14)
// Perform actions based on pinValues for A0
// Example:
if (pinValues & 0x01)
{
// A0 changed to HIGH
D14_OilPressure2_Alarm = HIGH;
Motor2_off(); //Stop the motors
} else
{
// A0 changed to LOW
}
// Add conditions for other pins if needed
}
#endif