Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 148 → Rev 149

/PIC Stuff/PIC_27J13/defines.h
14,7 → 14,7
// Option to disable SPI MISO
#define SPI2_WRITE_ONLY
 
#define _DEBUG
//#define _DEBUG
//#define _TEST_UART
//#define _TEST_I2C_MASTER
//#define _TEST_I2C_SLAVE
28,7 → 28,7
//#define _TEST_NFC_TO_SSD1306_OLED
//#define _TEST_TIMER1_RTC
//#define _TEST_LUX
#define _TEST_OLED_CHAR
//#define _TEST_OLED_CHAR
 
// Enable or disable debug prints depending on project preprocessor (_DEBUG)
#ifdef _DEBUG
/PIC Stuff/PIC_27J13/main.c
1132,7 → 1132,9
!defined(_TEST_LUX) && !defined(_TEST_OLED_CHAR)
 
void main(void) {
 
unsigned int ir, full;
unsigned long lum;
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
1143,21 → 1145,41
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART1_Init();
Timer1_Init();
// UART1_Init();
I2C_Init();
NHD_Init();
LUX_Init(TSL2561_ADDR_FLOAT);
 
I2C_Configure_Master(I2C_400KHZ);
 
interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
interrupt_init(); // Initialize the interrupt priorities
 
LED_BLUE_TRIS = 0;
LED_RED_TRIS = 0;
NHD_Begin(16, 2);
Timer1_Enable();
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
// LUX_SetGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
LUX_SetGain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
 
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
LUX_SetTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
// LUX_SetTiming(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
// LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
 
while (1) {
lum = LUX_GetFullLuminosity();
ir = lum >> 16;
full = lum & 0xFFFF;
NHD_Clear();
NHD_Set_Cursor(0, 0);
NHD_Write_String("I: %d ", ir);
NHD_Write_String("V: %d", full - ir);
NHD_Set_Cursor(0, 1);
NHD_Write_String("Lux: %ld", LUX_CalculateLux(full, ir));
 
Delay10KTCYx(255);
}
}
#endif