Subversion Repositories Code-Repo

Rev

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

Rev 280 Rev 281
Line 1... Line -...
1
#include <xc.h>
-
 
2
#include "defines.h"
1
#include "defines.h"
3
#include "INTERRUPTS.h"
2
#include "INTERRUPTS.h"
-
 
3
#include "I2C1.h"
4
#include "NEOPIXEL.h"
4
#include "NEOPIXEL.h"
-
 
5
#include "DS3231.h"
-
 
6
#include "TSL2561.h"
5
 
7
 
6
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
8
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
7
/* Config Register CONFIGL @ 0x8007 */
9
/* Config Register CONFIGL @ 0x8007 */
8
#pragma config CPD = OFF    // Data memory code protection is disabled
10
#pragma config CPD = OFF    // Data memory code protection is disabled
9
#pragma config BOREN = OFF  // Brown-out Reset disabled
11
#pragma config BOREN = OFF  // Brown-out Reset disabled
Line 22... Line 24...
22
#pragma config STVREN = OFF // Stack Overflow or Underflow will not cause a Reset
24
#pragma config STVREN = OFF // Stack Overflow or Underflow will not cause a Reset
23
#pragma config BORV = HI    // Brown-out Reset Voltage (Vbor), high trip point selected.
25
#pragma config BORV = HI    // Brown-out Reset Voltage (Vbor), high trip point selected.
24
#pragma config LVP = OFF    // High-voltage on MCLR/VPP must be used for programming
26
#pragma config LVP = OFF    // High-voltage on MCLR/VPP must be used for programming
25
// </editor-fold>
27
// </editor-fold>
26
 
28
 
-
 
29
I2C1_DATA i2c_data;
27
NEOPIXEL_DATA neopixel_data;
30
NEOPIXEL_DATA neopixel_data;
-
 
31
TSL2561_DATA tsl2561_data;
-
 
32
DS3231_TIME time;
28
 
33
 
29
int main() {
34
int main() {
30
 
-
 
31
    // Oscillator configuration (32Mhz HFINTOSC)
35
    // Oscillator configuration (32Mhz HFINTOSC)
32
    OSCCONbits.SCS = 0b00;
36
    OSCCONbits.SCS = 0b00;
33
    OSCCONbits.IRCF = 0b1110;
37
    OSCCONbits.IRCF = 0b1110;
34
    
38
    
35
    ANSELA = 0x00;  // All pins set to digital I/O
39
    ANSELA = 0x00;  // All pins set to digital I/O
36
    APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
40
    APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
37
 
41
 
38
    // Wait for HFINTOSC to be within 0.5% of target 32Mhz
42
    // Wait for HFINTOSC to be within 0.5% of target 32Mhz
39
    while (!OSCSTATbits.HFIOFS);
43
    while (!OSCSTATbits.HFIOFS);
40
 
44
 
41
//    Interrupt_Enable();
45
    Interrupt_Enable();
42
    
46
    
-
 
47
    I2C1_Init();
-
 
48
    I2C1_Configure_Master(I2C_1MHZ);
-
 
49
 
43
    NeoPixel_Init(&neopixel_data);
50
    NeoPixel_Init();
-
 
51
    NeoPixel_Offet(30);
-
 
52
 
-
 
53
    DS3231_Init();
-
 
54
 
-
 
55
    TSL2561_Init(TSL2561_ADDR_FLOAT);
-
 
56
 
-
 
57
    // You can change the gain on the fly, to adapt to brighter/dimmer light situations
-
 
58
    TSL2561_Set_Gain(TSL2561_GAIN_0X);   // set no gain (for bright situtations)
-
 
59
//    TSL2561_Set_Gain(TSL2561_GAIN_16X);  // set 16x gain (for dim situations)
-
 
60
 
-
 
61
    // Changing the integration time gives you a longer time over which to sense light
-
 
62
    // longer timelines are slower, but are good in very low light situtations!
-
 
63
//    TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_13MS);  // shortest integration time (bright light)
-
 
64
    TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium light)
-
 
65
//    TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim light)
-
 
66
 
-
 
67
//    uint16_t full, ir, vis;
44
 
68
 
45
    for (char i = 0; i < 60; i++) {
-
 
46
        if (i % 6 == 0)
-
 
47
            NeoPixel_Set(i, RED);
-
 
48
        else if (i % 6 == 1)
-
 
49
            NeoPixel_Set(i, ORANGE);
-
 
50
        else if (i % 6 == 2)
-
 
51
            NeoPixel_Set(i, YELLOW);
-
 
52
        else if (i % 6 == 3)
-
 
53
            NeoPixel_Set(i, GREEN);
-
 
54
        else if (i % 6 == 4)
-
 
55
            NeoPixel_Set(i, BLUE);
-
 
56
        else
-
 
57
            NeoPixel_Set(i, PURPLE);
-
 
58
    }
-
 
59
    
-
 
60
    while(1) {
69
    while(1) {
-
 
70
//        full = TSL2561_Get_Luminosity(0);
-
 
71
//        ir = TSL2561_Get_Luminosity(1);
-
 
72
//        vis = full - ir;
-
 
73
//
-
 
74
//        NeoPixel_Clear();
-
 
75
//        for (uint8_t i = 0; i < (vis >> 11); i++) {
-
 
76
//            NeoPixel_Set(i, 0x10, 0x00, 0x00);
-
 
77
//        }
-
 
78
//        NeoPixel_Write_All();
-
 
79
//
-
 
80
//        __delay_ms(100);
-
 
81
        
-
 
82
        DS3231_Get_Time(&time);
-
 
83
        NeoPixel_Clear();
-
 
84
 
-
 
85
        // Draw markers
-
 
86
        NeoPixel_Set(0, 0x10, 0x00, 0x00);
-
 
87
        NeoPixel_Set(5, 0x08, 0x02, 0x00);
-
 
88
        NeoPixel_Set(10, 0x08, 0x08, 0x00);
-
 
89
        NeoPixel_Set(15, 0x00, 0x10, 0x00);
-
 
90
        NeoPixel_Set(20, 0x00, 0x00, 0x10);
-
 
91
        NeoPixel_Set(25, 0x08, 0x00, 0x08);
-
 
92
        NeoPixel_Set(30, 0x10, 0x00, 0x00);
-
 
93
        NeoPixel_Set(35, 0x08, 0x02, 0x00);
-
 
94
        NeoPixel_Set(40, 0x08, 0x08, 0x00);
-
 
95
        NeoPixel_Set(45, 0x00, 0x10, 0x00);
-
 
96
        NeoPixel_Set(50, 0x00, 0x00, 0x10);
-
 
97
        NeoPixel_Set(55, 0x08, 0x00, 0x08);
-
 
98
 
-
 
99
        // Draw time
-
 
100
        NeoPixel_Or((time.hour * 5) % 60, BLUE);
-
 
101
        NeoPixel_Or(time.min, GREEN);
-
 
102
        NeoPixel_Or(time.sec, RED);
61
        NeoPixel_Write_All();
103
        NeoPixel_Write_All();
62
    }
104
    }
63
}
105
}