Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 230 → Rev 231

/PIC Stuff/Cerebot_32MX7_LED_Cube/main.c
35,9 → 35,6
/* ------------------------------------------------------------ */
// </editor-fold>
 
#include <xc.h>
#include <plib.h>
#include <stdlib.h>
#include "defines.h"
#include "UART1.h"
#include "SPI1.h"
52,23 → 49,23
void BTN2_Interrupt(void);
void BTN3_Interrupt(void);
 
void Delay_MS(unsigned int delay_ms) {
void Delay_MS(uint32_t delay_ms) {
// Delays the CPU for the given amount of time.
// Note: Watch out for integer overflow! (max delay_ms = 107374) ??
unsigned int delay = delay_ms * MS_TO_CT_TICKS;
unsigned int startTime = ReadCoreTimer();
while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
uint32_t delay = delay_ms * MS_TO_CT_TICKS;
uint32_t startTime = ReadCoreTimer();
while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
}
 
void Delay_US(unsigned int delay_us) {
void Delay_US(uint32_t delay_us) {
// Delays the CPU for the given amount of time.
// Note: Watch out for integer overflow!
unsigned int delay = delay_us * US_TO_CT_TICKS;
unsigned int startTime = ReadCoreTimer();
while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
uint32_t delay = delay_us * US_TO_CT_TICKS;
uint32_t startTime = ReadCoreTimer();
while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
}
 
int main() {
int32_t main() {
// WARNING!! THIS BOARD WILL RESET EVERY 1048.576s DUE TO THE WDT!!
/* Configure the target for maximum performance at 80 MHz. */
125,11 → 122,11
// Delay_MS(2000);
// Animation_Pseudo_Random_Colors(10,300);
 
// char start_text[] = "Cube Initialized\r\n";
// int8_t start_text[] = "Cube Initialized\r\n";
// UART1_Write(start_text, 18);
 
// Set the overlay text
char text_string[] = "Welcome to the AMP Lab ";
uint8_t text_string[] = "Welcome to the AMP Lab ";
Cube_Text_Init(text_string, 27, 0xFF, 0xFF, 0xFF);
TIMER4_Start();
 
151,7 → 148,7
 
// Function call on button 1 press to change refresh rate
void BTN1_Interrupt(void) {
static char state;
static uint8_t state;
state = (state == 4) ? 0 : state + 1;
TIMER5_Stop();
switch (state) {
176,11 → 173,11
 
// Function call on button 2 press to change brightness
void BTN2_Interrupt(void) {
static char state;
static uint8_t state;
state = (state == 6) ? 0 : state + 1;
TIMER5_Stop();
Delay_MS(1); // Need to wait for all SPI writes to complete
char BC;
uint8_t BC;
switch (state) {
case 0:
BC = 0x01;
210,7 → 207,7
 
// Function call on button 3 press to change text scroll speed
void BTN3_Interrupt(void) {
static char state;
static uint8_t state;
state = (state == 4) ? 0 : state + 1;
TIMER4_Stop();
switch (state) {