Subversion Repositories Code-Repo

Rev

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

Rev 148 Rev 149
Line 1130... Line 1130...
1130
    !defined(_TEST_ADC) && !defined(_TEST_XBEE) && \
1130
    !defined(_TEST_ADC) && !defined(_TEST_XBEE) && \
1131
    !defined(_TEST_NFC_TO_SSD1306_OLED) && !defined(_TEST_TIMER1_RTC) && \
1131
    !defined(_TEST_NFC_TO_SSD1306_OLED) && !defined(_TEST_TIMER1_RTC) && \
1132
    !defined(_TEST_LUX) && !defined(_TEST_OLED_CHAR)
1132
    !defined(_TEST_LUX) && !defined(_TEST_OLED_CHAR)
1133
 
1133
 
1134
void main(void) {
1134
void main(void) {
-
 
1135
    unsigned int ir, full;
-
 
1136
    unsigned long lum;
1135
 
1137
    
1136
    /* --------------------- Oscillator Configuration --------------------- */
1138
    /* --------------------- Oscillator Configuration --------------------- */
1137
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
1139
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
1138
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
1140
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
1139
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
1141
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
1140
    /* -------------------------------------------------------------------- */
1142
    /* -------------------------------------------------------------------- */
1141
 
1143
 
1142
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
1144
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
1143
    ANCON0 = 0xF8;
1145
    ANCON0 = 0xF8;
1144
    ANCON1 = 0x1F;
1146
    ANCON1 = 0x1F;
1145
 
1147
 
1146
    UART1_Init();
1148
//    UART1_Init();
-
 
1149
    I2C_Init();
1147
    Timer1_Init();
1150
    NHD_Init();
-
 
1151
    LUX_Init(TSL2561_ADDR_FLOAT);
-
 
1152
 
-
 
1153
    I2C_Configure_Master(I2C_400KHZ);
-
 
1154
    
1148
 
1155
 
1149
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
1156
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
1150
    interrupt_init(); // Initialize the interrupt priorities
1157
    interrupt_init(); // Initialize the interrupt priorities
1151
 
1158
 
1152
    LED_BLUE_TRIS = 0;
1159
    NHD_Begin(16, 2);
1153
    LED_RED_TRIS = 0;
-
 
1154
    
-
 
1155
    Timer1_Enable();
-
 
1156
    
1160
    
-
 
1161
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
-
 
1162
//    LUX_SetGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
1157
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
1163
    LUX_SetGain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
-
 
1164
 
-
 
1165
    // Changing the integration time gives you a longer time over which to sense light
-
 
1166
    // longer timelines are slower, but are good in very low light situtations!
-
 
1167
    LUX_SetTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
-
 
1168
    //    LUX_SetTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
-
 
1169
    //    LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
1158
 
1170
 
1159
    while (1) {
1171
    while (1) {
-
 
1172
        lum = LUX_GetFullLuminosity();
-
 
1173
        ir = lum >> 16;
-
 
1174
        full = lum & 0xFFFF;
-
 
1175
        NHD_Clear();
-
 
1176
        NHD_Set_Cursor(0, 0);
-
 
1177
        NHD_Write_String("I: %d ", ir);
-
 
1178
        NHD_Write_String("V: %d", full - ir);
-
 
1179
        NHD_Set_Cursor(0, 1);
-
 
1180
        NHD_Write_String("Lux: %ld", LUX_CalculateLux(full, ir));
1160
 
1181
 
-
 
1182
        Delay10KTCYx(255);
1161
    }
1183
    }
1162
}
1184
}
1163
#endif
1185
#endif