-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTemperature_controller.c
More file actions
106 lines (84 loc) · 2.22 KB
/
Temperature_controller.c
File metadata and controls
106 lines (84 loc) · 2.22 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
#include "ADC.h"
#include "tm4c123gh6pm.h"
#include "Nokia5110.h"
#include "Fan_control.h"
#include "misc.h"
#include "led_gpio.h"
#include "light_sensor.h"
#include "sensor_gpio.h"
#include "PC_Uart3.h"
//void EnableInterrupts(void); // Enable interrupts
unsigned char TEMP[]={'T','E','M','P','E','R','A','T','U','R','E','\r','\n','\0'}; // null-terminated ASCII string
unsigned char ALERT[]={'A','L','E','R','T','\r','\n','\0'};
unsigned long ADCdata; // 12-bit 0 to 4095 sample
unsigned char Temp_s[20];
void Convert_data_to_temp(unsigned long data){
unsigned long result;
unsigned char i=0;
// 3.3volts*(data)/4096
result=((33*1000*data)/4096)%100000;//rounding off to maximum 5 digits
//result=((((33*1000*data)/4096)%100000)*5/9)-32;//rounding off to maximum 5 digits
Temp_s[0]=0x30;
Temp_s[3]='.';
for(i=0;i<6;i++)
{
if(i==2){continue;}
Temp_s[5-i]=(result%10)+0x30;
result=result/10;
}
Temp_s[i]=32; Temp_s[i+1]=32;Temp_s[i+2]='*';Temp_s[i+3]=32;Temp_s[i+4]='C';Temp_s[i+5]=13;Temp_s[i+6]=10;
}
int main(void){
/*
* temperature Initializations
*/
Temperature_sensor_ADC0_Init();
Nokia5110_Init();
Fan_GPIO_Init();
PC_UART3_Init();
/*
* light Initializations
*/
Light_Sensor_GPIO_Init();
Led_GPIO_Init();
//delay100();
/* Sending initial messages to LCD module
*
*/
Nokia5110_SetCursor(0, 0);
Nokia5110_OutString(TEMP);
PC_UART3_OutString(TEMP);
//
/*main loop */
while(1){
delay_one_second();
ADCdata = read_temperature();
Convert_data_to_temp(ADCdata);
//
light_sensor();
if(ADCdata < 970) {//800 means round 70 degrees
Nokia5110_Clear();
Nokia5110_SetCursor(1, 0);
Nokia5110_OutString(Temp_s);
PC_UART3_OutString(Temp_s);
Fan_Turn_off();
light_sensor();
}
else{
Nokia5110_Clear();
Nokia5110_SetCursor(1, 0);
Nokia5110_OutString(ALERT);
PC_UART3_OutString(ALERT);
Fan_Turn_on();
light_sensor();
while (ADCdata < 970){
Nokia5110_Clear();
Nokia5110_SetCursor(1, 0);
Nokia5110_OutString(Temp_s);
PC_UART3_OutString(Temp_s);
Fan_Turn_off();
light_sensor();
}
}
}
}