Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 198 → Rev 199

/PIC Stuff/Cerebot_32MX7_LED_Cube/CUBE.c
0,0 → 1,190
#include <xc.h>
#include <plib.h>
#include "defines.h"
#include "CUBE.h"
#include "SPI1.h"
 
static CUBE_DATA *cube_data_ptr;
static unsigned char current_layer;
 
inline void Cube_Delay() {
// Small delay to ensure that latch speeds are < 30Mhz
Nop();
Nop();
Nop();
}
 
void Cube_Init(CUBE_DATA *data) {
cube_data_ptr = data;
current_layer = 0;
 
SFT_D = 0;
SFT_S = 0;
SFT_K = 0;
SFT_R = 0;
GSLAT = 0;
XBLNK = 0;
SFT_D_TRIS = 0;
SFT_S_TRIS = 0;
SFT_K_TRIS = 0;
SFT_R_TRIS = 0;
GSLAT_TRIS = 0;
XBLNK_TRIS = 0;
 
// Clear the shift register
Cube_Delay();
SFT_K = 1;
Cube_Delay();
SFT_K = 0;
Cube_Delay();
SFT_S = 1;
Cube_Delay();
SFT_S = 0;
Cube_Delay();
SFT_R = 1;
 
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) {
// Write to the GCS register
SPI1_Write(cube_data_ptr->GCS[current_layer], GCS_LAYER_SIZE, &Cube_GCS_Write_Callback);
}
 
void Cube_DCS_Write_Callback(void) {
// GSLAT must be >7ms after DCS write
Delay_MS(7);
GSLAT = 0;
Cube_Delay();
GSLAT = 1;
Cube_Delay();
GSLAT = 0;
}
 
void Cube_GCS_Write_Callback(void) {
// Disable LED output and latch in written data to GCS
XBLNK = 0;
Cube_Delay();
GSLAT = 1;
// Set the shift register to turn on the current layer
int i;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
Cube_Delay();
SFT_D = (i == CUBE_LAYER_COUNT - current_layer - 1) ? 1 : 0;
Cube_Delay();
SFT_K = 1;
Cube_Delay();
SFT_K = 0;
}
Cube_Delay();
SFT_S = 1;
Cube_Delay();
SFT_S = 0;
Cube_Delay();
// Enable LED output
XBLNK = 1;
Cube_Delay();
GSLAT = 0;
 
current_layer = (current_layer == CUBE_LAYER_COUNT-1) ? 0 : current_layer + 1;
}
 
void Cube_Clear(void) {
int i,j;
for (i = 0; i < CUBE_LAYER_COUNT; i++)
for (j = 0; j < GCS_LAYER_SIZE; j++)
cube_data_ptr->GCS[i][j] = 0x00;
}
 
void Cube_Set_All(int R, int G, int B) {
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
int i,j,k;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
int j_var = j * GCS_REG_SIZE;
for (k = 0; k < 4; k++) {
int k_var = j_var + (k * 9);
cube_data_ptr->GCS[i][k_var+0] = R & 0xFF;;
cube_data_ptr->GCS[i][k_var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[i][k_var+2] = G >> 4;
cube_data_ptr->GCS[i][k_var+3] = B & 0xFF;
cube_data_ptr->GCS[i][k_var+4] = (R << 4) | (B >> 8);
cube_data_ptr->GCS[i][k_var+5] = R >> 4;
cube_data_ptr->GCS[i][k_var+6] = G & 0xFF;
cube_data_ptr->GCS[i][k_var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[i][k_var+8] = B >> 4;
}
}
}
}
 
void Cube_Set_Layer(int layer, int R, int G, int B) {
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
int i,j;
for (i = 0; i < CUBE_ROW_COUNT; i++) {
int i_var = i * GCS_REG_SIZE;
for (j = 0; j < 4; j++) {
int j_var = i_var + (j * 9);
cube_data_ptr->GCS[layer][j_var+0] = R & 0xFF;;
cube_data_ptr->GCS[layer][j_var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[layer][j_var+2] = G >> 4;
cube_data_ptr->GCS[layer][j_var+3] = B & 0xFF;
cube_data_ptr->GCS[layer][j_var+4] = (R << 4) | (B >> 8);
cube_data_ptr->GCS[layer][j_var+5] = R >> 4;
cube_data_ptr->GCS[layer][j_var+6] = G & 0xFF;
cube_data_ptr->GCS[layer][j_var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[layer][j_var+8] = B >> 4;
}
}
}
 
void Cube_Set_Pixel(int layer, int row, int column, int R, int G, int B) {
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
int var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
case 0:
cube_data_ptr->GCS[layer][var+0] = R & 0xFF;
cube_data_ptr->GCS[layer][var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[layer][var+2] = G >> 4;
cube_data_ptr->GCS[layer][var+3] = B & 0xFF;
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0xF0) | (B >> 8);
break;
case 1:
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0x0F) | (R << 4);
cube_data_ptr->GCS[layer][var+5] = R >> 4;
cube_data_ptr->GCS[layer][var+6] = G & 0xFF;
cube_data_ptr->GCS[layer][var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[layer][var+8] = B >> 4;
break;
}
}
/PIC Stuff/Cerebot_32MX7_LED_Cube/CUBE.h
0,0 → 1,53
#ifndef CUBE_H
#define CUBE_H
 
#define CUBE_ROW_COUNT 8
#define CUBE_COLUMN_COUNT 8
#define CUBE_LAYER_COUNT 8
 
#define GCS_REG_SIZE 36
#define GCS_LAYER_SIZE (GCS_REG_SIZE*CUBE_ROW_COUNT)
 
#define RED 0x0FF,0x000,0x000
#define ORANGE 0x0FF,0x020,0x000
#define YELLOW 0x0FF,0x0FF,0x000
#define GREEN 0x000,0x0FF,0x000
#define TEAL 0x000,0x0FF,0x0FF
#define BLUE 0x000,0x000,0x0FF
#define PURPLE 0x0FF,0x000,0x0FF
 
#define SFT_D_TRIS TRISBbits.TRISB15
#define SFT_S_TRIS TRISDbits.TRISD5
#define SFT_K_TRIS TRISDbits.TRISD4
#define SFT_R_TRIS TRISBbits.TRISB14
 
#define SFT_D PORTBbits.RB15
#define SFT_S PORTDbits.RD5
#define SFT_K PORTDbits.RD4
#define SFT_R PORTBbits.RB14
 
#define GSLAT_TRIS TRISDbits.TRISD9
#define XBLNK_TRIS TRISDbits.TRISD2
 
#define GSLAT PORTDbits.RD9
#define XBLNK PORTDbits.RD2
 
typedef struct {
unsigned char GCS[CUBE_LAYER_COUNT][GCS_LAYER_SIZE];
} CUBE_DATA;
 
void Cube_Init(CUBE_DATA *data);
void Cube_Timer_Interrupt(void);
 
// Callbacks on completion of DCS/GCS writes
void Cube_DCS_Write_Callback(void);
void Cube_GCS_Write_Callback(void);
 
// Cube control functions
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);
void Cube_Set_Pixel(int layer, int row, int column, int R, int G, int B);
 
#endif /* CUBE_H */
 
/PIC Stuff/Cerebot_32MX7_LED_Cube/PWM2.c
0,0 → 1,23
#include <xc.h>
#include <plib.h>
#include "defines.h"
#include "PWM2.h"
 
void PWM2_Init(void) {
OC2CON = 0x0000;
OC2R = 0x0001; // PWM initial duty cycle
OC2RS = 0x0001; // PWM duty cycle
OC2CON = 0x0006; // PWM off, 16-bit, timer 2, fault pin disabled
 
IFS0CLR = 0x00000100; // Disable Timer 2 interrupt
T2CONSET = 0x8000; // Turn on Timer 2
PR2 = 0x0003; // PWM period ~ 16-20Mhz
}
 
void PWM2_Start(void) {
OC2CONSET = 0x8000;
}
 
void PWM2_Stop(void) {
OC2CONCLR = 0x8000;
}
/PIC Stuff/Cerebot_32MX7_LED_Cube/PWM2.h
0,0 → 1,9
#ifndef PWM2_H
#define PWM2_H
 
void PWM2_Init(void);
void PWM2_Start(void);
void PWM2_Stop(void);
 
#endif /* PWM2_H */
 
/PIC Stuff/Cerebot_32MX7_LED_Cube/SPI1.c
0,0 → 1,155
#include <xc.h>
#include <plib.h>
#include "defines.h"
#include "SPI1.h"
 
static SPI1_DATA *data_ptr;
static void (*callback_function)(void);
 
void SPI1_Init(SPI1_DATA *data) {
data_ptr = data;
data_ptr->outBufferInd = 0;
data_ptr->outBufferLen = 0;
#ifndef SPI1_WRITE_ONLY
data_ptr->inBufferInd = 0;
data_ptr->inBufferLen = 0;
#endif
INTDisableInterrupts();
 
// Note: FIFO enhanced buffer depth is 4/8/16 for 32/16/8 bit widths
// Alternative Configuration:
// The third value is the SPI bitrate which is 1/2 the frequency of the
// desired clock frequency. Thus 40Mhz / (20Mhz / 2) = 4.
// Note: SPI_OPEN_TBE_NOT_FULL should only be used at >10Mhz speeds
// SpiChnOpen(SPI_CHANNEL1, SPI_OPEN_MSTEN | SPI_OPEN_ENHBUF | SPI_OPEN_TBE_NOT_FULL | SPI_OPEN_RBF_NOT_EMPTY, 4);
// INTSetVectorPriority(INT_SPI_1_VECTOR, INT_PRIORITY_LEVEL_6);
// INTSetVectorSubPriority(INT_SPI_1_VECTOR, INT_SUB_PRIORITY_LEVEL_1);
// INTClearFlag(INT_SPI1E);
// INTClearFlag(INT_SPI1TX);
// INTClearFlag(INT_SPI1RX);
 
// FSCK = FPB / (2 * (SPIxBRG + 1))
IEC0CLR = 0x03800000; // Disable all SPI interrupts
SPI1CON = 0; // Stops and resets the SPI1.
int tmp = SPI1BUF; // Clears the receive buffer
IFS0CLR = 0x03800000; // Clear any existing event
IPC5CLR = 0x1F000000; // Clear the priority
IPC5SET = 0x19000000; // Set IPL=6, Subpriority 1
SPI1BRG = 0x1; // Use FPB/4 clock frequency
SPI1STATCLR = 0x40; // Clear the Overflow
#ifndef SPI1_WRITE_ONLY
IEC0SET = 0x01800000; // Enable RX and Error interrupts
#endif
// Enhanced buffer, SPI on, 8 bits transfer, SMP=1, Master mode
// SPIxTXIF set on buffer empty, SPIxRXIF set on buffer not empty
SPI1CON = 0x18225;
 
INTEnableInterrupts();
}
 
#ifndef SPI1_WRITE_ONLY
int SPI1_Read_Buffer(unsigned char *array, unsigned int count) {
if (count > SPI1_BUFFER_SIZE)
return 0;
if (data_ptr->inBufferLen == 0)
return 0;
 
// Save previous interrupt state
int prev = IEC0 & 0x03800000;
// Temporarily disable interrupts
IEC0CLR = 0x03800000;
int ret = data_ptr->inBufferLen;
int i;
for (i = 0; i < count; i++) {
array[i] = data_ptr->inBuffer[i];
}
// Reset buffer pointers
data_ptr->inBufferInd = 0;
data_ptr->inBufferLen = 0;
// Restore saved interrupt state
IEC0SET = prev;
// Return the number of valid bytes in the buffer
return ret;
}
#endif
 
int SPI1_Write(unsigned char *array, unsigned int count, void (*callback)(void)) {
callback_function = callback;
 
if (count > SPI1_BUFFER_SIZE)
return 0;
if (data_ptr->outBufferLen != 0)
return 0;
 
data_ptr->outBufferLen = count;
data_ptr->outBufferInd = count-1;
int i;
for (i = 0; i < count; i++) {
data_ptr->outBuffer[i] = array[i];
}
IEC0SET = 0x02000000; // Enable TX interrupt
return 1;
}
 
void __ISR(_SPI_1_VECTOR, ipl6) __SPI_1_Interrupt_Handler(void) {
#ifndef SPI1_WRITE_ONLY
// Process SPI1 error flag
if (IFS0bits.SPI1EIF) {
// Clear the receive overflow bit if it is set
if (SPI1STATbits.SPIROV) {
SPI1STATbits.SPIROV = 0;
}
IFS0CLR = 0x00800000; // Clear the error flag
}
 
// Process SPI1 receive flag
if (IFS0bits.SPI1RXIF) {
int i;
// Read the data received from the last transfer
int rxBufferCount = SPI1STATbits.RXBUFELM;
if (data_ptr->inBufferLen + rxBufferCount < SPI1_BUFFER_SIZE) {
for (i = 0; i < rxBufferCount; i++) {
data_ptr->inBuffer[data_ptr->inBufferInd] = SPI1BUF;
data_ptr->inBufferInd++;
data_ptr->inBufferLen++;
}
} else {
// If buffer is full, discard data in enhanced buffer
for (i = 0; i < rxBufferCount; i++) {
int tmp = SPI1BUF;
}
}
IFS0CLR = 0x01000000; // Clear the RX flag
}
#endif
 
// Process SPI1 transmit flag
if (IFS0bits.SPI1TXIF) {
int i;
// Disable the transmit interrupt if all data has been sent
if (data_ptr->outBufferLen == 0) {
IEC0CLR=0x02000000;
if (callback_function != NULL)
(*callback_function)();
} else {
// Start transmitting the data in the buffer
int txBufferFree = 16 - SPI1STATbits.TXBUFELM;
if (data_ptr->outBufferLen > txBufferFree) {
for (i = 0; i < txBufferFree; i++) {
SPI1BUF = data_ptr->outBuffer[data_ptr->outBufferInd];
data_ptr->outBufferInd--;
}
data_ptr->outBufferLen -= txBufferFree;
} else {
for (i = 0; i < data_ptr->outBufferLen; i++) {
SPI1BUF = data_ptr->outBuffer[data_ptr->outBufferInd];
data_ptr->outBufferInd--;
}
data_ptr->outBufferLen = 0;
}
}
IFS0CLR = 0x02000000; // Clear the TX flag
}
}
/PIC Stuff/Cerebot_32MX7_LED_Cube/SPI1.h
0,0 → 1,28
#ifndef SPI1_H
#define SPI1_H
 
#define SPI1_BUFFER_SIZE 300
 
// Flag for selecting write-only on SPI1
#define SPI1_WRITE_ONLY
 
typedef struct {
char outBuffer[SPI1_BUFFER_SIZE];
int outBufferInd;
int outBufferLen;
#ifndef SPI1_WRITE_ONLY
char inBuffer[SPI1_BUFFER_SIZE];
int inBufferInd;
int inBufferLen;
#endif
} SPI1_DATA;
 
void SPI1_Init(SPI1_DATA *data);
// Note: SPI1_Write() writes MSB -> LSB!
int SPI1_Write(unsigned char *array, unsigned int count, void (*callback)(void));
#ifndef SPI1_WRITE_ONLY
int SPI1_Read_Buffer(unsigned char *array, unsigned int count);
#endif
 
#endif /* SPI1_H */
 
/PIC Stuff/Cerebot_32MX7_LED_Cube/TIMER5.c
0,0 → 1,38
#include <xc.h>
#include <plib.h>
#include "defines.h"
#include "TIMER5.h"
 
static void (*callback_function)(void);
 
void TIMER5_Init(void (*callback)(void), unsigned int time_us) {
callback_function = callback;
int time = 5 * time_us;
 
INTDisableInterrupts();
T5CON = 0x0040; // Prescaler at 1:16, clock from peripheral clock
Nop();
TMR5 = 0x0; // Clear timer register
PR5 = time; // Load period register
IPC5SET = 0x00000011; // Set priority level = 4, sub-priority level = 1
IFS0CLR = 0x00100000; // Clear timer interrupt flag
IEC0SET = 0x00100000; // Enable timer interrupt
 
INTEnableInterrupts();
}
 
void TIMER5_Start(void) {
T5CONSET = 0x8000; // Start timer
}
 
void TIMER5_Stop(void) {
T5CONCLR = 0x8000; // Stop timer
}
 
void __ISR(_TIMER_5_VECTOR, ipl4) __TIMER_5_Interrupt_Handler(void) {
// Call the saved callback function
(*callback_function)();
IFS0CLR = 0x00100000; // Clear the timer interrupt flag
}
/PIC Stuff/Cerebot_32MX7_LED_Cube/TIMER5.h
0,0 → 1,9
#ifndef TIMER5_H
#define TIMER5_H
 
void TIMER5_Init(void (*callback)(void), unsigned int time_us);
void TIMER5_Start(void);
void TIMER5_Stop(void);
 
#endif /* TIMER5_H */
 
/PIC Stuff/Cerebot_32MX7_LED_Cube/defines.h
1,5 → 1,13
// PIC32MX795F512L
 
// Power supply must be 5V for proper operation of the board!
 
#define CPU_CLOCK_HZ 80000000UL
#define PERIPHERAL_CLOCK_HZ 80000000UL
#define CPU_CT_HZ (CPU_CLOCK_HZ/2UL)
#define MS_TO_CT_TICKS (CPU_CLOCK_HZ/2000UL)
#define US_TO_CT_TICKS (CPU_CLOCK_HZ/2000000UL)
 
#define ADDRESS_EEPROM 0x50
 
// BTN1 = RG6, BTN2 = RG7, BTN3 = RD13
21,95 → 29,98
#define LED4_TRIS TRISGbits.TRISG15
#define LED4_PORT PORTGbits.RG15
 
void Delay_MS(unsigned int delay_ms);
void Delay_US(unsigned int delay_us);
 
// <editor-fold defaultstate="collapsed" desc="PMOD to MCU Pinouts">
/*
JA-01 AN2/C2IN-/CN4/RB2 RB02
JA-02 AN3/C2IN+/CN5/RB3 RB03
JA-03 AN4/C1IN-/CN6/RB4 RB04
JA-04 PGEC2/AN6/OCFA/RB6 RB06
JA-07 PGED2/AN7/RB7 RB07
JA-08 AN8/C1OUT/RB8 RB08
JA-09 AN9/C2OUT/RB9 RB09
JA-10 CVrefout/PMA13/AN10/RB10 RB10
JA-01 AN2/C2IN-/CN4/RB2 RB02
JA-02 AN3/C2IN+/CN5/RB3 RB03
JA-03 AN4/C1IN-/CN6/RB4 RB04
JA-04 PGEC2/AN6/OCFA/RB6 RB06
JA-07 PGED2/AN7/RB7 RB07
JA-08 AN8/C1OUT/RB8 RB08
JA-09 AN9/C2OUT/RB9 RB09
JA-10 CVrefout/PMA13/AN10/RB10 RB10
*
JB-01 PMD0/RE0 RE00
JB-02 PMD1/RE1 RE01
JB-03 PMD2/RE2 RE02
JB-04 PMD3/RE3 RE03
JB-07 PMD4/RE4 RE04
JB-08 PMD5/RE5 RE05
JB-09 PMD6/RE6 RE06
JB-10 PMD7/RE7 RE07
JB-01 PMD0/RE0 RE00
JB-02 PMD1/RE1 RE01
JB-03 PMD2/RE2 RE02
JB-04 PMD3/RE3 RE03
JB-07 PMD4/RE4 RE04
JB-08 PMD5/RE5 RE05
JB-09 PMD6/RE6 RE06
JB-10 PMD7/RE7 RE07
*
JC-01 T2CK/RC1 RC01
JC-02 C2RX/PMD8/RG0 RG00
JC-03 C2TX/ETXERR/PMD9/RG1 RG01
JC-04 ETXCLK/PMD15/CN16/RD7 RD07
JC-07 AN15/?/OCFB/PMALL/PMA0/CN12/RB15 RB15
JC-08 PMRD/CN14/RD5 RD05
JC-09 OC5/PMWR/CN13/RD4 RD04
JC-10 AN14/ERXD2/AETXD3/PMALH/PMA1/RB14 RB14
JC-01 T2CK/RC1 RC01
JC-02 C2RX/PMD8/RG0 RG00
JC-03 C2TX/ETXERR/PMD9/RG1 RG01
JC-04 ETXCLK/PMD15/CN16/RD7 RD07
JC-07 AN15/ERXD3/AETXD2/OCFB/PMALL/PMA0/CN12/RB15 RB15 (SFT_D)
JC-08 PMRD/CN14/RD5 RD05 (SFT_S)
JC-09 OC5/PMWR/CN13/RD4 RD04 (SFT_K)
JC-10 AN14/ERXD2/AETXD3/PMALH/PMA1/RB14 RB14 (SFT_R)
*
JD-01 SS1/IC2/RD9 RD09
JD-02 SDO1/OC1/INT0/RD0 RD00
JD-03 T5CK/SDI1/RC4 RC04
JD-04 SCK1/IC3/PMCS2/PMA15/RD10 RD10
JD-07 OC2/RD1 RD01
JD-08 OC3/RD2 RD02
JD-09 OC4/RD3 RD03
JD-10 ETXD2/IC5/PMD12/RD12 RD12
JD-01 SS1/IC2/RD9 RD09 (GSLAT)
JD-02 SDO1/OC1/INT0/RD0 RD00 (GSSIN)
JD-03 T5CK/SDI1/RC4 RC04 (GSSOUT)
JD-04 SCK1/IC3/PMCS2/PMA15/RD10 RD10 (GSSCK)
JD-07 OC2/RD1 RD01 (PWMCK)
JD-08 OC3/RD2 RD02 (XBLNK)
JD-09 OC4/RD3 RD03
JD-10 ETXD2/IC5/PMD12/RD12 RD12
*
JE-01 AETXD0/SS1A/U1BRX/U1ACTS/CN20/RD14 RD14
JE-02 SCL1A/SDO1A/U1ATX/RF8 RF08
JE-03 SDA1A/SDI1A/U1ARX/RF2 RF02
JE-04 AETXD1/SCK1A/U1BTX/U1ARTS/CN21/RD15 RD15
JE-07 TRCLK/RA6 RA06
JE-08 TRD3/RA7 RA07
JE-09 Vref-/CVref-/AERXD2/PMA7/RA9 RA09
JE-10 Vref+/CVref+/AERXD3/PMA6/RA10 RA10
JE-01 AETXD0/SS3/U4RX/U1CTS/CN20/RD14 RD14
JE-02 SCL3/SDO3/U1TX/RF8 RF08
JE-03 SDA3/SDI3/U1RX/RF2 RF02
JE-04 AETXD1/SCK3/U4TX/U1RTS/CN21/RD15 RD15
JE-07 TRCLK/RA6 RA06
JE-08 TRD3/RA7 RA07
JE-09 Vref-/CVref-/AERXD2/PMA7/RA9 RA09
JE-10 Vref+/CVref+/AERXD3/PMA6/RA10 RA10
*
JF-01 AC1RX/SS3A/U3BRX/U3ACTS/RF12 RF12 shared with CAN1 Transceiver (JP-1)
JF-02 SCL3A/SDO3A/U3ATX/PMA8/CN18/RF5 RF05
JF-03 SDA3A/SDI3A/U3ARX/PMA9/CN17/RF4 RF04
JF-04 AC1TX/SCK3A/U3BTX/U3ARTS/RF13 RF13 shared with CAN1 Transceiver (JP-2)
JF-07 TMS/RA0 RA00
JF-08 TCK/RA1 RA01
JF-09 TDI/RA4 RA04
JF-10 TDO/RA5 RA05
JF-01 AC1RX/SS4/U5RX/U2CTS/RF12 RF12 shared with CAN1 Transceiver (JP-1)
JF-02 SCL5/SDO4/U2TX/PMA8/CN18/RF5 RF05
JF-03 SDA5/SDI4/U2RX/PMA9/CN17/RF4 RF04
JF-04 AC1TX/SCK4/U5TX/U2RTS/RF13 RF13 shared with CAN1 Transceiver (JP-2)
JF-07 TMS/RA0 RA00
JF-08 TCK/RA1 RA01
JF-09 TDI/RA4 RA04
JF-10 TDO/RA5 RA05
 
N/A SCL2/RA2 RA02 I2C bus #2, not shared with Pmod connector
N/A SDA2/RA3 RA03 I2C bus #2, not shared with Pmod connector
N/A AETXCLK/SCL1/INT3/RA14 RA14 I2C Bus #1, not shared with Pmod connector
N/A AETXEN/SDA1/INT4/RA15 RA15 I2C Bus #1, not shared with Pmod connector
N/A PGED1/AN0/CN2/RB0 RB00 Used by debug circuit, PGC
N/A PGEC1/AN1/CN3/RB1 RB01 Used by debug circuit, PGD
N/A AN5/C1IN+/VBUSON/CN7/RB5 RB05 USB VBUSON
N/A AN11/ERXERR/AETXERR/PMA12/RB11 RB11 Ethernet PHY
N/A AN12/ERXD0/AECRS/PMA11/RB12 RB12 Ethernet PHY
N/A AN13/ERXD1/AECOL/PMA10/RB13 RB13 Ethernet PHY
N/A OSC1/CLKI/RC12 RC12 Primary Oscillator Crystal
N/A SOSCI/CN1/RC13 RC13 Secondary Oscillator Crystal
N/A SOSCO/T1CK/CN0/RC14 RC14 Secondary Oscillator Crystal
N/A OSC2/CLKO/RC15 RC15 Primary Oscillator Crystal
N/A ETXEN/PMD14/CN15/RD6 RD06 Ethernet PHY
N/A RTCC/EMDIO/AEMDIO/IC1/RD8 RD08 Ethernet PHY
N/A EMDC/AEMDC/IC4/PMCS1/PMA14/RD11 RD11 Ethernet PHY
N/A ETXD3/PMD13/CN19/RD13 RD13 BTN3
N/A AERXD0/INT1/RE8 RE08 USB Overcurrent detect
N/A AERXD1/INT2/RE9 RE09 Ethernet PHY Reset
N/A C1RX/ETXD1/PMD11/RF0 RF00 Ethernet PHY
N/A C1TX/ETXD0/PMD10/RF1 RF01 Ethernet PHY
N/A USBID/RF3 RF03 USBID (USB-4)
N/A D+/RG2 RG02 D+ (USB-3)
N/A D-/RG3 RG03 D- (USB-2)
N/A ECOL/SCK2A/U2BTX/U2ARTS/PMA5/CN8/RG6 RG06 BTN1
N/A ECRS/SDA2A/SDI2A/U2ARX/PMA4/CN9/RG7 RG07 BTN2
N/A ?/SCL2A/SDO2A/U2ATX/PMA3/CN10/RG8 RG08 Ethernet PHY
N/A ?/SS2A/U2BRX/U2ACTS/PMA2/CN11/RG9 RG09 Ethernet PHY
N/A TRD1/RG12 RG12 LED1
N/A TRD0/RG13 RG13 LED2
N/A TRD2/RG14 RG14 LED3
N/A AERXERR/RG15 RG15 LED4
N/A SCL2/RA2 RA02 I2C bus #2, not shared with Pmod connector
N/A SDA2/RA3 RA03 I2C bus #2, not shared with Pmod connector
N/A AETXCLK/SCL1/INT3/RA14 RA14 I2C Bus #1, not shared with Pmod connector
N/A AETXEN/SDA1/INT4/RA15 RA15 I2C Bus #1, not shared with Pmod connector
N/A PGED1/AN0/CN2/RB0 RB00 Used by debug circuit, PGC
N/A PGEC1/AN1/CN3/RB1 RB01 Used by debug circuit, PGD
N/A AN5/C1IN+/VBUSON/CN7/RB5 RB05 USB VBUSON
N/A AN11/ERXERR/AETXERR/PMA12/RB11 RB11 Ethernet PHY
N/A AN12/ERXD0/AECRS/PMA11/RB12 RB12 Ethernet PHY
N/A AN13/ERXD1/AECOL/PMA10/RB13 RB13 Ethernet PHY
N/A OSC1/CLKI/RC12 RC12 Primary Oscillator Crystal
N/A SOSCI/CN1/RC13 RC13 Secondary Oscillator Crystal
N/A SOSCO/T1CK/CN0/RC14 RC14 Secondary Oscillator Crystal
N/A OSC2/CLKO/RC15 RC15 Primary Oscillator Crystal
N/A ETXEN/PMD14/CN15/RD6 RD06 Ethernet PHY
N/A RTCC/EMDIO/AEMDIO/IC1/RD8 RD08 Ethernet PHY
N/A EMDC/AEMDC/IC4/PMCS1/PMA14/RD11 RD11 Ethernet PHY
N/A ETXD3/PMD13/CN19/RD13 RD13 BTN3
N/A AERXD0/INT1/RE8 RE08 USB Overcurrent detect
N/A AERXD1/INT2/RE9 RE09 Ethernet PHY Reset
N/A C1RX/ETXD1/PMD11/RF0 RF00 Ethernet PHY
N/A C1TX/ETXD0/PMD10/RF1 RF01 Ethernet PHY
N/A USBID/RF3 RF03 USBID (USB-4)
N/A D+/RG2 RG02 D+ (USB-3)
N/A D-/RG3 RG03 D- (USB-2)
N/A ECOL/SCK2/U6TX/U3RTS/PMA5/CN8/RG6 RG06 BTN1
N/A ECRS/SDA4/SDI2/U3RX/PMA4/CN9/RG7 RG07 BTN2
N/A ERXDV/AERXDV/ECRSDV/AECRSDV/SCL4/SDO2/U3TX/PMA3/CN10/RG8 RG08 Ethernet PHY
N/A ERXCLK/AERXCLK/EREFCLK/AEREFCLK/SS2/U6RX/U3CTS/PMA2/CN11/RG9 RG09 Ethernet PHY
N/A TRD1/RG12 RG12 LED1
N/A TRD0/RG13 RG13 LED2
N/A TRD2/RG14 RG14 LED3
N/A AERXERR/RG15 RG15 LED4
*/
// </editor-fold>
 
132,14 → 143,14
debug circuit to the PC for use with the MPLAB IDE.
J16 - Power supply source select
* This jumper is used to select the source of main board power.
Place a shorting block in the upper, ?USB? position to have the
Place a shorting block in the upper, ?USB? position to have the
board powered from the USB device connector, J19.
Place a shorting block in the center, ?EXT? position to have the
Place a shorting block in the center, ?EXT? position to have the
board powered from one of the external power connectors, J17 or J18.
Place a shorting block in the lower, ?DBG? position to have the
Place a shorting block in the lower, ?DBG? position to have the
board powered from the debug USB connector, J15.
J17 - External Power Connector
* This is a 2.5mm x 5.5mm, center positive, coax power connector used to
* This is a 2.5mm x 5.5mm, center positive, coax power connector used to
provide external power to the board. The optional Digilent 5V Switching
Power Supply is connected here.
J18 - External Power Connector
151,7 → 162,7
* This is a USB micro-AB connector. It is used when using the PIC32MX795
microcontroller to implement a USB device or OTG Host/Device.
J20 - USB Host Connector
* This is a standard sized USB type A connector. This connector is used to
* This is a standard sized USB type A connector. This connector is used to
connect USB devices to the board when using the PIC32MX795 microcontroller
to implement an embedded USB host.
*/
160,11 → 171,11
// <editor-fold defaultstate="collapsed" desc="Jumpers">
/*
J20 - USB Host Connector
* This is a standard sized USB type A connector. This connector is used to
* This is a standard sized USB type A connector. This connector is used to
connect USB devices to the board when using the PIC32MX795 microcontroller
to implement an embedded USB host.
JP1 & JP2 - CAN or Pmod Select
* These jumpers select microcontroller signals RF12 and RF13 for use with CAN
* These jumpers select microcontroller signals RF12 and RF13 for use with CAN
#1 or Pmod connector JF. Place these jumpers in the CAN position to use CAN
#1. Place the jumpers in the PMOD position to use then with Pmod connector JF.
JP3 & JP4 - Pull-up enable for I2C port #2
173,19 → 184,19
resistors. Remove the shorting blocks to disable the pull-up resistors. Only
a single device on the I2C bus should have the pull-up resistors enabled.
JP5 - CAN #1 Termination
* This jumper is used to enable/disable the 120 ohm termination resistor for
* This jumper is used to enable/disable the 120 ohm termination resistor for
CAN #1. Insert the shorting block to enable the termination resistor, remove
it to disable the termination resistor.
JP6 - CAN #1 5V0 Enable
* This jumper is used to enable/disable providing 5V to the CAN #1 connector.
* This jumper is used to enable/disable providing 5V to the CAN #1 connector.
Insert the shorting block to connect the board 5V0 supply to pins 9 & 10 of
CAN #1 connector. Remove the shorting block to disconnect the 5V0 supply.
JP7 - CAN #2 Termination
* This jumper is used to enable/disable the 120 ohm termination resistor for
* This jumper is used to enable/disable the 120 ohm termination resistor for
CAN #2. Insert the shorting block to enable the termination resistor, remove
it to disable the termination resistor.
JP8 - CAN #1 5V0 Enable
* This jumper is used to enable/disable providing 5V to the CAN #1 connector.
* This jumper is used to enable/disable providing 5V to the CAN #1 connector.
Insert the shorting block to connect the board 5V0 supply to pins 9 & 10 of
CAN #1 connector. Remove the shorting block to disconnect the 5V0 supply.
JP9 - Do Not Use
/PIC Stuff/Cerebot_32MX7_LED_Cube/main.c
1,3 → 1,4
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
/* ------------------------------------------------------------ */
/* PIC32 Configuration Settings */
/* ------------------------------------------------------------ */
7,7 → 8,7
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
#pragma config FPLLODIV = DIV_1 // PLL Output Divider
#pragma config FPBDIV = DIV_8 // Peripheral Clock Divisor (timers/UART/SPI/I2C)
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (timers/UART/SPI/I2C)
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable
/* Clock Control Settings */
#pragma config IESO = OFF // Internal/External Clock Switch Over
32,26 → 33,369
/* Debug Settings */
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (on-board debugger)
/* ------------------------------------------------------------ */
// </editor-fold>
 
#include <xc.h>
#include <plib.h>
#include <stdlib.h>
#include "defines.h"
#include "SPI1.h"
#include "TIMER5.h"
#include "CUBE.h"
 
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);
void Animation_Full_Color_Sweep(int iterations, int delay_us);
void Animation_Row_Column_Sweep(int iterations, int delay_ms);
void Animation_Pixel_Sweep(int iterations, int delay_ms);
void Animation_Pseudo_Random_Colors(int iterations,int delay_ms);
void Animation_Random_Colors(int iterations, int delay_ms);
void Animation_Cube_In_Cube(int iterations, int delay_ms);
 
void Delay_MS(unsigned int delay_ms) {
unsigned int delay = delay_ms * MS_TO_CT_TICKS;
unsigned int startTime = ReadCoreTimer();
while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
}
 
void Delay_US(unsigned int delay_us) {
unsigned int delay = delay_us * US_TO_CT_TICKS;
unsigned int startTime = ReadCoreTimer();
while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
}
 
int main() {
/* Configure the target for maximum performance at 80 MHz. */
SYSTEMConfigPerformance(80000000UL);
// Note: This overrides the peripheral clock to 80Mhz regardless of config
SYSTEMConfigPerformance(CPU_CLOCK_HZ);
 
// Configure the interrupts for multiple vectors
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
 
LED1_TRIS = 0;
LED2_TRIS = 0;
LED3_TRIS = 0;
LED4_TRIS = 0;
LED1_PORT = 1;
LED2_PORT = 1;
LED3_PORT = 1;
LED4_PORT = 1;
// Set all analog I/O pins to digital
AD1PCFGSET = 0xFFFF;
 
while(1) {}
SPI1_DATA spi_data;
SPI1_Init(&spi_data);
 
PWM2_Init();
PWM2_Start();
 
CUBE_DATA cube_data;
Cube_Init(&cube_data);
 
// 2083 = 60Hz, 500 = 250Hz, 250 = 500Hz
TIMER5_Init(&Cube_Timer_Interrupt, 200);
TIMER5_Start();
 
// Loop through some preset animations
while(1) {
Animation_Solid_Colors(2,300);
Animation_Layer_Alternate(2,300);
Animation_Pixel_Alternate(1,200);
Animation_Full_Color_Sweep(2,1000);
Animation_Row_Column_Sweep(2,40);
Animation_Pseudo_Random_Colors(10,300);
Animation_Random_Colors(10,300);
Animation_Cube_In_Cube(4,300);
}
}
 
void Animation_Solid_Colors(int iterations, int delay_ms) {
int i;
for (i = 0; i < iterations; i++) {
Cube_Set_All(RED);
Delay_MS(delay_ms);
Cube_Set_All(GREEN);
Delay_MS(delay_ms);
Cube_Set_All(BLUE);
Delay_MS(delay_ms);
}
}
 
void Animation_Layer_Alternate(int iterations, int delay_ms) {
int i,z;
for (z = 0; z < iterations; z++) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if (i % 3 == 0)
Cube_Set_Layer(i,RED);
else if (i % 3 == 1)
Cube_Set_Layer(i,GREEN);
else
Cube_Set_Layer(i,BLUE);
}
Delay_MS(delay_ms);
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if (i % 3 == 0)
Cube_Set_Layer(i,GREEN);
else if (i % 3 == 1)
Cube_Set_Layer(i,BLUE);
else
Cube_Set_Layer(i,RED);
}
Delay_MS(delay_ms);
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if (i % 3 == 0)
Cube_Set_Layer(i,BLUE);
else if (i % 3 == 1)
Cube_Set_Layer(i,RED);
else
Cube_Set_Layer(i,GREEN);
}
Delay_MS(delay_ms);
}
}
 
void Animation_Pixel_Alternate(int iterations, int delay_ms) {
int i,j,k,z;
for (z = 0; z < iterations; z++) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
Cube_Clear();
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
int var = (j * 8) + k;
if (var % 3 == 0)
Cube_Set_Pixel(i,j,k,RED);
else if (var % 3 == 1)
Cube_Set_Pixel(i,j,k,GREEN);
else
Cube_Set_Pixel(i,j,k,BLUE);
}
}
Delay_MS(delay_ms);
Cube_Clear();
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
int var = (j * 8) + k;
if (var % 3 == 0)
Cube_Set_Pixel(i,j,k,GREEN);
else if (var % 3 == 1)
Cube_Set_Pixel(i,j,k,BLUE);
else
Cube_Set_Pixel(i,j,k,RED);
}
}
Delay_MS(delay_ms);
Cube_Clear();
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
int var = (j * 8) + k;
if (var % 3 == 0)
Cube_Set_Pixel(i,j,k,BLUE);
else if (var % 3 == 1)
Cube_Set_Pixel(i,j,k,RED);
else
Cube_Set_Pixel(i,j,k,GREEN);
}
}
Delay_MS(delay_ms);
}
}
}
 
void Animation_Full_Color_Sweep(int iterations, int delay_us) {
int i,z;
for (z = 0; z < iterations; z++) {
for (i = 0; i < 0x0FF; i+=2) {
Cube_Set_All(i,0,0);
Delay_US(delay_us);
}
for (i = 0; i < 0x0FF; i+=2) {
Cube_Set_All(0x0FF,i,0);
Delay_US(delay_us);
}
for (i = 0x0FF; i >= 0; i-=2) {
Cube_Set_All(i,0x0FF,0);
Delay_US(delay_us);
}
for (i = 0; i < 0x0FF; i+=2) {
Cube_Set_All(0,0x0FF,i);
Delay_US(delay_us);
}
for (i = 0; i < 0x0FF; i+=2) {
Cube_Set_All(i,0x0FF,0x0FF);
Delay_US(delay_us);
}
for (i = 0x0FF; i >= 0; i-=2) {
Cube_Set_All(0x0FF,i,0x0FF);
Delay_US(delay_us);
}
for (i = 0x0FF; i >= 0; i-=2) {
Cube_Set_All(i,0,0x0FF);
Delay_US(delay_us);
}
for (i = 0x100; i >= 0; i-=2) {
Cube_Set_All(0,0,i);
Delay_US(delay_us);
}
}
}
 
void Animation_Row_Column_Sweep(int iterations, int delay_ms) {
int i,j,k,a,z;
for (z = 0; z < iterations; z++) {
for (i = 0; i < 3; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
Cube_Clear();
for (k = 0; k < CUBE_COLUMN_COUNT; k++)
if (i % 3 == 0)
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,j,k,RED);
else if (i % 3 == 1)
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,j,k,GREEN);
else
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,j,k,BLUE);
Delay_MS(delay_ms);
}
for (j = 0; j < CUBE_ROW_COUNT; j++) {
Cube_Clear();
for (k = 0; k < CUBE_COLUMN_COUNT; k++)
if (i % 3 == 0)
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,k,j,RED);
else if (i % 3 == 1)
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,k,j,GREEN);
else
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,k,j,BLUE);
Delay_MS(delay_ms);
}
for (j = CUBE_LAYER_COUNT-1; j >= 0; j--) {
Cube_Clear();
if (i % 3 == 0) {
for (k = 0; k < CUBE_LAYER_COUNT; k++)
if (k == j)
Cube_Set_Layer(k,RED);
} else if (i % 3 == 1) {
for (k = 0; k < CUBE_LAYER_COUNT; k++)
if (k == j)
Cube_Set_Layer(k,GREEN);
} else {
for (k = 0; k < CUBE_LAYER_COUNT; k++)
if (k == j)
Cube_Set_Layer(k,BLUE);
}
Delay_MS(delay_ms);
}
}
}
}
 
void Animation_Pixel_Sweep(int iterations, int delay_ms) {
int i,j,k,z,a;
for (z = 0; z < iterations; z++) {
for (a = 0; a < 3; a++) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
Cube_Clear();
if (a % 3 == 0) {
Cube_Set_Pixel(i,j,k,RED);
} else if (a % 3 == 1) {
Cube_Set_Pixel(i,j,k,GREEN);
} else {
Cube_Set_Pixel(i,j,k,BLUE);
}
Delay_MS(delay_ms);
}
}
}
}
}
}
 
void Animation_Pseudo_Random_Colors(int iterations, int delay_ms) {
int i,j,k,z;
for (z = 0; z < iterations; z++) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
unsigned int a = rand();
if (a % 5 == 0)
Cube_Set_Pixel(i,j,k,RED);
else if (a % 5 == 1)
Cube_Set_Pixel(i,j,k,GREEN);
else if (a % 5 == 2)
Cube_Set_Pixel(i,j,k,BLUE);
else if (a % 5 == 3)
Cube_Set_Pixel(i,j,k,PURPLE);
else if (a % 5 == 4)
Cube_Set_Pixel(i,j,k,YELLOW);
else
Cube_Set_Pixel(i,j,k,ORANGE);
}
}
}
Delay_MS(delay_ms);
}
}
 
void Animation_Random_Colors(int iterations, int delay_ms) {
int i,j,k,z;
for (z = 0; z < iterations; z++) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
Cube_Set_Pixel(i,j,k,rand()&0x0FF,rand()&0x0FF,rand()&0x0FF);
}
}
}
Delay_MS(delay_ms);
}
}
 
void Animation_Cube_In_Cube(int iterations, int delay_ms) {
int z,x,i,j,k;
for (z = 0; z < iterations; z++) {
for (x = 0; x < 5; x++) {
Cube_Clear();
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if ((x == 0 || x == 4)&&(i == 0 || i == 7)) {
Cube_Set_Layer(i,RED);
} else if ((x == 1 || x == 4)&&(i == 1 || i == 6)) {
for (j = 1; j < CUBE_ROW_COUNT-1; j++)
for (k = 1; k < CUBE_COLUMN_COUNT-1; k++)
Cube_Set_Pixel(i,j,k,YELLOW);
} else if ((x == 2 || x == 4)&&(i == 2 || i == 5)) {
for (j = 2; j < CUBE_ROW_COUNT-2; j++)
for (k = 2; k < CUBE_COLUMN_COUNT-2; k++)
Cube_Set_Pixel(i,j,k,GREEN);
} else if ((x == 3 || x == 4)&&(i == 3 || i == 4)) {
for (j = 3; j < CUBE_ROW_COUNT-3; j++)
for (k = 3; k < CUBE_COLUMN_COUNT-3; k++)
Cube_Set_Pixel(i,j,k,BLUE);
}
 
if ((x == 0 || x == 4)&&(i > 0 && i < 8)) {
for (j = 0; j < 8; j++) {
Cube_Set_Pixel(i,j,0,RED);
Cube_Set_Pixel(i,j,7,RED);
Cube_Set_Pixel(i,0,j,RED);
Cube_Set_Pixel(i,7,j,RED);
}
}
if ((x == 1 || x == 4)&&(i > 1 && i < 7)) {
for (j = 1; j < 7; j++) {
Cube_Set_Pixel(i,j,1,YELLOW);
Cube_Set_Pixel(i,j,6,YELLOW);
Cube_Set_Pixel(i,1,j,YELLOW);
Cube_Set_Pixel(i,6,j,YELLOW);
}
}
if ((x == 2 || x == 4)&&(i > 2 && i < 6)) {
for (j = 2; j < 6; j++) {
Cube_Set_Pixel(i,j,2,GREEN);
Cube_Set_Pixel(i,j,5,GREEN);
Cube_Set_Pixel(i,2,j,GREEN);
Cube_Set_Pixel(i,5,j,GREEN);
}
}
}
Delay_MS(delay_ms);
}
}
}
/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
POSSIBLE_DEPFILES=${OBJECTDIR}/main.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
OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/SPI1.o ${OBJECTDIR}/TIMER5.o ${OBJECTDIR}/CUBE.o ${OBJECTDIR}/PWM2.o
 
 
CFLAGS=
88,14 → 88,54
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.o.d
@${FIXDEPS} "${OBJECTDIR}/main.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) -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c
@${FIXDEPS} "${OBJECTDIR}/main.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}/main.o.d" -o ${OBJECTDIR}/main.o main.c
${OBJECTDIR}/SPI1.o: SPI1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SPI1.o.d
@${FIXDEPS} "${OBJECTDIR}/SPI1.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}/SPI1.o.d" -o ${OBJECTDIR}/SPI1.o SPI1.c
${OBJECTDIR}/TIMER5.o: TIMER5.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER5.o.d
@${FIXDEPS} "${OBJECTDIR}/TIMER5.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}/TIMER5.o.d" -o ${OBJECTDIR}/TIMER5.o TIMER5.c
${OBJECTDIR}/CUBE.o: CUBE.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CUBE.o.d
@${FIXDEPS} "${OBJECTDIR}/CUBE.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}/CUBE.o.d" -o ${OBJECTDIR}/CUBE.o CUBE.c
${OBJECTDIR}/PWM2.o: PWM2.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${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
else
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.o.d
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c
@${FIXDEPS} "${OBJECTDIR}/main.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}/main.o.d" -o ${OBJECTDIR}/main.o main.c
${OBJECTDIR}/SPI1.o: SPI1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SPI1.o.d
@${FIXDEPS} "${OBJECTDIR}/SPI1.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}/SPI1.o.d" -o ${OBJECTDIR}/SPI1.o SPI1.c
${OBJECTDIR}/TIMER5.o: TIMER5.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER5.o.d
@${FIXDEPS} "${OBJECTDIR}/TIMER5.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}/TIMER5.o.d" -o ${OBJECTDIR}/TIMER5.o TIMER5.c
${OBJECTDIR}/CUBE.o: CUBE.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CUBE.o.d
@${FIXDEPS} "${OBJECTDIR}/CUBE.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}/CUBE.o.d" -o ${OBJECTDIR}/CUBE.o CUBE.c
${OBJECTDIR}/PWM2.o: PWM2.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${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
endif
 
# ------------------------------------------------------------------------------------
/PIC Stuff/Cerebot_32MX7_LED_Cube/nbproject/Makefile-genesis.properties
1,5 → 1,5
#
#Sun May 05 22:04:33 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
5,6 → 5,9
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>SPI1.h</itemPath>
<itemPath>TIMER5.h</itemPath>
<itemPath>CUBE.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
14,6 → 17,11
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>SPI1.c</itemPath>
<itemPath>TIMER5.c</itemPath>
<itemPath>CUBE.c</itemPath>
<itemPath>PWM2.h</itemPath>
<itemPath>PWM2.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
58,14 → 66,13
<property key="enable-app-io" value="false"/>
<property key="enable-omit-frame-pointer" value="false"/>
<property key="enable-symbols" value="true"/>
<property key="enable-unroll-loops" value="false"/>
<property key="enable-unroll-loops" value="true"/>
<property key="exclude-floating-point" value="false"/>
<property key="extra-include-directories" value=""/>
<property key="generate-16-bit-code" value="false"/>
<property key="isolate-each-function" value="false"/>
<property key="keep-inline" value="false"/>
<property key="make-warnings-into-errors" value="false"/>
<property key="optimization-level" value=""/>
<property key="optimization-level" value="-O1"/>
<property key="place-data-into-section" value="false"/>
<property key="post-instruction-scheduling" value="default"/>
<property key="pre-instruction-scheduling" value="default"/>
94,6 → 101,7
<property key="warning-level" value=""/>
</C32-AS>
<C32-LD>
<property key="additional-options-use-response-files" value="false"/>
<property key="enable-check-sections" value="false"/>
<property key="exclude-floating-point-library" value="false"/>
<property key="exclude-standard-libraries" value="false"/>
105,6 → 113,7
<property key="linker-symbols" value=""/>
<property key="map-file" value=""/>
<property key="no-startup-files" value="false"/>
<property key="oXC32ld-extra-opts" value=""/>
<property key="optimization-level" value=""/>
<property key="preprocessor-macros" value=""/>
<property key="remove-unused-sections" value="false"/>
121,15 → 130,14
<property key="enable-app-io" value="false"/>
<property key="enable-omit-frame-pointer" value="false"/>
<property key="enable-symbols" value="true"/>
<property key="enable-unroll-loops" value="false"/>
<property key="enable-unroll-loops" value="true"/>
<property key="exceptions" value="true"/>
<property key="exclude-floating-point" value="false"/>
<property key="extra-include-directories" value=""/>
<property key="generate-16-bit-code" value="false"/>
<property key="isolate-each-function" value="false"/>
<property key="keep-inline" value="false"/>
<property key="make-warnings-into-errors" value="false"/>
<property key="optimization-level" value=""/>
<property key="optimization-level" value="-O1"/>
<property key="place-data-into-section" value="false"/>
<property key="post-instruction-scheduling" value="default"/>
<property key="pre-instruction-scheduling" value="default"/>
141,6 → 149,7
</C32CPP>
<C32Global>
<property key="legacy-libc" value="false"/>
<property key="save-temps" value="false"/>
</C32Global>
<PK3OBPlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
148,6 → 157,8
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>