Subversion Repositories Code-Repo

Rev

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

Rev 158 Rev 159
Line 15... Line 15...
15
#include "display_led_HT16K33.h"
15
#include "display_led_HT16K33.h"
16
#include "display_oled_ssd1306.h"
16
#include "display_oled_ssd1306.h"
17
#include "display_oled_ssd1331.h"
17
#include "display_oled_ssd1331.h"
18
#include "display_oled_NHD-0216KZW-AB5.h"
18
#include "display_oled_NHD-0216KZW-AB5.h"
19
#include "comm_xbee.h"
19
#include "comm_xbee.h"
-
 
20
#include "sensor_gyro_L3G.h"
-
 
21
#include "sensor_accel_LSM303.h"
20
 
22
 
21
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
23
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
22
/* --------------------------- Configuration Bits --------------------------- */
24
/* --------------------------- Configuration Bits --------------------------- */
23
/* CONFIG1L @ 0x1FFF8 */
25
/* CONFIG1L @ 0x1FFF8 */
24
#pragma config CFGPLLEN = ON        // Enable PLL on startup
26
#pragma config CFGPLLEN = ON        // Enable PLL on startup
Line 60... Line 62...
60
#pragma config WPEND = PAGE_WPFP    // Pages WPFP<6:0> through Configuration Words erase/write protected
62
#pragma config WPEND = PAGE_WPFP    // Pages WPFP<6:0> through Configuration Words erase/write protected
61
#pragma config WPDIS = OFF          // WPFP<6:0>/WPEND region ignored
63
#pragma config WPDIS = OFF          // WPFP<6:0>/WPEND region ignored
62
/* -------------------------------------------------------------------------- */
64
/* -------------------------------------------------------------------------- */
63
// </editor-fold>
65
// </editor-fold>
64
 
66
 
65
#if  defined(_TEST_UART)
67
#if defined(_TEST_UART)
66
// <editor-fold defaultstate="collapsed" desc="_TEST_UART">
68
// <editor-fold defaultstate="collapsed" desc="_TEST_UART">
67
int main() {
69
int main() {
68
    char buffer[100];
70
    char buffer[100];
69
 
71
 
70
    // Set all ports as digial I/O
72
    // Set all ports as digial I/O
Line 257... Line 259...
257
        Delay10KTCYx(255);
259
        Delay10KTCYx(255);
258
        Delay10KTCYx(255);
260
        Delay10KTCYx(255);
259
    }
261
    }
260
}
262
}
261
// </editor-fold>
263
// </editor-fold>
-
 
264
#elif defined(_TEST_ADC)
-
 
265
// <editor-fold defaultstate="collapsed" desc="_TEST_ADC">
-
 
266
void main(void) {
-
 
267
    unsigned int x, y, z;
-
 
268
    char buffer[60];
-
 
269
 
-
 
270
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
271
    ANCON0 = 0xF8;
-
 
272
    ANCON1 = 0x1F;
-
 
273
 
-
 
274
    UART_DATA uart_data;
-
 
275
    UART1_Init(&uart_data); // Initialize the UART handler code
-
 
276
    SPI_DATA spi_data;
-
 
277
    SPI2_Init(&spi_data, SPI2_FOSC_8); // Initialize the SPI module
-
 
278
    SSD1306_DATA ssd1306_data;
-
 
279
    SSD1306_Init(&ssd1306_data); // Initialize the SSD1331 OLED display (uses SPI2)
-
 
280
    ADC_DATA adc_data;
-
 
281
    ADC_Init(&adc_data, ADC_TAD_20, ADC_FOSC_64_);
-
 
282
 
-
 
283
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
-
 
284
 
-
 
285
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
286
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
287
 
-
 
288
    sprintf(buffer, "\r\nBegin Program\r\n");
-
 
289
    SSD1306_Write_String(buffer, strlen(buffer));
-
 
290
 
-
 
291
    memset(buffer, 0, 60);
-
 
292
    SSD1306_Clear_Display();
-
 
293
    SSD1306_Display();
-
 
294
 
-
 
295
    while (1) {
-
 
296
        // ADC read from AN0-AN2 and prints to display
-
 
297
        ADC_Start(ADC_CHANNEL_AN2);
-
 
298
//        SSD1306_Fill_Rect(0, 0, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
-
 
299
        SSD1306_Set_Cursor(0, 0);
-
 
300
        while (!ADC_Get_Result(&x));
-
 
301
        sprintf(buffer, "X: %u", x);
-
 
302
        SSD1306_Write_String(buffer, strlen(buffer));
-
 
303
        SSD1306_Display();
-
 
304
 
-
 
305
        ADC_Start(ADC_CHANNEL_AN1);
-
 
306
//        SSD1306_Fill_Rect(0, 8, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
-
 
307
        SSD1306_Set_Cursor(0, 8);
-
 
308
        while (!ADC_Get_Result(&y));
-
 
309
        sprintf(buffer, "Y: %u", y);
-
 
310
        SSD1306_Write_String(buffer, strlen(buffer));
-
 
311
        SSD1306_Display();
-
 
312
 
-
 
313
        ADC_Start(ADC_CHANNEL_AN0);
-
 
314
//        SSD1306_Fill_Rect(0, 16, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
-
 
315
        SSD1306_Set_Cursor(0, 16);
-
 
316
        while (!ADC_Get_Result(&z));
-
 
317
        sprintf(buffer, "Z: %u", z);
-
 
318
        SSD1306_Write_String(buffer, strlen(buffer));
-
 
319
        SSD1306_Display();
-
 
320
    }
-
 
321
}
-
 
322
// </editor-fold>
-
 
323
#elif defined(_TEST_TIMER1_RTC)
-
 
324
// <editor-fold defaultstate="collapsed" desc="_TEST_TIMER1_RTC">
-
 
325
void main(void) {
-
 
326
 
-
 
327
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
328
    ANCON0 = 0xF8;
-
 
329
    ANCON1 = 0x1F;
-
 
330
 
-
 
331
    Timer1_Init();
-
 
332
 
-
 
333
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
334
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
335
 
-
 
336
    LED_BLUE_TRIS = 0;
-
 
337
    LED_RED_TRIS = 0;
-
 
338
 
-
 
339
    Timer1_Enable();
-
 
340
 
-
 
341
    while (1) {
-
 
342
 
-
 
343
    }
-
 
344
}
-
 
345
// </editor-fold>
262
#elif defined(_TEST_NFC)
346
#elif defined(_TEST_NFC)
263
// <editor-fold defaultstate="collapsed" desc="_TEST_NFC">
347
// <editor-fold defaultstate="collapsed" desc="_TEST_NFC">
264
void main(void) {
348
void main(void) {
265
    char length = 0;
349
    char length = 0;
266
    char output[64];
350
    char output[64];
Line 420... Line 504...
420
            }
504
            }
421
        }
505
        }
422
    }
506
    }
423
}
507
}
424
// </editor-fold>
508
// </editor-fold>
-
 
509
#elif defined(_TEST_LUX)
-
 
510
// <editor-fold defaultstate="collapsed" desc="_TEST_LUX">
-
 
511
void main(void) {
-
 
512
    char output[64];
-
 
513
 
-
 
514
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
515
    ANCON0 = 0xF8;
-
 
516
    ANCON1 = 0x1F;
-
 
517
 
-
 
518
    UART_DATA uart_data;
-
 
519
    UART1_Init(&uart_data);
-
 
520
    I2C_DATA i2c_data;
-
 
521
    I2C_Init(&i2c_data);
-
 
522
    TSL2561_DATA lux_data;
-
 
523
    LUX_Init(&lux_data, TSL2561_ADDR_FLOAT);
-
 
524
 
-
 
525
    I2C_Configure_Master(I2C_100KHZ);
-
 
526
 
-
 
527
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
528
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
529
 
-
 
530
    LUX_Begin();
-
 
531
 
-
 
532
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
-
 
533
//    LUX_Set_Gain(TSL2561_GAIN_0X);   // set no gain (for bright situtations)
-
 
534
    LUX_Set_Gain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
-
 
535
 
-
 
536
    // Changing the integration time gives you a longer time over which to sense light
-
 
537
    // longer timelines are slower, but are good in very low light situtations!
-
 
538
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS);  // shortest integration time (bright light)
-
 
539
    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
-
 
540
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
-
 
541
 
-
 
542
    sprintf(output, "\r\nBegin Program\r\n");
-
 
543
    DBG_PRINT_MAIN(output, strlen(output));
-
 
544
 
-
 
545
    while (1) {
-
 
546
        unsigned long lum = LUX_Get_Full_Luminosity();
-
 
547
        unsigned int ir = lum >> 16;
-
 
548
        unsigned int full = lum & 0xFFFF;
-
 
549
        sprintf(output, "IR: %d\r\n", ir);
-
 
550
        DBG_PRINT_MAIN(output, strlen(output));
-
 
551
        sprintf(output, "Visible: %d\r\n", full - ir);
-
 
552
        DBG_PRINT_MAIN(output, strlen(output));
-
 
553
        sprintf(output, "Full: %d\r\n", full);
-
 
554
        DBG_PRINT_MAIN(output, strlen(output));
-
 
555
        sprintf(output, "Lux: %ld\r\n\r\n", LUX_Calculate_Lux(full, ir));
-
 
556
        DBG_PRINT_MAIN(output, strlen(output));
-
 
557
 
-
 
558
        Delay10KTCYx(255);
-
 
559
        Delay10KTCYx(255);
-
 
560
        Delay10KTCYx(255);
-
 
561
        Delay10KTCYx(255);
-
 
562
    }
-
 
563
}
-
 
564
// </editor-fold>
-
 
565
#elif defined(_TEST_BMP)
-
 
566
// <editor-fold defaultstate="collapsed" desc="_TEST_BMP">
-
 
567
void main(void) {
-
 
568
    char output[64];
-
 
569
 
-
 
570
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
571
    ANCON0 = 0xF8;
-
 
572
    ANCON1 = 0x1F;
-
 
573
 
-
 
574
    UART_DATA uart_data;
-
 
575
    UART1_Init(&uart_data);
-
 
576
    I2C_DATA i2c_data;
-
 
577
    I2C_Init(&i2c_data);
-
 
578
    BMP085_DATA bmp_data;
-
 
579
    BMP_Init(&bmp_data);
-
 
580
 
-
 
581
    I2C_Configure_Master(I2C_400KHZ);
-
 
582
 
-
 
583
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
584
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
585
 
-
 
586
    BMP_Begin(BMP085_ULTRAHIGHRES);
-
 
587
 
-
 
588
    BMP_Read_Temperature();
-
 
589
    BMP_Read_Pressure();
-
 
590
    BMP_Read_Altitude(101592);
-
 
591
 
-
 
592
    while (1) {
-
 
593
        sprintf(output, "Temp: %f *C\r\n", BMP_Read_Temperature());
-
 
594
        DBG_PRINT_MAIN(output, strlen(output));
-
 
595
        sprintf(output, "Pressure: %ld Pa\r\n", BMP_Read_Pressure());
-
 
596
        DBG_PRINT_MAIN(output, strlen(output));
-
 
597
        sprintf(output, "Altitude: %f meters\r\n", BMP_Read_Altitude(101592));
-
 
598
        DBG_PRINT_MAIN(output, strlen(output));
-
 
599
 
-
 
600
        Delay10KTCYx(255);
-
 
601
        Delay10KTCYx(255);
-
 
602
        Delay10KTCYx(255);
-
 
603
        Delay10KTCYx(255);
-
 
604
    }
-
 
605
}
-
 
606
// </editor-fold>
-
 
607
#elif defined(_TEST_GYRO)
-
 
608
// <editor-fold defaultstate="collapsed" desc="_TEST_GYRO">
-
 
609
void main(void) {
-
 
610
    char output[64];
-
 
611
 
-
 
612
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
613
    ANCON0 = 0xF8;
-
 
614
    ANCON1 = 0x1F;
-
 
615
 
-
 
616
    UART_DATA uart_data;
-
 
617
    UART1_Init(&uart_data);
-
 
618
    I2C_DATA i2c_data;
-
 
619
    I2C_Init(&i2c_data);
-
 
620
    L3G_DATA gyro_data;
-
 
621
    L3G_Init(&gyro_data, L3GD20_DEVICE, L3G_SA0_HIGH);
-
 
622
 
-
 
623
    I2C_Configure_Master(I2C_100KHZ);
-
 
624
 
-
 
625
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
626
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
627
 
-
 
628
    sprintf(output, "\r\nBegin Program\r\n");
-
 
629
    DBG_PRINT_MAIN(output, strlen(output));
-
 
630
 
-
 
631
    L3G_Begin();
-
 
632
    int x,y,z;
-
 
633
    while (1) {
-
 
634
        L3G_Read(&x, &y, &z);
-
 
635
        sprintf(output, "X: %d  Y: %d  Z: %d\r\n", x, y, z);
-
 
636
        DBG_PRINT_MAIN(output, strlen(output));
-
 
637
 
-
 
638
        Delay10KTCYx(100);
-
 
639
    }
-
 
640
}
-
 
641
// </editor-fold>
-
 
642
#elif defined(_TEST_ACCEL)
-
 
643
// <editor-fold defaultstate="collapsed" desc="_TEST_ACCEL">
-
 
644
void main(void) {
-
 
645
    char output[64];
-
 
646
 
-
 
647
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
648
    ANCON0 = 0xF8;
-
 
649
    ANCON1 = 0x1F;
-
 
650
 
-
 
651
    UART_DATA uart_data;
-
 
652
    UART1_Init(&uart_data);
-
 
653
    I2C_DATA i2c_data;
-
 
654
    I2C_Init(&i2c_data);
-
 
655
    LSM303_DATA acc_data;
-
 
656
    LSM303_Init(&acc_data, LSM303DLHC_DEVICE, ACC_ADDRESS_SA0_A_LOW);
-
 
657
 
-
 
658
    I2C_Configure_Master(I2C_100KHZ);
-
 
659
 
-
 
660
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
661
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
662
 
-
 
663
    sprintf(output, "\r\nBegin Program\r\n");
-
 
664
    DBG_PRINT_MAIN(output, strlen(output));
-
 
665
 
-
 
666
    LSM303_Begin();
-
 
667
    int a_x, a_y, a_z, m_x, m_y, m_z;
-
 
668
    while (1) {
-
 
669
        LSM303_Read_Acc(&a_x, &a_y, &a_z);
-
 
670
        LSM303_Read_Mag(&m_x, &m_y, &m_z);
-
 
671
        sprintf(output, "A - X: %d  Y: %d  Z: %d\r\n", a_x, a_y, a_z);
-
 
672
        DBG_PRINT_MAIN(output, strlen(output));
-
 
673
        sprintf(output, "M - X: %d  Y: %d  Z: %d\r\n", m_x, m_y, m_z);
-
 
674
        DBG_PRINT_MAIN(output, strlen(output));
-
 
675
 
-
 
676
        Delay10KTCYx(100);
-
 
677
    }
-
 
678
}
-
 
679
// </editor-fold>
425
#elif defined(_TEST_LED_BACKPACK)
680
#elif defined(_TEST_LED_BACKPACK)
426
// <editor-fold defaultstate="collapsed" desc="_TEST_LED_BACKPACK">
681
// <editor-fold defaultstate="collapsed" desc="_TEST_LED_BACKPACK">
427
void main(void) {
682
void main(void) {
428
    unsigned int counter = 0;
683
    unsigned int counter = 0;
429
    char output[64];
684
    char output[64];
Line 718... Line 973...
718
        //        SSD1331_Write_String("%u", i);
973
        //        SSD1331_Write_String("%u", i);
719
        //        i++;
974
        //        i++;
720
    }
975
    }
721
}
976
}
722
// </editor-fold>
977
// </editor-fold>
723
#elif defined(_TEST_TIMER1_RTC)
-
 
724
// <editor-fold defaultstate="collapsed" desc="_TEST_TIMER1_RTC">
-
 
725
void main(void) {
-
 
726
 
-
 
727
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
728
    ANCON0 = 0xF8;
-
 
729
    ANCON1 = 0x1F;
-
 
730
 
-
 
731
    Timer1_Init();
-
 
732
 
-
 
733
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
734
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
735
 
-
 
736
    LED_BLUE_TRIS = 0;
-
 
737
    LED_RED_TRIS = 0;
-
 
738
 
-
 
739
    Timer1_Enable();
-
 
740
 
-
 
741
    while (1) {
-
 
742
 
-
 
743
    }
-
 
744
}
-
 
745
// </editor-fold>
-
 
746
#elif defined(_TEST_LUX)
-
 
747
// <editor-fold defaultstate="collapsed" desc="_TEST_LUX">
-
 
748
void main(void) {
-
 
749
    char output[64];
-
 
750
 
-
 
751
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
752
    ANCON0 = 0xF8;
-
 
753
    ANCON1 = 0x1F;
-
 
754
 
-
 
755
    UART_DATA uart_data;
-
 
756
    UART1_Init(&uart_data);
-
 
757
    I2C_DATA i2c_data;
-
 
758
    I2C_Init(&i2c_data);
-
 
759
    TSL2561_DATA lux_data;
-
 
760
    LUX_Init(&lux_data, TSL2561_ADDR_FLOAT);
-
 
761
 
-
 
762
    I2C_Configure_Master(I2C_100KHZ);
-
 
763
 
-
 
764
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
765
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
766
 
-
 
767
    LUX_Begin();
-
 
768
 
-
 
769
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
-
 
770
//    LUX_Set_Gain(TSL2561_GAIN_0X);   // set no gain (for bright situtations)
-
 
771
    LUX_Set_Gain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
-
 
772
 
-
 
773
    // Changing the integration time gives you a longer time over which to sense light
-
 
774
    // longer timelines are slower, but are good in very low light situtations!
-
 
775
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS);  // shortest integration time (bright light)
-
 
776
    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
-
 
777
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
-
 
778
 
-
 
779
    sprintf(output, "\r\nBegin Program\r\n");
-
 
780
    DBG_PRINT_MAIN(output, strlen(output));
-
 
781
    
-
 
782
    while (1) {
-
 
783
        unsigned long lum = LUX_Get_Full_Luminosity();
-
 
784
        unsigned int ir = lum >> 16;
-
 
785
        unsigned int full = lum & 0xFFFF;
-
 
786
        sprintf(output, "IR: %d\r\n", ir);
-
 
787
        DBG_PRINT_MAIN(output, strlen(output));
-
 
788
        sprintf(output, "Visible: %d\r\n", full - ir);
-
 
789
        DBG_PRINT_MAIN(output, strlen(output));
-
 
790
        sprintf(output, "Full: %d\r\n", full);
-
 
791
        DBG_PRINT_MAIN(output, strlen(output));
-
 
792
        sprintf(output, "Lux: %ld\r\n\r\n", LUX_Calculate_Lux(full, ir));
-
 
793
        DBG_PRINT_MAIN(output, strlen(output));
-
 
794
 
-
 
795
        Delay10KTCYx(255);
-
 
796
        Delay10KTCYx(255);
-
 
797
        Delay10KTCYx(255);
-
 
798
        Delay10KTCYx(255);
-
 
799
    }
-
 
800
}
-
 
801
// </editor-fold>
-
 
802
#elif defined(_TEST_OLED_CHAR)
978
#elif defined(_TEST_OLED_CHAR)
803
// <editor-fold defaultstate="collapsed" desc="_TEST_OLED_CHAR">
979
// <editor-fold defaultstate="collapsed" desc="_TEST_OLED_CHAR">
804
void main(void) {
980
void main(void) {
805
    char output[64];
981
    char output[64];
806
 
982
 
Line 962... Line 1138...
962
    LUX_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
1138
    LUX_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
963
//    LUX_Set_Gain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
1139
//    LUX_Set_Gain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
964
 
1140
 
965
    // Changing the integration time gives you a longer time over which to sense light
1141
    // Changing the integration time gives you a longer time over which to sense light
966
    // longer timelines are slower, but are good in very low light situtations!
1142
    // longer timelines are slower, but are good in very low light situtations!
967
    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
1143
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
968
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
1144
    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
969
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
1145
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
970
 
1146
 
971
    while (1) {
1147
    while (1) {
972
        unsigned long lum = LUX_Get_Full_Luminosity();
1148
        unsigned long lum = LUX_Get_Full_Luminosity();
973
        unsigned int ir = lum >> 16;
1149
        unsigned int ir = lum >> 16;
Line 979... Line 1155...
979
        NHD_Write_String(output, strlen(output));
1155
        NHD_Write_String(output, strlen(output));
980
        NHD_Set_Cursor(0, 1);
1156
        NHD_Set_Cursor(0, 1);
981
        sprintf(output, "Lux: %ld        ", LUX_Calculate_Lux(full, ir));
1157
        sprintf(output, "Lux: %ld        ", LUX_Calculate_Lux(full, ir));
982
        NHD_Write_String(output, strlen(output));
1158
        NHD_Write_String(output, strlen(output));
983
 
1159
 
984
        Delay10KTCYx(100);
1160
//        Delay10KTCYx(100);
985
    }
-
 
986
}
-
 
987
// </editor-fold>
-
 
988
#elif defined(_TEST_ADC)
-
 
989
// <editor-fold defaultstate="collapsed" desc="_TEST_ADC">
-
 
990
void main(void) {
-
 
991
    unsigned int x, y, z;
-
 
992
    char buffer[60];
-
 
993
 
-
 
994
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
995
    ANCON0 = 0xF8;
-
 
996
    ANCON1 = 0x1F;
-
 
997
 
-
 
998
    UART_DATA uart_data;
-
 
999
    UART1_Init(&uart_data); // Initialize the UART handler code
-
 
1000
    SPI_DATA spi_data;
-
 
1001
    SPI2_Init(&spi_data, SPI2_FOSC_8); // Initialize the SPI module
-
 
1002
    SSD1306_DATA ssd1306_data;
-
 
1003
    SSD1306_Init(&ssd1306_data); // Initialize the SSD1331 OLED display (uses SPI2)
-
 
1004
    ADC_DATA adc_data;
-
 
1005
    ADC_Init(&adc_data, ADC_TAD_20, ADC_FOSC_64_);
-
 
1006
 
-
 
1007
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
-
 
1008
 
-
 
1009
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
1010
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
1011
 
-
 
1012
    sprintf(buffer, "\r\nBegin Program\r\n");
-
 
1013
    SSD1306_Write_String(buffer, strlen(buffer));
-
 
1014
 
-
 
1015
    memset(buffer, 0, 60);
-
 
1016
    SSD1306_Clear_Display();
-
 
1017
    SSD1306_Display();
-
 
1018
 
-
 
1019
    while (1) {
-
 
1020
        // ADC read from AN0-AN2 and prints to display
-
 
1021
        ADC_Start(ADC_CHANNEL_AN2);
-
 
1022
//        SSD1306_Fill_Rect(0, 0, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
-
 
1023
        SSD1306_Set_Cursor(0, 0);
-
 
1024
        while (!ADC_Get_Result(&x));
-
 
1025
        sprintf(buffer, "X: %u", x);
-
 
1026
        SSD1306_Write_String(buffer, strlen(buffer));
-
 
1027
        SSD1306_Display();
-
 
1028
 
-
 
1029
        ADC_Start(ADC_CHANNEL_AN1);
-
 
1030
//        SSD1306_Fill_Rect(0, 8, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
-
 
1031
        SSD1306_Set_Cursor(0, 8);
-
 
1032
        while (!ADC_Get_Result(&y));
-
 
1033
        sprintf(buffer, "Y: %u", y);
-
 
1034
        SSD1306_Write_String(buffer, strlen(buffer));
-
 
1035
        SSD1306_Display();
-
 
1036
 
-
 
1037
        ADC_Start(ADC_CHANNEL_AN0);
-
 
1038
//        SSD1306_Fill_Rect(0, 16, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
-
 
1039
        SSD1306_Set_Cursor(0, 16);
-
 
1040
        while (!ADC_Get_Result(&z));
-
 
1041
        sprintf(buffer, "Z: %u", z);
-
 
1042
        SSD1306_Write_String(buffer, strlen(buffer));
-
 
1043
        SSD1306_Display();
-
 
1044
    }
-
 
1045
}
-
 
1046
// </editor-fold>
-
 
1047
#elif defined(_TEST_BMP)
-
 
1048
// <editor-fold defaultstate="collapsed" desc="_TEST_BMP">
-
 
1049
void main(void) {
-
 
1050
    char output[64];
-
 
1051
 
-
 
1052
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
1053
    ANCON0 = 0xF8;
-
 
1054
    ANCON1 = 0x1F;
-
 
1055
 
-
 
1056
    UART_DATA uart_data;
-
 
1057
    UART1_Init(&uart_data);
-
 
1058
    I2C_DATA i2c_data;
-
 
1059
    I2C_Init(&i2c_data);
-
 
1060
    BMP085_DATA bmp_data;
-
 
1061
    BMP_Init(&bmp_data);
-
 
1062
 
-
 
1063
    I2C_Configure_Master(I2C_400KHZ);
-
 
1064
 
-
 
1065
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
1066
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
1067
 
-
 
1068
    BMP_Begin(BMP085_ULTRAHIGHRES);
-
 
1069
 
-
 
1070
    BMP_Read_Temperature();
-
 
1071
    BMP_Read_Pressure();
-
 
1072
    BMP_Read_Altitude(101592);
-
 
1073
    
-
 
1074
    while (1) {
-
 
1075
        sprintf(output, "Temp: %f *C\r\n", BMP_Read_Temperature());
-
 
1076
        DBG_PRINT_MAIN(output, strlen(output));
-
 
1077
        sprintf(output, "Pressure: %ld Pa\r\n", BMP_Read_Pressure());
-
 
1078
        DBG_PRINT_MAIN(output, strlen(output));
-
 
1079
        sprintf(output, "Altitude: %f meters\r\n", BMP_Read_Altitude(101592));
-
 
1080
        DBG_PRINT_MAIN(output, strlen(output));
-
 
1081
 
-
 
1082
        Delay10KTCYx(255);
-
 
1083
        Delay10KTCYx(255);
-
 
1084
        Delay10KTCYx(255);
-
 
1085
        Delay10KTCYx(255);
-
 
1086
    }
1161
    }
1087
}
1162
}
1088
// </editor-fold>
1163
// </editor-fold>
1089
#elif defined(_TEST_XBEE)
1164
#elif defined(_TEST_XBEE)
1090
// <editor-fold defaultstate="collapsed" desc="_TEST_XBEE">
1165
// <editor-fold defaultstate="collapsed" desc="_TEST_XBEE">