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 bjtUnd(PTB11,1); 00004 DigitalOut bjtDec(PTC11,1); 00005 DigitalOut led3(PTA2,0); 00006 00007 InterruptIn btnInc(PTE25); 00008 InterruptIn btnDcr(PTE24); 00009 00010 PortOut OutC(PortC, 0x000103A3); 00011 00012 EventQueue queue1(32 * EVENTS_EVENT_SIZE); 00013 EventQueue queue2(32 * EVENTS_EVENT_SIZE); 00014 00015 Thread thread1; 00016 Thread thread2; 00017 Thread thread3; 00018 00019 unsigned char unidades = 0, decenas = 0; 00020 00021 void Incrementar() 00022 { 00023 unidades ++; 00024 if (unidades == 10){ 00025 unidades = 0; 00026 decenas ++; 00027 if (decenas == 10){ 00028 decenas = 0; 00029 } 00030 } 00031 } 00032 void Decrementar() 00033 { 00034 unidades --; 00035 if (unidades == 0xFF){ 00036 unidades = 9; 00037 decenas --; 00038 if (decenas == 0xFF){ 00039 decenas = 9; 00040 } 00041 } 00042 } 00043 void ContadorAscendente(){ 00044 while(!btnInc){ 00045 Incrementar(); 00046 wait(0.25); 00047 } 00048 } 00049 void ContadorDescendente(){ 00050 while(!btnDcr){ 00051 Decrementar(); 00052 wait(0.25); 00053 } 00054 } 00055 void BinTo7Seg(unsigned char n){ 00056 switch (n){ 00057 case 0: OutC.write(0x80); 00058 break; 00059 case 1: OutC.write(0x0102A2); 00060 break; 00061 case 2: OutC.write(0x0120); 00062 break; 00063 case 3: OutC.write(0x010020); 00064 break; 00065 case 4: OutC.write(0x010202); 00066 break; 00067 case 5: OutC.write(0x010001); 00068 break; 00069 case 6: OutC.write(0x01); 00070 break; 00071 case 7: OutC.write(0x0100A2); 00072 break; 00073 case 8: OutC.write(0x00); 00074 break; 00075 case 9: OutC.write(0x010000); 00076 break; 00077 } 00078 } 00079 void DisplayMultiplexado() 00080 { 00081 while(1){ 00082 BinTo7Seg(unidades); 00083 bjtUnd = 0; 00084 bjtDec = 1; 00085 wait(0.01); 00086 BinTo7Seg(decenas); 00087 bjtUnd = 1; 00088 bjtDec = 0; 00089 wait(0.01); 00090 } 00091 } 00092 int main() 00093 { 00094 thread1.start(callback(&queue1, &EventQueue::dispatch_forever)); 00095 btnInc.fall(queue1.event(ContadorAscendente)); 00096 thread2.start(callback(&queue2, &EventQueue::dispatch_forever)); 00097 btnDcr.fall(queue2.event(ContadorDescendente)); 00098 00099 thread3.start(DisplayMultiplexado); 00100 00101 while(1) 00102 { 00103 led3 = !led3; 00104 wait(0.4); 00105 } 00106 }
Generated on Sat Jul 16 2022 02:44:28 by
1.7.2