-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
executable file
·112 lines (87 loc) · 2.17 KB
/
main.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
/*
* GccApplication1.c
*
* Created: 2/17/2018 11:11:01 AM
* Author : tlfal_000
*/
#define F_CPU 1000000
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include "LCD_Controller.c"
#include "DHT.c"
#include "mpu9250.c"
#define LED PA0
#define BUZZER PA1
#define output_low(port, pin) port &= ~(1<<pin)
#define output_high(port, pin) port |= (1<<pin)
#define set_output(portdir, pin) portdir |= (1<<pin)
#define set_input(portdir, pin) portdir &= ~(1<<pin)
int main(void)
{
float gyroBias[3] = {0, 0, 0},
accelBias[3] = {0, 0, 0},
magBias[3] = {0, 0, 0},
magScale[3] = {0, 0, 0};
LCD_Init();
LCD_Clear();
LCD_String("Booting...");
set_output(DDRA, BUZZER);
set_output(DDRA, LED);
DHT_setup();
i2c_init();
mpu_calibrate(gyroBias,accelBias);
mpu_init();
double temp[1], hum[1];
char first_line[16];
char second_line[16];
uint8_t data;
temp[0] = hum[0] = 0;
uint8_t address = 0x00;
_delay_ms(1000);
while (1)
{
data = mpu_read_byte(AK8963_ADDRESS, WHO_AM_I_AK8963);
sprintf(first_line, "0x%02X :: 0x%02X", AK8963_ADDRESS, WHO_AM_I_AK8963);
sprintf(second_line, "0x%02X", data);
output_high(PORTA, LED);
output_low(PORTA, BUZZER);
DHT_read(temp, hum);
/*switch (DHT_STATUS)
{
case (DHT_OK):
sprintf(first_line, "Hum: %f", hum[0]);
sprintf(second_line, "Tmp: %f", temp[0]);
break;
case (DHT_ERROR_CHECKSUM):
sprintf(first_line, "Error!");
sprintf(second_line, "Checksum!");
break;
case (DHT_ERROR_TIMEOUT):
sprintf(first_line, "Error!");
sprintf(second_line, "Timeout!");
break;
case (DHT_ERROR_HUMIDITY):
sprintf(first_line, "Error!");
sprintf(second_line, "Humidity!");
break;
case (DHT_ERROR_TEMPERATURE):
sprintf(first_line, "Error!");
sprintf(second_line, "Temperature!");
break;
}*/
LCD_Clear();
LCD_String(first_line);
LCD_Command(0xC0); //Second Line
LCD_String(second_line);
/*_delay_ms(1000);
output_high(PORTA, BUZZER);
output_low(PORTA, LED);*/
if (data == 0xFF || data == 0x00){
_delay_ms(100);
}else{
_delay_ms(1000);
}
address ++;
}
}