Subversion Repositories Code-Repo

Rev

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

Rev 150 Rev 151
Line 75... Line 75...
75
    ANCON0 = 0xFF;
75
    ANCON0 = 0xFF;
76
    ANCON1 = 0x1F;
76
    ANCON1 = 0x1F;
77
 
77
 
78
    UART1_Init(); // Initialize the UART handler code
78
    UART1_Init(); // Initialize the UART handler code
79
 
79
 
80
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
80
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
81
    interrupt_init(); // Initialize the interrupt priorities
81
    Interrupt_Init(); // Initialize the interrupt priorities
82
 
82
 
83
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
83
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
84
 
84
 
85
    while (1) {
85
    while (1) {
86
 
86
 
Line 114... Line 114...
114
    UART1_Init(); // Initialize the UART handler code
114
    UART1_Init(); // Initialize the UART handler code
115
    I2C_Init(); // Initialize the I2C handler code
115
    I2C_Init(); // Initialize the I2C handler code
116
 
116
 
117
    I2C_Configure_Master(I2C_100KHZ);
117
    I2C_Configure_Master(I2C_100KHZ);
118
 
118
 
119
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
119
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
120
    interrupt_init(); // Initialize the interrupt priorities
120
    Interrupt_Init(); // Initialize the interrupt priorities
121
 
121
 
122
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
122
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
123
 
123
 
124
    while (1) {
124
    while (1) {
125
 
125
 
Line 181... Line 181...
181
    UART1_Init(); // Initialize the UART handler code
181
    UART1_Init(); // Initialize the UART handler code
182
    I2C_Init(); // Initialize the I2C handler code
182
    I2C_Init(); // Initialize the I2C handler code
183
 
183
 
184
    I2C_Configure_Slave(0x24);
184
    I2C_Configure_Slave(0x24);
185
 
185
 
186
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
186
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
187
    interrupt_init(); // Initialize the interrupt priorities
187
    Interrupt_Init(); // Initialize the interrupt priorities
188
 
188
 
189
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
189
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
190
 
190
 
191
    while (1) {
191
    while (1) {
192
 
192
 
Line 230... Line 230...
230
    I2C_Init(); // Initialize the I2C handler code
230
    I2C_Init(); // Initialize the I2C handler code
231
    NFC_Init(); // Initialize the NFC chip (uses I2C)
231
    NFC_Init(); // Initialize the NFC chip (uses I2C)
232
 
232
 
233
    I2C_Configure_Master(I2C_400KHZ);
233
    I2C_Configure_Master(I2C_400KHZ);
234
 
234
 
235
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
235
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
236
    interrupt_init(); // Initialize the interrupt priorities
236
    Interrupt_Init(); // Initialize the interrupt priorities
237
 
237
 
238
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
238
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
239
 
239
 
240
    version = NFC_getFirmwareVersion();
240
    version = NFC_getFirmwareVersion();
241
    while (!version.IC) {
241
    while (!version.IC) {
Line 371... Line 371...
371
    I2C_Init(); // Initialize the I2C handler code
371
    I2C_Init(); // Initialize the I2C handler code
372
    LED_Init(); // Initialize the LED backpack (uses I2C);
372
    LED_Init(); // Initialize the LED backpack (uses I2C);
373
 
373
 
374
    I2C_Configure_Master(I2C_400KHZ);
374
    I2C_Configure_Master(I2C_400KHZ);
375
 
375
 
376
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
376
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
377
    interrupt_init(); // Initialize the interrupt priorities
377
    Interrupt_Init(); // Initialize the interrupt priorities
378
 
378
 
379
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
379
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
380
 
380
 
381
    LED_Start();
381
    LED_Start();
382
    LED_writeDigitNum(0, 1, 1);
382
    LED_writeDigitNum(0, 1, 1);
Line 423... Line 423...
423
    ANCON1 = 0x1F;
423
    ANCON1 = 0x1F;
424
 
424
 
425
    UART1_Init(); // Initialize the UART handler code
425
    UART1_Init(); // Initialize the UART handler code
426
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
426
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
427
 
427
 
428
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
428
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
429
    interrupt_init(); // Initialize the interrupt priorities
429
    Interrupt_Init(); // Initialize the interrupt priorities
430
 
430
 
431
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
431
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
432
 
432
 
433
    while (1) {
433
    while (1) {
434
 
434
 
Line 468... Line 468...
468
 
468
 
469
    UART1_Init(); // Initialize the UART handler code
469
    UART1_Init(); // Initialize the UART handler code
470
    SPI2_Init(SPI2_FOSC_4); // Initialize the SPI module
470
    SPI2_Init(SPI2_FOSC_4); // Initialize the SPI module
471
    SSD1306_Init(); // Initialize the OLED code
471
    SSD1306_Init(); // Initialize the OLED code
472
 
472
 
473
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
473
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
474
    interrupt_init(); // Initialize the interrupt priorities
474
    Interrupt_Init(); // Initialize the interrupt priorities
475
 
475
 
476
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
476
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
477
 
477
 
478
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
478
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
479
 
479
 
Line 584... Line 584...
584
 
584
 
585
    UART1_Init(); // Initialize the UART handler code
585
    UART1_Init(); // Initialize the UART handler code
586
    SPI2_Init(SPI2_FOSC_64); // Initialize the SPI module
586
    SPI2_Init(SPI2_FOSC_64); // Initialize the SPI module
587
    SSD1331_Init(); // Initialize the OLED code
587
    SSD1331_Init(); // Initialize the OLED code
588
 
588
 
589
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
589
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
590
    interrupt_init(); // Initialize the interrupt priorities
590
    Interrupt_Init(); // Initialize the interrupt priorities
591
 
591
 
592
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
592
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
593
 
593
 
594
    SSD1331_Begin();
594
    SSD1331_Begin();
595
    
595
    
Line 718... Line 718...
718
    ADC_Init(ADC_TAD_20, ADC_FOSC_64);
718
    ADC_Init(ADC_TAD_20, ADC_FOSC_64);
719
 
719
 
720
    //    I2C_Configure_Master(I2C_400KHZ);
720
    //    I2C_Configure_Master(I2C_400KHZ);
721
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
721
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
722
 
722
 
723
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
723
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
724
    interrupt_init(); // Initialize the interrupt priorities
724
    Interrupt_Init(); // Initialize the interrupt priorities
725
 
725
 
726
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
726
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
727
 
727
 
728
    memset(buffer, 0, 60);
728
    memset(buffer, 0, 60);
729
    SSD1306_Clear_Display();
729
    SSD1306_Clear_Display();
Line 777... Line 777...
777
    ANCON1 = 0x1F;
777
    ANCON1 = 0x1F;
778
 
778
 
779
    UART1_Init(); // Initialize the UART handler code
779
    UART1_Init(); // Initialize the UART handler code
780
    XBee_Init();
780
    XBee_Init();
781
 
781
 
782
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
782
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
783
    interrupt_init(); // Initialize the interrupt priorities
783
    Interrupt_Init(); // Initialize the interrupt priorities
784
 
784
 
785
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
785
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
786
 
786
 
787
    while (1) {
787
    while (1) {
788
 
788
 
Line 937... Line 937...
937
    SPI2_Init(SPI2_FOSC_4);
937
    SPI2_Init(SPI2_FOSC_4);
938
    SSD1306_Init();
938
    SSD1306_Init();
939
 
939
 
940
    I2C_Configure_Master(I2C_400KHZ);
940
    I2C_Configure_Master(I2C_400KHZ);
941
 
941
 
942
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
942
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
943
    interrupt_init(); // Initialize the interrupt priorities
943
    Interrupt_Init(); // Initialize the interrupt priorities
944
 
944
 
945
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
945
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
946
 
946
 
947
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
947
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
948
    memset(cardData, 0, 24);
948
    memset(cardData, 0, 24);
Line 1023... Line 1023...
1023
    ANCON0 = 0xF8;
1023
    ANCON0 = 0xF8;
1024
    ANCON1 = 0x1F;
1024
    ANCON1 = 0x1F;
1025
    
1025
    
1026
    Timer1_Init();
1026
    Timer1_Init();
1027
 
1027
 
1028
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
1028
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1029
    interrupt_init(); // Initialize the interrupt priorities
1029
    Interrupt_Init(); // Initialize the interrupt priorities
1030
 
1030
 
1031
    LED_BLUE_TRIS = 0;
1031
    LED_BLUE_TRIS = 0;
1032
    LED_RED_TRIS = 0;
1032
    LED_RED_TRIS = 0;
1033
    
1033
    
1034
    Timer1_Enable();
1034
    Timer1_Enable();
Line 1057... Line 1057...
1057
    I2C_Init();
1057
    I2C_Init();
1058
    LUX_Init(TSL2561_ADDR_FLOAT);
1058
    LUX_Init(TSL2561_ADDR_FLOAT);
1059
    
1059
    
1060
    I2C_Configure_Master(I2C_100KHZ);
1060
    I2C_Configure_Master(I2C_100KHZ);
1061
 
1061
 
1062
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
1062
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1063
    interrupt_init(); // Initialize the interrupt priorities
1063
    Interrupt_Init(); // Initialize the interrupt priorities
1064
 
1064
 
1065
    LUX_Begin();
1065
    LUX_Begin();
1066
    
1066
    
1067
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
1067
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
1068
    LUX_SetGain(TSL2561_GAIN_0X);   // set no gain (for bright situtations)
1068
    LUX_SetGain(TSL2561_GAIN_0X);   // set no gain (for bright situtations)
Line 1106... Line 1106...
1106
    ANCON1 = 0x1F;
1106
    ANCON1 = 0x1F;
1107
 
1107
 
1108
//    UART1_Init();
1108
//    UART1_Init();
1109
    NHD_Init();
1109
    NHD_Init();
1110
 
1110
 
1111
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
1111
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1112
    interrupt_init(); // Initialize the interrupt priorities
1112
    Interrupt_Init(); // Initialize the interrupt priorities
1113
 
1113
 
1114
    NHD_Begin(16, 2);
1114
    NHD_Begin(16, 2);
1115
    
1115
    
1116
    NHD_Write_String("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do");
1116
    NHD_Write_String("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do");
1117
    NHD_Set_Cursor(0,1);
1117
    NHD_Set_Cursor(0,1);
Line 1140... Line 1140...
1140
    I2C_Init();
1140
    I2C_Init();
1141
    BMP_Init();
1141
    BMP_Init();
1142
            
1142
            
1143
    I2C_Configure_Master(I2C_100KHZ);
1143
    I2C_Configure_Master(I2C_100KHZ);
1144
 
1144
 
1145
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
1145
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1146
    interrupt_init(); // Initialize the interrupt priorities
1146
    Interrupt_Init(); // Initialize the interrupt priorities
1147
 
1147
 
1148
    BMP_Begin(BMP085_ULTRAHIGHRES);
1148
    BMP_Begin(BMP085_ULTRAHIGHRES);
1149
 
1149
 
1150
    while (1) {
1150
    while (1) {
1151
        DBG_PRINT_MAIN("Temp: ");
1151
        DBG_PRINT_MAIN("Temp: ");
Line 1184... Line 1184...
1184
    LUX_Init(TSL2561_ADDR_FLOAT);
1184
    LUX_Init(TSL2561_ADDR_FLOAT);
1185
 
1185
 
1186
    I2C_Configure_Master(I2C_400KHZ);
1186
    I2C_Configure_Master(I2C_400KHZ);
1187
    
1187
    
1188
 
1188
 
1189
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
1189
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1190
    interrupt_init(); // Initialize the interrupt priorities
1190
    Interrupt_Init(); // Initialize the interrupt priorities
1191
 
1191
 
1192
    NHD_Begin(16, 2);
1192
    NHD_Begin(16, 2);
1193
    
1193
    
1194
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
1194
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
1195
//    LUX_SetGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
1195
//    LUX_SetGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
1196
    LUX_SetGain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
1196
    LUX_SetGain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
1197
 
1197
 
1198
    // Changing the integration time gives you a longer time over which to sense light
1198
    // Changing the integration time gives you a longer time over which to sense light
1199
    // longer timelines are slower, but are good in very low light situtations!
1199
    // longer timelines are slower, but are good in very low light situtations!
1200
    LUX_SetTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
1200
    LUX_SetTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
1201
    //    LUX_SetTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
1201
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
1202
    //    LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
1202
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
1203
 
1203
 
1204
    while (1) {
1204
    while (1) {
1205
        lum = LUX_GetFullLuminosity();
1205
        lum = LUX_GetFullLuminosity();
1206
        ir = lum >> 16;
1206
        ir = lum >> 16;
1207
        full = lum & 0xFFFF;
1207
        full = lum & 0xFFFF;
1208
//        NHD_Clear();
-
 
1209
        NHD_Set_Cursor(0, 0);
1208
        NHD_Set_Cursor(0, 0);
1210
        NHD_Write_String("I: %d ", ir);
1209
        NHD_Write_String("I: %d ", ir);
1211
        NHD_Write_String("V: %d        ", full - ir);
1210
        NHD_Write_String("V: %d        ", full - ir);
1212
        NHD_Set_Cursor(0, 1);
1211
        NHD_Set_Cursor(0, 1);
1213
        NHD_Write_String("Lux: %ld        ", LUX_CalculateLux(full, ir));
1212
        NHD_Write_String("Lux: %ld        ", LUX_CalculateLux(full, ir));