Counter

Dependencies:   mbed

Committer:
Eduvance
Date:
Tue May 27 07:28:31 2014 +0000
Revision:
1:97ee52dedac3
Parent:
0:776a127ae50b
A

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Eduvance 0:776a127ae50b 1 #include "mbed.h"
Eduvance 0:776a127ae50b 2
Eduvance 1:97ee52dedac3 3 BusOut Disp1(p26,p25,p24,p23,p22,p21,p20); // ABCDEFGdp
Eduvance 1:97ee52dedac3 4 DigitalOut vdd(p19);
Eduvance 1:97ee52dedac3 5 DigitalOut vddn(p18);
Eduvance 1:97ee52dedac3 6
Eduvance 1:97ee52dedac3 7
Eduvance 1:97ee52dedac3 8 DigitalIn row1(p14); // row1 output
Eduvance 1:97ee52dedac3 9 DigitalIn row2(p15); // row2 output
Eduvance 1:97ee52dedac3 10 DigitalIn row3(p16); // row3 output
Eduvance 1:97ee52dedac3 11 DigitalIn row4(p17);
Eduvance 1:97ee52dedac3 12
Eduvance 1:97ee52dedac3 13 DigitalOut col1(p11); // col2 input with 6k8 pullup to 3.3v
Eduvance 1:97ee52dedac3 14 DigitalOut col2(p12); // col3 input with 6k8 pullup to 3.3v
Eduvance 1:97ee52dedac3 15 DigitalOut col3(p13); // col4 input with 6k8 pullup to 3.3v
Eduvance 1:97ee52dedac3 16
Eduvance 1:97ee52dedac3 17
Eduvance 1:97ee52dedac3 18 void setvdd() {
Eduvance 1:97ee52dedac3 19 vddn=1;
Eduvance 1:97ee52dedac3 20 vdd=0;
Eduvance 1:97ee52dedac3 21 }
Eduvance 1:97ee52dedac3 22
Eduvance 1:97ee52dedac3 23 int loop = 10; // non zero value for the while loop
Eduvance 1:97ee52dedac3 24
Eduvance 1:97ee52dedac3 25 void setcolhigh() {
Eduvance 1:97ee52dedac3 26 col1=1; // set row1 low
Eduvance 1:97ee52dedac3 27 col2=1; // set row2 low
Eduvance 1:97ee52dedac3 28 col3=1;
Eduvance 1:97ee52dedac3 29 // set row3 low
Eduvance 1:97ee52dedac3 30 }
Eduvance 1:97ee52dedac3 31 void setcol1() {
Eduvance 1:97ee52dedac3 32 col1=0; // set row1 low
Eduvance 1:97ee52dedac3 33 col2=1; // set row2 high
Eduvance 1:97ee52dedac3 34 col3=1;
Eduvance 1:97ee52dedac3 35 // set row3 high
Eduvance 1:97ee52dedac3 36 }
Eduvance 1:97ee52dedac3 37 void setcol2() {
Eduvance 1:97ee52dedac3 38 col1=1; // set row1 high
Eduvance 1:97ee52dedac3 39 col2=0; // set row2 low
Eduvance 1:97ee52dedac3 40 col3=1;
Eduvance 1:97ee52dedac3 41 // set row3 high
Eduvance 1:97ee52dedac3 42 }
Eduvance 1:97ee52dedac3 43 void setcol3() {
Eduvance 1:97ee52dedac3 44 col1=1; // set row1 high
Eduvance 1:97ee52dedac3 45 col2=1; // set row2 high
Eduvance 1:97ee52dedac3 46 col3=0;
Eduvance 1:97ee52dedac3 47 // set row3 low
Eduvance 1:97ee52dedac3 48 }
Eduvance 1:97ee52dedac3 49
Eduvance 1:97ee52dedac3 50 // set row3 low
Eduvance 1:97ee52dedac3 51
Eduvance 1:97ee52dedac3 52
Eduvance 0:776a127ae50b 53
Eduvance 1:97ee52dedac3 54 void key_1() {
Eduvance 1:97ee52dedac3 55 Disp1 = 0xF9;
Eduvance 1:97ee52dedac3 56
Eduvance 1:97ee52dedac3 57 }
Eduvance 1:97ee52dedac3 58 void key_2() {
Eduvance 1:97ee52dedac3 59 Disp1 = 0xA4;
Eduvance 1:97ee52dedac3 60 }
Eduvance 1:97ee52dedac3 61 void key_3() {
Eduvance 1:97ee52dedac3 62 Disp1 = 0xB0;
Eduvance 1:97ee52dedac3 63 }
Eduvance 1:97ee52dedac3 64 void key_4() {
Eduvance 1:97ee52dedac3 65 Disp1 = 0x99;
Eduvance 1:97ee52dedac3 66 }
Eduvance 1:97ee52dedac3 67 void key_5() {
Eduvance 1:97ee52dedac3 68 Disp1 = 0x92;
Eduvance 1:97ee52dedac3 69 }
Eduvance 1:97ee52dedac3 70 void key_6() {
Eduvance 1:97ee52dedac3 71 Disp1 = 0x82;
Eduvance 1:97ee52dedac3 72 }
Eduvance 1:97ee52dedac3 73 void key_7() {
Eduvance 1:97ee52dedac3 74 Disp1 = 0xF8;
Eduvance 1:97ee52dedac3 75 }
Eduvance 1:97ee52dedac3 76 void key_8() {
Eduvance 1:97ee52dedac3 77 Disp1 = 0x80;
Eduvance 1:97ee52dedac3 78 }
Eduvance 1:97ee52dedac3 79 void key_9() {
Eduvance 1:97ee52dedac3 80 Disp1 = 0x90;
Eduvance 1:97ee52dedac3 81 }
Eduvance 1:97ee52dedac3 82 void key_0() {
Eduvance 1:97ee52dedac3 83 Disp1 = 0xC0;
Eduvance 1:97ee52dedac3 84 }
Eduvance 1:97ee52dedac3 85 void key_le() {
Eduvance 1:97ee52dedac3 86 // lcd.locate(7,1);
Eduvance 1:97ee52dedac3 87 // lcd.printf("*");
Eduvance 1:97ee52dedac3 88 Disp1 = 0x88;
Eduvance 1:97ee52dedac3 89 }
Eduvance 1:97ee52dedac3 90 void key_r() {
Eduvance 1:97ee52dedac3 91 // lcd.locate(7,1);
Eduvance 1:97ee52dedac3 92 // lcd.printf("#");
Eduvance 1:97ee52dedac3 93 Disp1 = 0xC6;
Eduvance 1:97ee52dedac3 94 }
Eduvance 1:97ee52dedac3 95
Eduvance 1:97ee52dedac3 96 void key_nope() {
Eduvance 1:97ee52dedac3 97 Disp1 = 0x3F;
Eduvance 0:776a127ae50b 98 }
Eduvance 1:97ee52dedac3 99
Eduvance 1:97ee52dedac3 100 // keyscan function routine
Eduvance 1:97ee52dedac3 101 void keyscan() {
Eduvance 1:97ee52dedac3 102 setcolhigh();
Eduvance 1:97ee52dedac3 103 wait(0.2);
Eduvance 1:97ee52dedac3 104 setcol1();
Eduvance 1:97ee52dedac3 105 wait(0.2);
Eduvance 1:97ee52dedac3 106 if (row1 == 0)
Eduvance 1:97ee52dedac3 107 key_1();
Eduvance 1:97ee52dedac3 108 if (row2 == 0)
Eduvance 1:97ee52dedac3 109 key_4();
Eduvance 1:97ee52dedac3 110 if (row3 == 0)
Eduvance 1:97ee52dedac3 111 key_7();
Eduvance 1:97ee52dedac3 112 if (row4 == 0)
Eduvance 1:97ee52dedac3 113 key_le();
Eduvance 1:97ee52dedac3 114 wait(0.1);
Eduvance 1:97ee52dedac3 115 setcol2();
Eduvance 1:97ee52dedac3 116 wait(0.2);
Eduvance 1:97ee52dedac3 117 if (row1 == 0)
Eduvance 1:97ee52dedac3 118 key_2();
Eduvance 1:97ee52dedac3 119 if (row2 == 0)
Eduvance 1:97ee52dedac3 120 key_5();
Eduvance 1:97ee52dedac3 121 if (row3 == 0)
Eduvance 1:97ee52dedac3 122 key_8();
Eduvance 1:97ee52dedac3 123 if (row4 == 0)
Eduvance 1:97ee52dedac3 124 key_0();
Eduvance 1:97ee52dedac3 125
Eduvance 1:97ee52dedac3 126 wait(0.1);
Eduvance 1:97ee52dedac3 127 setcol3();
Eduvance 1:97ee52dedac3 128 wait(0.2);
Eduvance 1:97ee52dedac3 129 if (row1 == 0)
Eduvance 1:97ee52dedac3 130 key_3();
Eduvance 1:97ee52dedac3 131 if (row2 == 0)
Eduvance 1:97ee52dedac3 132 key_6();
Eduvance 1:97ee52dedac3 133 if (row3 == 0)
Eduvance 1:97ee52dedac3 134 key_9();
Eduvance 1:97ee52dedac3 135 if (row4 == 0)
Eduvance 1:97ee52dedac3 136 key_r();
Eduvance 1:97ee52dedac3 137
Eduvance 1:97ee52dedac3 138
Eduvance 1:97ee52dedac3 139 // wait(0.1)
Eduvance 1:97ee52dedac3 140 //else
Eduvance 1:97ee52dedac3 141 //key_nope();
Eduvance 1:97ee52dedac3 142
Eduvance 1:97ee52dedac3 143
Eduvance 1:97ee52dedac3 144 }
Eduvance 1:97ee52dedac3 145
Eduvance 1:97ee52dedac3 146 // main program routine
Eduvance 1:97ee52dedac3 147 int main() {
Eduvance 1:97ee52dedac3 148
Eduvance 1:97ee52dedac3 149 while (loop>0) {
Eduvance 1:97ee52dedac3 150 setvdd();
Eduvance 1:97ee52dedac3 151 keyscan(); // run keyscan routine
Eduvance 1:97ee52dedac3 152 wait(0.2);
Eduvance 1:97ee52dedac3 153
Eduvance 1:97ee52dedac3 154 }
Eduvance 1:97ee52dedac3 155 }