Subversion Repositories Code-Repo

Rev

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

Rev 127 Rev 129
Line 1... Line 1...
1
#include "maindefs.h"
1
#include "maindefs.h"
2
#include "Adafruit_GFX.h"
-
 
3
#include "interrupts.h"
2
#include "interrupts.h"
4
#include "uart.h"
3
#include "uart.h"
5
#include "i2c.h"
4
#include "i2c.h"
6
#include "spi.h"
5
#include "spi.h"
7
#include "nfc.h"
6
#include "nfc.h"
Line 26... Line 25...
26
#pragma config PLLSEL = PLL96       // Use 96MHz PLL 4MHz -> 96MHz / 2 = 48MHz
25
#pragma config PLLSEL = PLL96       // Use 96MHz PLL 4MHz -> 96MHz / 2 = 48MHz
27
//#pragma config SOSCSEL = HIGH       // High Power T1OSC/SOSC circuit selected
26
//#pragma config SOSCSEL = HIGH       // High Power T1OSC/SOSC circuit selected
28
//#pragma config ADCSEL = BIT12       // 12-bit ADrC
27
//#pragma config ADCSEL = BIT12       // 12-bit ADrC
29
//#pragma config IOL1WAY = OFF        // IOLOCK bit can be set and cleared as needed
28
//#pragma config IOL1WAY = OFF        // IOLOCK bit can be set and cleared as needed
30
 
29
 
31
/* ----------- IO Pins -----------
-
 
32
 * RA0 - A/D X
-
 
33
 * RA1 - A/D Y
-
 
34
 * RA2 - A/D Z
-
 
35
 * RA3 - 
-
 
36
 * RA4 - [CANNOT BE USED (VDDCORE/VCAP)]
-
 
37
 * RA5 - 
-
 
38
 * RA6 - Oscillator
-
 
39
 * RA7 - Oscillator
-
 
40
 * 
-
 
41
 * RB0 - UART2 Tx
-
 
42
 * RB1 - UART2 Rx
-
 
43
 * RB2 - SPI2 MOSI
-
 
44
 * RB3 - SPI2 MISO
-
 
45
 * RB4 - SPI2 CLK
-
 
46
 * RB5 - SPI2 D/C
-
 
47
 * RB6 - SPI2 RESET
-
 
48
 * RB7 - SPI2 CS
-
 
49
 *
-
 
50
 * RC0 -
-
 
51
 * RC1 - IRQ
-
 
52
 * RC2 - Reset
-
 
53
 * RC3 - I2C CLK
-
 
54
 * RC4 - I2C DATA
-
 
55
 * RC5 -
-
 
56
 * RC6 - UART1 Tx
-
 
57
 * RC7 - UART1 Rx
-
 
58
 * ---------------------------- */
-
 
59
 
-
 
60
#ifdef _TEST_UART
30
#ifdef _TEST_UART
61
 
31
 
62
void main(void) {
32
void main(void) {
63
    unsigned char length = 0;
33
    unsigned char length = 0;
64
    unsigned char buffer[100];
34
    unsigned char buffer[100];
Line 254... Line 224...
254
    NFC_SAMConfig();
224
    NFC_SAMConfig();
255
 
225
 
256
    memset(cardData, 0, 24);
226
    memset(cardData, 0, 24);
257
 
227
 
258
    while (1) {
228
    while (1) {
259
        
229
 
260
//        // This query will hang until the NFC chip replies (card detected)
230
        //        // This query will hang until the NFC chip replies (card detected)
261
//        length = NFC_readPassiveTargetID(cardData);
231
        //        length = NFC_readPassiveTargetID(cardData);
262
//        if (length) {
232
        //        if (length) {
263
//            DBG_PRINT_MAIN("Cards Found: %u\r\n", length);
233
        //            DBG_PRINT_MAIN("Cards Found: %u\r\n", length);
264
//            DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[0].NFCID_LEN);
234
        //            DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[0].NFCID_LEN);
265
//            DBG_PRINT_MAIN("UID: ");
235
        //            DBG_PRINT_MAIN("UID: ");
266
//            for (i = 0; i < cardData[0].NFCID_LEN; i++) {
236
        //            for (i = 0; i < cardData[0].NFCID_LEN; i++) {
267
//                DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
237
        //                DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
268
//            }
238
        //            }
269
//            DBG_PRINT_MAIN("\r\n");
239
        //            DBG_PRINT_MAIN("\r\n");
270
//            if (length == 2) {
240
        //            if (length == 2) {
271
//                DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[1].NFCID_LEN);
241
        //                DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[1].NFCID_LEN);
272
//                DBG_PRINT_MAIN("UID: ");
242
        //                DBG_PRINT_MAIN("UID: ");
273
//                for (i = 0; i < cardData[1].NFCID_LEN; i++) {
243
        //                for (i = 0; i < cardData[1].NFCID_LEN; i++) {
274
//                    DBG_PRINT_MAIN("%02X ", cardData[1].NFCID[i]);
244
        //                    DBG_PRINT_MAIN("%02X ", cardData[1].NFCID[i]);
275
//                }
245
        //                }
276
//                DBG_PRINT_MAIN("\r\n");
246
        //                DBG_PRINT_MAIN("\r\n");
277
//            }
247
        //            }
278
//        }
248
        //        }
279
 
249
 
280
        //        // This query will hang until the NFC chip replies (card detected)
250
        //        // This query will hang until the NFC chip replies (card detected)
281
        //        length = NFC_readPassiveTargetID(cardData);
251
        //        length = NFC_readPassiveTargetID(cardData);
282
        //        if (length) {
252
        //        if (length) {
283
        //            DBG_PRINT_MAIN("Cards Found: %u\r\n", length);
253
        //            DBG_PRINT_MAIN("Cards Found: %u\r\n", length);
Line 492... Line 462...
492
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
462
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
493
 
463
 
494
    SSD1306_Display(); // Show splashscreen
464
    SSD1306_Display(); // Show splashscreen
495
 
465
 
496
    while (1) {
466
    while (1) {
497
        //        Delay10KTCYx(255);
467
        Delay10KTCYx(255);
498
        //        Delay10KTCYx(255);
468
        Delay10KTCYx(255);
499
        //        SSD1306_Clear_Display();
469
        SSD1306_Clear_Display();
500
        //        for (i = 0; i < 32; i++) {
-
 
501
        //            SSD1306_Draw_Pixel(i, i, WHITE);
470
        SSD1306_Test_DrawLine();
502
        //        }
-
 
503
        //        SSD1306_Display();
471
        SSD1306_Display();
504
 
472
 
505
        //        Delay10KTCYx(255);
-
 
506
        //        Delay10KTCYx(255);
473
        Delay10KTCYx(255);
507
        //        SSD1306_Clear_Display();
-
 
508
        //        SSD1306_Test_DrawLine();
-
 
509
        //        SSD1306_Display();
-
 
510
        //
-
 
511
        //        Delay10KTCYx(255);
-
 
512
        //        Delay10KTCYx(255);
474
        Delay10KTCYx(255);
513
        //        SSD1306_Clear_Display();
475
        SSD1306_Clear_Display();
514
        //        SSD1306_Test_DrawRect();
476
        SSD1306_Test_DrawRect();
515
        //        SSD1306_Display();
-
 
516
        //
-
 
517
        //        Delay10KTCYx(255);
-
 
518
        //        Delay10KTCYx(255);
-
 
519
        //        SSD1306_Clear_Display();
-
 
520
        //        SSD1306_Test_FillRect();
-
 
521
        //        SSD1306_Display();
-
 
522
        //
-
 
523
        //        Delay10KTCYx(255);
-
 
524
        //        Delay10KTCYx(255);
-
 
525
        //        SSD1306_Clear_Display();
-
 
526
        //        SSD1306_Test_DrawCircle();
-
 
527
        //        SSD1306_Display();
-
 
528
        //
-
 
529
        //        Delay10KTCYx(255);
-
 
530
        //        Delay10KTCYx(255);
-
 
531
        //        SSD1306_Clear_Display();
-
 
532
        //        GFX_fillCircle(GFX_width() / 2, GFX_height() / 2, 10, WHITE);
-
 
533
        //        SSD1306_Display();
-
 
534
        //
-
 
535
        //        Delay10KTCYx(255);
-
 
536
        //        Delay10KTCYx(255);
-
 
537
        //        SSD1306_Clear_Display();
-
 
538
        //        SSD1306_Test_DrawRoundRect();
-
 
539
        //        SSD1306_Display();
-
 
540
        //
-
 
541
        //        Delay10KTCYx(255);
-
 
542
        //        Delay10KTCYx(255);
-
 
543
        //        SSD1306_Clear_Display();
-
 
544
        //        SSD1306_Test_FillRoundRect();
-
 
545
        //        SSD1306_Display();
477
        SSD1306_Display();
546
        //
-
 
547
        //        Delay10KTCYx(255);
-
 
548
        //        Delay10KTCYx(255);
-
 
549
        //        SSD1306_Clear_Display();
-
 
550
        //        SSD1306_Test_DrawTriangle();
-
 
551
        //        SSD1306_Display();
-
 
552
        //
-
 
553
        //        Delay10KTCYx(255);
-
 
554
        //        Delay10KTCYx(255);
-
 
555
        //        SSD1306_Clear_Display();
-
 
556
        //        SSD1306_Test_FillTriangle();
-
 
557
        //        SSD1306_Display();
-
 
558
 
478
 
559
        //        Delay10KTCYx(255);
479
        Delay10KTCYx(255);
560
        //        Delay10KTCYx(255);
480
        Delay10KTCYx(255);
561
        //        SSD1306_Clear_Display();
481
        SSD1306_Clear_Display();
562
        //        SSD1306_Test_DrawChar();
482
        SSD1306_Test_FillRect();
563
        //        SSD1306_Display();
483
        SSD1306_Display();
564
 
484
 
565
        //        Delay10KTCYx(255);
485
        Delay10KTCYx(255);
566
        //        Delay10KTCYx(255);
486
        Delay10KTCYx(255);
567
        //        SSD1306_Clear_Display();
487
        SSD1306_Clear_Display();
568
        //        GFX_setTextSize(1);
488
        SSD1306_Test_DrawCircle();
-
 
489
        SSD1306_Display();
-
 
490
 
569
        //        GFX_setTextColor(WHITE);
491
        Delay10KTCYx(255);
570
        //        GFX_setCursor(0,0);
492
        Delay10KTCYx(255);
571
        //        GFX_writeString("Hello World!\n");
493
        SSD1306_Clear_Display();
-
 
494
        SSD1306_Fill_Circle(SSD1306_LCDWIDTH / 2, SSD1306_LCDHEIGHT / 2, 10, SSD1306_WHITE);
-
 
495
        SSD1306_Display();
-
 
496
 
572
        ////        GFX_setTextColorBG(BLACK, WHITE);
497
        Delay10KTCYx(255);
573
        //        i = 65535;
498
        Delay10KTCYx(255);
-
 
499
        SSD1306_Clear_Display();
574
        //        GFX_writeString("%u %d\n", i, i);
500
        SSD1306_Test_DrawRoundRect();
575
        ////        GFX_setTextSize(2);
501
        SSD1306_Display();
-
 
502
 
-
 
503
        Delay10KTCYx(255);
576
        ////        GFX_setTextColor(WHITE);
504
        Delay10KTCYx(255);
577
        //        l = 0xDEADBEEF;
505
        SSD1306_Clear_Display();
578
        //        GFX_writeString("0x%X", (long)l);
506
        SSD1306_Test_FillRoundRect();
579
        //        SSD1306_Display();
507
        SSD1306_Display();
580
 
508
 
-
 
509
        Delay10KTCYx(255);
-
 
510
        Delay10KTCYx(255);
-
 
511
        SSD1306_Clear_Display();
-
 
512
        SSD1306_Test_DrawTriangle();
-
 
513
        SSD1306_Display();
-
 
514
 
-
 
515
        Delay10KTCYx(255);
-
 
516
        Delay10KTCYx(255);
581
        SSD1306_Clear_Display();
517
        SSD1306_Clear_Display();
582
        GFX_setRotation(0);
-
 
583
        GFX_setTextSize(1);
518
        SSD1306_Test_FillTriangle();
584
        GFX_setTextColor(SSD1306_WHITE);
-
 
585
        GFX_setCursor(0, 0);
-
 
586
        GFX_writeString("%u", i);
-
 
587
        i++;
-
 
588
        SSD1306_Display();
519
        SSD1306_Display();
589
 
520
 
-
 
521
        Delay10KTCYx(255);
-
 
522
        Delay10KTCYx(255);
-
 
523
        SSD1306_Clear_Display();
-
 
524
        SSD1306_Test_DrawChar();
-
 
525
        SSD1306_Display();
-
 
526
 
-
 
527
        Delay10KTCYx(255);
-
 
528
        Delay10KTCYx(255);
-
 
529
        SSD1306_Clear_Display();
-
 
530
        SSD1306_Set_Text_Size(1);
-
 
531
        SSD1306_Set_Text_Color(SSD1306_WHITE);
-
 
532
        SSD1306_Set_Cursor(0, 0);
-
 
533
        SSD1306_Write_String("Hello World!\n");
-
 
534
        //        SSD1306_Set_Text_Color_BG(BLACK, WHITE);
-
 
535
        i = 65535;
-
 
536
        SSD1306_Write_String("%u %d\n", i, i);
-
 
537
        //        SSD1306_Set_Text_Size(2);
-
 
538
        //        SSD1306_Set_Text_Color(WHITE);
-
 
539
        l = 0xDEADBEEF;
-
 
540
        SSD1306_Write_String("0x%lX", (long) l);
-
 
541
        SSD1306_Display();
-
 
542
 
-
 
543
        //        SSD1306_Clear_Display();
-
 
544
        //        SSD1306_Set_Rotation(0);
-
 
545
        //        SSD1306_Set_Text_Size(1);
-
 
546
        //        SSD1306_Set_Text_Color(SSD1306_WHITE);
-
 
547
        //        SSD1306_Set_Cursor(0, 0);
-
 
548
        //        SSD1306_Write_String("%u", i);
-
 
549
        //        i++;
-
 
550
        //        SSD1306_Display();
-
 
551
 
590
    }
552
    }
591
}
553
}
592
#endif
554
#endif
593
 
555
 
594
#ifdef _TEST_SSD1331_OLED
556
#ifdef _TEST_SSD1331_OLED
Line 619... Line 581...
619
 
581
 
620
    while (1) {
582
    while (1) {
621
 
583
 
622
        Delay10KTCYx(255);
584
        Delay10KTCYx(255);
623
        Delay10KTCYx(255);
585
        Delay10KTCYx(255);
624
        GFX_setRotation(0);
586
        SSD1331_Set_Rotation(0);
625
        SSD1331_Test_Pattern();
587
        SSD1331_Test_Pattern();
626
 
588
 
627
        Delay10KTCYx(255);
589
        Delay10KTCYx(255);
628
        Delay10KTCYx(255);
590
        Delay10KTCYx(255);
629
        GFX_clearScreen();
591
        SSD1331_Clear_Display();
630
        GFX_setRotation(0);
592
        SSD1331_Set_Rotation(0);
631
        GFX_setCursor(0, 0);
593
        SSD1331_Set_Cursor(0, 0);
632
        GFX_writeString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
594
        SSD1331_Write_String("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
633
 
595
 
634
        Delay10KTCYx(255);
596
        Delay10KTCYx(255);
635
        Delay10KTCYx(255);
597
        Delay10KTCYx(255);
636
        GFX_clearScreen();
598
        SSD1331_Clear_Display();
637
        GFX_setRotation(3);
599
        SSD1331_Set_Rotation(3);
638
        GFX_setCursor(0, 0);
600
        SSD1331_Set_Cursor(0, 0);
639
        GFX_writeString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
601
        SSD1331_Write_String("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
640
 
602
 
641
        Delay10KTCYx(255);
603
        Delay10KTCYx(255);
642
        Delay10KTCYx(255);
604
        Delay10KTCYx(255);
643
        GFX_setRotation(0);
605
        SSD1331_Set_Rotation(0);
644
        SSD1331_Test_DrawLines(SSD1331_YELLOW);
606
        SSD1331_Test_DrawLines(SSD1331_YELLOW);
645
 
607
 
646
        Delay10KTCYx(255);
608
        Delay10KTCYx(255);
647
        Delay10KTCYx(255);
609
        Delay10KTCYx(255);
648
        GFX_setRotation(3);
610
        SSD1331_Set_Rotation(3);
649
        SSD1331_Test_DrawLines(SSD1331_BLUE);
611
        SSD1331_Test_DrawLines(SSD1331_BLUE);
650
 
612
 
651
        Delay10KTCYx(255);
613
        Delay10KTCYx(255);
652
        Delay10KTCYx(255);
614
        Delay10KTCYx(255);
653
        GFX_setRotation(0);
615
        SSD1331_Set_Rotation(0);
654
        SSD1331_Test_DrawRect(SSD1331_GREEN);
616
        SSD1331_Test_DrawRect(SSD1331_GREEN);
655
 
617
 
656
        Delay10KTCYx(255);
618
        Delay10KTCYx(255);
657
        Delay10KTCYx(255);
619
        Delay10KTCYx(255);
658
        GFX_setRotation(1);
620
        SSD1331_Set_Rotation(1);
659
        SSD1331_Test_DrawRect(SSD1331_RED);
621
        SSD1331_Test_DrawRect(SSD1331_RED);
660
 
622
 
661
        Delay10KTCYx(255);
623
        Delay10KTCYx(255);
662
        Delay10KTCYx(255);
624
        Delay10KTCYx(255);
663
        GFX_setRotation(2);
625
        SSD1331_Set_Rotation(2);
664
        SSD1331_Test_DrawRect(SSD1331_BLUE);
626
        SSD1331_Test_DrawRect(SSD1331_BLUE);
665
 
627
 
666
        Delay10KTCYx(255);
628
        Delay10KTCYx(255);
667
        Delay10KTCYx(255);
629
        Delay10KTCYx(255);
668
        GFX_setRotation(3);
630
        SSD1331_Set_Rotation(3);
669
        SSD1331_Test_DrawRect(SSD1331_YELLOW);
631
        SSD1331_Test_DrawRect(SSD1331_YELLOW);
670
 
632
 
671
        Delay10KTCYx(255);
633
        Delay10KTCYx(255);
672
        Delay10KTCYx(255);
634
        Delay10KTCYx(255);
673
        GFX_setRotation(0);
635
        SSD1331_Set_Rotation(0);
674
        SSD1331_Test_FillRect(SSD1331_YELLOW, SSD1331_MAGENTA);
636
        SSD1331_Test_FillRect(SSD1331_YELLOW, SSD1331_MAGENTA);
675
 
637
 
676
        Delay10KTCYx(255);
638
        Delay10KTCYx(255);
677
        Delay10KTCYx(255);
639
        Delay10KTCYx(255);
678
        GFX_setRotation(3);
640
        SSD1331_Set_Rotation(3);
679
        SSD1331_Test_FillRect(SSD1331_BLUE, SSD1331_GREEN);
641
        SSD1331_Test_FillRect(SSD1331_BLUE, SSD1331_GREEN);
680
 
642
 
681
        Delay10KTCYx(255);
643
        Delay10KTCYx(255);
682
        Delay10KTCYx(255);
644
        Delay10KTCYx(255);
683
        GFX_setRotation(0);
645
        SSD1331_Set_Rotation(0);
684
        GFX_clearScreen();
646
        SSD1331_Clear_Display();
685
        SSD1331_Test_FillCircle(10, SSD1331_BLUE);
647
        SSD1331_Test_FillCircle(10, SSD1331_BLUE);
686
        SSD1331_Test_DrawCircle(10, SSD1331_WHITE);
648
        SSD1331_Test_DrawCircle(10, SSD1331_WHITE);
687
 
649
 
688
        Delay10KTCYx(255);
650
        Delay10KTCYx(255);
689
        Delay10KTCYx(255);
651
        Delay10KTCYx(255);
690
        GFX_setRotation(3);
652
        SSD1331_Set_Rotation(3);
691
        GFX_clearScreen();
653
        SSD1331_Clear_Display();
692
        SSD1331_Test_FillCircle(10, SSD1331_MAGENTA);
654
        SSD1331_Test_FillCircle(10, SSD1331_MAGENTA);
693
        SSD1331_Test_DrawCircle(10, SSD1331_YELLOW);
655
        SSD1331_Test_DrawCircle(10, SSD1331_YELLOW);
694
 
656
 
695
        Delay10KTCYx(255);
657
        Delay10KTCYx(255);
696
        Delay10KTCYx(255);
658
        Delay10KTCYx(255);
697
        GFX_setRotation(0);
659
        SSD1331_Set_Rotation(0);
698
        SSD1331_Test_DrawTria();
660
        SSD1331_Test_DrawTria();
699
 
661
 
700
        Delay10KTCYx(255);
662
        Delay10KTCYx(255);
701
        Delay10KTCYx(255);
663
        Delay10KTCYx(255);
702
        GFX_setRotation(3);
664
        SSD1331_Set_Rotation(3);
703
        SSD1331_Test_DrawTria();
665
        SSD1331_Test_DrawTria();
704
 
666
 
705
        Delay10KTCYx(255);
667
        Delay10KTCYx(255);
706
        Delay10KTCYx(255);
668
        Delay10KTCYx(255);
707
        GFX_setRotation(0);
669
        SSD1331_Set_Rotation(0);
708
        SSD1331_Test_DrawRoundRect();
670
        SSD1331_Test_DrawRoundRect();
709
 
671
 
710
        Delay10KTCYx(255);
672
        Delay10KTCYx(255);
711
        Delay10KTCYx(255);
673
        Delay10KTCYx(255);
712
        GFX_setRotation(3);
674
        SSD1331_Set_Rotation(3);
713
        SSD1331_Test_DrawRoundRect();
675
        SSD1331_Test_DrawRoundRect();
714
 
676
 
715
        //        GFX_clearScreen();
677
        //        SSD1331_Clear_Display();
716
        //        GFX_setRotation(3);
678
        //        SSD1331_Set_Rotation(3);
717
        //        GFX_setCursor(0,0);
679
        //        SSD1331_Set_Cursor(0,0);
718
        //        GFX_setTextColorBG(SSD1331_WHITE, SSD1331_BLACK);
680
        //        SSD1331_Set_Text_Color_BG(SSD1331_WHITE, SSD1331_BLACK);
719
        //        GFX_writeString("%u", i);
681
        //        SSD1331_Write_String("%u", i);
720
        //        i++;
682
        //        i++;
721
    }
683
    }
722
}
684
}
723
#endif
685
#endif
724
 
686
 
Line 738... Line 700...
738
    ANCON0 = 0xF8;
700
    ANCON0 = 0xF8;
739
    ANCON1 = 0x1F;
701
    ANCON1 = 0x1F;
740
 
702
 
741
    UART1_Init(); // Initialize the UART handler code
703
    UART1_Init(); // Initialize the UART handler code
742
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
704
    SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
743
    SSD1331_Init(); // Initialize the SSD1331 OLED display (uses SPI2)
705
    SSD1306_Init(); // Initialize the SSD1331 OLED display (uses SPI2)
744
    ADC_Init(ADC_TAD_20, ADC_FOSC_64);
706
    ADC_Init(ADC_TAD_20, ADC_FOSC_64);
745
 
707
 
746
    //    I2C_Configure_Master(I2C_400KHZ);
708
    //    I2C_Configure_Master(I2C_400KHZ);
747
    SSD1331_Begin();
709
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
748
 
710
 
749
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
711
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
750
    interrupt_init(); // Initialize the interrupt priorities
712
    interrupt_init(); // Initialize the interrupt priorities
751
 
713
 
752
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
714
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
753
 
715
 
754
    memset(buffer, 0, 60);
716
    memset(buffer, 0, 60);
755
    GFX_clearScreen();
717
    SSD1306_Clear_Display();
756
    GFX_setRotation(3);
718
    SSD1306_Display();
757
 
719
 
758
    while (1) {
720
    while (1) {
759
        // ADC read from AN0-AN2 and prints to display
721
        // ADC read from AN0-AN2 and prints to display
760
        ADC_Start(ADC_CHANNEL_AN2);
722
        ADC_Start(ADC_CHANNEL_AN2);
761
        GFX_fillRect(0, 0, GFX_width(), 8, SSD1331_BLACK);
723
//        SSD1306_Fill_Rect(0, 0, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
762
        GFX_setCursor(0, 0);
724
        SSD1306_Set_Cursor(0, 0);
763
        while (!ADC_Get_Result(&x));
725
        while (!ADC_Get_Result(&x));
764
        GFX_writeString("X: %u", x);
726
        SSD1306_Write_String("X: %u", x);
-
 
727
        SSD1306_Display();
765
 
728
 
766
        ADC_Start(ADC_CHANNEL_AN1);
729
        ADC_Start(ADC_CHANNEL_AN1);
767
        GFX_fillRect(0, 8, GFX_width(), 8, SSD1331_BLACK);
730
//        SSD1306_Fill_Rect(0, 8, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
768
        GFX_setCursor(0, 8);
731
        SSD1306_Set_Cursor(0, 8);
769
        while (!ADC_Get_Result(&y));
732
        while (!ADC_Get_Result(&y));
770
        GFX_writeString("Y: %u", y);
733
        SSD1306_Write_String("Y: %u", y);
-
 
734
        SSD1306_Display();
771
 
735
 
772
        ADC_Start(ADC_CHANNEL_AN0);
736
        ADC_Start(ADC_CHANNEL_AN0);
773
        GFX_fillRect(0, 16, GFX_width(), 8, SSD1331_BLACK);
737
//        SSD1306_Fill_Rect(0, 16, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
774
        GFX_setCursor(0, 16);
738
        SSD1306_Set_Cursor(0, 16);
775
        while (!ADC_Get_Result(&z));
739
        while (!ADC_Get_Result(&z));
776
        GFX_writeString("Z: %u", z);
740
        SSD1306_Write_String("Z: %u", z);
-
 
741
        SSD1306_Display();
777
    }
742
    }
778
}
743
}
779
 
744
 
780
#endif
745
#endif
781
 
746
 
Line 783... Line 748...
783
 
748
 
784
void main(void) {
749
void main(void) {
785
    unsigned int i, length = 0;
750
    unsigned int i, length = 0;
786
    unsigned char buffer[100];
751
    unsigned char buffer[100];
787
 
752
 
-
 
753
    XBEE_RX_AT_COMMAND_RESPONSE_FRAME *rx_at_cmd_response_frame;
788
    XBEE_RX_DATA_PACKET_FRAME *rx_data_frame;
754
    XBEE_RX_DATA_PACKET_FRAME *rx_data_frame;
-
 
755
    XBEE_RX_DATA_TX_STATUS_FRAME *rx_tx_status_frame;
-
 
756
    XBEE_RX_REMOTE_AT_COMMAND_FRAME *rx_remote_at_cmd_frame;
-
 
757
    XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME *rx_node_ident_frame;
-
 
758
    XBEE_RX_MODEM_STATUS_FRAME *rx_modem_status_frame;
789
 
759
 
790
    /* --------------------- Oscillator Configuration --------------------- */
760
    /* --------------------- Oscillator Configuration --------------------- */
791
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
761
    //    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
792
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
762
    OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
793
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
763
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
Line 827... Line 797...
827
        tx_data_frame->data[4] = 0x6F;
797
        tx_data_frame->data[4] = 0x6F;
828
        tx_data_frame->data[5] = 0x6F;
798
        tx_data_frame->data[5] = 0x6F;
829
        tx_data_frame->data[6] = 0x72;
799
        tx_data_frame->data[6] = 0x72;
830
        tx_data_frame->data[7] = 0x11;
800
        tx_data_frame->data[7] = 0x11;
831
        XBee_Process_Transmit_Frame(buffer, XBEE_TX_DATA_PACKET_FRAME_SIZE + 8);
801
        XBee_Process_Transmit_Frame(buffer, XBEE_TX_DATA_PACKET_FRAME_SIZE + 8);
832
        
802
 
833
        Delay10KTCYx(255);
803
        Delay10KTCYx(255);
834
        Delay10KTCYx(255);
804
        Delay10KTCYx(255);
835
        Delay10KTCYx(255);
805
        Delay10KTCYx(255);
836
        Delay10KTCYx(255);
806
        Delay10KTCYx(255);
837
        Delay10KTCYx(255);
807
        Delay10KTCYx(255);
Line 844... Line 814...
844
        length = XBee_Get_Received_Frame(buffer);
814
        length = XBee_Get_Received_Frame(buffer);
845
        if (length != 0) {
815
        if (length != 0) {
846
            switch (*(unsigned char *) buffer) {
816
            switch (*(unsigned char *) buffer) {
847
                case XBEE_RX_AT_COMMAND_RESPONSE:
817
                case XBEE_RX_AT_COMMAND_RESPONSE:
848
                    DBG_PRINT_MAIN("XBEE: parsing recieved AT command response frame\r\n");
818
                    DBG_PRINT_MAIN("XBEE: parsing recieved AT command response frame\r\n");
-
 
819
                    rx_at_cmd_response_frame = (void *) buffer;
-
 
820
                    DBG_PRINT_MAIN("Frame ID: %u\r\n", rx_at_cmd_response_frame->frame_id);
-
 
821
                    DBG_PRINT_MAIN("AT Command: %c%c  Status: %02X\r\n", rx_at_cmd_response_frame->command[0], \\
-
 
822
                            rx_at_cmd_response_frame->command[1], rx_at_cmd_response_frame->command_status);
-
 
823
                    if (length > XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE) {
-
 
824
                        DBG_PRINT_MAIN("Command Data: ");
-
 
825
                        for (i = 0; i < length - XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE; i++) {
-
 
826
                            DBG_PRINT_MAIN("%02X ", rx_at_cmd_response_frame->data[i]);
-
 
827
                        }
-
 
828
                        DBG_PRINT_MAIN("\r\n");
-
 
829
                    }
849
                    break;
830
                    break;
850
                case XBEE_RX_DATA_PACKET:
831
                case XBEE_RX_DATA_PACKET:
851
                    rx_data_frame = (void *)buffer;
-
 
852
                    DBG_PRINT_MAIN("XBEE: parsing recieved data recieved frame\r\n");
832
                    DBG_PRINT_MAIN("XBEE: parsing recieved data recieved frame\r\n");
-
 
833
                    rx_data_frame = (void *) buffer;
853
                    XBee_ConvertEndian64(&(rx_data_frame->source_64));
834
                    XBee_ConvertEndian64(&(rx_data_frame->source_64));
854
                    XBee_ConvertEndian16(&(rx_data_frame->source_16));
835
                    XBee_ConvertEndian16(&(rx_data_frame->source_16));
855
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %X\r\n", \\
836
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
856
                            rx_data_frame->source_64.UPPER_32.long_value, \\
837
                            rx_data_frame->source_64.UPPER_32.long_value, \\
857
                            rx_data_frame->source_64.LOWER_32.long_value, \\
838
                            rx_data_frame->source_64.LOWER_32.long_value, \\
858
                            rx_data_frame->source_16.INT_16.int_value, \\
839
                            rx_data_frame->source_16.INT_16.int_value, \\
859
                            rx_data_frame->recieve_options);
840
                            rx_data_frame->recieve_options);
860
                    DBG_PRINT_MAIN("Data: ");
841
                    DBG_PRINT_MAIN("Data: ");
Line 863... Line 844...
863
                    }
844
                    }
864
                    DBG_PRINT_MAIN("\r\n");
845
                    DBG_PRINT_MAIN("\r\n");
865
                    break;
846
                    break;
866
                case XBEE_RX_DATA_TX_STATUS:
847
                case XBEE_RX_DATA_TX_STATUS:
867
                    DBG_PRINT_MAIN("XBEE: parsing recieved TX status frame\r\n");
848
                    DBG_PRINT_MAIN("XBEE: parsing recieved TX status frame\r\n");
-
 
849
                    rx_tx_status_frame = (void *) buffer;
-
 
850
                    XBee_ConvertEndian16(&(rx_tx_status_frame->destination_16));
-
 
851
                    DBG_PRINT_MAIN("Frame ID: %u  Destination 16: %04X\r\n", \\
-
 
852
                            rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
-
 
853
                    DBG_PRINT_MAIN("Transmit Retry Count: %02X  Delivery Status: %02X  Discovery Status: %02X\r\n", \\
-
 
854
                            rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
-
 
855
                            rx_tx_status_frame->discovery_status);
868
                    break;
856
                    break;
869
                case XBEE_RX_IO_DATA_SAMPLE:
857
                case XBEE_RX_IO_DATA_SAMPLE:
870
                    DBG_PRINT_MAIN("XBEE: parsing recieved IO data sample frame\r\n");
858
                    DBG_PRINT_MAIN("XBEE: parsing recieved IO data sample frame\r\n");
871
                    break;
859
                    break;
872
                case XBEE_RX_EXPLICIT_COMMAND:
860
                case XBEE_RX_EXPLICIT_COMMAND:
873
                    DBG_PRINT_MAIN("XBEE: parsing recieved explicit command frame\r\n");
861
                    DBG_PRINT_MAIN("XBEE: parsing recieved explicit command frame\r\n");
874
                    break;
862
                    break;
875
                case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
863
                case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
876
                    DBG_PRINT_MAIN("XBEE: parsing recieved remote AT command frame\r\n");
864
                    DBG_PRINT_MAIN("XBEE: parsing recieved remote AT command frame\r\n");
-
 
865
                    rx_remote_at_cmd_frame = (void *) buffer;
877
                    break;
866
                    break;
878
                case XBEE_RX_ROUTE_RECORD:
867
                case XBEE_RX_ROUTE_RECORD:
879
                    DBG_PRINT_MAIN("XBEE: parsing recieved route record frame\r\n");
868
                    DBG_PRINT_MAIN("XBEE: parsing recieved route record frame\r\n");
880
                    break;
869
                    break;
881
                case XBEE_RX_NODE_IDENTIFICATION:
870
                case XBEE_RX_NODE_IDENTIFICATION:
882
                    DBG_PRINT_MAIN("XBEE: parsing recieved node identification frame\r\n");
871
                    DBG_PRINT_MAIN("XBEE: parsing recieved node identification frame\r\n");
-
 
872
                    rx_node_ident_frame = (void *) buffer;
-
 
873
                    XBee_ConvertEndian64(&(rx_node_ident_frame->source_64));
-
 
874
                    XBee_ConvertEndian16(&(rx_node_ident_frame->source_16));
-
 
875
                    XBee_ConvertEndian64(&(rx_node_ident_frame->remote_64));
-
 
876
                    XBee_ConvertEndian16(&(rx_node_ident_frame->remote_16));
-
 
877
                    XBee_ConvertEndian16(&(rx_node_ident_frame->parent_16));
-
 
878
                    DBG_PRINT_MAIN("Source 64: %08lX %08lX  Source 16: %04X  Options: %02X\r\n", \\
-
 
879
                            rx_node_ident_frame->source_64.UPPER_32.long_value, \\
-
 
880
                            rx_node_ident_frame->source_64.LOWER_32.long_value, \\
-
 
881
                            rx_node_ident_frame->source_16.INT_16.int_value, \\
-
 
882
                            rx_node_ident_frame->recieve_options);
-
 
883
                    DBG_PRINT_MAIN("Remote 64: %08lX %08lX  Remote 16: %04X  Parent 16: %04X\r\n", \\
-
 
884
                            rx_node_ident_frame->remote_64.UPPER_32.long_value, \\
-
 
885
                            rx_node_ident_frame->remote_64.LOWER_32.long_value, \\
-
 
886
                            rx_node_ident_frame->remote_16.INT_16.int_value, \\
-
 
887
                            rx_node_ident_frame->parent_16.INT_16.int_value);
-
 
888
                    DBG_PRINT_MAIN("Device Type: %02X  Source Event: %02X\r\n", \\
-
 
889
                            rx_node_ident_frame->device_type, rx_node_ident_frame->source_event);
883
                    break;
890
                    break;
884
                case XBEE_RX_FRAME_MODEM_STATUS:
891
                case XBEE_RX_FRAME_MODEM_STATUS:
885
                    DBG_PRINT_MAIN("XBEE: parsing recieved modem status frame\r\n");
892
                    DBG_PRINT_MAIN("XBEE: parsing recieved modem status frame\r\n");
-
 
893
                    rx_modem_status_frame = (void *) buffer;
-
 
894
                    DBG_PRINT_MAIN("Status: %02X\r\n", rx_modem_status_frame->status);
886
                    break;
895
                    break;
887
                default:
896
                default:
888
                    DBG_PRINT_MAIN("??\r\n");
897
                    DBG_PRINT_MAIN("??\r\n");
889
                    break;
898
                    break;
890
            }
899
            }
Line 921... Line 930...
921
 
930
 
922
    UART1_Init();
931
    UART1_Init();
923
    I2C_Init();
932
    I2C_Init();
924
    NFC_Init();
933
    NFC_Init();
925
    SPI2_Init(SPI2_FOSC_8);
934
    SPI2_Init(SPI2_FOSC_8);
926
    SSD1331_Init();
935
    SSD1306_Init();
927
 
936
 
928
    I2C_Configure_Master(I2C_400KHZ);
937
    I2C_Configure_Master(I2C_400KHZ);
929
 
938
 
930
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
939
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
931
    interrupt_init(); // Initialize the interrupt priorities
940
    interrupt_init(); // Initialize the interrupt priorities
932
 
941
 
933
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
942
    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
934
 
943
 
935
    SSD1331_Begin();
944
    SSD1306_Begin(SSD1306_SWITCHCAPVCC);
936
    memset(cardData, 0, 24);
945
    memset(cardData, 0, 24);
937
    memset(cardData_prev, 0, 24);
946
    memset(cardData_prev, 0, 24);
938
    GFX_clearScreen();
947
    SSD1306_Clear_Display();
939
    GFX_setRotation(0);
948
    SSD1306_Set_Rotation(0);
940
    GFX_setCursor(0, 0);
949
    SSD1306_Set_Cursor(0, 0);
941
 
950
 
942
    version = NFC_getFirmwareVersion();
951
    version = NFC_getFirmwareVersion();
943
    while (!version.IC) {
952
    while (!version.IC) {
944
        GFX_appendString("Waiting for NFC board..\r");
953
        SSD1306_Write_String("Waiting for NFC board..\r");
-
 
954
        SSD1306_Display();
945
        Delay10KTCYx(3);
955
        Delay10KTCYx(3);
946
        version = NFC_getFirmwareVersion();
956
        version = NFC_getFirmwareVersion();
947
    }
957
    }
948
    GFX_appendString("PN5%X Ver. %d.%d\r", version.IC, version.Ver, version.Rev);
958
    SSD1306_Write_String("PN5%X Ver. %d.%d\r", version.IC, version.Ver, version.Rev);
-
 
959
    SSD1306_Display();
949
    NFC_SAMConfig();
960
    NFC_SAMConfig();
950
 
961
 
951
    while (1) {
962
    while (1) {
952
 
963
 
953
        // This query will not wait for a detection before responding
964
        // This query will not wait for a detection before responding
Line 958... Line 969...
958
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
969
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
959
                // Do nothing
970
                // Do nothing
960
            } else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0) {
971
            } else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0) {
961
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
972
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
962
            } else {
973
            } else {
963
                GFX_appendString("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
974
                SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
-
 
975
                SSD1306_Display();
964
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
976
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
965
            }
977
            }
966
            memset(&cardData_prev[1], 0, 12);
978
            memset(&cardData_prev[1], 0, 12);
967
        } else if (length == 2) {
979
        } else if (length == 2) {
968
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0 &&
980
            if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0 &&
Line 972... Line 984...
972
                    memcmp(&cardData[1].NFCID, &cardData_prev[0].NFCID, cardData[1].NFCID_LEN) == 0) {
984
                    memcmp(&cardData[1].NFCID, &cardData_prev[0].NFCID, cardData[1].NFCID_LEN) == 0) {
973
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
985
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
974
                memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
986
                memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
975
            } else if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
987
            } else if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
976
                // First card matched
988
                // First card matched
977
                GFX_appendString("UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
989
                SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
-
 
990
                SSD1306_Display();
978
                memcpy(&cardData_prev[1], (const char *) &cardData[1], 12);
991
                memcpy(&cardData_prev[1], (const char *) &cardData[1], 12);
979
            } else if (memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
992
            } else if (memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
980
                // Second card matched
993
                // Second card matched
981
                GFX_appendString("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
994
                SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
-
 
995
                SSD1306_Display();
982
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
996
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
983
            } else {
997
            } else {
984
                // No match
998
                // No match
985
                GFX_appendString("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
999
                SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
-
 
1000
                SSD1306_Display();
986
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
1001
                memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
987
                GFX_appendString("UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
1002
                SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
-
 
1003
                SSD1306_Display();
988
                memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
1004
                memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
989
            }
1005
            }
990
        }
1006
        }
991
    }
1007
    }
992
}
1008
}