Subversion Repositories Code-Repo

Rev

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

Rev 151 Rev 154
Line 235... Line 235...
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_Get_Firmware_Version();
241
    while (!version.IC) {
241
    while (!version.IC) {
242
        DBG_PRINT_MAIN("Waiting for NFC board..\r\n");
242
        DBG_PRINT_MAIN("Waiting for NFC board..\r\n");
243
        Delay10KTCYx(3);
243
        Delay10KTCYx(3);
244
        version = NFC_getFirmwareVersion();
244
        version = NFC_Get_Firmware_Version();
245
    }
245
    }
246
    DBG_PRINT_MAIN("Found chip PN5%X\r\n", version.IC);
246
    DBG_PRINT_MAIN("Found chip PN5%X\r\n", version.IC);
247
    DBG_PRINT_MAIN("Firmware ver. %d.%d\r\n", version.Ver, version.Rev);
247
    DBG_PRINT_MAIN("Firmware ver. %d.%d\r\n", version.Ver, version.Rev);
248
    NFC_SAMConfig();
248
    NFC_SAMConfig();
249
 
249
 
Line 290... Line 290...
290
        //                DBG_PRINT_MAIN("\r\n");
290
        //                DBG_PRINT_MAIN("\r\n");
291
        //            }
291
        //            }
292
        //        }
292
        //        }
293
 
293
 
294
        // This query will not wait for a detection before responding
294
        // This query will not wait for a detection before responding
295
        length = NFC_pollTargets(1, 1, cardData);
295
        length = NFC_Poll_Targets(1, 1, cardData);
296
        if (!length) {
296
        if (!length) {
297
            memset(cardData_prev, 0, 24);
297
            memset(cardData_prev, 0, 24);
298
        } else if (length == 1) {
298
        } else if (length == 1) {
299
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
299
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
300
                // Do nothing
300
                // Do nothing
Line 377... Line 377...
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_Write_Digit_Num(0, 1, 1);
383
    LED_writeDigitNum(1, 2, 0);
383
    LED_Write_Digit_Num(1, 2, 0);
384
    LED_writeDigitNum(2, 3, 0);
384
    LED_Write_Digit_Num(2, 3, 0);
385
    LED_writeDigitNum(3, 4, 0);
385
    LED_Write_Digit_Num(3, 4, 0);
386
    LED_writeDisplay();
386
    LED_Write_Display();
387
    for (i = 0; i < 15; i++) {
387
    for (i = 0; i < 15; i++) {
388
        LED_setBrightness(15 - i);
388
        LED_Set_Brightness(15 - i);
389
        Delay10KTCYx(100);
389
        Delay10KTCYx(100);
390
    }
390
    }
391
    for (i = 0; i < 15; i++) {
391
    for (i = 0; i < 15; i++) {
392
        LED_setBrightness(i);
392
        LED_Set_Brightness(i);
393
        Delay10KTCYx(100);
393
        Delay10KTCYx(100);
394
    }
394
    }
395
    LED_blinkRate(HT16K33_BLINK_OFF);
395
    LED_Blink_Rate(HT16K33_BLINK_OFF);
396
 
396
 
397
    while (1) {
397
    while (1) {
398
        LED_writeNum(counter);
398
        LED_Write_Num(counter);
399
        counter++;
399
        counter++;
400
        if (counter > 9999)
400
        if (counter > 9999)
401
            counter = 0;
401
            counter = 0;
402
 
402
 
403
        //        Delay10KTCYx(255);
403
        //        Delay10KTCYx(255);
Line 838... Line 838...
838
                    }
838
                    }
839
                    break;
839
                    break;
840
                case XBEE_RX_DATA_PACKET:
840
                case XBEE_RX_DATA_PACKET:
841
                    DBG_PRINT_MAIN("XBEE: parsing recieved data recieved frame\r\n");
841
                    DBG_PRINT_MAIN("XBEE: parsing recieved data recieved frame\r\n");
842
                    rx_data_frame = (void *) buffer;
842
                    rx_data_frame = (void *) buffer;
843
                    XBee_ConvertEndian64(&(rx_data_frame->source_64));
843
                    XBee_Convert_Endian_64(&(rx_data_frame->source_64));
844
                    XBee_ConvertEndian16(&(rx_data_frame->source_16));
844
                    XBee_Convert_Endian_16(&(rx_data_frame->source_16));
845
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
845
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
846
                            rx_data_frame->source_64.UPPER_32.long_value, \\
846
                            rx_data_frame->source_64.UPPER_32.long_value, \\
847
                            rx_data_frame->source_64.LOWER_32.long_value, \\
847
                            rx_data_frame->source_64.LOWER_32.long_value, \\
848
                            rx_data_frame->source_16.INT_16.int_value, \\
848
                            rx_data_frame->source_16.INT_16.int_value, \\
849
                            rx_data_frame->recieve_options);
849
                            rx_data_frame->recieve_options);
Line 854... Line 854...
854
                    DBG_PRINT_MAIN("\r\n");
854
                    DBG_PRINT_MAIN("\r\n");
855
                    break;
855
                    break;
856
                case XBEE_RX_DATA_TX_STATUS:
856
                case XBEE_RX_DATA_TX_STATUS:
857
                    DBG_PRINT_MAIN("XBEE: parsing recieved TX status frame\r\n");
857
                    DBG_PRINT_MAIN("XBEE: parsing recieved TX status frame\r\n");
858
                    rx_tx_status_frame = (void *) buffer;
858
                    rx_tx_status_frame = (void *) buffer;
859
                    XBee_ConvertEndian16(&(rx_tx_status_frame->destination_16));
859
                    XBee_Convert_Endian_16(&(rx_tx_status_frame->destination_16));
860
                    DBG_PRINT_MAIN("Frame ID: %u  Destination 16: %04X\r\n", \\
860
                    DBG_PRINT_MAIN("Frame ID: %u  Destination 16: %04X\r\n", \\
861
                            rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
861
                            rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
862
                    DBG_PRINT_MAIN("Transmit Retry Count: %02X  Delivery Status: %02X  Discovery Status: %02X\r\n", \\
862
                    DBG_PRINT_MAIN("Transmit Retry Count: %02X  Delivery Status: %02X  Discovery Status: %02X\r\n", \\
863
                            rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
863
                            rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
864
                            rx_tx_status_frame->discovery_status);
864
                            rx_tx_status_frame->discovery_status);
Line 877... Line 877...
877
                    DBG_PRINT_MAIN("XBEE: parsing recieved route record frame\r\n");
877
                    DBG_PRINT_MAIN("XBEE: parsing recieved route record frame\r\n");
878
                    break;
878
                    break;
879
                case XBEE_RX_NODE_IDENTIFICATION:
879
                case XBEE_RX_NODE_IDENTIFICATION:
880
                    DBG_PRINT_MAIN("XBEE: parsing recieved node identification frame\r\n");
880
                    DBG_PRINT_MAIN("XBEE: parsing recieved node identification frame\r\n");
881
                    rx_node_ident_frame = (void *) buffer;
881
                    rx_node_ident_frame = (void *) buffer;
882
                    XBee_ConvertEndian64(&(rx_node_ident_frame->source_64));
882
                    XBee_Convert_Endian_64(&(rx_node_ident_frame->source_64));
883
                    XBee_ConvertEndian16(&(rx_node_ident_frame->source_16));
883
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->source_16));
884
                    XBee_ConvertEndian64(&(rx_node_ident_frame->remote_64));
884
                    XBee_Convert_Endian_64(&(rx_node_ident_frame->remote_64));
885
                    XBee_ConvertEndian16(&(rx_node_ident_frame->remote_16));
885
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->remote_16));
886
                    XBee_ConvertEndian16(&(rx_node_ident_frame->parent_16));
886
                    XBee_Convert_Endian_16(&(rx_node_ident_frame->parent_16));
887
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
887
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
888
                            rx_node_ident_frame->source_64.UPPER_32.long_value, \\
888
                            rx_node_ident_frame->source_64.UPPER_32.long_value, \\
889
                            rx_node_ident_frame->source_64.LOWER_32.long_value, \\
889
                            rx_node_ident_frame->source_64.LOWER_32.long_value, \\
890
                            rx_node_ident_frame->source_16.INT_16.int_value, \\
890
                            rx_node_ident_frame->source_16.INT_16.int_value, \\
891
                            rx_node_ident_frame->recieve_options);
891
                            rx_node_ident_frame->recieve_options);
Line 949... Line 949...
949
    memset(cardData_prev, 0, 24);
949
    memset(cardData_prev, 0, 24);
950
    SSD1306_Clear_Display();
950
    SSD1306_Clear_Display();
951
    SSD1306_Set_Rotation(0);
951
    SSD1306_Set_Rotation(0);
952
    SSD1306_Set_Cursor(0, 0);
952
    SSD1306_Set_Cursor(0, 0);
953
 
953
 
954
    version = NFC_getFirmwareVersion();
954
    version = NFC_Get_Firmware_Version();
955
    while (!version.IC) {
955
    while (!version.IC) {
956
        SSD1306_Write_String("Waiting for NFC board..\r");
956
        SSD1306_Write_String("Waiting for NFC board..\r");
957
        SSD1306_Display();
957
        SSD1306_Display();
958
        Delay10KTCYx(3);
958
        Delay10KTCYx(3);
959
        version = NFC_getFirmwareVersion();
959
        version = NFC_Get_Firmware_Version();
960
    }
960
    }
961
    SSD1306_Write_String("PN5%X Ver. %d.%d\r", version.IC, version.Ver, version.Rev);
961
    SSD1306_Write_String("PN5%X Ver. %d.%d\r", version.IC, version.Ver, version.Rev);
962
    SSD1306_Display();
962
    SSD1306_Display();
963
    NFC_SAMConfig();
963
    NFC_SAMConfig();
964
 
964
 
965
    while (1) {
965
    while (1) {
966
 
966
 
967
        // This query will not wait for a detection before responding
967
        // This query will not wait for a detection before responding
968
        length = NFC_pollTargets(1, 1, cardData);
968
        length = NFC_Poll_Targets(1, 1, cardData);
969
        if (!length) {
969
        if (!length) {
970
            memset(cardData_prev, 0, 24);
970
            memset(cardData_prev, 0, 24);
971
        } else if (length == 1) {
971
        } else if (length == 1) {
972
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
972
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
973
                // Do nothing
973
                // Do nothing
Line 1063... Line 1063...
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_Set_Gain(TSL2561_GAIN_0X);   // set no gain (for bright situtations)
1069
//    LUX_SetGain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
1069
//    LUX_SetGain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
1070
 
1070
 
1071
    // Changing the integration time gives you a longer time over which to sense light
1071
    // Changing the integration time gives you a longer time over which to sense light
1072
    // longer timelines are slower, but are good in very low light situtations!
1072
    // longer timelines are slower, but are good in very low light situtations!
1073
    LUX_SetTiming(TSL2561_INTEGRATIONTIME_13MS);  // shortest integration time (bright light)
1073
    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS);  // shortest integration time (bright light)
1074
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
1074
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
1075
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
1075
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
1076
 
1076
 
1077
    while (1) {
1077
    while (1) {
1078
        lum = LUX_GetFullLuminosity();
1078
        lum = LUX_Get_Full_Luminosity();
1079
        ir = lum >> 16;
1079
        ir = lum >> 16;
1080
        full = lum & 0xFFFF;
1080
        full = lum & 0xFFFF;
1081
        DBG_PRINT_LUX("IR: %d\r\n", ir);
1081
        DBG_PRINT_LUX("IR: %d\r\n", ir);
1082
        DBG_PRINT_LUX("Visible: %d\r\n", full - ir);
1082
        DBG_PRINT_LUX("Visible: %d\r\n", full - ir);
1083
        DBG_PRINT_LUX("Full: %d\r\n", full);
1083
        DBG_PRINT_LUX("Full: %d\r\n", full);
1084
        DBG_PRINT_LUX("Lux: %ld\r\n\r\n", LUX_CalculateLux(full, ir));
1084
        DBG_PRINT_LUX("Lux: %ld\r\n\r\n", LUX_Calculate_Lux(full, ir));
1085
 
1085
 
1086
        Delay10KTCYx(255);
1086
        Delay10KTCYx(255);
1087
        Delay10KTCYx(255);
1087
        Delay10KTCYx(255);
1088
        Delay10KTCYx(255);
1088
        Delay10KTCYx(255);
1089
        Delay10KTCYx(255);
1089
        Delay10KTCYx(255);
Line 1182... Line 1182...
1182
    I2C_Init();
1182
    I2C_Init();
1183
    NHD_Init();
1183
    NHD_Init();
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
    
-
 
1188
 
1187
 
1189
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1188
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
1190
    Interrupt_Init(); // Initialize the interrupt priorities
1189
    Interrupt_Init(); // Initialize the interrupt priorities
1191
 
1190
 
1192
    NHD_Begin(16, 2);
1191
    NHD_Begin(16, 2);
1193
    
1192
    
1194
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
1193
    // 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)
1194
//    LUX_SetGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
1196
    LUX_SetGain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
1195
    LUX_Set_Gain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
1197
 
1196
 
1198
    // Changing the integration time gives you a longer time over which to sense light
1197
    // 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!
1198
    // longer timelines are slower, but are good in very low light situtations!
1200
    LUX_SetTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
1199
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
1201
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
1200
    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
1202
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
1201
//    LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
1203
 
1202
 
1204
    while (1) {
1203
    while (1) {
1205
        lum = LUX_GetFullLuminosity();
1204
        lum = LUX_Get_Full_Luminosity();
1206
        ir = lum >> 16;
1205
        ir = lum >> 16;
1207
        full = lum & 0xFFFF;
1206
        full = lum & 0xFFFF;
1208
        NHD_Set_Cursor(0, 0);
1207
        NHD_Set_Cursor(0, 0);
1209
        NHD_Write_String("I: %d ", ir);
1208
        NHD_Write_String("I: %d ", ir);
1210
        NHD_Write_String("V: %d        ", full - ir);
1209
        NHD_Write_String("V: %d        ", full - ir);
1211
        NHD_Set_Cursor(0, 1);
1210
        NHD_Set_Cursor(0, 1);
1212
        NHD_Write_String("Lux: %ld        ", LUX_CalculateLux(full, ir));
1211
        NHD_Write_String("Lux: %ld        ", LUX_Calculate_Lux(full, ir));
1213
 
1212
 
1214
        Delay10KTCYx(100);
1213
        Delay10KTCYx(100);
1215
    }
1214
    }
1216
}
1215
}
1217
#endif
1216
#endif