Eduvance vanmat
/
07Counter_WITH_Buttons
Counter
main.cpp
- Committer:
- Eduvance
- Date:
- 2014-05-27
- Revision:
- 1:97ee52dedac3
- Parent:
- 0:776a127ae50b
File content as of revision 1:97ee52dedac3:
#include "mbed.h" BusOut Disp1(p26,p25,p24,p23,p22,p21,p20); // ABCDEFGdp DigitalOut vdd(p19); DigitalOut vddn(p18); DigitalIn row1(p14); // row1 output DigitalIn row2(p15); // row2 output DigitalIn row3(p16); // row3 output DigitalIn row4(p17); DigitalOut col1(p11); // col2 input with 6k8 pullup to 3.3v DigitalOut col2(p12); // col3 input with 6k8 pullup to 3.3v DigitalOut col3(p13); // col4 input with 6k8 pullup to 3.3v void setvdd() { vddn=1; vdd=0; } int loop = 10; // non zero value for the while loop void setcolhigh() { col1=1; // set row1 low col2=1; // set row2 low col3=1; // set row3 low } void setcol1() { col1=0; // set row1 low col2=1; // set row2 high col3=1; // set row3 high } void setcol2() { col1=1; // set row1 high col2=0; // set row2 low col3=1; // set row3 high } void setcol3() { col1=1; // set row1 high col2=1; // set row2 high col3=0; // set row3 low } // set row3 low void key_1() { Disp1 = 0xF9; } void key_2() { Disp1 = 0xA4; } void key_3() { Disp1 = 0xB0; } void key_4() { Disp1 = 0x99; } void key_5() { Disp1 = 0x92; } void key_6() { Disp1 = 0x82; } void key_7() { Disp1 = 0xF8; } void key_8() { Disp1 = 0x80; } void key_9() { Disp1 = 0x90; } void key_0() { Disp1 = 0xC0; } void key_le() { // lcd.locate(7,1); // lcd.printf("*"); Disp1 = 0x88; } void key_r() { // lcd.locate(7,1); // lcd.printf("#"); Disp1 = 0xC6; } void key_nope() { Disp1 = 0x3F; } // keyscan function routine void keyscan() { setcolhigh(); wait(0.2); setcol1(); wait(0.2); if (row1 == 0) key_1(); if (row2 == 0) key_4(); if (row3 == 0) key_7(); if (row4 == 0) key_le(); wait(0.1); setcol2(); wait(0.2); if (row1 == 0) key_2(); if (row2 == 0) key_5(); if (row3 == 0) key_8(); if (row4 == 0) key_0(); wait(0.1); setcol3(); wait(0.2); if (row1 == 0) key_3(); if (row2 == 0) key_6(); if (row3 == 0) key_9(); if (row4 == 0) key_r(); // wait(0.1) //else //key_nope(); } // main program routine int main() { while (loop>0) { setvdd(); keyscan(); // run keyscan routine wait(0.2); } }