-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
120 lines (100 loc) · 3.31 KB
/
main.c
File metadata and controls
120 lines (100 loc) · 3.31 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
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
/* Device header file */
#if defined(__XC16__)
#include <xc.h>
#elif defined(__C30__)
#if defined(__PIC24E__)
#include <p24Exxxx.h>
#elif defined (__PIC24F__)||defined (__PIC24FK__)
#include <p24Fxxxx.h>
#elif defined(__PIC24H__)
#include <p24Hxxxx.h>
#endif
#endif
#define FCY SYS_FREQ/2
#define NUM_SENSORS 5
#include <stdint.h> /* Includes uint16_t definition */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h> /* Includes true/false definition */
#include "uart1.h"
#include "system.h" /* System funct/params, like osc/peripheral config */
#include "user.h" /* User funct/params, such as InitApp */
#include "1wire.h"
#include "SMS.h"
#include "sensor.h"
#include "alarms.h"
#include <libpic30.h>
void readSensors();
void initSensors();
/******************************************************************************/
/* Global Variable Declaration */
/******************************************************************************/
unsigned char serial_number[8];
unsigned char DEVICE_PRESENT;
int BAUD = 9600;
uint16_t contador = 0;
tempLogic sensors[NUM_SENSORS];
/******************************************************************************/
/* Main Program */
/******************************************************************************/
int16_t main(void) {
/* Configure the oscillator for the device */
ConfigureOscillator();
__delay_ms(100);
/* Initialize IO ports and peripherals */
InitApp();
__delay_ms(1000);
//LED =1;
/* Initialize UART */
UART1Init(BAUD);
__delay_ms(5000);
/* Initialize GSM module */
initSMS();
/* Initialize sensors*/
initSensors();
//Main Program Loop, Loop forever
while (1) {
readSensors();
if (RUN_READ_PIN == 1) {
checkTemperatures(&sensors[0],NUM_SENSORS);
LEDALR = isAlarmActive(&sensors[0],NUM_SENSORS);
}
__delay_ms(200);
contador++;
}
return 0;
}
void readSensors() {
int loop;
for (loop = 0; loop < NUM_SENSORS; loop++) {
getTemperature(loop+1, &sensors[loop]);
}
}
void initSensors() {
int loop;
for (loop = 0; loop < NUM_SENSORS; loop++) {
sensors[loop].alarmActive = 0;
}
}
//_INT1Interrupt() is the INT1 interrupt service routine (ISR).
void __attribute__((__interrupt__)) _INT1Interrupt(void);
void __attribute__((__interrupt__, auto_psv)) _INT1Interrupt(void) {
sendInfoSMS(sensors[0], sensors[1], sensors[2], sensors[3], sensors[4]);
IFS1bits.INT1IF = 0; //Clear the INT1 interrupt flag or else
//the CPU will keep vectoring back to the ISR
}
//_T1Interrupt() is the T1 interrupt service routine (ISR).
void __attribute__((__interrupt__)) _T1Interrupt(void);
void __attribute__((__interrupt__, auto_psv)) _T1Interrupt(void) {
if (RUN_READ_PIN == 1) {
LEDRUN = !LEDRUN;
}
else{
LEDRUN = 0;
}
IFS0bits.T1IF = 0;
}