Subversion Repositories Code-Repo

Rev

Rev 226 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 226 Rev 231
Line 33... Line 33...
33
/* Debug Settings */
33
/* Debug Settings */
34
#pragma config ICESEL = ICS_PGx1    // ICE/ICD Comm Channel Select (on-board debugger)
34
#pragma config ICESEL = ICS_PGx1    // ICE/ICD Comm Channel Select (on-board debugger)
35
/* ------------------------------------------------------------ */
35
/* ------------------------------------------------------------ */
36
// </editor-fold>
36
// </editor-fold>
37
 
37
 
38
#include <xc.h>
-
 
39
#include <plib.h>
-
 
40
#include <stdlib.h>
-
 
41
#include "defines.h"
38
#include "defines.h"
42
#include "UART1.h"
39
#include "UART1.h"
43
#include "SPI1.h"
40
#include "SPI1.h"
44
#include "SPI4.h"
41
#include "SPI4.h"
45
#include "TIMER4.h"
42
#include "TIMER4.h"
Line 50... Line 47...
50
 
47
 
51
void BTN1_Interrupt(void);
48
void BTN1_Interrupt(void);
52
void BTN2_Interrupt(void);
49
void BTN2_Interrupt(void);
53
void BTN3_Interrupt(void);
50
void BTN3_Interrupt(void);
54
 
51
 
55
void Delay_MS(unsigned int delay_ms) {
52
void Delay_MS(uint32_t delay_ms) {
56
    // Delays the CPU for the given amount of time.
53
    // Delays the CPU for the given amount of time.
57
    // Note: Watch out for integer overflow! (max delay_ms = 107374) ??
54
    // Note: Watch out for integer overflow! (max delay_ms = 107374) ??
58
    unsigned int delay = delay_ms * MS_TO_CT_TICKS;
55
    uint32_t delay = delay_ms * MS_TO_CT_TICKS;
59
    unsigned int startTime = ReadCoreTimer();
56
    uint32_t startTime = ReadCoreTimer();
60
    while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
57
    while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
61
}
58
}
62
 
59
 
63
void Delay_US(unsigned int delay_us) {
60
void Delay_US(uint32_t delay_us) {
64
    // Delays the CPU for the given amount of time.
61
    // Delays the CPU for the given amount of time.
65
    // Note: Watch out for integer overflow!
62
    // Note: Watch out for integer overflow!
66
    unsigned int delay = delay_us * US_TO_CT_TICKS;
63
    uint32_t delay = delay_us * US_TO_CT_TICKS;
67
    unsigned int startTime = ReadCoreTimer();
64
    uint32_t startTime = ReadCoreTimer();
68
    while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
65
    while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
69
}
66
}
70
 
67
 
71
int main() {
68
int32_t main() {
72
    // WARNING!! THIS BOARD WILL RESET EVERY 1048.576s DUE TO THE WDT!!
69
    // WARNING!! THIS BOARD WILL RESET EVERY 1048.576s DUE TO THE WDT!!
73
    
70
    
74
    /* Configure the target for maximum performance at 80 MHz. */
71
    /* Configure the target for maximum performance at 80 MHz. */
75
    // Note: This overrides the peripheral clock to 80Mhz regardless of config
72
    // Note: This overrides the peripheral clock to 80Mhz regardless of config
76
    SYSTEMConfigPerformance(CPU_CLOCK_HZ);
73
    SYSTEMConfigPerformance(CPU_CLOCK_HZ);
Line 123... Line 120...
123
//    Delay_MS(2000);
120
//    Delay_MS(2000);
124
//    Cube_Set_All(BLUE);
121
//    Cube_Set_All(BLUE);
125
//    Delay_MS(2000);
122
//    Delay_MS(2000);
126
//    Animation_Pseudo_Random_Colors(10,300);
123
//    Animation_Pseudo_Random_Colors(10,300);
127
 
124
 
128
//    char start_text[] = "Cube Initialized\r\n";
125
//    int8_t start_text[] = "Cube Initialized\r\n";
129
//    UART1_Write(start_text, 18);
126
//    UART1_Write(start_text, 18);
130
 
127
 
131
    // Set the overlay text
128
    // Set the overlay text
132
    char text_string[] = "Welcome to the AMP Lab     ";
129
    uint8_t text_string[] = "Welcome to the AMP Lab     ";
133
    Cube_Text_Init(text_string, 27, 0xFF, 0xFF, 0xFF);
130
    Cube_Text_Init(text_string, 27, 0xFF, 0xFF, 0xFF);
134
    TIMER4_Start();
131
    TIMER4_Start();
135
 
132
 
136
    // Loop through some preset animations
133
    // Loop through some preset animations
137
    while(1) {
134
    while(1) {
Line 149... Line 146...
149
    }
146
    }
150
}
147
}
151
 
148
 
152
// Function call on button 1 press to change refresh rate
149
// Function call on button 1 press to change refresh rate
153
void BTN1_Interrupt(void) {
150
void BTN1_Interrupt(void) {
154
    static char state;
151
    static uint8_t state;
155
    state = (state == 4) ? 0 : state + 1;
152
    state = (state == 4) ? 0 : state + 1;
156
    TIMER5_Stop();
153
    TIMER5_Stop();
157
    switch (state) {
154
    switch (state) {
158
        case 0:
155
        case 0:
159
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500); // 250Hz
156
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500); // 250Hz
Line 174... Line 171...
174
    TIMER5_Start();
171
    TIMER5_Start();
175
}
172
}
176
 
173
 
177
// Function call on button 2 press to change brightness
174
// Function call on button 2 press to change brightness
178
void BTN2_Interrupt(void) {
175
void BTN2_Interrupt(void) {
179
    static char state;
176
    static uint8_t state;
180
    state = (state == 6) ? 0 : state + 1;
177
    state = (state == 6) ? 0 : state + 1;
181
    TIMER5_Stop();
178
    TIMER5_Stop();
182
    Delay_MS(1); // Need to wait for all SPI writes to complete
179
    Delay_MS(1); // Need to wait for all SPI writes to complete
183
    char BC;
180
    uint8_t BC;
184
    switch (state) {
181
    switch (state) {
185
        case 0:
182
        case 0:
186
            BC = 0x01;
183
            BC = 0x01;
187
            break;
184
            break;
188
        case 1:
185
        case 1:
Line 208... Line 205...
208
    TIMER5_Start();
205
    TIMER5_Start();
209
}
206
}
210
 
207
 
211
// Function call on button 3 press to change text scroll speed
208
// Function call on button 3 press to change text scroll speed
212
void BTN3_Interrupt(void)  {
209
void BTN3_Interrupt(void)  {
213
    static char state;
210
    static uint8_t state;
214
    state = (state == 4) ? 0 : state + 1;
211
    state = (state == 4) ? 0 : state + 1;
215
    TIMER4_Stop();
212
    TIMER4_Stop();
216
    switch (state) {
213
    switch (state) {
217
        case 0:
214
        case 0:
218
            TIMER4_Init(NULL, &Cube_Text_Interrupt, 209712);
215
            TIMER4_Init(NULL, &Cube_Text_Interrupt, 209712);