Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 200 → Rev 199

/PIC Stuff/Cerebot_32MX7_LED_Cube/BTN.h
File deleted
/PIC Stuff/Cerebot_32MX7_LED_Cube/BTN.c
File deleted
\ No newline at end of file
/PIC Stuff/Cerebot_32MX7_LED_Cube/CUBE.c
14,7 → 14,7
Nop();
}
 
void Cube_Init(CUBE_DATA *data, char BC) {
void Cube_Init(CUBE_DATA *data) {
cube_data_ptr = data;
current_layer = 0;
 
44,8 → 44,30
Cube_Delay();
SFT_R = 1;
 
Cube_Write_DCS(BC);
int i,j;
// Write configuration data to the DC/BC/FC/UD registers
unsigned char DCS[GCS_LAYER_SIZE] = {0};
for (i = 0; i < 8; i++) {
int offset = i * GCS_REG_SIZE;
 
for (j = 0; j < 21; j++) {
DCS[offset + j] = 0xFF; // Dot correction
}
// Warning: do not set BC > 0x8F
DCS[offset + 21] = 0x1F; // Global red brightness
DCS[offset + 22] = 0x1F; // Global green brightness
DCS[offset + 23] = 0x1F; // Global blue brightness
 
// DC low range, auto repeat, no timing reset, 8 bit counter mode
DCS[offset + 24] = 0x68; // 0110 1000
}
 
Cube_Clear();
GSLAT = 1;
SPI1_Write(DCS, GCS_LAYER_SIZE, &Cube_DCS_Write_Callback);
Delay_MS(8); // Delay until the entire DCS write is finished
}
 
void Cube_Timer_Interrupt(void) {
91,35 → 113,6
current_layer = (current_layer == CUBE_LAYER_COUNT-1) ? 0 : current_layer + 1;
}
 
void Cube_Write_DCS(char BC) {
if (BC > CUBE_MAX_BRIGHTNESS)
BC = CUBE_MAX_BRIGHTNESS;
 
XBLNK = 0;
int i,j;
// Write configuration data to the DC/BC/FC/UD registers
unsigned char DCS[GCS_LAYER_SIZE] = {0};
for (i = 0; i < 8; i++) {
int offset = i * GCS_REG_SIZE;
 
for (j = 0; j < 21; j++) {
DCS[offset + j] = 0xFF; // Dot correction
}
 
// Warning: do not set BC > 0x6F
DCS[offset + 21] = BC; // Global red brightness
DCS[offset + 22] = BC; // Global green brightness
DCS[offset + 23] = BC; // Global blue brightness
 
// DC low range, auto repeat, no timing reset, 8 bit counter mode
DCS[offset + 24] = 0x68; // 0110 1000
}
GSLAT = 1;
SPI1_Write(DCS, GCS_LAYER_SIZE, &Cube_DCS_Write_Callback);
Delay_MS(8); // Delay until the entire DCS write is finished
}
 
void Cube_Clear(void) {
int i,j;
for (i = 0; i < CUBE_LAYER_COUNT; i++)
/PIC Stuff/Cerebot_32MX7_LED_Cube/CUBE.h
32,13 → 32,11
#define GSLAT PORTDbits.RD9
#define XBLNK PORTDbits.RD2
 
#define CUBE_MAX_BRIGHTNESS 0x7F
 
typedef struct {
unsigned char GCS[CUBE_LAYER_COUNT][GCS_LAYER_SIZE];
} CUBE_DATA;
 
void Cube_Init(CUBE_DATA *data, char BC);
void Cube_Init(CUBE_DATA *data);
void Cube_Timer_Interrupt(void);
 
// Callbacks on completion of DCS/GCS writes
46,7 → 44,6
void Cube_GCS_Write_Callback(void);
 
// Cube control functions
void Cube_Write_DCS(char BC);
void Cube_Clear(void);
void Cube_Set_All(int R, int G, int B);
void Cube_Set_Layer(int layer, int R, int G, int B);
/PIC Stuff/Cerebot_32MX7_LED_Cube/defines.h
10,7 → 10,16
 
#define ADDRESS_EEPROM 0x50
 
// LED1 = G12, LED2 = G13, LED3 = G14, LED4 = G15 (active high)
// BTN1 = RG6, BTN2 = RG7, BTN3 = RD13
// Note: Write to PORTx is effectively the same as write to LATx
#define BTN1_TRIS TRISGbits.TRISG6
#define BTN1_PORT PORTGbits.RG6
#define BTN2_TRIS TRISGbits.TRISG7
#define BTN2_PORT PORTGbits.RG7
#define BTN3_TRIS TRISDbits.TRISD13
#define BTN3_PORT PORTDbits.RD13
 
// LED1 = G12, LED2 = G13, LED3 = G14, LED4 = G15
#define LED1_TRIS TRISGbits.TRISG12
#define LED1_PORT PORTGbits.RG12
#define LED2_TRIS TRISGbits.TRISG13
23,7 → 32,7
void Delay_MS(unsigned int delay_ms);
void Delay_US(unsigned int delay_us);
 
// <editor-fold desc="PMOD to MCU Pinouts">
// <editor-fold defaultstate="collapsed" desc="PMOD to MCU Pinouts">
/*
JA-01 AN2/C2IN-/CN4/RB2 RB02
JA-02 AN3/C2IN+/CN5/RB3 RB03
/PIC Stuff/Cerebot_32MX7_LED_Cube/main.c
42,10 → 42,7
#include "SPI1.h"
#include "TIMER5.h"
#include "CUBE.h"
#include "BTN.h"
 
void BTN1_Interrupt(void);
void BTN2_Interrupt(void);
void Animation_Solid_Colors(int iterations, int delay_ms);
void Animation_Layer_Alternate(int iterations, int delay_ms);
void Animation_Pixel_Alternate(int iterations, int delay_ms);
86,17 → 83,12
PWM2_Start();
 
CUBE_DATA cube_data;
Cube_Init(&cube_data, 0x01);
Cube_Init(&cube_data);
 
// 2083 = 60Hz, 500 = 250Hz, 250 = 500Hz
TIMER5_Init(&Cube_Timer_Interrupt, 500);
TIMER5_Init(&Cube_Timer_Interrupt, 200);
TIMER5_Start();
 
BTN_Init(&BTN1_Interrupt, &BTN2_Interrupt, NULL);
 
Cube_Set_All(0xFF,0xFF,0xFF);
Delay_MS(3000);
 
// Loop through some preset animations
while(1) {
Animation_Solid_Colors(2,300);
110,59 → 102,6
}
}
 
// Function call on button 1 press to change refresh rate
void BTN1_Interrupt(void) {
static char state;
state = (state == 3) ? 0 : state + 1;
TIMER5_Stop();
switch (state) {
case 0:
TIMER5_Init(&Cube_Timer_Interrupt, 500);
break;
case 1:
TIMER5_Init(&Cube_Timer_Interrupt, 2083);
break;
case 2:
TIMER5_Init(&Cube_Timer_Interrupt, 4166);
break;
case 3:
TIMER5_Init(&Cube_Timer_Interrupt, 13107);
break;
}
TIMER5_Start();
}
 
// Function call on button 2 press to change brightness
void BTN2_Interrupt(void) {
static char state;
state = (state == 5) ? 0 : state + 1;
TIMER5_Stop();
Delay_MS(1); // Need to wait for all SPI writes to complete
char BC;
switch (state) {
case 0:
BC = 0x01;
break;
case 1:
BC = 0x08;
break;
case 2:
BC = 0x10;
break;
case 3:
BC = 0x20;
break;
case 4:
BC = 0x40;
break;
case 5:
BC = 0x70;
break;
}
Cube_Write_DCS(BC);
TIMER5_Start();
}
 
void Animation_Solid_Colors(int iterations, int delay_ms) {
int i;
for (i = 0; i < iterations; i++) {
/PIC Stuff/Cerebot_32MX7_LED_Cube/nbproject/Makefile-default.mk
45,11 → 45,11
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.o ${OBJECTDIR}/SPI1.o ${OBJECTDIR}/TIMER5.o ${OBJECTDIR}/CUBE.o ${OBJECTDIR}/PWM2.o ${OBJECTDIR}/BTN.o
POSSIBLE_DEPFILES=${OBJECTDIR}/main.o.d ${OBJECTDIR}/SPI1.o.d ${OBJECTDIR}/TIMER5.o.d ${OBJECTDIR}/CUBE.o.d ${OBJECTDIR}/PWM2.o.d ${OBJECTDIR}/BTN.o.d
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.o ${OBJECTDIR}/SPI1.o ${OBJECTDIR}/TIMER5.o ${OBJECTDIR}/CUBE.o ${OBJECTDIR}/PWM2.o
POSSIBLE_DEPFILES=${OBJECTDIR}/main.o.d ${OBJECTDIR}/SPI1.o.d ${OBJECTDIR}/TIMER5.o.d ${OBJECTDIR}/CUBE.o.d ${OBJECTDIR}/PWM2.o.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/SPI1.o ${OBJECTDIR}/TIMER5.o ${OBJECTDIR}/CUBE.o ${OBJECTDIR}/PWM2.o ${OBJECTDIR}/BTN.o
OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/SPI1.o ${OBJECTDIR}/TIMER5.o ${OBJECTDIR}/CUBE.o ${OBJECTDIR}/PWM2.o
 
 
CFLAGS=
110,11 → 110,6
@${RM} ${OBJECTDIR}/PWM2.o.d
@${FIXDEPS} "${OBJECTDIR}/PWM2.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/PWM2.o.d" -o ${OBJECTDIR}/PWM2.o PWM2.c
${OBJECTDIR}/BTN.o: BTN.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/BTN.o.d
@${FIXDEPS} "${OBJECTDIR}/BTN.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/BTN.o.d" -o ${OBJECTDIR}/BTN.o BTN.c
else
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
141,11 → 136,6
@${RM} ${OBJECTDIR}/PWM2.o.d
@${FIXDEPS} "${OBJECTDIR}/PWM2.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/PWM2.o.d" -o ${OBJECTDIR}/PWM2.o PWM2.c
${OBJECTDIR}/BTN.o: BTN.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/BTN.o.d
@${FIXDEPS} "${OBJECTDIR}/BTN.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/BTN.o.d" -o ${OBJECTDIR}/BTN.o BTN.c
endif
 
# ------------------------------------------------------------------------------------
/PIC Stuff/Cerebot_32MX7_LED_Cube/nbproject/Makefile-genesis.properties
1,5 → 1,5
#
#Fri May 24 23:27:07 EDT 2013
#Wed May 22 16:14:25 EDT 2013
default.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=6b4fa04caf3910c7c3a4666b1aea8c5c
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc32\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=415494acd195d89b2f6d7a36797a5ab4
/PIC Stuff/Cerebot_32MX7_LED_Cube/nbproject/configurations.xml
8,8 → 8,6
<itemPath>SPI1.h</itemPath>
<itemPath>TIMER5.h</itemPath>
<itemPath>CUBE.h</itemPath>
<itemPath>BTN.h</itemPath>
<itemPath>PWM2.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
22,8 → 20,8
<itemPath>SPI1.c</itemPath>
<itemPath>TIMER5.c</itemPath>
<itemPath>CUBE.c</itemPath>
<itemPath>PWM2.h</itemPath>
<itemPath>PWM2.c</itemPath>
<itemPath>BTN.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"