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 DigitalOut gpo(D0); 00004 DigitalOut led(LED_RED); 00005 */ 00006 //>< 00007 DigitalOut BjtUnd(PTA2,1); 00008 DigitalOut BjtDcn(PTA1,1); 00009 00010 InterruptIn BtnInc(PTE25); 00011 InterruptIn BtnDec(PTE24); 00012 00013 PortOut OutC(PortC,0x000000FF); 00014 PortOut OutD(PortD,0x000000FF); 00015 00016 unsigned char unidades, decenas; 00017 00018 void ISR_Incrementar(){ 00019 00020 unidades ++; 00021 if (unidades == 10){ 00022 unidades = 0; 00023 decenas ++; 00024 if (decenas == 10){ 00025 decenas = 0; 00026 } 00027 } 00028 wait_ms(30); 00029 } 00030 00031 void ISR_Decrementar(){ 00032 00033 unidades --; 00034 if (unidades == 0xFF){ 00035 unidades = 9; 00036 decenas --; 00037 if (decenas == 0xFF){ 00038 decenas = 9; 00039 } 00040 } 00041 wait_ms(30); 00042 } 00043 00044 void BinToDisplay(unsigned char num){ 00045 switch (num){ 00046 case 0: OutC.write(0); 00047 OutD.write(8); 00048 break; 00049 case 1: OutC.write(3); 00050 OutD.write(11); 00051 break; 00052 case 2: OutC.write(4); 00053 OutD.write(2); 00054 break; 00055 case 3: OutC.write(2); 00056 OutD.write(2); 00057 break; 00058 case 4: OutC.write(3); 00059 OutD.write(1); 00060 break; 00061 case 5: OutC.write(2); 00062 OutD.write(4); 00063 break; 00064 case 6: OutC.write(0); 00065 OutD.write(5); 00066 break; 00067 case 7: OutC.write(3); 00068 OutD.write(10); 00069 break; 00070 case 8: OutC.write(0); 00071 OutD.write(0); 00072 break; 00073 case 9: OutC.write(3); 00074 OutD.write(0); 00075 break; 00076 } 00077 } 00078 00079 int main() 00080 { 00081 BtnInc.mode(PullUp); 00082 BtnDec.mode(PullUp); 00083 00084 BtnInc.rise(&ISR_Incrementar); 00085 BtnDec.rise(&ISR_Decrementar); 00086 00087 unidades = 0; 00088 decenas = 0; 00089 00090 while (true) { 00091 00092 BinToDisplay(unidades); 00093 BjtUnd = 0; 00094 BjtDcn = 1; 00095 wait(0.02); 00096 BinToDisplay(decenas); 00097 BjtUnd = 1; 00098 BjtDcn = 0; 00099 wait(0.02); 00100 /* 00101 gpo = !gpo; // toggle pin 00102 led = !led; // toggle led 00103 wait(0.2f); 00104 */ 00105 } 00106 }
Generated on Thu Jul 14 2022 01:28:17 by
1.7.2