Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 Kevin 1
#include "maindefs.h"
121 Kevin 2
#include "Adafruit_GFX.h"
119 Kevin 3
#include "interrupts.h"
4
#include "uart.h"
120 Kevin 5
#include "i2c.h"
121 Kevin 6
#include "spi.h"
7
#include "nfc.h"
8
#include "led_backpack.h"
9
#include "oled_ssd1306.h"
10
#include "oled_ssd1331.h"
123 Kevin 11
#include "adc.h"
119 Kevin 12
#include <usart.h>
13
#include <delays.h>
121 Kevin 14
#include <string.h>
119 Kevin 15
 
16
#pragma config WDTEN = OFF          // Turn off watchdog timer
17
#pragma config XINST = OFF          // Turn off extended instruction set
18
#pragma config OSC = HSPLL          // Use external oscillator (101)
19
#pragma config PLLDIV = 3           // Set PPL prescaler to 3 (to get 4MHz)
20
#pragma config CFGPLLEN = ON        // Enable PLL on startup
21
#pragma config PLLSEL = PLL96       // Use 96MHz PLL 4MHz -> 96MHz / 2 = 48MHz
22
//#pragma config SOSCSEL = HIGH       // High Power T1OSC/SOSC circuit selected
123 Kevin 23
#pragma config ADCSEL = BIT12       // 12-bit ADrC
119 Kevin 24
//#pragma config IOL1WAY = OFF        // IOLOCK bit can be set and cleared as needed
25
 
26
/* ----------- IO Pins -----------
123 Kevin 27
 * RA0 - A/D X
28
 * RA1 - A/D Y
29
 * RA2 - A/D Z
119 Kevin 30
 * RA3 - 
31
 * RA4 - [CANNOT BE USED (VDDCORE/VCAP)]
32
 * RA5 - 
33
 * RA6 - Oscillator
34
 * RA7 - Oscillator
35
 * 
121 Kevin 36
 * RB0 - UART2 Tx
37
 * RB1 - UART2 Rx
38
 * RB2 - SPI2 MOSI
39
 * RB3 - SPI2 MISO
40
 * RB4 - SPI2 CLK
41
 * RB5 - SPI2 D/C
42
 * RB6 - SPI2 RESET
43
 * RB7 - SPI2 CS
119 Kevin 44
 *
121 Kevin 45
 * RC0 -
46
 * RC1 - IRQ
47
 * RC2 - Reset
48
 * RC3 - I2C CLK
49
 * RC4 - I2C DATA
50
 * RC5 -
51
 * RC6 - UART1 Tx
52
 * RC7 - UART1 Rx
119 Kevin 53
 * ---------------------------- */
54
 
121 Kevin 55
#ifdef _TEST_UART
119 Kevin 56
 
57
void main(void) {
121 Kevin 58
    unsigned char length = 0;
59
    unsigned char buffer[100];
60
 
61
    /* --------------------- Oscillator Configuration --------------------- */
62
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
63
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
64
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
65
    /* -------------------------------------------------------------------- */
66
 
67
    // Set all ports as digial I/O
68
    ANCON0 = 0xFF;
69
    ANCON1 = 0x1F;
70
 
71
    UART1_Init(); // Initialize the UART handler code
72
 
73
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
74
    interrupt_init(); // Initialize the interrupt priorities
75
 
76
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
77
 
78
    while (1) {
79
 
80
        length = UART1_Read((char *) buffer);
81
        if (length != 0) {
82
            UART1_WriteB((char *) buffer, length);
83
        }
84
 
85
        Delay10KTCYx(255);
86
        Delay10KTCYx(255);
87
    }
88
}
89
#endif
90
 
91
#ifdef _TEST_I2C_MASTER
92
 
93
void main(void) {
119 Kevin 94
    unsigned char i = 0;
95
    unsigned char length = 0;
120 Kevin 96
    unsigned char result = 0;
119 Kevin 97
    unsigned char buffer[100];
121 Kevin 98
 
119 Kevin 99
    /* --------------------- Oscillator Configuration --------------------- */
121 Kevin 100
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
101
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
119 Kevin 102
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
103
    /* -------------------------------------------------------------------- */
104
 
105
    // Set all ports as digial I/O
106
    ANCON0 = 0xFF;
107
    ANCON1 = 0x1F;
108
 
109
    UART1_Init(); // Initialize the UART handler code
120 Kevin 110
    I2C_Init(); // Initialize the I2C handler code
121 Kevin 111
 
112
    I2C_Configure_Master();
113
 
119 Kevin 114
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
115
    interrupt_init(); // Initialize the interrupt priorities
116
 
117
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
118
 
121 Kevin 119
    while (1) {
120
 
121
        buffer[0] = 0xBB;
122
 
123
        I2C_Master_Send(0x30, 1, buffer);
124
        result = I2C_Get_Status();
125
        while (!result) {
126
            result = I2C_Get_Status();
127
        }
128
        DBG_PRINT_MAIN("S:%X ", result);
129
 
130
        I2C_Master_Recv(0x30, 2);
131
        result = I2C_Get_Status();
132
        while (!result) {
133
            result = I2C_Get_Status();
134
        }
135
        DBG_PRINT_MAIN("S:%X ", result);
136
        length = I2C_Read_Buffer(buffer);
137
        DBG_PRINT_MAIN("L:%d D:", length);
138
        for (i = 0; i < length; i++) {
139
            DBG_PRINT_MAIN("%c ", buffer[i]);
140
        }
141
 
142
        I2C_Master_Restart(0x30, 0xBB, 2);
143
        result = I2C_Get_Status();
144
        while (!result) {
145
            result = I2C_Get_Status();
146
        }
147
        DBG_PRINT_MAIN("S:%X ", result);
148
        length = I2C_Read_Buffer(buffer);
149
        DBG_PRINT_MAIN("L:%d D:", length);
150
        for (i = 0; i < length; i++) {
151
            DBG_PRINT_MAIN("%c ", buffer[i]);
152
        }
153
 
154
        DBG_PRINT_MAIN("\r\n");
155
 
156
        Delay10KTCYx(255);
157
        Delay10KTCYx(255);
158
    }
159
}
160
#endif
161
 
162
#ifdef _TEST_I2C_SLAVE
163
 
164
void main(void) {
165
    unsigned char i = 0;
166
    unsigned char length = 0;
167
    unsigned char result = 0;
168
    unsigned char buffer[100];
169
 
170
    /* --------------------- Oscillator Configuration --------------------- */
171
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
172
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
173
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
174
    /* -------------------------------------------------------------------- */
175
 
176
    // Set all ports as digial I/O
177
    ANCON0 = 0xFF;
178
    ANCON1 = 0x1F;
179
 
180
    UART1_Init(); // Initialize the UART handler code
181
    I2C_Init(); // Initialize the I2C handler code
182
 
120 Kevin 183
    I2C_Configure_Slave(0x30);
184
 
121 Kevin 185
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
186
    interrupt_init(); // Initialize the interrupt priorities
187
 
188
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
189
 
119 Kevin 190
    while (1) {
120 Kevin 191
 
192
        result = I2C_Get_Status();
193
        while (!result) {
194
            result = I2C_Get_Status();
119 Kevin 195
        }
120 Kevin 196
        DBG_PRINT_MAIN("%X ", result);
197
        length = I2C_Read_Buffer(buffer);
198
        DBG_PRINT_MAIN("%d ", length);
199
        for (i = 0; i < length; i++) {
200
            DBG_PRINT_MAIN("%X ", buffer[i]);
201
        }
202
        DBG_PRINT_MAIN("\r\n");
121 Kevin 203
 
204
        Delay10KTCYx(255);
205
        Delay10KTCYx(255);
119 Kevin 206
    }
121 Kevin 207
}
208
#endif
209
 
210
#ifdef _TEST_NFC
211
 
212
void main(void) {
213
    unsigned char i = 0;
214
    unsigned char length = 0;
215
    unsigned char result = 0;
216
    NFC_FIRMWARE_VERSION version;
217
    unsigned char buffer[50];
218
 
219
    // NFC stuff
220
    unsigned char uid[7];
221
    unsigned char uidLen;
222
 
223
    /* --------------------- Oscillator Configuration --------------------- */
224
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
225
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
226
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
227
    /* -------------------------------------------------------------------- */
228
 
229
    // Set all ports as digial I/O
230
    ANCON0 = 0xFF;
231
    ANCON1 = 0x1F;
232
 
233
    UART1_Init(); // Initialize the UART handler code
234
    I2C_Init(); // Initialize the I2C handler code
235
    NFC_Init(); // Initialize the NFC chip (uses I2C)
236
 
237
    I2C_Configure_Master(I2C_400KHZ);
238
 
239
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
240
    interrupt_init(); // Initialize the interrupt priorities
241
 
242
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
243
 
244
    version = NFC_getFirmwareVersion();
245
    while (!version.IC) {
246
        DBG_PRINT_MAIN("Waiting for NFC board..\r\n");
247
        Delay10KTCYx(3);
248
        version = NFC_getFirmwareVersion();
249
    }
250
    DBG_PRINT_MAIN("Found chip PN5%X\r\n", version.IC);
251
    DBG_PRINT_MAIN("Firmware ver. %d.%d\r\n", version.Ver, version.Rev);
252
    NFC_SAMConfig();
253
 
254
    while (1) {
255
 
256
        // This call will hang until the NFC chip replies (card detected)
257
        if (NFC_readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLen)) {
258
            DBG_PRINT_MAIN("Card Found!\r\n");
259
            DBG_PRINT_MAIN("UID Length: %d bytes\r\n", uidLen);
260
            DBG_PRINT_MAIN("UID: ");
261
            for (i = 0; i < uidLen; i++) {
262
                DBG_PRINT_MAIN("%02X ", uid[i]);
263
            }
264
            DBG_PRINT_MAIN("\r\n");
265
        }
266
 
267
        //        Delay10KTCYx(255);
268
        //        Delay10KTCYx(255);
269
    }
270
}
271
#endif
272
 
273
#ifdef _TEST_LED_BACKPACK
274
 
275
void main(void) {
276
    unsigned char i = 0;
277
    unsigned char length = 0;
278
    unsigned char buffer[100];
279
    unsigned int counter = 0;
280
 
281
    /* --------------------- Oscillator Configuration --------------------- */
282
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
283
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
284
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
285
    /* -------------------------------------------------------------------- */
286
 
287
    // Set all ports as digial I/O
288
    ANCON0 = 0xFF;
289
    ANCON1 = 0x1F;
290
 
291
    UART1_Init(); // Initialize the UART handler code
292
    I2C_Init(); // Initialize the I2C handler code
293
    LED_Init(); // Initialize the LED backpack (uses I2C);
294
 
295
    I2C_Configure_Master(I2C_400KHZ);
296
 
297
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
298
    interrupt_init(); // Initialize the interrupt priorities
299
 
300
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
301
 
302
    LED_Start();
303
    LED_writeDigitNum(0, 1, 1);
304
    LED_writeDigitNum(1, 2, 0);
305
    LED_writeDigitNum(2, 3, 0);
306
    LED_writeDigitNum(3, 4, 0);
307
    LED_writeDisplay();
308
    for (i = 0; i < 15; i++) {
309
        LED_setBrightness(15 - i);
310
        Delay10KTCYx(100);
311
    }
312
    for (i = 0; i < 15; i++) {
313
        LED_setBrightness(i);
314
        Delay10KTCYx(100);
315
    }
316
    LED_blinkRate(HT16K33_BLINK_OFF);
317
 
318
    while (1) {
319
        LED_writeNum(counter);
320
        counter++;
321
        if (counter > 9999)
322
            counter = 0;
323
 
324
        //        Delay10KTCYx(255);
325
    }
326
}
327
#endif
328
 
329
#ifdef _TEST_SPI
330
 
331
void main(void) {
332
    unsigned char i = 0;
333
    unsigned char length = 0;
334
    unsigned char result = 0;
335
    unsigned char buffer[100];
336
    unsigned char test[8] = "ASDF123";
337
 
338
    /* --------------------- Oscillator Configuration --------------------- */
339
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
340
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
341
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
342
    /* -------------------------------------------------------------------- */
343
 
344
    // Set all ports as digial I/O
345
    ANCON0 = 0xFF;
346
    ANCON1 = 0x1F;
347
 
348
    UART1_Init(); // Initialize the UART handler code
349
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
350
 
351
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
352
    interrupt_init(); // Initialize the interrupt priorities
353
 
354
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
355
 
356
    while (1) {
357
 
358
        SPI2_Write(test, 7);
359
        while (result != 7) {
360
            length = SPI2_Buffer_Read(buffer);
361
            if (length) {
362
                result += length;
363
            }
364
        }
365
        result = 0;
366
 
367
        for (i = 0; i < result; i++) {
368
            DBG_PRINT_MAIN("%X ", buffer[i]);
369
        }
370
        DBG_PRINT_MAIN("\r\n");
371
 
372
        Delay10KTCYx(255);
373
        Delay10KTCYx(255);
374
    }
375
}
376
#endif
377
 
378
#ifdef _TEST_SSD1306_OLED
379
 
380
void main(void) {
381
    unsigned int i = 0;
382
    unsigned long l = 0;
383
 
384
    /* --------------------- Oscillator Configuration --------------------- */
385
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
386
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
387
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
388
    /* -------------------------------------------------------------------- */
389
 
390
    // Set all ports as digial I/O
391
    ANCON0 = 0xFF;
392
    ANCON1 = 0x1F;
393
 
394
    UART1_Init(); // Initialize the UART handler code
395
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
396
    SSD1306_Init(); // Initialize the OLED code
397
 
398
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
399
    interrupt_init(); // Initialize the interrupt priorities
400
 
401
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
402
 
403
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
404
 
405
    SSD1306_Display(); // Show splashscreen
406
 
407
    while (1) {
408
        //        Delay10KTCYx(255);
409
        //        Delay10KTCYx(255);
410
        //        SSD1306_Clear_Display();
411
        //        for (i = 0; i < 32; i++) {
412
        //            SSD1306_Draw_Pixel(i, i, WHITE);
413
        //        }
414
        //        SSD1306_Display();
415
 
416
        //        Delay10KTCYx(255);
417
        //        Delay10KTCYx(255);
418
        //        SSD1306_Clear_Display();
419
        //        SSD1306_Test_DrawLine();
420
        //        SSD1306_Display();
421
        //
422
        //        Delay10KTCYx(255);
423
        //        Delay10KTCYx(255);
424
        //        SSD1306_Clear_Display();
425
        //        SSD1306_Test_DrawRect();
426
        //        SSD1306_Display();
427
        //
428
        //        Delay10KTCYx(255);
429
        //        Delay10KTCYx(255);
430
        //        SSD1306_Clear_Display();
431
        //        SSD1306_Test_FillRect();
432
        //        SSD1306_Display();
433
        //
434
        //        Delay10KTCYx(255);
435
        //        Delay10KTCYx(255);
436
        //        SSD1306_Clear_Display();
437
        //        SSD1306_Test_DrawCircle();
438
        //        SSD1306_Display();
439
        //
440
        //        Delay10KTCYx(255);
441
        //        Delay10KTCYx(255);
442
        //        SSD1306_Clear_Display();
443
        //        GFX_fillCircle(GFX_width() / 2, GFX_height() / 2, 10, WHITE);
444
        //        SSD1306_Display();
445
        //
446
        //        Delay10KTCYx(255);
447
        //        Delay10KTCYx(255);
448
        //        SSD1306_Clear_Display();
449
        //        SSD1306_Test_DrawRoundRect();
450
        //        SSD1306_Display();
451
        //
452
        //        Delay10KTCYx(255);
453
        //        Delay10KTCYx(255);
454
        //        SSD1306_Clear_Display();
455
        //        SSD1306_Test_FillRoundRect();
456
        //        SSD1306_Display();
457
        //
458
        //        Delay10KTCYx(255);
459
        //        Delay10KTCYx(255);
460
        //        SSD1306_Clear_Display();
461
        //        SSD1306_Test_DrawTriangle();
462
        //        SSD1306_Display();
463
        //
464
        //        Delay10KTCYx(255);
465
        //        Delay10KTCYx(255);
466
        //        SSD1306_Clear_Display();
467
        //        SSD1306_Test_FillTriangle();
468
        //        SSD1306_Display();
469
 
470
        //        Delay10KTCYx(255);
471
        //        Delay10KTCYx(255);
472
        //        SSD1306_Clear_Display();
473
        //        SSD1306_Test_DrawChar();
474
        //        SSD1306_Display();
475
 
476
        //        Delay10KTCYx(255);
477
        //        Delay10KTCYx(255);
478
        //        SSD1306_Clear_Display();
479
        //        GFX_setTextSize(1);
480
        //        GFX_setTextColor(WHITE);
481
        //        GFX_setCursor(0,0);
482
        //        GFX_writeString("Hello World!\n");
483
        ////        GFX_setTextColorBG(BLACK, WHITE);
484
        //        i = 65535;
485
        //        GFX_writeString("%u %d\n", i, i);
486
        ////        GFX_setTextSize(2);
487
        ////        GFX_setTextColor(WHITE);
488
        //        l = 0xDEADBEEF;
489
        //        GFX_writeString("0x%X", (long)l);
490
        //        SSD1306_Display();
491
 
492
        SSD1306_Clear_Display();
493
        GFX_setRotation(0);
494
        GFX_setTextSize(1);
495
        GFX_setTextColor(SSD1306_WHITE);
496
        GFX_setCursor(0, 0);
497
        GFX_writeString("%u", i);
498
        i++;
499
        SSD1306_Display();
500
 
501
    }
502
}
503
#endif
504
 
505
#ifdef _TEST_SSD1331_OLED
506
 
507
void main(void) {
508
    unsigned int i = 0;
509
 
510
    /* --------------------- Oscillator Configuration --------------------- */
511
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
512
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
513
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
514
    /* -------------------------------------------------------------------- */
515
 
516
    // Set all ports as digial I/O
517
    ANCON0 = 0xFF;
518
    ANCON1 = 0x1F;
519
 
520
    UART1_Init(); // Initialize the UART handler code
521
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
522
    SSD1331_Init(); // Initialize the OLED code
523
 
524
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
525
    interrupt_init(); // Initialize the interrupt priorities
526
 
527
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
528
 
529
    SSD1331_Begin();
530
 
531
    while (1) {
532
 
533
        Delay10KTCYx(255);
534
        Delay10KTCYx(255);
535
        GFX_setRotation(0);
536
        SSD1331_Test_Pattern();
537
 
538
        Delay10KTCYx(255);
539
        Delay10KTCYx(255);
540
        GFX_clearScreen();
541
        GFX_setRotation(0);
542
        GFX_setCursor(0, 0);
543
        GFX_writeString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
544
 
545
        Delay10KTCYx(255);
546
        Delay10KTCYx(255);
547
        GFX_clearScreen();
548
        GFX_setRotation(3);
549
        GFX_setCursor(0, 0);
550
        GFX_writeString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
551
 
552
        Delay10KTCYx(255);
553
        Delay10KTCYx(255);
554
        GFX_setRotation(0);
555
        SSD1331_Test_DrawLines(SSD1331_YELLOW);
556
 
557
        Delay10KTCYx(255);
558
        Delay10KTCYx(255);
559
        GFX_setRotation(3);
560
        SSD1331_Test_DrawLines(SSD1331_BLUE);
561
 
562
        Delay10KTCYx(255);
563
        Delay10KTCYx(255);
564
        GFX_setRotation(0);
565
        SSD1331_Test_DrawRect(SSD1331_GREEN);
566
 
567
        Delay10KTCYx(255);
568
        Delay10KTCYx(255);
569
        GFX_setRotation(1);
570
        SSD1331_Test_DrawRect(SSD1331_RED);
571
 
572
        Delay10KTCYx(255);
573
        Delay10KTCYx(255);
574
        GFX_setRotation(2);
575
        SSD1331_Test_DrawRect(SSD1331_BLUE);
576
 
577
        Delay10KTCYx(255);
578
        Delay10KTCYx(255);
579
        GFX_setRotation(3);
580
        SSD1331_Test_DrawRect(SSD1331_YELLOW);
581
 
582
        Delay10KTCYx(255);
583
        Delay10KTCYx(255);
584
        GFX_setRotation(0);
585
        SSD1331_Test_FillRect(SSD1331_YELLOW, SSD1331_MAGENTA);
586
 
587
        Delay10KTCYx(255);
588
        Delay10KTCYx(255);
589
        GFX_setRotation(3);
590
        SSD1331_Test_FillRect(SSD1331_BLUE, SSD1331_GREEN);
591
 
592
        Delay10KTCYx(255);
593
        Delay10KTCYx(255);
594
        GFX_setRotation(0);
595
        GFX_clearScreen();
596
        SSD1331_Test_FillCircle(10, SSD1331_BLUE);
597
        SSD1331_Test_DrawCircle(10, SSD1331_WHITE);
598
 
599
        Delay10KTCYx(255);
600
        Delay10KTCYx(255);
601
        GFX_setRotation(3);
602
        GFX_clearScreen();
603
        SSD1331_Test_FillCircle(10, SSD1331_MAGENTA);
604
        SSD1331_Test_DrawCircle(10, SSD1331_YELLOW);
605
 
606
        Delay10KTCYx(255);
607
        Delay10KTCYx(255);
608
        GFX_setRotation(0);
609
        SSD1331_Test_DrawTria();
610
 
611
        Delay10KTCYx(255);
612
        Delay10KTCYx(255);
613
        GFX_setRotation(3);
614
        SSD1331_Test_DrawTria();
615
 
616
        Delay10KTCYx(255);
617
        Delay10KTCYx(255);
618
        GFX_setRotation(0);
619
        SSD1331_Test_DrawRoundRect();
620
 
621
        Delay10KTCYx(255);
622
        Delay10KTCYx(255);
623
        GFX_setRotation(3);
624
        SSD1331_Test_DrawRoundRect();
625
 
626
        //        GFX_clearScreen();
627
        //        GFX_setRotation(3);
628
        //        GFX_setCursor(0,0);
629
        //        GFX_setTextColorBG(SSD1331_WHITE, SSD1331_BLACK);
630
        //        GFX_writeString("%u", i);
631
        //        i++;
632
    }
633
}
634
#endif
635
 
123 Kevin 636
#ifdef _TEST_ADC
637
 
638
void main(void) {
639
    unsigned int x,y,z;
640
    unsigned char buffer[60];
641
 
642
    /* --------------------- Oscillator Configuration --------------------- */
643
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
644
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
645
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
646
    /* -------------------------------------------------------------------- */
647
 
648
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
649
    ANCON0 = 0xF8;
650
    ANCON1 = 0x1F;
651
 
652
    UART1_Init(); // Initialize the UART handler code
653
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
654
    SSD1331_Init(); // Initialize the SSD1331 OLED display (uses SPI2)
655
    ADC_Init(ADC_TAD_0, ADC_FOSC_64);
656
 
657
    //    I2C_Configure_Master(I2C_400KHZ);
658
    SSD1331_Begin();
659
 
660
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
661
    interrupt_init(); // Initialize the interrupt priorities
662
 
663
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
664
 
665
    memset(buffer, 0, 60);
666
    GFX_clearScreen();
667
    GFX_setRotation(3);
668
 
669
    while (1) {
670
        // ADC read from AN0-AN2 and prints to display
671
        ADC_Start(ADC_CHANNEL_AN0);
672
        GFX_fillRect(0,0,GFX_width(),8,SSD1331_BLACK);
673
        GFX_setCursor(0,0);
674
        while (!ADC_Get_Result(&x));
675
        GFX_writeString("X: %u", x);
676
 
677
        ADC_Start(ADC_CHANNEL_AN1);
678
        GFX_fillRect(0,8,GFX_width(),8,SSD1331_BLACK);
679
        GFX_setCursor(0,8);
680
        while (!ADC_Get_Result(&y));
681
        GFX_writeString("Y: %u", y);
682
 
683
        ADC_Start(ADC_CHANNEL_AN2);
684
        GFX_fillRect(0,16,GFX_width(),8,SSD1331_BLACK);
685
        GFX_setCursor(0,16);
686
        while (!ADC_Get_Result(&z));
687
        GFX_writeString("Z: %u", z);
688
    }
689
}
690
 
691
#endif
692
 
121 Kevin 693
#if !defined(_TEST_UART) && !defined(_TEST_I2C_MASTER) && \
694
    !defined(_TEST_I2C_SLAVE) && !defined(_TEST_SPI) && \
695
    !defined(_TEST_NFC) && !defined(_TEST_LED_BACKPACK) && \
123 Kevin 696
    !defined(_TEST_SSD1306_OLED) && !defined(_TEST_SSD1331_OLED) && \
697
    !defined(_TEST_ADC)
121 Kevin 698
 
699
void main(void) {
123 Kevin 700
    unsigned int x,y,z;
121 Kevin 701
    unsigned char length = 0;
122 Kevin 702
    unsigned char buffer[60];
121 Kevin 703
 
704
    /* --------------------- Oscillator Configuration --------------------- */
705
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
706
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
707
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
708
    /* -------------------------------------------------------------------- */
709
 
123 Kevin 710
    // Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
711
    ANCON0 = 0xF8;
121 Kevin 712
    ANCON1 = 0x1F;
713
 
714
    UART1_Init(); // Initialize the UART handler code
122 Kevin 715
    //    I2C_Init(); // Initialize the I2C handler code
121 Kevin 716
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
717
    SSD1331_Init(); // Initialize the SSD1331 OLED display (uses SPI2)
122 Kevin 718
    //    NFC_Init(); // Initialize the NFC chip (uses I2C)
123 Kevin 719
    //    LED_Init(); // Initialize the LED backpack (uses I2C)
720
    ADC_Init(ADC_TAD_0, ADC_FOSC_64);
121 Kevin 721
 
122 Kevin 722
    //    I2C_Configure_Master(I2C_400KHZ);
121 Kevin 723
    SSD1331_Begin();
724
 
725
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
726
    interrupt_init(); // Initialize the interrupt priorities
727
 
728
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
729
 
122 Kevin 730
    memset(buffer, 0, 60);
731
    GFX_clearScreen();
732
    GFX_setRotation(3);
733
 
121 Kevin 734
    while (1) {
735
 
123 Kevin 736
        // Reads input from UART and prints to display
737
//        length = UART1_Read_Buffer(buffer);
738
//        if (length != 0) {
739
//            buffer[length] = 0;
740
//            GFX_appendString("%s", buffer);
741
//        }
742
 
743
        // ADC read from AN0-AN2 and prints to display
744
        ADC_Start(ADC_CHANNEL_AN0);
745
        GFX_fillRect(0,0,GFX_width(),8,SSD1331_BLACK);
746
        GFX_setCursor(0,0);
747
        while (!ADC_Get_Result(&x));
748
        GFX_writeString("X: %u", x);
749
 
750
        ADC_Start(ADC_CHANNEL_AN1);
751
        GFX_fillRect(0,8,GFX_width(),8,SSD1331_BLACK);
752
        GFX_setCursor(0,8);
753
        while (!ADC_Get_Result(&y));
754
        GFX_writeString("Y: %u", y);
755
 
756
        ADC_Start(ADC_CHANNEL_AN2);
757
        GFX_fillRect(0,16,GFX_width(),8,SSD1331_BLACK);
758
        GFX_setCursor(0,16);
759
        while (!ADC_Get_Result(&z));
760
        GFX_writeString("Z: %u", z);
121 Kevin 761
    }
762
}
763
#endif