-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwater_level.c
136 lines (123 loc) · 3.49 KB
/
water_level.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
/*
#include<stdio.h> test
#include<stdlib.h>
*/
int main() {
//int test,test1,test2,test3,test4;
int liquidSensorPin;
int buzzerPin = 0;
int buzzer_reg;
int solenoid = 0;
int solenoid_reg; // Register for the solenoid
int switchValue; // Input switch pin
int mask1 = 0xFFFFFFF3;
buzzer_reg = buzzerPin * 4;
solenoid_reg = solenoid * 8; // Calculate the register for the solenoid
asm volatile(
"and x30, x30, %2\n\t"
"or x30, x30, %0\n\t"
"or x30, x30, %1\n\t"
:
: "r"(buzzer_reg), "r"(solenoid_reg),"r"(mask1)
: "x30"
);
/*
asm volatile(
"addi x30, x30, 0\n\t"
:"=r"(test)
:
:"x30"
);
printf("Test = %d\n",test);
printf("LiquidSensorPin = %d, switchvalue=%d,buzzer_reg = %d, solenoid_reg=%d\n",liquidSensorPin,switchValue,buzzer_reg,solenoid_reg);
//printf("Inside while 1\n");*/
//int z;
//for(z=0;z<1;z++)
while (1)
{
asm volatile(
"andi %0, x30, 1\n\t" // Assuming switch is connected to bit 3 (8 in binary)
: "=r"(switchValue)
:
:
);
int solenoid = 1;
/*asm volatile(
"addi %0, x30, 0\n\t"
:"=r"(test1)
:
:"x30"
);
printf("test1 = %d\n",test1);*/
//switchValue=0;
//printf("Reset Button_val=%d\n",reset_button);
if (switchValue) {
// Simulate activating the buzzer and solenoid (replace with actual control)
asm volatile(
"andi %0, x30, 2\n\t"
: "=r"(liquidSensorPin)
:
:
);
/*asm volatile(
"addi %0, x30, 0\n\t"
:"=r"(test2)
:
:"x30"
);
printf("test2 = %d\n",test2);*/
//liquidSensorPin=0;
if (liquidSensorPin) {
// Simulate activating the buzzer and solenoid (replace with actual control)
// digital_write(buzzerPin, 1);
// digital_write(solenoid, 0);
// printf("Buzzer ON and solenoid are Off\n");
buzzerPin = 1;
solenoid = 0;
/* asm volatile(
"addi %0, x30, 0\n\t"
:"=r"(test3)
:
:"x30"
);
printf("test3 = %d\n",test3);*/
} else {
// Simulate deactivating the buzzer and solenoid (replace with actual control)
// digital_write(buzzerPin, 0);
// digital_write(solenoid, 1);
// printf("Buzzer OFF and solenoid are ON\n");
buzzerPin = 0;
solenoid = 1;
/*asm volatile(
"addi %0, x30, 0\n\t"
:"=r"(test3)
:
:"x30"
);
printf("test3 = %d\n",test3);*/
}
// Update the corresponding registers for the buzzer and solenoid
buzzer_reg = buzzerPin * 4;
solenoid_reg = solenoid * 8;
asm volatile(
"and x30, x30, %2\n\t"
"or x30, x30, %0\n\t"
"or x30, x30, %1\n\t"
:
: "r"(buzzer_reg), "r"(solenoid_reg),"r"(mask1)
: "x30"
);
/*
asm volatile(
"addi %0, x30, 0\n\t"
:"=r"(test4)
:
:"x30"
);
printf("Test4 = %d\n",test4);
printf("LiquidSensorPin = %d, switchvalue=%d,buzzer_reg = %d, solenoid_reg=%d\n",liquidSensorPin,switchValue,buzzer_reg,solenoid_reg);
*/
}
}
return 0;
}