Subversion Repositories Code-Repo

Rev

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

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