COntador UP/DOWN con display de 7 segmentos multiplexado haciendo uso de la EventQueueAPI

Committer:
Otakutronics
Date:
Wed Dec 26 03:55:26 2018 +0000
Revision:
6:fdf022429fda
Parent:
4:20d7dabbd3b5
Contador de 00-99 multiplexado con display de 7 segmentos UP/DOWN utilizando EventQueueAPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mab5449 0:aea2e03f5625 1 #include "mbed.h"
Otakutronics 6:fdf022429fda 2 //<\>
Otakutronics 6:fdf022429fda 3 DigitalOut bjtUnd(PTB11,1);
Otakutronics 6:fdf022429fda 4 DigitalOut bjtDec(PTC11,1);
Otakutronics 6:fdf022429fda 5 DigitalOut led3(PTA2,0);
Otakutronics 6:fdf022429fda 6
Otakutronics 6:fdf022429fda 7 InterruptIn btnInc(PTE25);
Otakutronics 6:fdf022429fda 8 InterruptIn btnDcr(PTE24);
mab5449 0:aea2e03f5625 9
Otakutronics 6:fdf022429fda 10 PortOut OutC(PortC, 0x000103A3);
Otakutronics 6:fdf022429fda 11
Otakutronics 6:fdf022429fda 12 EventQueue queue1(32 * EVENTS_EVENT_SIZE);
Otakutronics 6:fdf022429fda 13 EventQueue queue2(32 * EVENTS_EVENT_SIZE);
mab5449 0:aea2e03f5625 14
Otakutronics 6:fdf022429fda 15 Thread thread1;
Otakutronics 6:fdf022429fda 16 Thread thread2;
Otakutronics 6:fdf022429fda 17 Thread thread3;
Otakutronics 6:fdf022429fda 18
Otakutronics 6:fdf022429fda 19 unsigned char unidades = 0, decenas = 0;
mab5449 0:aea2e03f5625 20
Otakutronics 6:fdf022429fda 21 void Incrementar()
Otakutronics 6:fdf022429fda 22 {
Otakutronics 6:fdf022429fda 23 unidades ++;
Otakutronics 6:fdf022429fda 24 if (unidades == 10){
Otakutronics 6:fdf022429fda 25 unidades = 0;
Otakutronics 6:fdf022429fda 26 decenas ++;
Otakutronics 6:fdf022429fda 27 if (decenas == 10){
Otakutronics 6:fdf022429fda 28 decenas = 0;
Otakutronics 6:fdf022429fda 29 }
Otakutronics 6:fdf022429fda 30 }
Otakutronics 6:fdf022429fda 31 }
Otakutronics 6:fdf022429fda 32 void Decrementar()
Otakutronics 6:fdf022429fda 33 {
Otakutronics 6:fdf022429fda 34 unidades --;
Otakutronics 6:fdf022429fda 35 if (unidades == 0xFF){
Otakutronics 6:fdf022429fda 36 unidades = 9;
Otakutronics 6:fdf022429fda 37 decenas --;
Otakutronics 6:fdf022429fda 38 if (decenas == 0xFF){
Otakutronics 6:fdf022429fda 39 decenas = 9;
Otakutronics 6:fdf022429fda 40 }
Otakutronics 6:fdf022429fda 41 }
Otakutronics 6:fdf022429fda 42 }
Otakutronics 6:fdf022429fda 43 void ContadorAscendente(){
Otakutronics 6:fdf022429fda 44 while(!btnInc){
Otakutronics 6:fdf022429fda 45 Incrementar();
Otakutronics 6:fdf022429fda 46 wait(0.25);
Otakutronics 6:fdf022429fda 47 }
Otakutronics 6:fdf022429fda 48 }
Otakutronics 6:fdf022429fda 49 void ContadorDescendente(){
Otakutronics 6:fdf022429fda 50 while(!btnDcr){
Otakutronics 6:fdf022429fda 51 Decrementar();
Otakutronics 6:fdf022429fda 52 wait(0.25);
Otakutronics 6:fdf022429fda 53 }
mab5449 0:aea2e03f5625 54 }
Otakutronics 6:fdf022429fda 55 void BinTo7Seg(unsigned char n){
Otakutronics 6:fdf022429fda 56 switch (n){
Otakutronics 6:fdf022429fda 57 case 0: OutC.write(0x80);
Otakutronics 6:fdf022429fda 58 break;
Otakutronics 6:fdf022429fda 59 case 1: OutC.write(0x0102A2);
Otakutronics 6:fdf022429fda 60 break;
Otakutronics 6:fdf022429fda 61 case 2: OutC.write(0x0120);
Otakutronics 6:fdf022429fda 62 break;
Otakutronics 6:fdf022429fda 63 case 3: OutC.write(0x010020);
Otakutronics 6:fdf022429fda 64 break;
Otakutronics 6:fdf022429fda 65 case 4: OutC.write(0x010202);
Otakutronics 6:fdf022429fda 66 break;
Otakutronics 6:fdf022429fda 67 case 5: OutC.write(0x010001);
Otakutronics 6:fdf022429fda 68 break;
Otakutronics 6:fdf022429fda 69 case 6: OutC.write(0x01);
Otakutronics 6:fdf022429fda 70 break;
Otakutronics 6:fdf022429fda 71 case 7: OutC.write(0x0100A2);
Otakutronics 6:fdf022429fda 72 break;
Otakutronics 6:fdf022429fda 73 case 8: OutC.write(0x00);
Otakutronics 6:fdf022429fda 74 break;
Otakutronics 6:fdf022429fda 75 case 9: OutC.write(0x010000);
Otakutronics 6:fdf022429fda 76 break;
Otakutronics 6:fdf022429fda 77 }
mab5449 0:aea2e03f5625 78 }
Otakutronics 6:fdf022429fda 79 void DisplayMultiplexado()
Otakutronics 6:fdf022429fda 80 {
Otakutronics 6:fdf022429fda 81 while(1){
Otakutronics 6:fdf022429fda 82 BinTo7Seg(unidades);
Otakutronics 6:fdf022429fda 83 bjtUnd = 0;
Otakutronics 6:fdf022429fda 84 bjtDec = 1;
Otakutronics 6:fdf022429fda 85 wait(0.01);
Otakutronics 6:fdf022429fda 86 BinTo7Seg(decenas);
Otakutronics 6:fdf022429fda 87 bjtUnd = 1;
Otakutronics 6:fdf022429fda 88 bjtDec = 0;
Otakutronics 6:fdf022429fda 89 wait(0.01);
Otakutronics 6:fdf022429fda 90 }
Otakutronics 6:fdf022429fda 91 }
Otakutronics 6:fdf022429fda 92 int main()
Otakutronics 6:fdf022429fda 93 {
Otakutronics 6:fdf022429fda 94 thread1.start(callback(&queue1, &EventQueue::dispatch_forever));
Otakutronics 6:fdf022429fda 95 btnInc.fall(queue1.event(ContadorAscendente));
Otakutronics 6:fdf022429fda 96 thread2.start(callback(&queue2, &EventQueue::dispatch_forever));
Otakutronics 6:fdf022429fda 97 btnDcr.fall(queue2.event(ContadorDescendente));
Otakutronics 6:fdf022429fda 98
Otakutronics 6:fdf022429fda 99 thread3.start(DisplayMultiplexado);
Otakutronics 6:fdf022429fda 100
Otakutronics 6:fdf022429fda 101 while(1)
Otakutronics 6:fdf022429fda 102 {
Otakutronics 6:fdf022429fda 103 led3 = !led3;
Otakutronics 6:fdf022429fda 104 wait(0.4);
Otakutronics 6:fdf022429fda 105 }
Otakutronics 6:fdf022429fda 106 }