diff options
author | RossTheRoss <msattr@gmail.com> | 2020-02-22 19:58:57 -0600 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2020-02-22 19:58:57 -0600 |
commit | 40e6fa2722fa3c37edbc0d0faa5a1164c7a68e34 (patch) | |
tree | 65b870de5587aa07d2eb79fca40ba0e356fbd3f3 | |
parent | Merge origin/master (diff) | |
download | ee2361-40e6fa2722fa3c37edbc0d0faa5a1164c7a68e34.tar ee2361-40e6fa2722fa3c37edbc0d0faa5a1164c7a68e34.tar.gz ee2361-40e6fa2722fa3c37edbc0d0faa5a1164c7a68e34.tar.bz2 ee2361-40e6fa2722fa3c37edbc0d0faa5a1164c7a68e34.tar.lz ee2361-40e6fa2722fa3c37edbc0d0faa5a1164c7a68e34.tar.xz ee2361-40e6fa2722fa3c37edbc0d0faa5a1164c7a68e34.tar.zst ee2361-40e6fa2722fa3c37edbc0d0faa5a1164c7a68e34.zip |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
(Lab 3 partially working)
-rw-r--r-- | Lab3.X/display.c | 72 | ||||
-rw-r--r-- | Lab3.X/display.h | 22 | ||||
-rw-r--r-- | Lab3.X/lab3_c.c | 108 | ||||
-rw-r--r-- | Lab3.X/lab3_main_c.c | 38 | ||||
-rw-r--r-- | Lab3.X/numpad.c | 9 | ||||
-rw-r--r-- | Lab3.X/numpad.h | 18 |
6 files changed, 159 insertions, 108 deletions
diff --git a/Lab3.X/display.c b/Lab3.X/display.c new file mode 100644 index 0000000..2c2fd1f --- /dev/null +++ b/Lab3.X/display.c @@ -0,0 +1,72 @@ +#include "xc.h"
+#include "display.h"
+//Functions used for Display
+
+
+void delay(long num) {
+ long i;
+ for (i; i < num; i++) {
+ asm("nop");
+ }
+}
+void init7seg(void) {
+ TRISB = 0b0000000000000011; //and port B to outputs
+ LATB = 0x0000; //and all of port B to LOW
+}
+void showChar7seg(char myChar, enum DIGIT myDigit) {
+ LATB &= 0x00;
+ switch (myChar) {
+ case '0':
+ LATB ^= (0b11 << 2);
+ break;
+ case '1':
+ LATB ^= (0b10011111 << 2);
+ break;
+ case '2':
+ LATB ^= (0b00100101 << 2);
+ break;
+ case '3':
+ LATB ^= (0b1101 << 2);
+ break;
+ case '4':
+ LATB ^= (0b10011001 << 2);
+ break;
+ case '5':
+ LATB ^= (0b1001001 << 2);
+ break;
+ case '6':
+ LATB ^= (0b1000001 << 2);
+ break;
+ case '7':
+ LATB ^= (0b11111 << 2);
+ break;
+ case '8':
+ LATB ^= (0b1 << 2);
+ break;
+ case '9':
+ LATB ^= (0b1001 << 2);
+ break;
+ case 'A':
+ LATB ^= (0b10001 << 2);
+ break;
+ case 'b':
+ LATB ^= (0b11000001 << 2);
+ break;
+ case 'C':
+ LATB ^= (0b01100011 << 2);
+ break;
+ case 'd':
+ LATB ^= (0b10000101 << 2);
+ break;
+ case 'E':
+ LATB ^= (0b01100001 << 2);
+ break;
+ case 'F':
+ LATB ^= (0b01110001 << 2);
+ break;
+ default:
+ LATB ^= (0b1010001 << 2);
+ break;
+ } //END OF SWITCH
+ LATB |= myDigit;
+}
\ No newline at end of file diff --git a/Lab3.X/display.h b/Lab3.X/display.h new file mode 100644 index 0000000..fa2dfa1 --- /dev/null +++ b/Lab3.X/display.h @@ -0,0 +1,22 @@ +#ifndef DISPLAY_H
+#define DISPLAY_H
+
+#include <xc.h> // include processor files - each processor file is guarded.
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+ // Insert declarations
+enum DIGIT {
+ MSB = (0b1 << 11),
+ LSB = (0b1 << 10)
+};
+void init7seg(void);
+void showChar7seg(char myChar, enum DIGIT myDigit);
+void delay(long num);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file diff --git a/Lab3.X/lab3_c.c b/Lab3.X/lab3_c.c deleted file mode 100644 index 5050d50..0000000 --- a/Lab3.X/lab3_c.c +++ /dev/null @@ -1,108 +0,0 @@ -#include "xc.h"
-// CW1: FLASH CONFIGURATION WORD 1 (see PIC24 Family Reference Manual 24.1)
-#pragma config ICS = PGx1 // Comm Channel Select (Emulator EMUC1/EMUD1 pins are shared with PGC1/PGD1)
-#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled)
-#pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed)
-#pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled)
-#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
-
-
-// CW2: FLASH CONFIGURATION WORD 2 (see PIC24 Family Reference Manual 24.1)
-#pragma config I2C1SEL = PRI // I2C1 Pin Location Select (Use default SCL1/SDA1 pins)
-#pragma config IOL1WAY = OFF // IOLOCK Protection (IOLOCK may be changed via unlocking seq)
-#pragma config OSCIOFNC = ON // Primary Oscillator I/O Function (CLKO/RC15 functions as I/O pin)
-#pragma config FCKSM = CSECME // Clock Switching and Monitor (Clock switching is enabled,
- // Fail-Safe Clock Monitor is enabled)
-#pragma config FNOSC = FRCPLL // Oscillator Select (Fast RC Oscillator with PLL module (FRCPLL))
-
-void init7seg(void);
-void showChar7seg(char myChar, int myDigit);
-//where myChar is the character being displayed
-//where myDigit indicates LEFT (1) or RIGHT (0)
-
-
-void setup(void) {
- CLKDIVbits.RCDIV = 0; //Set RCDIV=1:1 (default 2:1) 32MHz or FCY/2=16M
- init7seg();
-}
-
-void init7seg(void) {
- AD1PCFG = 0x9fff; //sets all pins to digital I/O
- TRISA = 0b0000000000011111; //set port A to inputs,
- TRISB = 0b0000000000000011; //and port B to outputs
- LATA = 0x0000; //Set all of port A to LOW
- LATB = 0xF000; //and all of port B to LOW
-}
-
-int main(void) {
- setup();
- LATB |= (0b01 << 10);
- LATB ^= (0b001111111);
- while (1) {
-
- }
-}
-
-void showChar7seg(char myChar, int myDigit) {
- LATB |= 0xFF;
- switch (myChar) {
- case '0':
- LATB ^= (0b11 << 2);
- break;
- case '1':
- LATB ^= (0b11 << 6);
- break;
- case '2':
- //
- break;
- case '3':
- //
- break;
- case '4':
- //
- break;
- case '5':
- //
- break;
- case '6':
- //
- break;
- case '7':
- LATB ^= (0b001111110);
- break;
- case '8':
- //
- break;
- case '9':
- //
- break;
- case 'A':
- //
- break;
- case 'b':
- //
- break;
- case 'C':
- //
- break;
- case 'd':
- //
- break;
- case 'E':
- //
- break;
- case 'F':
- //
- break;
- default:
- break;
- } //END OF SWITCH
- if (myDigit == 0) {
- //0 = left
- LATB ^= (0b10 << 10);
- } else if (myDigit == 1) {
- //0 = right
- LATB ^= (0b01 << 10);
- }
-
-}
\ No newline at end of file diff --git a/Lab3.X/lab3_main_c.c b/Lab3.X/lab3_main_c.c new file mode 100644 index 0000000..1ead16d --- /dev/null +++ b/Lab3.X/lab3_main_c.c @@ -0,0 +1,38 @@ +#include "xc.h"
+#include "display.h"
+#include "numpad.h"
+// CW1: FLASH CONFIGURATION WORD 1 (see PIC24 Family Reference Manual 24.1)
+#pragma config ICS = PGx1 // Comm Channel Select (Emulator EMUC1/EMUD1 pins are shared with PGC1/PGD1)
+#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled)
+#pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed)
+#pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled)
+#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
+
+
+// CW2: FLASH CONFIGURATION WORD 2 (see PIC24 Family Reference Manual 24.1)
+#pragma config I2C1SEL = PRI // I2C1 Pin Location Select (Use default SCL1/SDA1 pins)
+#pragma config IOL1WAY = OFF // IOLOCK Protection (IOLOCK may be changed via unlocking seq)
+#pragma config OSCIOFNC = ON // Primary Oscillator I/O Function (CLKO/RC15 functions as I/O pin)
+#pragma config FCKSM = CSECME // Clock Switching and Monitor (Clock switching is enabled,
+ // Fail-Safe Clock Monitor is enabled)
+#pragma config FNOSC = FRCPLL // Oscillator Select (Fast RC Oscillator with PLL module (FRCPLL))
+
+
+void setup(void) {
+ CLKDIVbits.RCDIV = 0; //Set RCDIV=1:1 (default 2:1) 32MHz or FCY/2=16M
+ AD1PCFG = 0x9fff; //sets all pins to digital I/O
+ init7seg();
+ initKeyPad();
+}
+
+int main(void) {
+ setup();
+ while (1) {
+ showChar7seg('1', LSB);
+ delay(170);
+ showChar7seg('0', MSB);
+ delay(170);
+ }
+}
+
+
diff --git a/Lab3.X/numpad.c b/Lab3.X/numpad.c new file mode 100644 index 0000000..fcd87cc --- /dev/null +++ b/Lab3.X/numpad.c @@ -0,0 +1,9 @@ +#include "xc.h"
+void initKeyPad(void) {
+ TRISA = 0b0000000000011111; //set port A to inputs,
+ LATA = 0x0000; //Set all of port A to LOW
+ CNPU1bits.CN11PUE = 1;
+ CNPU1bits.CN12PUE = 1;
+ CNPU1bits.CN13PUE = 1;
+ CNPU1bits.CN14PUE = 1;
+}
diff --git a/Lab3.X/numpad.h b/Lab3.X/numpad.h new file mode 100644 index 0000000..d94bf42 --- /dev/null +++ b/Lab3.X/numpad.h @@ -0,0 +1,18 @@ +#ifndef NUMPAD_H
+#define NUMPAD_H
+
+#include <xc.h> // include processor files - each processor file is guarded.
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+ // Insert declarations
+ void initKeyPad(void);
+ unsigned int readKeyPadRAW(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file |