-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
180 lines (147 loc) · 3.78 KB
/
main.c
File metadata and controls
180 lines (147 loc) · 3.78 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* main.c
*
* Created on: Oct 28, 2023
* Author: AHMED
*/
/* ADC PROJECT*/
/**************************************/
#include "LIB/STD_TYPES.h"
#include <avr/delay.h>
#include "HAL/LCD2/LCD_Interface.h"
#include "MCAL/DIO/DIO_Interface.h"
#include "MCAL/Port/Port_Interface.h"
#include "MCAL/GIE/GIE_Interface.h"
#include "MCAL/ADC/NTI_ADC_Interface.h"
#include "MCAL/EXT_INT/EXT_INT_Interface.h"
#define CH_0 0
#define CH_1 1
#define CH_4 4
f32 volatile Globalu8Readings[5] = {0};
u8 Sensor_index = 0;
void ADC_LM35()
{
Globalu8Readings[Sensor_index] = (f32)ADC_u16ReadADCInMV() > 1500 ? 1500 : (f32)ADC_u16ReadADCInMV()/10 ;
}
void ADC_LDR()
{
// u16 Local_u16LDRRead = ADC_u16ReadADCInMV();
Globalu8Readings[Sensor_index] = (f32)ADC_u16ReadADCInMV()/1000UL;
}
void ADC_POT()
{
// u16 Local_u16POTRead = ADC_u16ReadADCInMV();
Globalu8Readings[Sensor_index] = (f32)ADC_u16ReadADCInMV()/1000UL;
}
void ADC_voidChannelRun()
{
ADC_voidDisable();
if(Sensor_index == CH_0)
{
ADC_LM35();
Sensor_index = 1;
}
else if(Sensor_index == CH_1)
{
ADC_POT();
Sensor_index = 4;
}
else if(Sensor_index == CH_4)
{
ADC_LDR();
Sensor_index = 0;
}
else
{
Sensor_index = 0;
}
}
void LM32_Interrupt()
{
LCD_voidGoToPosition(1,0);
LCD_voidWriteString((u8*)"LM35 value:");
LCD_voidWriteFloatData(Globalu8Readings[CH_0]);
LCD_voidWriteString((u8*)" C");
}
void LDR_Interrupt()
{
LCD_voidGoToPosition(3,0);
LCD_voidWriteString((u8*)"LDR value:");
LCD_voidWriteFloatData(Globalu8Readings[CH_4]);
LCD_voidWriteString((u8*)" volt");
}
void POT_Interrupt()
{
LCD_voidGoToPosition(2,0);
LCD_voidWriteString((u8*)"POT value:");
LCD_voidWriteFloatData(Globalu8Readings[CH_1]);
LCD_voidWriteString((u8*)" volt");
}
int main(void)
{
PORT_voidInit();
LCD_voidInit();
GIE_voidEnable();
EXTI0_voidInit();
EXTI1_voidInit();
EXTI2_voidInit();
EXTI2_voidEnable();
EXTI1_voidEnable();
EXTI0_voidEnable();
ADC_voidEnable();
ADC_voidInterrputEnable();
ADC_voidStartInterruptConversion(CH_0); // Start First Conversion
ADC_SetCallback(ADC_voidChannelRun); // Call Back Function
// ISR Functions
EXT0_VID_SET_CALL_BACK(LM32_Interrupt);
EXT1_VID_SET_CALL_BACK(POT_Interrupt);
EXT2_VID_SET_CALL_BACK(LDR_Interrupt);
while(1)
{
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_0, DIO_u8PIN_HIGH); // LM35
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_1, DIO_u8PIN_HIGH); // POT
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_2, DIO_u8PIN_HIGH); // LDR
// DIO_u8SetPinValue(DIO_u8PORTD, DIO_u8PIN_2, DIO_u8PIN_HIGH);
// DIO_u8SetPinValue(DIO_u8PORTD, DIO_u8PIN_3, DIO_u8PIN_HIGH);
// DIO_u8SetPinValue(DIO_u8PORTB, DIO_u8PIN_2, DIO_u8PIN_HIGH);
if(Globalu8Readings[CH_0] > 28)
{
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_0, DIO_u8PIN_LOW); // Interrupt Occur
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_3, DIO_u8PIN_HIGH);
_delay_ms(150);
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_3, DIO_u8PIN_LOW);
}
else
{
LCD_voidClearLine(1,19);
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_0, DIO_u8PIN_HIGH);
}
if(Globalu8Readings[CH_1] > 2.5f)
{
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_1, DIO_u8PIN_LOW);
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_4, DIO_u8PIN_HIGH);
_delay_ms(150);
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_4, DIO_u8PIN_LOW);
}
else
{
LCD_voidClearLine(2,19);
DIO_u8SetPinValue(DIO_u8PORTD, DIO_u8PIN_1, DIO_u8PIN_HIGH);
}
if(Globalu8Readings[CH_4] > 2.5f)
{
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_2, DIO_u8PIN_LOW);
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_5, DIO_u8PIN_HIGH);
_delay_ms(150);
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_5, DIO_u8PIN_LOW);
}
else
{
LCD_voidClearLine(3,19);
DIO_u8SetPinValue(DIO_u8PORTC, DIO_u8PIN_2, DIO_u8PIN_HIGH);
}
ADC_voidEnable();
ADC_voidStartInterruptConversion(Sensor_index);
}
return 0;
}