-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPregnancy_testercode.txt
71 lines (53 loc) · 1.68 KB
/
Pregnancy_testercode.txt
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
#include <reg51.h>
// Define LED pins
sbit LED_Positive = P1^0;
sbit LED_Negative = P1^1;
// Define Button pins
sbit Button = P3^2;
// Define Hormone Sensor input pin
sbit HormoneSensor = P0^0;
// Function to initialize the microcontroller
void Initialize() {
LED_Positive = 0; // Clear LED
LED_Negative = 0; // Clear LED
}
// Function to read hormone levels from the sensor
unsigned int ReadHormoneLevels() {
unsigned int hormoneLevel;
// Configure ADC
ADCON = 0x80; // Turn on ADC and set conversion clock to Fosc/32
P1ASF = 0x01; // Set P1.0 as analog input
// Start ADC conversion
ADCF = 0x00; // Clear ADC result flags
ADCCON0 = 0x01; // Start ADC conversion on channel 0
// Wait for ADC conversion to complete
while (!ADCF);
// Read ADC result
hormoneLevel = ADCH;
// Turn off ADC
ADCON = 0x00; // Turn off ADC
return hormoneLevel;
}
}
// Function to check for pregnancy based on hormone levels
unsigned char CheckPregnancy() {
unsigned int hormoneLevel = ReadHormoneLevels();
// Define a threshold value for positive pregnancy detection
unsigned int threshold = 800; // Adjust this based on your sensor's characteristics
if (hormoneLevel >= threshold) {
return 1; // Positive result
}
return 0; // Negative result
}
void main() {
Initialize();
while (1) {
if (CheckPregnancy()) {
LED_Positive = 1; // Turn on Positive LED
LED_Negative = 0; // Turn off Negative LED
} else {
LED_Positive = 0; // Turn off Positive LED
LED_Negative = 1; // Turn on Negative LED
}
}
}