Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 156 → Rev 157

/PIC Stuff/PICX_27J13/main.c
7,15 → 7,16
#include "uart.h"
#include "i2c.h"
#include "spi.h"
#include "timers.h"
#include "nfc_PN532.h"
#include "led_HT16K33.h"
#include "lux_TSL2561.h"
#include "temp_BMP085.h"
#include "oled_ssd1306.h"
#include "oled_ssd1331.h"
#include "timers.h"
#include "lux_TSL2561.h"
#include "oled_NHD-0216KZW-AB5.h"
#include "adc.h"
#include "temp_BMP085.h"
#include "xbee.h"
 
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
/* --------------------------- Configuration Bits --------------------------- */
611,9 → 612,8
SSD1331_Clear_Display();
SSD1331_Set_Rotation(0);
SSD1331_Set_Cursor(0, 0);
// TODO: Figure out why this isnt working (probably a compiler issue)
sprintf(output, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabit adipiscing ante sed nibh tincidunt feugiat.");
DBG_PRINT_MAIN(output, strlen(output));
SSD1331_Write_String(output, strlen(output));
 
// Delay10KTCYx(255);
// Delay10KTCYx(255);
1031,7 → 1031,7
BMP085_DATA bmp_data;
BMP_Init(&bmp_data);
 
I2C_Configure_Master(I2C_100KHZ);
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1038,6 → 1038,10
 
BMP_Begin(BMP085_ULTRAHIGHRES);
 
BMP_Read_Temperature();
BMP_Read_Pressure();
BMP_Read_Altitude(101592);
while (1) {
sprintf(output, "Temp: %f *C\r\n", BMP_Read_Temperature());
DBG_PRINT_MAIN(output, strlen(output));
1054,8 → 1058,7
}
#elif defined(_TEST_XBEE)
void main(void) {
unsigned int i, length = 0;
unsigned char buffer[100];
char buffer[100];
 
XBEE_RX_AT_COMMAND_RESPONSE_FRAME *rx_at_cmd_response_frame;
XBEE_RX_DATA_PACKET_FRAME *rx_data_frame;
1074,17 → 1077,21
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
XBee_Init();
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
XBEE_DATA xbee_data;
XBee_Init(&xbee_data);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
sprintf(buffer, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
 
while (1) {
 
//#define _ROUTER
//#define _ROUTER
#define _COORDINATOR
 
#ifdef _ROUTER
1118,64 → 1125,72
#endif
 
#ifdef _COORDINATOR
length = XBee_Get_Received_Frame(buffer);
int length = XBee_Get_Received_Frame(buffer);
if (length != 0) {
switch (*(unsigned char *) buffer) {
switch (*(char *) buffer) {
case XBEE_RX_AT_COMMAND_RESPONSE:
DBG_PRINT_MAIN("XBEE: parsing recieved AT command response frame\r\n");
sprintf(buffer, "XBEE: parsing recieved AT command response frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_at_cmd_response_frame = (void *) buffer;
DBG_PRINT_MAIN("Frame ID: %u\r\n", rx_at_cmd_response_frame->frame_id);
DBG_PRINT_MAIN("AT Command: %c%c Status: %02X\r\n", rx_at_cmd_response_frame->command[0], \\
rx_at_cmd_response_frame->command[1], rx_at_cmd_response_frame->command_status);
// DBG_PRINT_MAIN("Frame ID: %u\r\n", rx_at_cmd_response_frame->frame_id);
// DBG_PRINT_MAIN("AT Command: %c%c Status: %02X\r\n", rx_at_cmd_response_frame->command[0], \\
// rx_at_cmd_response_frame->command[1], rx_at_cmd_response_frame->command_status);
if (length > XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE) {
DBG_PRINT_MAIN("Command Data: ");
for (i = 0; i < length - XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE; i++) {
DBG_PRINT_MAIN("%02X ", rx_at_cmd_response_frame->data[i]);
// DBG_PRINT_MAIN("Command Data: ");
for (int i = 0; i < length - XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE; i++) {
// DBG_PRINT_MAIN("%02X ", rx_at_cmd_response_frame->data[i]);
}
DBG_PRINT_MAIN("\r\n");
// DBG_PRINT_MAIN("\r\n");
}
break;
case XBEE_RX_DATA_PACKET:
DBG_PRINT_MAIN("XBEE: parsing recieved data recieved frame\r\n");
sprintf(buffer, "XBEE: parsing recieved data recieved frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_data_frame = (void *) buffer;
XBee_Convert_Endian_64(&(rx_data_frame->source_64));
XBee_Convert_Endian_16(&(rx_data_frame->source_16));
DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %02X\r\n", \\
rx_data_frame->source_64.UPPER_32.long_value, \\
rx_data_frame->source_64.LOWER_32.long_value, \\
rx_data_frame->source_16.INT_16.int_value, \\
rx_data_frame->recieve_options);
DBG_PRINT_MAIN("Data: ");
for (i = 0; i < length - XBEE_RX_DATA_PACKET_FRAME_SIZE; i++) {
DBG_PRINT_MAIN("%02X ", rx_data_frame->data[i]);
// DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %02X\r\n", \\
// rx_data_frame->source_64.UPPER_32.long_value, \\
// rx_data_frame->source_64.LOWER_32.long_value, \\
// rx_data_frame->source_16.INT_16.int_value, \\
// rx_data_frame->recieve_options);
// DBG_PRINT_MAIN("Data: ");
for (int i = 0; i < length - XBEE_RX_DATA_PACKET_FRAME_SIZE; i++) {
// DBG_PRINT_MAIN("%02X ", rx_data_frame->data[i]);
}
DBG_PRINT_MAIN("\r\n");
// DBG_PRINT_MAIN("\r\n");
break;
case XBEE_RX_DATA_TX_STATUS:
DBG_PRINT_MAIN("XBEE: parsing recieved TX status frame\r\n");
sprintf(buffer, "XBEE: parsing recieved TX status frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_tx_status_frame = (void *) buffer;
XBee_Convert_Endian_16(&(rx_tx_status_frame->destination_16));
DBG_PRINT_MAIN("Frame ID: %u Destination 16: %04X\r\n", \\
rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
DBG_PRINT_MAIN("Transmit Retry Count: %02X Delivery Status: %02X Discovery Status: %02X\r\n", \\
rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
rx_tx_status_frame->discovery_status);
// DBG_PRINT_MAIN("Frame ID: %u Destination 16: %04X\r\n", \\
// rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
// DBG_PRINT_MAIN("Transmit Retry Count: %02X Delivery Status: %02X Discovery Status: %02X\r\n", \\
// rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
// rx_tx_status_frame->discovery_status);
break;
case XBEE_RX_IO_DATA_SAMPLE:
DBG_PRINT_MAIN("XBEE: parsing recieved IO data sample frame\r\n");
sprintf(buffer, "XBEE: parsing recieved IO data sample frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
break;
case XBEE_RX_EXPLICIT_COMMAND:
DBG_PRINT_MAIN("XBEE: parsing recieved explicit command frame\r\n");
sprintf(buffer, "XBEE: parsing recieved explicit command frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
break;
case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
DBG_PRINT_MAIN("XBEE: parsing recieved remote AT command frame\r\n");
sprintf(buffer, "XBEE: parsing recieved remote AT command frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_remote_at_cmd_frame = (void *) buffer;
break;
case XBEE_RX_ROUTE_RECORD:
DBG_PRINT_MAIN("XBEE: parsing recieved route record frame\r\n");
sprintf(buffer, "XBEE: parsing recieved route record frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
break;
case XBEE_RX_NODE_IDENTIFICATION:
DBG_PRINT_MAIN("XBEE: parsing recieved node identification frame\r\n");
sprintf(buffer, "XBEE: parsing recieved node identification frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_node_ident_frame = (void *) buffer;
XBee_Convert_Endian_64(&(rx_node_ident_frame->source_64));
XBee_Convert_Endian_16(&(rx_node_ident_frame->source_16));
1182,26 → 1197,28
XBee_Convert_Endian_64(&(rx_node_ident_frame->remote_64));
XBee_Convert_Endian_16(&(rx_node_ident_frame->remote_16));
XBee_Convert_Endian_16(&(rx_node_ident_frame->parent_16));
DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %02X\r\n", \\
rx_node_ident_frame->source_64.UPPER_32.long_value, \\
rx_node_ident_frame->source_64.LOWER_32.long_value, \\
rx_node_ident_frame->source_16.INT_16.int_value, \\
rx_node_ident_frame->recieve_options);
DBG_PRINT_MAIN("Remote 64: %08lX %08lX Remote 16: %04X Parent 16: %04X\r\n", \\
rx_node_ident_frame->remote_64.UPPER_32.long_value, \\
rx_node_ident_frame->remote_64.LOWER_32.long_value, \\
rx_node_ident_frame->remote_16.INT_16.int_value, \\
rx_node_ident_frame->parent_16.INT_16.int_value);
DBG_PRINT_MAIN("Device Type: %02X Source Event: %02X\r\n", \\
rx_node_ident_frame->device_type, rx_node_ident_frame->source_event);
// DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %02X\r\n", \\
// rx_node_ident_frame->source_64.UPPER_32.long_value, \\
// rx_node_ident_frame->source_64.LOWER_32.long_value, \\
// rx_node_ident_frame->source_16.INT_16.int_value, \\
// rx_node_ident_frame->recieve_options);
// DBG_PRINT_MAIN("Remote 64: %08lX %08lX Remote 16: %04X Parent 16: %04X\r\n", \\
// rx_node_ident_frame->remote_64.UPPER_32.long_value, \\
// rx_node_ident_frame->remote_64.LOWER_32.long_value, \\
// rx_node_ident_frame->remote_16.INT_16.int_value, \\
// rx_node_ident_frame->parent_16.INT_16.int_value);
// DBG_PRINT_MAIN("Device Type: %02X Source Event: %02X\r\n", \\
// rx_node_ident_frame->device_type, rx_node_ident_frame->source_event);
break;
case XBEE_RX_FRAME_MODEM_STATUS:
DBG_PRINT_MAIN("XBEE: parsing recieved modem status frame\r\n");
sprintf(buffer, "XBEE: parsing recieved modem status frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_modem_status_frame = (void *) buffer;
DBG_PRINT_MAIN("Status: %02X\r\n", rx_modem_status_frame->status);
// DBG_PRINT_MAIN("Status: %02X\r\n", rx_modem_status_frame->status);
break;
default:
DBG_PRINT_MAIN("??\r\n");
sprintf(buffer, "??\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
break;
}
}
1211,6 → 1228,6
}
#else
int main() {
 
}
#endif
#endif