Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 280 → Rev 281

/PIC Stuff/PICX_12F1840_Clock/main.c
1,7 → 1,9
#include <xc.h>
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
#include "NEOPIXEL.h"
#include "DS3231.h"
#include "TSL2561.h"
 
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
/* Config Register CONFIGL @ 0x8007 */
24,10 → 26,12
#pragma config LVP = OFF // High-voltage on MCLR/VPP must be used for programming
// </editor-fold>
 
I2C1_DATA i2c_data;
NEOPIXEL_DATA neopixel_data;
TSL2561_DATA tsl2561_data;
DS3231_TIME time;
 
int main() {
 
// Oscillator configuration (32Mhz HFINTOSC)
OSCCONbits.SCS = 0b00;
OSCCONbits.IRCF = 0b1110;
38,26 → 42,64
// Wait for HFINTOSC to be within 0.5% of target 32Mhz
while (!OSCSTATbits.HFIOFS);
 
// Interrupt_Enable();
Interrupt_Enable();
NeoPixel_Init(&neopixel_data);
I2C1_Init();
I2C1_Configure_Master(I2C_1MHZ);
 
for (char i = 0; i < 60; i++) {
if (i % 6 == 0)
NeoPixel_Set(i, RED);
else if (i % 6 == 1)
NeoPixel_Set(i, ORANGE);
else if (i % 6 == 2)
NeoPixel_Set(i, YELLOW);
else if (i % 6 == 3)
NeoPixel_Set(i, GREEN);
else if (i % 6 == 4)
NeoPixel_Set(i, BLUE);
else
NeoPixel_Set(i, PURPLE);
}
NeoPixel_Init();
NeoPixel_Offet(30);
 
DS3231_Init();
 
TSL2561_Init(TSL2561_ADDR_FLOAT);
 
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
TSL2561_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
// TSL2561_Set_Gain(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!
// TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
// TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
 
// uint16_t full, ir, vis;
 
while(1) {
// full = TSL2561_Get_Luminosity(0);
// ir = TSL2561_Get_Luminosity(1);
// vis = full - ir;
//
// NeoPixel_Clear();
// for (uint8_t i = 0; i < (vis >> 11); i++) {
// NeoPixel_Set(i, 0x10, 0x00, 0x00);
// }
// NeoPixel_Write_All();
//
// __delay_ms(100);
DS3231_Get_Time(&time);
NeoPixel_Clear();
 
// Draw markers
NeoPixel_Set(0, 0x10, 0x00, 0x00);
NeoPixel_Set(5, 0x08, 0x02, 0x00);
NeoPixel_Set(10, 0x08, 0x08, 0x00);
NeoPixel_Set(15, 0x00, 0x10, 0x00);
NeoPixel_Set(20, 0x00, 0x00, 0x10);
NeoPixel_Set(25, 0x08, 0x00, 0x08);
NeoPixel_Set(30, 0x10, 0x00, 0x00);
NeoPixel_Set(35, 0x08, 0x02, 0x00);
NeoPixel_Set(40, 0x08, 0x08, 0x00);
NeoPixel_Set(45, 0x00, 0x10, 0x00);
NeoPixel_Set(50, 0x00, 0x00, 0x10);
NeoPixel_Set(55, 0x08, 0x00, 0x08);
 
// Draw time
NeoPixel_Or((time.hour * 5) % 60, BLUE);
NeoPixel_Or(time.min, GREEN);
NeoPixel_Or(time.sec, RED);
NeoPixel_Write_All();
}
}