-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_3.c
89 lines (78 loc) · 1.97 KB
/
project_3.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
/***************************************************************************************
*module: project 3
*file name : project_3
*description: application to control a fan
*date: 10/12/2022
*Author: Mustafa Mahmoud
****************************************************************************************/
#include"gpio.h"
#include"lcd.h"
#include"adc.h"
#include"motor.h"
#include<avr/io.h>
#define FAN_ON 1
#define FAN_OFF 0
int main(void)
{
uint8 value;
ADC_ConfigType configuration={Internal_VOLT,PRE_8};
/* to initialize the LCD */
LCD_Init();
/* to initialize the DC motor*/
DcMotor_Init();
/* to initialize the ADC */
ADC_Init(&configuration);
/*to move the cursor and starting writing on the screen from coloumn 6, row0*/
LCD_moveCursor(0,4);
LCD_displayString("Fan is");
/*to move the cursor and starting writing on the screen from coloumn 6, row1*/
LCD_moveCursor(1,4);
LCD_displayString("Temp= ");
while(1)
{
value = LM35_getTemprature();
/* to control the speed of motor and its state(ON-OFF)*/
if (value < 30)
{
DcMotor_Rotate(STATE_STOP,0);
LCD_moveCursor(0,11);
LCD_displayString("OFF");
}
else if(value>=30 && value < 60)
{
DcMotor_Rotate(STATE_CW,25);
LCD_moveCursor(0,11);
LCD_displayString("ON ");
}
else if(value>=60 && value < 90)
{
DcMotor_Rotate(STATE_CW,50);
LCD_moveCursor(0,11);
LCD_displayString("ON ");
}
else if(value>=90 && value < 120)
{
DcMotor_Rotate(STATE_CW,75);
LCD_moveCursor(0,11);
LCD_displayString("ON ");
}
else if(value>=120)
{
DcMotor_Rotate(STATE_CW,100);
LCD_moveCursor(0,11);
LCD_displayString("ON ");
}
/* to display the temp on the screen everytime at the same place*/
if (value>=100)
{
LCD_moveCursor(1,9);
LCD_integerTostring(value);
}
else
{
LCD_moveCursor(1,9);
LCD_integerTostring(value);
LCD_displayCharacter(' ');
}
}
}