Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 281 → Rev 282

/PIC Stuff/PICX_12F1840_Clock/I2C1.c
6,6 → 6,9
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C1_Init(void) {
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
i2c_data.buffer_in_len = 0;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
22,11 → 25,6
 
// Setup the PIC to operate as a master.
void I2C1_Configure_Master(uint8_t speed) {
// i2c_data.operating_mode = I2C_MODE_MASTER;
 
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
/PIC Stuff/PICX_12F1840_Clock/NEOPIXEL.c
45,20 → 45,32
}
}
 
void NeoPixel_Set(uint8_t index, uint8_t R, uint8_t G, uint8_t B) {
void NeoPixel_Set(uint8_t index, uint8_t R, uint8_t G, uint8_t B, uint8_t multiplier) {
uint8_t i = ((index + neopixel_data.offset) % NEOPIXEL_LENGTH);
neopixel_data.values[(i * 3) + 0] = G;
neopixel_data.values[(i * 3) + 1] = R;
neopixel_data.values[(i * 3) + 2] = B;
if (G == 0)
neopixel_data.values[(i * 3) + 0] = 0;
else
neopixel_data.values[(i * 3) + 0] = (G * multiplier) - 1;
if (R == 0)
neopixel_data.values[(i * 3) + 1] = 0;
else
neopixel_data.values[(i * 3) + 1] = (R * multiplier) - 1;
if (B == 0)
neopixel_data.values[(i * 3) + 2] = 0;
else
neopixel_data.values[(i * 3) + 2] = (B * multiplier) - 1;
}
 
void NeoPixel_Or(uint8_t index, uint8_t R, uint8_t G, uint8_t B) {
void NeoPixel_Or(uint8_t index, uint8_t R, uint8_t G, uint8_t B, uint8_t multiplier) {
uint8_t i = ((index + neopixel_data.offset) % NEOPIXEL_LENGTH);
 
neopixel_data.values[(i * 3) + 0] |= G;
neopixel_data.values[(i * 3) + 1] |= R;
neopixel_data.values[(i * 3) + 2] |= B;
if (G != 0)
neopixel_data.values[(i * 3) + 0] |= (G * multiplier) - 1;
if (R != 0)
neopixel_data.values[(i * 3) + 1] |= (R * multiplier) - 1;
if (B != 0)
neopixel_data.values[(i * 3) + 2] |= (B * multiplier) - 1;
}
 
void NeoPixel_Write_All(void) {
/PIC Stuff/PICX_12F1840_Clock/NEOPIXEL.h
6,16 → 6,16
#define NEOPIXEL_LOGIC_1 0b00000110
#define NEOPIXEL_LOGIC_0 0b00000011
 
// Color Definitions
// Color Definitions (base of 16 levels)
#define CLEAR 0x00,0x00,0x00
#define RED 0xFF,0x00,0x00
#define ORANGE 0x8F,0x20,0x00
#define YELLOW 0x8F,0x8F,0x00
#define GREEN 0x00,0xFF,0x00
#define TEAL 0x00,0x8F,0x40
#define BLUE 0x00,0x00,0xFF
#define PURPLE 0x8F,0x00,0x8F
#define WHITE 0x6F,0x6F,0x6F
#define RED 0x10,0x00,0x00
#define ORANGE 0x08,0x02,0x00
#define YELLOW 0x08,0x08,0x00
#define GREEN 0x00,0x10,0x00
#define TEAL 0x00,0x08,0x04
#define BLUE 0x00,0x00,0x10
#define PURPLE 0x08,0x00,0x08
#define WHITE 0x08,0x08,0x08
 
typedef struct {
uint8_t values[NEOPIXEL_LENGTH * 3];
25,8 → 25,8
void NeoPixel_Init(void);
void NeoPixel_Offet(uint8_t value);
void NeoPixel_Clear(void);
void NeoPixel_Set(uint8_t index, uint8_t R, uint8_t G, uint8_t B);
void NeoPixel_Or(uint8_t index, uint8_t R, uint8_t G, uint8_t B);
void NeoPixel_Set(uint8_t index, uint8_t R, uint8_t G, uint8_t B, uint8_t multiplier);
void NeoPixel_Or(uint8_t index, uint8_t R, uint8_t G, uint8_t B, uint8_t multiplier);
void NeoPixel_Write_All(void);
void NeoPixel_Write_One(uint8_t value);
 
/PIC Stuff/PICX_12F1840_Clock/TSL2561.c
182,10 → 182,10
 
if (channel == 0) {
// Reads two byte value from channel 0 (visible + infrared)
return TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
return TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
} else if (channel == 1) {
// Reads two byte value from channel 1 (infrared)
return TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
return TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
}
 
TSL2561_Disable();
/PIC Stuff/PICX_12F1840_Clock/funclist
1,31 → 1,35
_DS3231_Init: CODE, 1584 0 29
_I2C1_Init: CODE, 1766 0 15
_I2C1_Read_Buffer: CODE, 1456 0 38
_TSL2561_Set_Timing: CODE, 1688 0 22
_I2C1_Master_Restart: CODE, 1367 0 45
___awmod: CODE, 1195 0 72
_TSL2561_Disable: CODE, 1824 0 6
_main: CODE, 410 0 273
_Interrupt_Enable: CODE, 1830 0 3
___awdiv: CODE, 1571 0 84
_DS3231_Init: CODE, 4000 0 29
_I2C1_Init: CODE, 3834 0 18
_I2C1_Read_Buffer: CODE, 4058 0 38
_TSL2561_Set_Timing: CODE, 3874 0 22
_I2C1_Master_Restart: CODE, 1930 0 45
___awmod: CODE, 1655 0 72
_TSL2561_Disable: CODE, 3751 0 6
_main: CODE, 19 0 394
_Interrupt_Enable: CODE, 3748 0 3
_InterruptHandler: CODE, 4 0 13
_TSL2561_Write_2_Bytes: CODE, 1555 0 29
__initialization: CODE, 1641 0 21
_DS3231_Get_Status: CODE, 1665 0 23
_I2C1_Configure_Master: CODE, 1494 0 32
_NeoPixel_Or: CODE, 972 0 122
_DS3231_Get_Time: CODE, 683 0 155
_NeoPixel_Set: CODE, 838 0 134
_I2C1_Master_Send: CODE, 1267 0 50
_I2C1_Interrupt_Handler: CODE, 19 0 391
_NeoPixel_Init: CODE, 1317 0 50
_TSL2561_Init: CODE, 1412 0 44
_NeoPixel_Clear: CODE, 1732 0 17
_TSL2561_Set_Gain: CODE, 1710 0 22
_NeoPixel_Offet: CODE, 1805 0 10
_NeoPixel_Write_One: CODE, 1094 0 101
_I2C1_Get_Status: CODE, 1793 0 12
___wmul: CODE, 1526 0 29
_NeoPixel_Write_All: CODE, 1613 0 28
___bmul: CODE, 1749 0 17
_TSL2561_Enable: CODE, 1815 0 9
Total: 1812
_TSL2561_Write_2_Bytes: CODE, 4029 0 29
__initialization: CODE, 3919 0 21
_DS3231_Get_Status: CODE, 3896 0 23
___lwdiv: CODE, 1727 0 55
_I2C1_Configure_Master: CODE, 3971 0 29
_TSL2561_Read_2_Bytes: CODE, 1882 0 48
_NeoPixel_Or: CODE, 1066 0 158
_DS3231_Get_Time: CODE, 1224 0 155
_NeoPixel_Set: CODE, 804 0 262
_I2C1_Master_Send: CODE, 1782 0 50
_I2C1_Interrupt_Handler: CODE, 413 0 391
_NeoPixel_Init: CODE, 1832 0 50
_TSL2561_Init: CODE, 1975 0 44
_NeoPixel_Clear: CODE, 3817 0 17
_TSL2561_Set_Gain: CODE, 3852 0 22
_NeoPixel_Offet: CODE, 3766 0 10
_NeoPixel_Write_One: CODE, 1379 0 101
_I2C1_Get_Status: CODE, 3776 0 12
___wmul: CODE, 2019 0 29
_NeoPixel_Write_All: CODE, 3943 0 28
_TSL2561_Get_Luminosity: CODE, 1480 0 91
___bmul: CODE, 3800 0 17
_TSL2561_Enable: CODE, 3757 0 9
Total: 2375
/PIC Stuff/PICX_12F1840_Clock/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Stuff/PICX_12F1840_Clock/main.c
15,7 → 15,7
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
#pragma config WDTE = OFF // WDT disabled
#pragma config CP = OFF // Program memory code protection is disabled
#pragma config PWRTE = OFF // PWRT disabled
#pragma config PWRTE = ON // PWRT enabled
#pragma config CLKOUTEN = OFF // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
 
/* Config Register CONFIG2 @ 0x8008 */
38,12 → 38,13
ANSELA = 0x00; // All pins set to digital I/O
APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
WPUA = 0x00; // Disable weak pull-ups
 
// Wait for HFINTOSC to be within 0.5% of target 32Mhz
while (!OSCSTATbits.HFIOFS);
 
Interrupt_Enable();
 
I2C1_Init();
I2C1_Configure_Master(I2C_1MHZ);
 
55,8 → 56,8
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)
// 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!
64,42 → 65,50
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;
uint16_t full;
uint8_t multiplier, multiplier_2;
 
// time.sec = 0;
// time.min = 16;
// time.hour = 7;
// time.h_mil = 0;
// time.h_am_pm = 1;
//
// DS3231_Set_Time(&time);
 
while(1) {
// full = TSL2561_Get_Luminosity(0);
// ir = TSL2561_Get_Luminosity(1);
// vis = full - ir;
//
// ~37200 seems to be the max value at 16X gain, 101ms period
full = TSL2561_Get_Luminosity(0);
multiplier = (full / 3100) + 1; // 12 levels (1-12)
multiplier_2 = (multiplier / 7) + 1; // 2 levels (1-2)
 
// NeoPixel_Clear();
// for (uint8_t i = 0; i < (vis >> 11); i++) {
// NeoPixel_Set(i, 0x10, 0x00, 0x00);
// for (uint8_t i = 0; i < multiplier; i++) {
// NeoPixel_Set(i, 0x10, 0x00, 0x00, 1);
// }
// 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);
NeoPixel_Set(00, RED, multiplier_2);
NeoPixel_Set(30, RED, multiplier_2);
NeoPixel_Set(05, ORANGE, multiplier_2);
NeoPixel_Set(35, ORANGE, multiplier_2);
NeoPixel_Set(10, YELLOW, multiplier_2);
NeoPixel_Set(40, YELLOW, multiplier_2);
NeoPixel_Set(15, GREEN, multiplier_2);
NeoPixel_Set(45, GREEN, multiplier_2);
NeoPixel_Set(20, BLUE, multiplier_2);
NeoPixel_Set(50, BLUE, multiplier_2);
NeoPixel_Set(25, PURPLE, multiplier_2);
NeoPixel_Set(55, PURPLE, multiplier_2);
 
// Draw time
NeoPixel_Or((time.hour * 5) % 60, BLUE);
NeoPixel_Or(time.min, GREEN);
NeoPixel_Or(time.sec, RED);
NeoPixel_Or((time.hour * 5) % 60, BLUE, multiplier + 4);
NeoPixel_Or(time.min, GREEN, multiplier + 4);
NeoPixel_Or(time.sec, RED, multiplier + 4);
NeoPixel_Write_All();
}
}
/PIC Stuff/PICX_12F1840_Clock/nbproject/Makefile-genesis.properties
1,5 → 1,5
#
#Sun Mar 30 00:42:55 EDT 2014
#Sun Mar 30 17:07:11 EDT 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.20