aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Lab3.X/display.c10
-rw-r--r--Lab3.X/lab3_main_c.c19
-rw-r--r--Lab3.X/nbproject/private/private.xml13
-rw-r--r--Lab3.X/numpad.c95
4 files changed, 125 insertions, 12 deletions
diff --git a/Lab3.X/display.c b/Lab3.X/display.c
index 2c2fd1f..5ad9c4f 100644
--- a/Lab3.X/display.c
+++ b/Lab3.X/display.c
@@ -2,17 +2,11 @@
#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) {
@@ -65,7 +59,7 @@ void showChar7seg(char myChar, enum DIGIT myDigit) {
LATB ^= (0b01110001 << 2);
break;
default:
- LATB ^= (0b1010001 << 2);
+ LATB ^= (0b11111111 << 2);
break;
} //END OF SWITCH
LATB |= myDigit;
diff --git a/Lab3.X/lab3_main_c.c b/Lab3.X/lab3_main_c.c
index 1ead16d..406f657 100644
--- a/Lab3.X/lab3_main_c.c
+++ b/Lab3.X/lab3_main_c.c
@@ -17,6 +17,11 @@
// Fail-Safe Clock Monitor is enabled)
#pragma config FNOSC = FRCPLL // Oscillator Select (Fast RC Oscillator with PLL module (FRCPLL))
+void delay(long n) {
+ for (n=n; n>0; n--) {
+ asm("nop");
+ }
+}
void setup(void) {
CLKDIVbits.RCDIV = 0; //Set RCDIV=1:1 (default 2:1) 32MHz or FCY/2=16M
@@ -27,11 +32,17 @@ void setup(void) {
int main(void) {
setup();
+ char right, left, temp;
while (1) {
- showChar7seg('1', LSB);
- delay(170);
- showChar7seg('0', MSB);
- delay(170);
+ temp = readKeyPadRAW();
+ if (temp != '\0') {
+ left = right;
+ right = temp;
+ }
+ showChar7seg(right, LSB);
+ delay(200);
+ showChar7seg(left, MSB);
+ delay(200);
}
}
diff --git a/Lab3.X/nbproject/private/private.xml b/Lab3.X/nbproject/private/private.xml
new file mode 100644
index 0000000..c10361e
--- /dev/null
+++ b/Lab3.X/nbproject/private/private.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
+ <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
+ <group>
+ <file>file:/C:/Users/Ross/MPLABXProjects/EE2361Projects/Lab3.X/display.h</file>
+ <file>file:/C:/Users/Ross/MPLABXProjects/EE2361Projects/Lab3.X/numpad.h</file>
+ <file>file:/C:/Users/Ross/MPLABXProjects/EE2361Projects/Lab3.X/display.c</file>
+ <file>file:/C:/Users/Ross/MPLABXProjects/EE2361Projects/Lab3.X/numpad.c</file>
+ <file>file:/C:/Users/Ross/MPLABXProjects/EE2361Projects/Lab3.X/lab3_main_c.c</file>
+ </group>
+ </open-files>
+</project-private>
diff --git a/Lab3.X/numpad.c b/Lab3.X/numpad.c
index fcd87cc..271b324 100644
--- a/Lab3.X/numpad.c
+++ b/Lab3.X/numpad.c
@@ -7,3 +7,98 @@ void initKeyPad(void) {
CNPU1bits.CN13PUE = 1;
CNPU1bits.CN14PUE = 1;
}
+void padDelay(long n) {
+ for (n=n; n>0; n--) {
+ asm("nop");
+ }
+}
+// 1 2 3 4 5 6 7 8
+// RA0 RA1 RA2 RA3 RB15 RB14 RB13 RB12
+char readKeyPadRAW(void) {
+ int i;
+ char num;
+ num = (!_RB15 << 3) | (!_RB14 << 2) | (!_RB13 << 1) | !_RB12;
+ LATB |= (0b1111 << 12);
+ for (i = 0; i < 4; i++) {
+ LATB ^= 0b1 << (15 - i);
+ padDelay(10);
+ switch (i) {
+ case 0:
+ switch (num) {
+ case 0b1110:
+ return 'A';
+ break;
+ case 0b1101:
+ return '3';
+ break;
+ case 0b1011:
+ return '2';
+ break;
+ case 0b111:
+ return '1';
+ break;
+ } break;
+ case 1:
+ switch (num) {
+ case 0b1110:
+ return 'b';
+ break;
+ case 0b1101:
+ return '6';
+ break;
+ case 0b1011:
+ return '5';
+ break;
+ case 0b111:
+ return '4';
+ break;
+ } break;
+ case 2:
+ switch (num) {
+ case 0b1110:
+ return 'C';
+ break;
+ case 0b1101:
+ return '9';
+ break;
+ case 0b1011:
+ return '8';
+ break;
+ case 0b111:
+ return '7';
+ break;
+ } break;
+ case 3:
+ switch (num) {
+ case 0b1110:
+ return 'd';
+ break;
+ case 0b1101:
+ return 'E';
+ break;
+ case 0b1011:
+ return '0';
+ break;
+ case 0b111:
+ return 'F';
+ break;
+ } break;
+ } //END switch(i);
+ LATB |= (0b1111 << 12);
+ }
+ return '\0';
+}
+/*
+Outputs<8:5> = 0b0111; // Set Row 1 output Low
+delay(1us); // this delay could be lower, probably 2-3 cycles
+RowOne = Inputs<4:1>; // returns 0b1111 (no buttons pressed in row 1)
+
+Outputs<8:5> = 0b1011; // Set Row 2 output Low
+delay(1us);
+RowTwo = Inputs<4:1>; // returns 0b1101 (the ?6? key was pressed!)
+...
+Outputs<8:5> = 0b1110; // Set Row 4 output Low
+delay(1us);
+RowFour = Inputs<4:1>; // returns 0b1111 (no buttons pressed in row 4)
+
+ */ \ No newline at end of file