Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 280 → Rev 281

/PIC Stuff/PICX_12F1840_Clock/DS3231.c
0,0 → 1,113
#include "defines.h"
#include "DS3231.h"
#include "I2C1.h"
 
void DS3231_Init() {
uint8_t reg[3];
reg[0] = DS3231_CONTROL;
/* Control Register (0x0E)
* Bit 7 - !EOSC
* Bit 6 - BBSQW
* Bit 5 - CONV
* Bit 4 - RS2
* Bit 3 - RS1
* Bit 2 - INTCN
* Bit 1 - A2IE
* Bit 0 - A1IE
*/
reg[1] = 0x04;
 
/* Control Register 2 (0x0F)
* Bit 3 = EN32kHZ
*/
reg[2] = 0x00;
 
// Set the configuration registers
I2C1_Master_Send(DS3231_ADDRESS, 3, reg);
while (!I2C1_Get_Status());
}
 
uint8_t DS3231_Get_Status(void) {
/* Status Register (0x0F)
* Bit 7 - OSF
* Bit 3 - EN32kHz
* Bit 2 - BSY
* Bit 1 - A2F
* Bit 0 - A1F
*/
uint8_t value;
I2C1_Master_Restart(DS3231_ADDRESS, 0x0F, 1);
while (!I2C1_Get_Status());
I2C1_Read_Buffer(&value);
return value;
}
 
void DS3231_Set_Time(DS3231_TIME *time) {
 
// Format the data in a way that the chip expects
#ifndef DS3231_TIME_ONLY
uint8_t output[8];
#else
uint8_t output[4];
#endif
output[0] = DS3231_SECONDS;
output[1] = ((time->sec / 10) << 4) | (time->sec % 10);
output[2] = ((time->min / 10) << 4) | (time->min % 10);
output[3] = ((time->hour / 10) << 4) | (time->hour % 10);
#ifndef DS3231_TIME_ONLY
if (!time->h_mil) {
output[3] |= (time->h_am_pm) ? 0x60 : 0x40;
}
output[4] = time->day;
output[5] = ((time->date / 10) << 4) | (time->date % 10);
output[6] = ((time->month / 10) << 4) | (time->month % 10);
output[7] = ((time->year / 10) << 4) | (time->year % 10);
#endif
 
// Check the status to make sure that it isnt currently busy
while (DS3231_Get_Status() & 0x04);
 
// Write the data to the chip
#ifndef DS3231_TIME_ONLY
I2C1_Master_Send(DS3231_ADDRESS, 8, output);
#else
I2C1_Master_Send(DS3231_ADDRESS, 4, output);
#endif
while (!I2C1_Get_Status());
}
 
void DS3231_Get_Time(DS3231_TIME *time) {
 
// Check the status to make sure that it isnt currently busy
while (DS3231_Get_Status() & 0x04);
 
// Request time data from the chip
#ifndef DS3231_TIME_ONLY
uint8_t input[7];
I2C1_Master_Restart(DS3231_ADDRESS, 0x00, 7);
#else
uint8_t input[3];
I2C1_Master_Restart(DS3231_ADDRESS, 0x00, 3);
#endif
while (!I2C1_Get_Status());
I2C1_Read_Buffer(input);
 
// Parse BCD format into decimal and return
time->sec = ((input[0] >> 4) * 10) + (input[0] & 0x0F);
time->min = ((input[1] >> 4) * 10) + (input[1] & 0x0F);
if (input[2] & 0x40) {
time->h_mil = 0;
time->h_am_pm = (input[2] & 0x20) ? 1 : 0;
time->hour = (((input[2] >> 4) & 0x01) * 10) + (input[2] & 0x0F);
} else {
time->h_mil = 1;
time->hour = ((input[2] >> 4) * 10) + (input[2] & 0x0F);
}
#ifndef DS3231_TIME_ONLY
time->day = input[3];
time->date = ((input[4] >> 4) * 10) + (input[4] & 0x0F);
time->month = ((input[5] >> 4) * 10) + (input[5] & 0x0F);
time->year = ((input[6] >> 4) * 10) + (input[6] & 0x0F);
#endif
}
/PIC Stuff/PICX_12F1840_Clock/DS3231.h
0,0 → 1,54
#ifndef RTC_DS3231_H
#define RTC_DS3231_H
 
#define DS3231_ADDRESS 0x68
 
#define DS3231_SECONDS 0x00
#define DS3231_MINUTES 0x01
#define DS3231_HOUR 0x02
#define DS3231_DAY 0x03
#define DS3231_DATE 0x04
#define DS3231_MONTH 0x05
#define DS3231_YEAR 0x06
 
#define DS3231_ALARM1_SECONDS 0x07
#define DS3231_ALARM1_MINUTES 0x08
#define DS3231_ALARM1_HOUR 0x09
#define DS3231_ALARM1_DAY_DATE 0x0A
 
#define DS3231_ALARM2_MINUTES 0x0B
#define DS3231_ALARM2_HOUR 0x0C
#define DS3231_ALARM2_DAY_DATE 0x0D
 
#define DS3231_CONTROL 0x0E
#define DS3231_STATUS 0x0F
 
#define DS3231_TIME_ONLY
 
typedef struct {
uint8_t sec;
uint8_t min;
uint8_t hour;
uint8_t h_mil;
uint8_t h_am_pm;
#ifndef DS3231_TIME_ONLY
uint8_t day;
uint8_t date;
uint8_t month;
uint8_t year;
#endif
} DS3231_TIME;
 
void DS3231_Init(void);
 
uint8_t DS3231_Get_Status(void);
 
void DS3231_Set_Time(DS3231_TIME *time);
 
void DS3231_Get_Time(DS3231_TIME *time);
 
//void DS3231_Set_Alarm1(uint8_t sec, uint8_t min, uint8_t hour, uint8_t date, bit mil, bit am_pm, bit dt_dy);
//void DS3231_Set_Alarm2(uint8_t min, uint8_t hour, uint8_t date, bit mil, bit am_pm, bit dt_dy);
 
#endif
 
/PIC Stuff/PICX_12F1840_Clock/I2C1.c
0,0 → 1,320
#include "defines.h"
#include "I2C1.h"
 
extern I2C1_DATA i2c_data;
 
// 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_data.buffer_in_len = 0;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
i2c_data.operating_state = I2C_IDLE;
i2c_data.return_status = 0;
 
i2c_data.master_dest_addr = 0;
i2c_data.master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSP1IE = 1;
}
 
// 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;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x8; // I2C Master Mode
if (speed == 0x01) {
SSP1ADD = 0x13; // Operate at 400KHz (32MHz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else if (speed == 0x02) {
SSP1ADD = 0x07; // Operate at 1Mhz (32Mhz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else {
SSP1ADD = 0x4F; // Operate at 100KHz (32MHz)
SSP1STATbits.SMP = 0; // Enable Slew Rate Control
}
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg) {
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (uint8_t i = 0; i < length; i++) {
i2c_data.buffer_in[i] = msg[i];
}
i2c_data.buffer_in_len = length;
i2c_data.master_dest_addr = address;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data.operating_state = I2C_SEND_ADDR;
i2c_data.master_status = I2C_MASTER_SEND;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C1_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data.buffer_in_len = length;
i2c_data.master_dest_addr = address;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data.operating_state = I2C_SEND_ADDR;
i2c_data.master_status = I2C_MASTER_RECV;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C1_Master_Send(address, 1, &c);
return;
}
 
// Save length and address to get data from
i2c_data.buffer_in[0] = msg;
i2c_data.buffer_in_len = length;
i2c_data.master_dest_addr = address;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data.operating_state = I2C_SEND_ADDR;
i2c_data.master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
void I2C1_Interrupt_Handler() {
// If we are in the middle of sending data
if (i2c_data.master_status == I2C_MASTER_SEND) {
switch (i2c_data.operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data.operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data.master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data.buffer_in_read_ind < i2c_data.buffer_in_len) {
SSP1BUF = i2c_data.buffer_in[i2c_data.buffer_in_read_ind];
i2c_data.buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data.master_status == I2C_MASTER_RECV) {
switch (i2c_data.operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data.operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data.master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data.operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data.buffer_in[i2c_data.buffer_in_write_ind] = SSP1BUF;
i2c_data.buffer_in_write_ind++;
if (i2c_data.buffer_in_write_ind < i2c_data.buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data.operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data.operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data.operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data.master_status == I2C_MASTER_RESTART) {
switch (i2c_data.operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data.operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data.master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSP1BUF = i2c_data.buffer_in[0];
i2c_data.operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSP1CON2bits.ACKSTAT) {
SSP1CON2bits.RSEN = 1;
i2c_data.operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data.operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data.master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data.operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data.buffer_in[i2c_data.buffer_in_write_ind] = SSP1BUF;
i2c_data.buffer_in_write_ind++;
if (i2c_data.buffer_in_write_ind < i2c_data.buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data.operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data.operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data.operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_RECV_OK;
break;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C1_Get_Status() {
// if (i2c_data.operating_mode == I2C_MODE_MASTER) {
if (i2c_data.master_status != I2C_MASTER_IDLE || i2c_data.buffer_in_len == 0) {
return 0;
} else {
return i2c_data.return_status;
}
}
 
uint8_t I2C1_Buffer_Len() {
return i2c_data.buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C1_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data.buffer_in_len != 0) {
buffer[i] = i2c_data.buffer_in[i2c_data.buffer_in_read_ind];
i++;
if (i2c_data.buffer_in_read_ind == MAXI2C1BUF-1) {
i2c_data.buffer_in_read_ind = 0;
} else {
i2c_data.buffer_in_read_ind++;
}
i2c_data.buffer_in_len--;
}
return i;
}
/PIC Stuff/PICX_12F1840_Clock/I2C1.h
0,0 → 1,69
#ifndef I2C1_H
#define I2C1_H
 
#define MAXI2C1BUF 8
 
// I2C Operating Speed
#define I2C_100KHZ 0x0
#define I2C_400KHZ 0x1
#define I2C_1MHZ 0x2
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2C1BUF];
uint8_t buffer_in_len;
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
} I2C1_DATA;
 
void I2C1_Init(void);
void I2C1_Interrupt_Handler(void);
void I2C1_Configure_Master(uint8_t speed);
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg);
void I2C1_Master_Recv(uint8_t address, uint8_t length);
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
uint8_t I2C1_Get_Status(void);
uint8_t I2C1_Buffer_Len(void);
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
 
#endif
/PIC Stuff/PICX_12F1840_Clock/INTERRUPTS.c
1,6 → 1,6
#include <xc.h>
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
 
void Interrupt_Enable() {
INTCONbits.GIE = 1;
14,11 → 14,11
 
void interrupt InterruptHandler(void) {
// // Check to see if we have an I2C interrupt
// if (PIR1bits.SSPIF) {
// I2C_Interrupt_Handler();
// PIR1bits.SSPIF = 0;
// }
// Check to see if we have an I2C1 interrupt
if (PIR1bits.SSP1IF) {
I2C1_Interrupt_Handler();
PIR1bits.SSP1IF = 0;
}
 
//#ifndef UART_TX_ONLY
// // Check to see if we have an interrupt on USART1 RX
/PIC Stuff/PICX_12F1840_Clock/NEOPIXEL.c
1,17 → 1,17
#include <xc.h>
#include "defines.h"
#include "NEOPIXEL.h"
 
static NEOPIXEL_DATA* neopixel_data_ptr;
extern NEOPIXEL_DATA neopixel_data;
 
void NeoPixel_Init(NEOPIXEL_DATA *data) {
neopixel_data_ptr = data;
void NeoPixel_Init(void) {
 
// Clear buffer
for (char i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
neopixel_data_ptr->values[i] = 0x0;
for (uint8_t i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
neopixel_data.values[i] = 0x0;
}
 
neopixel_data.offset = 0;
 
// Output pin initially blocked
NEOPIXEL_TRIS = 1;
 
34,23 → 34,42
NEOPIXEL_TRIS = 0;
}
 
void NeoPixel_Set(char index, char R, char G, char B) {
if (index >= NEOPIXEL_LENGTH) return;
void NeoPixel_Offet(uint8_t value) {
neopixel_data.offset = value;
}
 
neopixel_data_ptr->values[(index * 3) + 0] = G;
neopixel_data_ptr->values[(index * 3) + 1] = R;
neopixel_data_ptr->values[(index * 3) + 2] = B;
void NeoPixel_Clear(void) {
// Clear buffer
for (uint8_t i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
neopixel_data.values[i] = 0x0;
}
}
 
void NeoPixel_Set(uint8_t index, uint8_t R, uint8_t G, uint8_t B) {
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;
}
 
void NeoPixel_Or(uint8_t index, uint8_t R, uint8_t G, uint8_t B) {
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;
}
 
void NeoPixel_Write_All(void) {
for (char i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
NeoPixel_Write_One(neopixel_data_ptr->values[i]);
for (uint8_t i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
NeoPixel_Write_One(neopixel_data.values[i]);
}
// Delay for 50us to latch data
__delay_us(50);
}
 
void NeoPixel_Write_One(char value) {
void NeoPixel_Write_One(uint8_t value) {
// Enable timer and wait for it to overflow
T2CONbits.TMR2ON = 1;
while (!PIR1bits.TMR2IF);
/PIC Stuff/PICX_12F1840_Clock/NEOPIXEL.h
18,13 → 18,17
#define WHITE 0x6F,0x6F,0x6F
 
typedef struct {
char values[NEOPIXEL_LENGTH * 3];
uint8_t values[NEOPIXEL_LENGTH * 3];
uint8_t offset;
} NEOPIXEL_DATA;
 
void NeoPixel_Init(NEOPIXEL_DATA *data);
void NeoPixel_Set(char index, char R, char G, char B);
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_Write_All(void);
void NeoPixel_Write_One(char value);
void NeoPixel_Write_One(uint8_t value);
 
#endif /* NEOPIXEL_H */
 
/PIC Stuff/PICX_12F1840_Clock/TSL2561.c
0,0 → 1,216
#include "defines.h"
#include "I2C1.h"
#include "TSL2561.h"
 
extern TSL2561_DATA tsl2561_data;
 
void TSL2561_Init(uint8_t address) {
tsl2561_data.address = address;
tsl2561_data.integration = TSL2561_INTEGRATIONTIME_13MS;
tsl2561_data.gain = TSL2561_GAIN_16X;
 
uint8_t buffer[1];
I2C1_Master_Restart(tsl2561_data.address, TSL2561_REGISTER_ID, 1);
while (!I2C1_Get_Status());
I2C1_Read_Buffer(buffer);
 
// Set default integration time and gain
TSL2561_Set_Timing(tsl2561_data.integration);
TSL2561_Set_Gain(tsl2561_data.gain);
 
// Start the chip in power-down mode
TSL2561_Disable();
}
 
void TSL2561_Enable() {
TSL2561_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON);
}
 
void TSL2561_Disable() {
TSL2561_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF);
}
 
void TSL2561_Set_Gain(tsl2561Gain_t gain) {
TSL2561_Enable();
tsl2561_data.gain = gain;
TSL2561_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data.integration | tsl2561_data.gain);
TSL2561_Disable();
}
 
void TSL2561_Set_Timing(tsl2561IntegrationTime_t integration) {
TSL2561_Enable();
tsl2561_data.integration = integration;
TSL2561_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data.integration | tsl2561_data.gain);
TSL2561_Disable();
}
 
uint32_t TSL2561_Calculate_Lux(uint16_t ch0, uint16_t ch1) {
uint32_t chScale, channel0, channel1, ratio1, ratio, temp, lux;
uint16_t b, m;
 
switch (tsl2561_data.integration) {
case TSL2561_INTEGRATIONTIME_13MS:
chScale = TSL2561_LUX_CHSCALE_TINT0;
break;
case TSL2561_INTEGRATIONTIME_101MS:
chScale = TSL2561_LUX_CHSCALE_TINT1;
break;
default: // No scaling ... integration time = 402ms
chScale = (1 << TSL2561_LUX_CHSCALE);
break;
}
 
// Scale for gain (1x or 16x)
if (!tsl2561_data.gain)
chScale = chScale << 4;
 
// scale the channel values
channel0 = (ch0 * chScale) >> TSL2561_LUX_CHSCALE;
channel1 = (ch1 * chScale) >> TSL2561_LUX_CHSCALE;
 
// find the ratio of the channel values (Channel1/Channel0)
ratio1 = 0;
if (channel0 != 0)
ratio1 = (channel1 << (TSL2561_LUX_RATIOSCALE+1)) / channel0;
 
// round the ratio value
ratio = (ratio1 + 1) >> 1;
 
#ifdef TSL2561_PACKAGE_CS
if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1C)) {
b = TSL2561_LUX_B1C; m = TSL2561_LUX_M1C;
} else if (ratio <= TSL2561_LUX_K2C) {
b = TSL2561_LUX_B2C; m = TSL2561_LUX_M2C;
} else if (ratio <= TSL2561_LUX_K3C) {
b = TSL2561_LUX_B3C; m = TSL2561_LUX_M3C;
} else if (ratio <= TSL2561_LUX_K4C) {
b = TSL2561_LUX_B4C; m = TSL2561_LUX_M4C;
} else if (ratio <= TSL2561_LUX_K5C) {
b = TSL2561_LUX_B5C; m = TSL2561_LUX_M5C;
} else if (ratio <= TSL2561_LUX_K6C) {
b = TSL2561_LUX_B6C; m = TSL2561_LUX_M6C;
} else if (ratio <= TSL2561_LUX_K7C) {
b = TSL2561_LUX_B7C; m = TSL2561_LUX_M7C;
} else if (ratio > TSL2561_LUX_K8C) {
b = TSL2561_LUX_B8C; m = TSL2561_LUX_M8C;
}
#else
// if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1T)) {
if ((ratio <= TSL2561_LUX_K1T)) {
b = TSL2561_LUX_B1T; m = TSL2561_LUX_M1T;
} else if (ratio <= TSL2561_LUX_K2T) {
b = TSL2561_LUX_B2T; m = TSL2561_LUX_M2T;
} else if (ratio <= TSL2561_LUX_K3T) {
b = TSL2561_LUX_B3T; m = TSL2561_LUX_M3T;
} else if (ratio <= TSL2561_LUX_K4T) {
b = TSL2561_LUX_B4T; m = TSL2561_LUX_M4T;
} else if (ratio <= TSL2561_LUX_K5T) {
b = TSL2561_LUX_B5T; m = TSL2561_LUX_M5T;
} else if (ratio <= TSL2561_LUX_K6T) {
b = TSL2561_LUX_B6T; m = TSL2561_LUX_M6T;
} else if (ratio <= TSL2561_LUX_K7T) {
b = TSL2561_LUX_B7T; m = TSL2561_LUX_M7T;
} else if (ratio > TSL2561_LUX_K8T) {
b = TSL2561_LUX_B8T; m = TSL2561_LUX_M8T;
}
#endif
// temp = ((channel0 * b) - (channel1 * m));
// TODO: Change this back once they fix compiler
temp = (channel0 * b);
temp -= (channel1 * m);
 
// // do not allow negative lux value
// if (temp < 0)
// temp = 0;
 
// round lsb (2^(LUX_SCALE-1))
temp += (1 << (TSL2561_LUX_LUXSCALE-1));
 
// strip off fractional portion
lux = temp >> TSL2561_LUX_LUXSCALE;
 
return lux;
}
 
uint32_t TSL2561_Get_Full_Luminosity() {
uint32_t x;
 
// Enable the device by setting the control bit to 0x03
TSL2561_Enable();
 
// Wait x ms for ADC to complete
switch (tsl2561_data.integration) {
case TSL2561_INTEGRATIONTIME_13MS:
__delay_ms(15);
break;
case TSL2561_INTEGRATIONTIME_101MS:
__delay_ms(105);
break;
default:
__delay_ms(405);
break;
}
 
x = TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
x <<= 16;
x |= TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
 
TSL2561_Disable();
 
return x;
}
 
uint16_t TSL2561_Get_Luminosity(uint8_t channel) {
// Enable the device by setting the control bit to 0x03
TSL2561_Enable();
 
// Wait x ms for ADC to complete
switch (tsl2561_data.integration) {
case TSL2561_INTEGRATIONTIME_13MS:
__delay_ms(15);
break;
case TSL2561_INTEGRATIONTIME_101MS:
__delay_ms(105);
break;
default:
__delay_ms(405);
break;
}
 
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);
} 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);
}
 
TSL2561_Disable();
 
// Unknown channel!
return 0;
}
 
void TSL2561_Write_2_Bytes(uint8_t reg, uint8_t value) {
uint8_t buffer[2];
buffer[0] = reg;
buffer[1] = value;
I2C1_Master_Send(tsl2561_data.address, 2, buffer);
while (!I2C1_Get_Status());
}
 
uint16_t TSL2561_Read_2_Bytes(uint8_t reg) {
uint8_t buffer[2];
uint16_t ret;
 
I2C1_Master_Restart(tsl2561_data.address, reg, 2);
while (!I2C1_Get_Status());
I2C1_Read_Buffer(buffer);
ret = buffer[1] << 8;
ret |= buffer[0];
 
return ret;
}
/PIC Stuff/PICX_12F1840_Clock/TSL2561.h
0,0 → 1,131
#ifndef LUX_TSL2561_H
#define LUX_TSL2561_H
 
#define TSL2561_VISIBLE 2 // channel 0 - channel 1
#define TSL2561_INFRARED 1 // channel 1
#define TSL2561_FULLSPECTRUM 0 // channel 0
 
// 3 i2c address options!
#define TSL2561_ADDR_LOW 0x29
#define TSL2561_ADDR_FLOAT 0x39
#define TSL2561_ADDR_HIGH 0x49
 
// Lux calculations differ slightly for CS package
//#define TSL2561_PACKAGE_CS
#define TSL2561_PACKAGE_T_FN_CL
 
#define TSL2561_READBIT (0x01)
 
#define TSL2561_COMMAND_BIT (0x80) // Must be 1
#define TSL2561_CLEAR_BIT (0x40) // Clears any pending interrupt (write 1 to clear)
#define TSL2561_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
#define TSL2561_BLOCK_BIT (0x10) // 1 = using block read/write
 
#define TSL2561_CONTROL_POWERON (0x03)
#define TSL2561_CONTROL_POWEROFF (0x00)
 
#define TSL2561_LUX_LUXSCALE (14) // Scale by 2^14
#define TSL2561_LUX_RATIOSCALE (9) // Scale ratio by 2^9
#define TSL2561_LUX_CHSCALE (10) // Scale channel values by 2^10
#define TSL2561_LUX_CHSCALE_TINT0 (0x7517) // 322/11 * 2^TSL2561_LUX_CHSCALE
#define TSL2561_LUX_CHSCALE_TINT1 (0x0FE7) // 322/81 * 2^TSL2561_LUX_CHSCALE
 
// T, FN and CL package values
#define TSL2561_LUX_K1T (0x0040) // 0.125 * 2^RATIO_SCALE
#define TSL2561_LUX_B1T (0x01f2) // 0.0304 * 2^LUX_SCALE
#define TSL2561_LUX_M1T (0x01be) // 0.0272 * 2^LUX_SCALE
#define TSL2561_LUX_K2T (0x0080) // 0.250 * 2^RATIO_SCALE
#define TSL2561_LUX_B2T (0x0214) // 0.0325 * 2^LUX_SCALE
#define TSL2561_LUX_M2T (0x02d1) // 0.0440 * 2^LUX_SCALE
#define TSL2561_LUX_K3T (0x00c0) // 0.375 * 2^RATIO_SCALE
#define TSL2561_LUX_B3T (0x023f) // 0.0351 * 2^LUX_SCALE
#define TSL2561_LUX_M3T (0x037b) // 0.0544 * 2^LUX_SCALE
#define TSL2561_LUX_K4T (0x0100) // 0.50 * 2^RATIO_SCALE
#define TSL2561_LUX_B4T (0x0270) // 0.0381 * 2^LUX_SCALE
#define TSL2561_LUX_M4T (0x03fe) // 0.0624 * 2^LUX_SCALE
#define TSL2561_LUX_K5T (0x0138) // 0.61 * 2^RATIO_SCALE
#define TSL2561_LUX_B5T (0x016f) // 0.0224 * 2^LUX_SCALE
#define TSL2561_LUX_M5T (0x01fc) // 0.0310 * 2^LUX_SCALE
#define TSL2561_LUX_K6T (0x019a) // 0.80 * 2^RATIO_SCALE
#define TSL2561_LUX_B6T (0x00d2) // 0.0128 * 2^LUX_SCALE
#define TSL2561_LUX_M6T (0x00fb) // 0.0153 * 2^LUX_SCALE
#define TSL2561_LUX_K7T (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B7T (0x0018) // 0.00146 * 2^LUX_SCALE
#define TSL2561_LUX_M7T (0x0012) // 0.00112 * 2^LUX_SCALE
#define TSL2561_LUX_K8T (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B8T (0x0000) // 0.000 * 2^LUX_SCALE
#define TSL2561_LUX_M8T (0x0000) // 0.000 * 2^LUX_SCALE
 
// CS package values
#define TSL2561_LUX_K1C (0x0043) // 0.130 * 2^RATIO_SCALE
#define TSL2561_LUX_B1C (0x0204) // 0.0315 * 2^LUX_SCALE
#define TSL2561_LUX_M1C (0x01ad) // 0.0262 * 2^LUX_SCALE
#define TSL2561_LUX_K2C (0x0085) // 0.260 * 2^RATIO_SCALE
#define TSL2561_LUX_B2C (0x0228) // 0.0337 * 2^LUX_SCALE
#define TSL2561_LUX_M2C (0x02c1) // 0.0430 * 2^LUX_SCALE
#define TSL2561_LUX_K3C (0x00c8) // 0.390 * 2^RATIO_SCALE
#define TSL2561_LUX_B3C (0x0253) // 0.0363 * 2^LUX_SCALE
#define TSL2561_LUX_M3C (0x0363) // 0.0529 * 2^LUX_SCALE
#define TSL2561_LUX_K4C (0x010a) // 0.520 * 2^RATIO_SCALE
#define TSL2561_LUX_B4C (0x0282) // 0.0392 * 2^LUX_SCALE
#define TSL2561_LUX_M4C (0x03df) // 0.0605 * 2^LUX_SCALE
#define TSL2561_LUX_K5C (0x014d) // 0.65 * 2^RATIO_SCALE
#define TSL2561_LUX_B5C (0x0177) // 0.0229 * 2^LUX_SCALE
#define TSL2561_LUX_M5C (0x01dd) // 0.0291 * 2^LUX_SCALE
#define TSL2561_LUX_K6C (0x019a) // 0.80 * 2^RATIO_SCALE
#define TSL2561_LUX_B6C (0x0101) // 0.0157 * 2^LUX_SCALE
#define TSL2561_LUX_M6C (0x0127) // 0.0180 * 2^LUX_SCALE
#define TSL2561_LUX_K7C (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B7C (0x0037) // 0.00338 * 2^LUX_SCALE
#define TSL2561_LUX_M7C (0x002b) // 0.00260 * 2^LUX_SCALE
#define TSL2561_LUX_K8C (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B8C (0x0000) // 0.000 * 2^LUX_SCALE
#define TSL2561_LUX_M8C (0x0000) // 0.000 * 2^LUX_SCALE
 
enum {
TSL2561_REGISTER_CONTROL = 0x00,
TSL2561_REGISTER_TIMING = 0x01,
TSL2561_REGISTER_THRESHHOLDL_LOW = 0x02,
TSL2561_REGISTER_THRESHHOLDL_HIGH = 0x03,
TSL2561_REGISTER_THRESHHOLDH_LOW = 0x04,
TSL2561_REGISTER_THRESHHOLDH_HIGH = 0x05,
TSL2561_REGISTER_INTERRUPT = 0x06,
TSL2561_REGISTER_CRC = 0x08,
TSL2561_REGISTER_ID = 0x0A,
TSL2561_REGISTER_CHAN0_LOW = 0x0C,
TSL2561_REGISTER_CHAN0_HIGH = 0x0D,
TSL2561_REGISTER_CHAN1_LOW = 0x0E,
TSL2561_REGISTER_CHAN1_HIGH = 0x0F
};
 
typedef enum {
TSL2561_INTEGRATIONTIME_13MS = 0x00, // 13.7ms
TSL2561_INTEGRATIONTIME_101MS = 0x01, // 101ms
TSL2561_INTEGRATIONTIME_402MS = 0x02 // 402ms
} tsl2561IntegrationTime_t;
 
typedef enum {
TSL2561_GAIN_0X = 0x00, // No gain
TSL2561_GAIN_16X = 0x10 // 16x gain
} tsl2561Gain_t;
 
typedef struct __TSL25611_DATA {
uint8_t address;
tsl2561IntegrationTime_t integration;
tsl2561Gain_t gain;
} TSL2561_DATA;
 
void TSL2561_Init(uint8_t address);
void TSL2561_Enable(void);
void TSL2561_Disable(void);
void TSL2561_Set_Timing(tsl2561IntegrationTime_t integration);
void TSL2561_Set_Gain(tsl2561Gain_t gain);
uint32_t TSL2561_Calculate_Lux(uint16_t ch0, uint16_t ch1);
uint32_t TSL2561_Get_Full_Luminosity(void);
uint16_t TSL2561_Get_Luminosity(uint8_t channel);
 
void TSL2561_Write_2_Bytes(uint8_t reg, uint8_t value);
uint16_t TSL2561_Read_2_Bytes(uint8_t reg);
 
#endif /* LUX_TSL2561_H */
 
/PIC Stuff/PICX_12F1840_Clock/defines.h
1,10 → 1,15
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <stdint.h>
 
// Preprocessor define for __delay_ms() and __delay_us()
#define _XTAL_FREQ 32000000
 
#define NEOPIXEL_TRIS TRISAbits.TRISA5
#define NEOPIXEL_TRIS TRISAbits.TRISA5
#define I2C_1_CLK_TRIS TRISAbits.TRISA1
#define I2C_1_DAT_TRIS TRISAbits.TRISA2
 
#endif /* DEFINES_H */
 
/PIC Stuff/PICX_12F1840_Clock/funclist
1,10 → 1,31
___awmod: CODE, 404 0 71
_main: CODE, 13 0 185
_InterruptHandler: CODE, 4 0 7
__initialization: CODE, 591 0 12
_NeoPixel_Set: CODE, 198 0 105
_NeoPixel_Init: CODE, 475 0 55
_NeoPixel_Write_One: CODE, 303 0 101
___wmul: CODE, 562 0 29
_NeoPixel_Write_All: CODE, 530 0 32
Total: 597
_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
_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
/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
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();
}
}
/PIC Stuff/PICX_12F1840_Clock/nbproject/Makefile-default.mk
45,17 → 45,17
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c NEOPIXEL.c INTERRUPTS.c
SOURCEFILES_QUOTED_IF_SPACED=main.c NEOPIXEL.c INTERRUPTS.c I2C1.c DS3231.c TSL2561.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/NEOPIXEL.p1 ${OBJECTDIR}/INTERRUPTS.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/NEOPIXEL.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/NEOPIXEL.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/DS3231.p1 ${OBJECTDIR}/TSL2561.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/NEOPIXEL.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d ${OBJECTDIR}/I2C1.p1.d ${OBJECTDIR}/DS3231.p1.d ${OBJECTDIR}/TSL2561.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/NEOPIXEL.p1 ${OBJECTDIR}/INTERRUPTS.p1
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/NEOPIXEL.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/DS3231.p1 ${OBJECTDIR}/TSL2561.p1
 
# Source Files
SOURCEFILES=main.c NEOPIXEL.c INTERRUPTS.c
SOURCEFILES=main.c NEOPIXEL.c INTERRUPTS.c I2C1.c DS3231.c TSL2561.c
 
 
CFLAGS=
102,6 → 102,30
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/DS3231.p1: DS3231.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/DS3231.p1.d
@${RM} ${OBJECTDIR}/DS3231.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/DS3231.p1 DS3231.c
@-${MV} ${OBJECTDIR}/DS3231.d ${OBJECTDIR}/DS3231.p1.d
@${FIXDEPS} ${OBJECTDIR}/DS3231.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TSL2561.p1: TSL2561.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TSL2561.p1.d
@${RM} ${OBJECTDIR}/TSL2561.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TSL2561.p1 TSL2561.c
@-${MV} ${OBJECTDIR}/TSL2561.d ${OBJECTDIR}/TSL2561.p1.d
@${FIXDEPS} ${OBJECTDIR}/TSL2561.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
127,6 → 151,30
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/DS3231.p1: DS3231.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/DS3231.p1.d
@${RM} ${OBJECTDIR}/DS3231.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/DS3231.p1 DS3231.c
@-${MV} ${OBJECTDIR}/DS3231.d ${OBJECTDIR}/DS3231.p1.d
@${FIXDEPS} ${OBJECTDIR}/DS3231.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TSL2561.p1: TSL2561.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TSL2561.p1.d
@${RM} ${OBJECTDIR}/TSL2561.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TSL2561.p1 TSL2561.c
@-${MV} ${OBJECTDIR}/TSL2561.d ${OBJECTDIR}/TSL2561.p1.d
@${FIXDEPS} ${OBJECTDIR}/TSL2561.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
/PIC Stuff/PICX_12F1840_Clock/nbproject/Makefile-genesis.properties
1,5 → 1,5
#
#Sat Mar 29 17:34:07 EDT 2014
#Sun Mar 30 00:42:55 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
/PIC Stuff/PICX_12F1840_Clock/nbproject/configurations.xml
7,6 → 7,9
<itemPath>defines.h</itemPath>
<itemPath>NEOPIXEL.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
<itemPath>I2C1.h</itemPath>
<itemPath>DS3231.h</itemPath>
<itemPath>TSL2561.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
18,6 → 21,9
<itemPath>main.c</itemPath>
<itemPath>NEOPIXEL.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
<itemPath>I2C1.c</itemPath>
<itemPath>DS3231.c</itemPath>
<itemPath>TSL2561.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"