Subversion Repositories Code-Repo

Rev

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

Rev 160 Rev 161
Line 700... Line 700...
700
    sprintf(output, "\r\nBegin Program\r\n");
700
    sprintf(output, "\r\nBegin Program\r\n");
701
    DBG_PRINT_MAIN(output, strlen(output));
701
    DBG_PRINT_MAIN(output, strlen(output));
702
 
702
 
703
    DS3231_Begin();
703
    DS3231_Begin();
704
    // Sec, Min, Hour, DOW, Day, Month, Year, Mil Time, AM/PM
704
    // Sec, Min, Hour, DOW, Day, Month, Year, Mil Time, AM/PM
705
//    DS3231_Set_Time(30, 44, 12, 5, 4, 1, 13, 0, 0);
705
    DS3231_Set_Time(00, 59, 7, 5, 18, 1, 13, 0, 0);
706
 
706
 
707
    char sec, min, hour, day, date, month, year, h_mil, h_am_pm;
707
    char sec, min, hour, day, date, month, year, h_mil, h_am_pm;
708
    while (1) {
708
    while (1) {
709
        DS3231_Get_Time(&sec, &min, &hour, &day, &date, &month, &year, &h_mil, &h_am_pm);
709
        DS3231_Get_Time(&sec, &min, &hour, &day, &date, &month, &year, &h_mil, &h_am_pm);
710
        sprintf(output, "%02d:%02d:%02d %s %s - %d/%d/%d (%d)\r\n", hour, min, sec, (h_am_pm) ? "PM" : "AM",
710
        sprintf(output, "%02d:%02d:%02d %s %s - %d/%d/%d (%d)\r\n", hour, min, sec, (h_am_pm) ? "PM" : "AM",
Line 1312... Line 1312...
1312
 
1312
 
1313
        Delay10KTCYx(100);
1313
        Delay10KTCYx(100);
1314
    }
1314
    }
1315
}
1315
}
1316
// </editor-fold>
1316
// </editor-fold>
-
 
1317
#elif defined(_TEST_AHRS)
-
 
1318
// <editor-fold defaultstate="collapsed" desc="_TEST_AHRS">
-
 
1319
void main(void) {
-
 
1320
    char output[64];
-
 
1321
 
-
 
1322
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
-
 
1323
    ANCON0 = 0xF8;
-
 
1324
    ANCON1 = 0x1F;
-
 
1325
 
-
 
1326
    UART_DATA uart_data;
-
 
1327
    UART1_Init(&uart_data);
-
 
1328
    I2C_DATA i2c_data;
-
 
1329
    I2C_Init(&i2c_data);
-
 
1330
    L3G_DATA gyro_data;
-
 
1331
    L3G_Init(&gyro_data, L3GD20_DEVICE, L3G_SA0_HIGH);
-
 
1332
    LSM303_DATA acc_data;
-
 
1333
    LSM303_Init(&acc_data, LSM303DLHC_DEVICE, ACC_ADDRESS_SA0_A_LOW);
-
 
1334
 
-
 
1335
    I2C_Configure_Master(I2C_100KHZ);
-
 
1336
 
-
 
1337
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
1338
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
1339
 
-
 
1340
    sprintf(output, "\r\nBegin Program\r\n");
-
 
1341
    DBG_PRINT_MAIN(output, strlen(output));
-
 
1342
 
-
 
1343
    L3G_Begin();
-
 
1344
    LSM303_Begin();
-
 
1345
    int a_x, a_y, a_z, m_x, m_y, m_z, g_x, g_y, g_z;
-
 
1346
    while (1) {
-
 
1347
        L3G_Read(&g_x, &g_y, &g_z);
-
 
1348
        LSM303_Read_Acc(&a_x, &a_y, &a_z);
-
 
1349
        LSM303_Read_Mag(&m_x, &m_y, &m_z);
-
 
1350
        sprintf(output, "GAM:%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",
-
 
1351
                g_x,g_y,g_z,a_x,a_y,a_z,m_x,m_y,m_z);
-
 
1352
        DBG_PRINT_MAIN(output, strlen(output));
-
 
1353
 
-
 
1354
        Delay10KTCYx(255);
-
 
1355
    }
-
 
1356
}
-
 
1357
// </editor-fold>
1317
#elif defined(_TEST_XBEE)
1358
#elif defined(_TEST_XBEE)
1318
// <editor-fold defaultstate="collapsed" desc="_TEST_XBEE">
1359
// <editor-fold defaultstate="collapsed" desc="_TEST_XBEE">
1319
void main(void) {
1360
void main(void) {
1320
    char buffer[100];
1361
    char buffer[100];
1321
 
1362
 
Line 1486... Line 1527...
1486
    }
1527
    }
1487
}
1528
}
1488
// </editor-fold>
1529
// </editor-fold>
1489
#else
1530
#else
1490
int main() {
1531
int main() {
-
 
1532
    char output[64];
-
 
1533
 
-
 
1534
    // Set all ports as digial I/O
-
 
1535
    ANCON0 = 0xFF;
-
 
1536
    ANCON1 = 0x1F;
-
 
1537
 
-
 
1538
    // NFC stuff
-
 
1539
    NFC_FIRMWARE_VERSION version;
-
 
1540
    NFC_TargetDataMiFare cardData[2];
-
 
1541
    NFC_TargetDataMiFare cardData_prev[2];
-
 
1542
 
-
 
1543
    I2C_DATA i2c_data;
-
 
1544
    I2C_Init(&i2c_data);
-
 
1545
    LED_DATA led_data;
-
 
1546
    LED_Init(&led_data);
-
 
1547
    OLED_CHAR_DATA oled_data;
-
 
1548
    NHD_Init(&oled_data);
-
 
1549
    TSL2561_DATA lux_data;
-
 
1550
    LUX_Init(&lux_data, TSL2561_ADDR_FLOAT);
-
 
1551
    NFC_DATA nfc_data;
-
 
1552
    NFC_Init(&nfc_data);
-
 
1553
    SPI_DATA spi_data;
-
 
1554
    SPI2_Init(&spi_data, SPI2_FOSC_4);
-
 
1555
    SSD1306_DATA ssd1306_data;
-
 
1556
    SSD1306_Init(&ssd1306_data);
-
 
1557
 
-
 
1558
    I2C_Configure_Master(I2C_400KHZ);
-
 
1559
 
-
 
1560
    Interrupt_Init(); // Initialize the interrupt priorities
-
 
1561
    Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
-
 
1562
 
-
 
1563
    LED_Start();
-
 
1564
    LED_Draw_Colon(1);
-
 
1565
    NHD_Begin(16, 2);
-
 
1566
    DS3231_Begin();
-
 
1567
 
-
 
1568
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
-
 
1569
//    LUX_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
-
 
1570
    LUX_Set_Gain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
-
 
1571
 
-
 
1572
    // Changing the integration time gives you a longer time over which to sense light
-
 
1573
    // longer timelines are slower, but are good in very low light situtations!
-
 
1574
    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
-
 
1575
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
-
 
1576
//    LUX_Set_Timing(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
-
 
1577
 
-
 
1578
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
-
 
1579
    memset(cardData, 0, 24);
-
 
1580
    memset(cardData_prev, 0, 24);
-
 
1581
    SSD1306_Clear_Display();
-
 
1582
    SSD1306_Set_Rotation(0);
-
 
1583
    SSD1306_Set_Cursor(0, 0);
1491
    
1584
    
-
 
1585
    char sec, min, hour, day, date, month, year, h_mil, h_am_pm;
-
 
1586
    int time;
-
 
1587
 
-
 
1588
    version = NFC_Get_Firmware_Version();
-
 
1589
    while (!version.IC) {
-
 
1590
        sprintf(output, "Waiting for NFC board..\n");
-
 
1591
        SSD1306_Write_String(output, strlen(output));
-
 
1592
        SSD1306_Display();
-
 
1593
        Delay10KTCYx(255);
-
 
1594
        version = NFC_Get_Firmware_Version();
-
 
1595
    }
-
 
1596
    sprintf(output, "PN5%X Ver. %d.%d\n", version.IC, version.Ver, version.Rev);
-
 
1597
    SSD1306_Write_String(output, strlen(output));
-
 
1598
    SSD1306_Display();
-
 
1599
    NFC_SAMConfig();
-
 
1600
 
-
 
1601
    while (1) {
-
 
1602
        // Time to LED backpack
-
 
1603
        DS3231_Get_Time(&sec, &min, &hour, &day, &date, &month, &year, &h_mil, &h_am_pm);
-
 
1604
        time = hour * 100 + min;
-
 
1605
        LED_Write_Num(time);
-
 
1606
 
-
 
1607
        // Lux to Character OLED
-
 
1608
        unsigned long lum = LUX_Get_Full_Luminosity();
-
 
1609
        unsigned int ir = lum >> 16;
-
 
1610
        unsigned int full = lum & 0xFFFF;
-
 
1611
        NHD_Set_Cursor(0, 0);
-
 
1612
        sprintf(output, "I: %d ", ir);
-
 
1613
        NHD_Write_String(output, strlen(output));
-
 
1614
        sprintf(output, "V: %d        ", full - ir);
-
 
1615
        NHD_Write_String(output, strlen(output));
-
 
1616
        NHD_Set_Cursor(0, 1);
-
 
1617
        sprintf(output, "Lux: %ld        ", LUX_Calculate_Lux(full, ir));
-
 
1618
        NHD_Write_String(output, strlen(output));
-
 
1619
 
-
 
1620
        // NFC Query
-
 
1621
        char length = NFC_Poll_Targets(1, 1, cardData);
-
 
1622
        if (!length) {
-
 
1623
            memset(cardData_prev, 0, 24);
-
 
1624
        } else if (length == 1) {
-
 
1625
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
-
 
1626
                // Do nothing
-
 
1627
            } else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0) {
-
 
1628
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
-
 
1629
            } else {
-
 
1630
                sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
-
 
1631
                SSD1306_Write_String(output, strlen(output));
-
 
1632
                SSD1306_Display();
-
 
1633
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
-
 
1634
            }
-
 
1635
            memset(&cardData_prev[1], 0, 12);
-
 
1636
        } else if (length == 2) {
-
 
1637
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0 &&
-
 
1638
                    memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
-
 
1639
                // Do nothing
-
 
1640
            } else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0 &&
-
 
1641
                    memcmp(&cardData[1].NFCID, &cardData_prev[0].NFCID, cardData[1].NFCID_LEN) == 0) {
-
 
1642
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
-
 
1643
                memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
-
 
1644
            } else if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
-
 
1645
                // First card matched
-
 
1646
                sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
-
 
1647
                SSD1306_Write_String(output, strlen(output));
-
 
1648
                SSD1306_Display();
-
 
1649
                memcpy(&cardData_prev[1], (const char *) &cardData[1], 12);
-
 
1650
            } else if (memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
-
 
1651
                // Second card matched
-
 
1652
                sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
-
 
1653
                SSD1306_Write_String(output, strlen(output));
-
 
1654
                SSD1306_Display();
-
 
1655
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
-
 
1656
            } else {
-
 
1657
                // No match
-
 
1658
                sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
-
 
1659
                SSD1306_Write_String(output, strlen(output));
-
 
1660
                SSD1306_Display();
-
 
1661
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
-
 
1662
                sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
-
 
1663
                SSD1306_Write_String(output, strlen(output));
-
 
1664
                SSD1306_Display();
-
 
1665
                memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
-
 
1666
            }
-
 
1667
        }
-
 
1668
 
-
 
1669
 
-
 
1670
        Delay10KTCYx(100);
-
 
1671
    }
1492
}
1672
}
1493
#endif
1673
#endif
1494
1674