Marcos Velazquez / Mbed 2 deprecated 7segmentos_easy

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
marcosvh
Date:
Thu Oct 06 16:07:07 2022 +0000
Parent:
0:cee1c4dd8c94
Commit message:
contador de 7 segmentos para stm32, cuenta con incremento, decremento y seteo a cero

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Dec 18 01:21:25 2018 +0000
+++ b/main.cpp	Thu Oct 06 16:07:07 2022 +0000
@@ -1,106 +1,33 @@
 #include "mbed.h"
-/*
-DigitalOut gpo(D0);
-DigitalOut led(LED_RED);
-*/
-//><
-DigitalOut  BjtUnd(PTA2,1);
-DigitalOut  BjtDcn(PTA1,1);
-
-InterruptIn BtnInc(PTE25);
-InterruptIn BtnDec(PTE24);
+#include "stdio.h"
+//Declaracion de Puertos
+BusIn ent(PB_12,PB_13,PB_14);
+PortOut OutA(PortA,0x00FF);
+//Declaracion de Variables
+short display[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
+unsigned char cont=0;
 
-PortOut OutC(PortC,0x000000FF);
-PortOut OutD(PortD,0x000000FF);
-
-unsigned char unidades, decenas;
-
-void ISR_Incrementar(){
-    
-    unidades ++;
-    if (unidades == 10){
-        unidades = 0;
-        decenas ++;
-        if (decenas == 10){
-            decenas = 0;
+int main(){
+    while(1){
+    OutA=display[cont];
+    switch(ent){
+        case (0x1): //funcion incrementar
+            cont ++;
+            if (cont == 10)
+            cont = 0;
+            wait_ms(200);    
+            break;
+        case (0x2): //funcion decrementar
+            cont --;
+            if (cont == 0xff)
+            cont = 9;
+            wait_ms(200); 
+            break;
+        case (0x4): //funcion setear
+            cont = 0;
+            break;
+        default: OutA=display[cont];
+            break;
         }
     }
-    wait_ms(30);    
 }
-
-void ISR_Decrementar(){
-
-    unidades --;
-    if (unidades == 0xFF){
-        unidades = 9;
-        decenas --;
-        if (decenas == 0xFF){
-            decenas = 9;    
-        }   
-    } 
-    wait_ms(30);  
-}
-
-void BinToDisplay(unsigned char num){
-    switch (num){
-        case 0: OutC.write(0);
-                OutD.write(8);
-                break;
-        case 1: OutC.write(3);
-                OutD.write(11);
-                break;    
-        case 2: OutC.write(4);
-                OutD.write(2);
-                break; 
-        case 3: OutC.write(2);
-                OutD.write(2);
-                break; 
-        case 4: OutC.write(3);
-                OutD.write(1);
-                break; 
-        case 5: OutC.write(2);
-                OutD.write(4);
-                break; 
-        case 6: OutC.write(0);
-                OutD.write(5);
-                break; 
-        case 7: OutC.write(3);
-                OutD.write(10);
-                break; 
-        case 8: OutC.write(0);
-                OutD.write(0);
-                break;
-        case 9: OutC.write(3);
-                OutD.write(0);
-                break;  
-    }   
-}
-
-int main()
-{
-    BtnInc.mode(PullUp);
-    BtnDec.mode(PullUp);
-    
-    BtnInc.rise(&ISR_Incrementar);
-    BtnDec.rise(&ISR_Decrementar);
-    
-    unidades = 0;
-    decenas = 0;
-    
-    while (true) {
-        
-        BinToDisplay(unidades);
-        BjtUnd = 0;
-        BjtDcn = 1;
-        wait(0.02);
-        BinToDisplay(decenas);
-        BjtUnd = 1;
-        BjtDcn = 0;
-        wait(0.02);
-/*
-        gpo = !gpo; // toggle pin
-        led = !led; // toggle led
-        wait(0.2f);
-*/
-    }
-}
\ No newline at end of file