Subversion Repositories Code-Repo

Rev

Rev 155 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 155 Rev 157
Line 5... Line 5...
5
#include "defines.h"
5
#include "defines.h"
6
#include "interrupts.h"
6
#include "interrupts.h"
7
#include "uart.h"
7
#include "uart.h"
8
#include "i2c.h"
8
#include "i2c.h"
9
#include "spi.h"
9
#include "spi.h"
-
 
10
#include "timers.h"
10
#include "nfc_PN532.h"
11
#include "nfc_PN532.h"
11
#include "led_HT16K33.h"
12
#include "led_HT16K33.h"
-
 
13
#include "lux_TSL2561.h"
-
 
14
#include "temp_BMP085.h"
12
#include "oled_ssd1306.h"
15
#include "oled_ssd1306.h"
13
#include "oled_ssd1331.h"
16
#include "oled_ssd1331.h"
14
#include "timers.h"
-
 
15
#include "lux_TSL2561.h"
-
 
16
#include "oled_NHD-0216KZW-AB5.h"
17
#include "oled_NHD-0216KZW-AB5.h"
17
#include "adc.h"
18
#include "adc.h"
18
#include "temp_BMP085.h"
19
#include "xbee.h"
19
 
20
 
20
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
21
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
21
/* --------------------------- Configuration Bits --------------------------- */
22
/* --------------------------- Configuration Bits --------------------------- */
22
/* CONFIG1L @ 0x1FFF8 */
23
/* CONFIG1L @ 0x1FFF8 */
23
#pragma config CFGPLLEN = ON        // Enable PLL on startup
24
#pragma config CFGPLLEN = ON        // Enable PLL on startup
Line 609... Line 610...
609
        Delay10KTCYx(255);
610
        Delay10KTCYx(255);
610
        Delay10KTCYx(255);
611
        Delay10KTCYx(255);
611
        SSD1331_Clear_Display();
612
        SSD1331_Clear_Display();
612
        SSD1331_Set_Rotation(0);
613
        SSD1331_Set_Rotation(0);
613
        SSD1331_Set_Cursor(0, 0);
614
        SSD1331_Set_Cursor(0, 0);
614
        // TODO: Figure out why this isnt working (probably a compiler issue)
-
 
615
        sprintf(output, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabit adipiscing ante sed nibh tincidunt feugiat.");
615
        sprintf(output, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabit adipiscing ante sed nibh tincidunt feugiat.");
616
        DBG_PRINT_MAIN(output, strlen(output));
616
        SSD1331_Write_String(output, strlen(output));
617
 
617
 
618
//        Delay10KTCYx(255);
618
//        Delay10KTCYx(255);
619
//        Delay10KTCYx(255);
619
//        Delay10KTCYx(255);
620
//        SSD1331_Clear_Display();
620
//        SSD1331_Clear_Display();
621
//        SSD1331_Set_Rotation(3);
621
//        SSD1331_Set_Rotation(3);
Line 1029... Line 1029...
1029
    I2C_DATA i2c_data;
1029
    I2C_DATA i2c_data;
1030
    I2C_Init(&i2c_data);
1030
    I2C_Init(&i2c_data);
1031
    BMP085_DATA bmp_data;
1031
    BMP085_DATA bmp_data;
1032
    BMP_Init(&bmp_data);
1032
    BMP_Init(&bmp_data);
1033
 
1033
 
1034
    I2C_Configure_Master(I2C_100KHZ);
1034
    I2C_Configure_Master(I2C_400KHZ);
1035
 
1035
 
1036
    Interrupt_Init(); // Initialize the interrupt priorities
1036
    Interrupt_Init(); // Initialize the interrupt priorities
1037
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1037
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1038
 
1038
 
1039
    BMP_Begin(BMP085_ULTRAHIGHRES);
1039
    BMP_Begin(BMP085_ULTRAHIGHRES);
1040
 
1040
 
-
 
1041
    BMP_Read_Temperature();
-
 
1042
    BMP_Read_Pressure();
-
 
1043
    BMP_Read_Altitude(101592);
-
 
1044
    
1041
    while (1) {
1045
    while (1) {
1042
        sprintf(output, "Temp: %f *C\r\n", BMP_Read_Temperature());
1046
        sprintf(output, "Temp: %f *C\r\n", BMP_Read_Temperature());
1043
        DBG_PRINT_MAIN(output, strlen(output));
1047
        DBG_PRINT_MAIN(output, strlen(output));
1044
        sprintf(output, "Pressure: %ld Pa\r\n", BMP_Read_Pressure());
1048
        sprintf(output, "Pressure: %ld Pa\r\n", BMP_Read_Pressure());
1045
        DBG_PRINT_MAIN(output, strlen(output));
1049
        DBG_PRINT_MAIN(output, strlen(output));
Line 1052... Line 1056...
1052
        Delay10KTCYx(255);
1056
        Delay10KTCYx(255);
1053
    }
1057
    }
1054
}
1058
}
1055
#elif defined(_TEST_XBEE)
1059
#elif defined(_TEST_XBEE)
1056
void main(void) {
1060
void main(void) {
1057
    unsigned int i, length = 0;
-
 
1058
    unsigned char buffer[100];
1061
    char buffer[100];
1059
 
1062
 
1060
    XBEE_RX_AT_COMMAND_RESPONSE_FRAME *rx_at_cmd_response_frame;
1063
    XBEE_RX_AT_COMMAND_RESPONSE_FRAME *rx_at_cmd_response_frame;
1061
    XBEE_RX_DATA_PACKET_FRAME *rx_data_frame;
1064
    XBEE_RX_DATA_PACKET_FRAME *rx_data_frame;
1062
    XBEE_RX_DATA_TX_STATUS_FRAME *rx_tx_status_frame;
1065
    XBEE_RX_DATA_TX_STATUS_FRAME *rx_tx_status_frame;
1063
    XBEE_RX_REMOTE_AT_COMMAND_FRAME *rx_remote_at_cmd_frame;
1066
    XBEE_RX_REMOTE_AT_COMMAND_FRAME *rx_remote_at_cmd_frame;
Line 1072... Line 1075...
1072
 
1075
 
1073
    // Set all ports as digial I/O
1076
    // Set all ports as digial I/O
1074
    ANCON0 = 0xFF;
1077
    ANCON0 = 0xFF;
1075
    ANCON1 = 0x1F;
1078
    ANCON1 = 0x1F;
1076
 
1079
 
-
 
1080
    UART_DATA uart_data;
1077
    UART1_Init(); // Initialize the UART handler code
1081
    UART1_Init(&uart_data); // Initialize the UART handler code
-
 
1082
    XBEE_DATA xbee_data;
1078
    XBee_Init();
1083
    XBee_Init(&xbee_data);
1079
 
1084
 
1080
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
1081
    Interrupt_Init(); // Initialize the interrupt priorities
1085
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
1086
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1082
 
1087
 
-
 
1088
 
1083
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
1089
    sprintf(buffer, "\r\nBegin Program\r\n");
-
 
1090
    DBG_PRINT_MAIN(buffer, strlen(buffer));
1084
 
1091
 
1085
    while (1) {
1092
    while (1) {
1086
 
1093
 
1087
        //#define _ROUTER
1094
//#define _ROUTER
1088
#define _COORDINATOR
1095
#define _COORDINATOR
1089
 
1096
 
1090
#ifdef _ROUTER
1097
#ifdef _ROUTER
1091
        XBEE_TX_DATA_PACKET_FRAME *tx_data_frame;
1098
        XBEE_TX_DATA_PACKET_FRAME *tx_data_frame;
1092
        tx_data_frame = (void *) buffer;
1099
        tx_data_frame = (void *) buffer;
Line 1116... Line 1123...
1116
        Delay10KTCYx(255);
1123
        Delay10KTCYx(255);
1117
        Delay10KTCYx(255);
1124
        Delay10KTCYx(255);
1118
#endif
1125
#endif
1119
 
1126
 
1120
#ifdef _COORDINATOR
1127
#ifdef _COORDINATOR
1121
        length = XBee_Get_Received_Frame(buffer);
1128
        int length = XBee_Get_Received_Frame(buffer);
1122
        if (length != 0) {
1129
        if (length != 0) {
1123
            switch (*(unsigned char *) buffer) {
1130
            switch (*(char *) buffer) {
1124
                case XBEE_RX_AT_COMMAND_RESPONSE:
1131
                case XBEE_RX_AT_COMMAND_RESPONSE:
1125
                    DBG_PRINT_MAIN("XBEE: parsing recieved AT command response frame\r\n");
1132
                    sprintf(buffer, "XBEE: parsing recieved AT command response frame\r\n");
-
 
1133
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1126
                    rx_at_cmd_response_frame = (void *) buffer;
1134
                    rx_at_cmd_response_frame = (void *) buffer;
1127
                    DBG_PRINT_MAIN("Frame ID: %u\r\n", rx_at_cmd_response_frame->frame_id);
1135
//                    DBG_PRINT_MAIN("Frame ID: %u\r\n", rx_at_cmd_response_frame->frame_id);
1128
                    DBG_PRINT_MAIN("AT Command: %c%c  Status: %02X\r\n", rx_at_cmd_response_frame->command[0], \\
1136
//                    DBG_PRINT_MAIN("AT Command: %c%c  Status: %02X\r\n", rx_at_cmd_response_frame->command[0], \\
1129
                            rx_at_cmd_response_frame->command[1], rx_at_cmd_response_frame->command_status);
1137
//                            rx_at_cmd_response_frame->command[1], rx_at_cmd_response_frame->command_status);
1130
                    if (length > XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE) {
1138
                    if (length > XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE) {
1131
                        DBG_PRINT_MAIN("Command Data: ");
1139
//                        DBG_PRINT_MAIN("Command Data: ");
1132
                        for (i = 0; i < length - XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE; i++) {
1140
                        for (int i = 0; i < length - XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE; i++) {
1133
                            DBG_PRINT_MAIN("%02X ", rx_at_cmd_response_frame->data[i]);
1141
//                            DBG_PRINT_MAIN("%02X ", rx_at_cmd_response_frame->data[i]);
1134
                        }
1142
                        }
1135
                        DBG_PRINT_MAIN("\r\n");
1143
//                        DBG_PRINT_MAIN("\r\n");
1136
                    }
1144
                    }
1137
                    break;
1145
                    break;
1138
                case XBEE_RX_DATA_PACKET:
1146
                case XBEE_RX_DATA_PACKET:
1139
                    DBG_PRINT_MAIN("XBEE: parsing recieved data recieved frame\r\n");
1147
                    sprintf(buffer, "XBEE: parsing recieved data recieved frame\r\n");
-
 
1148
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1140
                    rx_data_frame = (void *) buffer;
1149
                    rx_data_frame = (void *) buffer;
1141
                    XBee_Convert_Endian_64(&(rx_data_frame->source_64));
1150
                    XBee_Convert_Endian_64(&(rx_data_frame->source_64));
1142
                    XBee_Convert_Endian_16(&(rx_data_frame->source_16));
1151
                    XBee_Convert_Endian_16(&(rx_data_frame->source_16));
1143
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
1152
//                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
1144
                            rx_data_frame->source_64.UPPER_32.long_value, \\
1153
//                            rx_data_frame->source_64.UPPER_32.long_value, \\
1145
                            rx_data_frame->source_64.LOWER_32.long_value, \\
1154
//                            rx_data_frame->source_64.LOWER_32.long_value, \\
1146
                            rx_data_frame->source_16.INT_16.int_value, \\
1155
//                            rx_data_frame->source_16.INT_16.int_value, \\
1147
                            rx_data_frame->recieve_options);
1156
//                            rx_data_frame->recieve_options);
1148
                    DBG_PRINT_MAIN("Data: ");
1157
//                    DBG_PRINT_MAIN("Data: ");
1149
                    for (i = 0; i < length - XBEE_RX_DATA_PACKET_FRAME_SIZE; i++) {
1158
                    for (int i = 0; i < length - XBEE_RX_DATA_PACKET_FRAME_SIZE; i++) {
1150
                        DBG_PRINT_MAIN("%02X ", rx_data_frame->data[i]);
1159
//                        DBG_PRINT_MAIN("%02X ", rx_data_frame->data[i]);
1151
                    }
1160
                    }
1152
                    DBG_PRINT_MAIN("\r\n");
1161
//                    DBG_PRINT_MAIN("\r\n");
1153
                    break;
1162
                    break;
1154
                case XBEE_RX_DATA_TX_STATUS:
1163
                case XBEE_RX_DATA_TX_STATUS:
1155
                    DBG_PRINT_MAIN("XBEE: parsing recieved TX status frame\r\n");
1164
                    sprintf(buffer, "XBEE: parsing recieved TX status frame\r\n");
-
 
1165
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1156
                    rx_tx_status_frame = (void *) buffer;
1166
                    rx_tx_status_frame = (void *) buffer;
1157
                    XBee_Convert_Endian_16(&(rx_tx_status_frame->destination_16));
1167
                    XBee_Convert_Endian_16(&(rx_tx_status_frame->destination_16));
1158
                    DBG_PRINT_MAIN("Frame ID: %u  Destination 16: %04X\r\n", \\
1168
//                    DBG_PRINT_MAIN("Frame ID: %u  Destination 16: %04X\r\n", \\
1159
                            rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
1169
//                            rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
1160
                    DBG_PRINT_MAIN("Transmit Retry Count: %02X  Delivery Status: %02X  Discovery Status: %02X\r\n", \\
1170
//                    DBG_PRINT_MAIN("Transmit Retry Count: %02X  Delivery Status: %02X  Discovery Status: %02X\r\n", \\
1161
                            rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
1171
//                            rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
1162
                            rx_tx_status_frame->discovery_status);
1172
//                            rx_tx_status_frame->discovery_status);
1163
                    break;
1173
                    break;
1164
                case XBEE_RX_IO_DATA_SAMPLE:
1174
                case XBEE_RX_IO_DATA_SAMPLE:
1165
                    DBG_PRINT_MAIN("XBEE: parsing recieved IO data sample frame\r\n");
1175
                    sprintf(buffer, "XBEE: parsing recieved IO data sample frame\r\n");
-
 
1176
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1166
                    break;
1177
                    break;
1167
                case XBEE_RX_EXPLICIT_COMMAND:
1178
                case XBEE_RX_EXPLICIT_COMMAND:
1168
                    DBG_PRINT_MAIN("XBEE: parsing recieved explicit command frame\r\n");
1179
                    sprintf(buffer, "XBEE: parsing recieved explicit command frame\r\n");
-
 
1180
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1169
                    break;
1181
                    break;
1170
                case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
1182
                case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
1171
                    DBG_PRINT_MAIN("XBEE: parsing recieved remote AT command frame\r\n");
1183
                    sprintf(buffer, "XBEE: parsing recieved remote AT command frame\r\n");
-
 
1184
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1172
                    rx_remote_at_cmd_frame = (void *) buffer;
1185
                    rx_remote_at_cmd_frame = (void *) buffer;
1173
                    break;
1186
                    break;
1174
                case XBEE_RX_ROUTE_RECORD:
1187
                case XBEE_RX_ROUTE_RECORD:
1175
                    DBG_PRINT_MAIN("XBEE: parsing recieved route record frame\r\n");
1188
                    sprintf(buffer, "XBEE: parsing recieved route record frame\r\n");
-
 
1189
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1176
                    break;
1190
                    break;
1177
                case XBEE_RX_NODE_IDENTIFICATION:
1191
                case XBEE_RX_NODE_IDENTIFICATION:
1178
                    DBG_PRINT_MAIN("XBEE: parsing recieved node identification frame\r\n");
1192
                    sprintf(buffer, "XBEE: parsing recieved node identification frame\r\n");
-
 
1193
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1179
                    rx_node_ident_frame = (void *) buffer;
1194
                    rx_node_ident_frame = (void *) buffer;
1180
                    XBee_Convert_Endian_64(&(rx_node_ident_frame->source_64));
1195
                    XBee_Convert_Endian_64(&(rx_node_ident_frame->source_64));
1181
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->source_16));
1196
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->source_16));
1182
                    XBee_Convert_Endian_64(&(rx_node_ident_frame->remote_64));
1197
                    XBee_Convert_Endian_64(&(rx_node_ident_frame->remote_64));
1183
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->remote_16));
1198
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->remote_16));
1184
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->parent_16));
1199
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->parent_16));
1185
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
1200
//                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
1186
                            rx_node_ident_frame->source_64.UPPER_32.long_value, \\
1201
//                            rx_node_ident_frame->source_64.UPPER_32.long_value, \\
1187
                            rx_node_ident_frame->source_64.LOWER_32.long_value, \\
1202
//                            rx_node_ident_frame->source_64.LOWER_32.long_value, \\
1188
                            rx_node_ident_frame->source_16.INT_16.int_value, \\
1203
//                            rx_node_ident_frame->source_16.INT_16.int_value, \\
1189
                            rx_node_ident_frame->recieve_options);
1204
//                            rx_node_ident_frame->recieve_options);
1190
                    DBG_PRINT_MAIN("Remote 64: %08lX %08lX  Remote 16: %04X  Parent 16: %04X\r\n", \\
1205
//                    DBG_PRINT_MAIN("Remote 64: %08lX %08lX  Remote 16: %04X  Parent 16: %04X\r\n", \\
1191
                            rx_node_ident_frame->remote_64.UPPER_32.long_value, \\
1206
//                            rx_node_ident_frame->remote_64.UPPER_32.long_value, \\
1192
                            rx_node_ident_frame->remote_64.LOWER_32.long_value, \\
1207
//                            rx_node_ident_frame->remote_64.LOWER_32.long_value, \\
1193
                            rx_node_ident_frame->remote_16.INT_16.int_value, \\
1208
//                            rx_node_ident_frame->remote_16.INT_16.int_value, \\
1194
                            rx_node_ident_frame->parent_16.INT_16.int_value);
1209
//                            rx_node_ident_frame->parent_16.INT_16.int_value);
1195
                    DBG_PRINT_MAIN("Device Type: %02X  Source Event: %02X\r\n", \\
1210
//                    DBG_PRINT_MAIN("Device Type: %02X  Source Event: %02X\r\n", \\
1196
                            rx_node_ident_frame->device_type, rx_node_ident_frame->source_event);
1211
//                            rx_node_ident_frame->device_type, rx_node_ident_frame->source_event);
1197
                    break;
1212
                    break;
1198
                case XBEE_RX_FRAME_MODEM_STATUS:
1213
                case XBEE_RX_FRAME_MODEM_STATUS:
1199
                    DBG_PRINT_MAIN("XBEE: parsing recieved modem status frame\r\n");
1214
                    sprintf(buffer, "XBEE: parsing recieved modem status frame\r\n");
-
 
1215
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1200
                    rx_modem_status_frame = (void *) buffer;
1216
                    rx_modem_status_frame = (void *) buffer;
1201
                    DBG_PRINT_MAIN("Status: %02X\r\n", rx_modem_status_frame->status);
1217
//                    DBG_PRINT_MAIN("Status: %02X\r\n", rx_modem_status_frame->status);
1202
                    break;
1218
                    break;
1203
                default:
1219
                default:
1204
                    DBG_PRINT_MAIN("??\r\n");
1220
                    sprintf(buffer, "??\r\n");
-
 
1221
                    DBG_PRINT_MAIN(buffer, strlen(buffer));
1205
                    break;
1222
                    break;
1206
            }
1223
            }
1207
        }
1224
        }
1208
#endif
1225
#endif
1209
 
1226
 
1210
    }
1227
    }
1211
}
1228
}
1212
#else
1229
#else
1213
int main() {
1230
int main() {
1214
 
1231
    
1215
}
1232
}
1216
#endif
1233
#endif
1217
1234