Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 BusOut Disp1(p26,p25,p24,p23,p22,p21,p20); // ABCDEFGdp 00004 DigitalOut vdd(p19); 00005 DigitalOut vddn(p18); 00006 00007 00008 DigitalIn row1(p14); // row1 output 00009 DigitalIn row2(p15); // row2 output 00010 DigitalIn row3(p16); // row3 output 00011 DigitalIn row4(p17); 00012 00013 DigitalOut col1(p11); // col2 input with 6k8 pullup to 3.3v 00014 DigitalOut col2(p12); // col3 input with 6k8 pullup to 3.3v 00015 DigitalOut col3(p13); // col4 input with 6k8 pullup to 3.3v 00016 00017 00018 void setvdd() { 00019 vddn=1; 00020 vdd=0; 00021 } 00022 00023 int loop = 10; // non zero value for the while loop 00024 00025 void setcolhigh() { 00026 col1=1; // set row1 low 00027 col2=1; // set row2 low 00028 col3=1; 00029 // set row3 low 00030 } 00031 void setcol1() { 00032 col1=0; // set row1 low 00033 col2=1; // set row2 high 00034 col3=1; 00035 // set row3 high 00036 } 00037 void setcol2() { 00038 col1=1; // set row1 high 00039 col2=0; // set row2 low 00040 col3=1; 00041 // set row3 high 00042 } 00043 void setcol3() { 00044 col1=1; // set row1 high 00045 col2=1; // set row2 high 00046 col3=0; 00047 // set row3 low 00048 } 00049 00050 // set row3 low 00051 00052 00053 00054 void key_1() { 00055 Disp1 = 0xF9; 00056 00057 } 00058 void key_2() { 00059 Disp1 = 0xA4; 00060 } 00061 void key_3() { 00062 Disp1 = 0xB0; 00063 } 00064 void key_4() { 00065 Disp1 = 0x99; 00066 } 00067 void key_5() { 00068 Disp1 = 0x92; 00069 } 00070 void key_6() { 00071 Disp1 = 0x82; 00072 } 00073 void key_7() { 00074 Disp1 = 0xF8; 00075 } 00076 void key_8() { 00077 Disp1 = 0x80; 00078 } 00079 void key_9() { 00080 Disp1 = 0x90; 00081 } 00082 void key_0() { 00083 Disp1 = 0xC0; 00084 } 00085 void key_le() { 00086 // lcd.locate(7,1); 00087 // lcd.printf("*"); 00088 Disp1 = 0x88; 00089 } 00090 void key_r() { 00091 // lcd.locate(7,1); 00092 // lcd.printf("#"); 00093 Disp1 = 0xC6; 00094 } 00095 00096 void key_nope() { 00097 Disp1 = 0x3F; 00098 } 00099 00100 // keyscan function routine 00101 void keyscan() { 00102 setcolhigh(); 00103 wait(0.2); 00104 setcol1(); 00105 wait(0.2); 00106 if (row1 == 0) 00107 key_1(); 00108 if (row2 == 0) 00109 key_4(); 00110 if (row3 == 0) 00111 key_7(); 00112 if (row4 == 0) 00113 key_le(); 00114 wait(0.1); 00115 setcol2(); 00116 wait(0.2); 00117 if (row1 == 0) 00118 key_2(); 00119 if (row2 == 0) 00120 key_5(); 00121 if (row3 == 0) 00122 key_8(); 00123 if (row4 == 0) 00124 key_0(); 00125 00126 wait(0.1); 00127 setcol3(); 00128 wait(0.2); 00129 if (row1 == 0) 00130 key_3(); 00131 if (row2 == 0) 00132 key_6(); 00133 if (row3 == 0) 00134 key_9(); 00135 if (row4 == 0) 00136 key_r(); 00137 00138 00139 // wait(0.1) 00140 //else 00141 //key_nope(); 00142 00143 00144 } 00145 00146 // main program routine 00147 int main() { 00148 00149 while (loop>0) { 00150 setvdd(); 00151 keyscan(); // run keyscan routine 00152 wait(0.2); 00153 00154 } 00155 }
Generated on Sat Jul 16 2022 05:22:08 by
1.7.2