voltimetro LCD, 7seg_4digitos

Dependencies:   mbed TextLCD

Committer:
birda
Date:
Fri Jun 12 23:54:02 2020 +0000
Revision:
0:288eb4592f41
Child:
1:aedb77569443
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
birda 0:288eb4592f41 1 #include "mbed.h"
birda 0:288eb4592f41 2 #include "TextLCD.h"
birda 0:288eb4592f41 3
birda 0:288eb4592f41 4 TextLCD lcd(A0,A1,A2,A3,A4,A5,TextLCD::LCD16x2);
birda 0:288eb4592f41 5 AnalogIn entrada(PC_3);//pin entrada analogica
birda 0:288eb4592f41 6 DigitalOut led (LED1);
birda 0:288eb4592f41 7 int voltaje;
birda 0:288eb4592f41 8 int entero, decimal;
birda 0:288eb4592f41 9 double volt_in;
birda 0:288eb4592f41 10
birda 0:288eb4592f41 11 BusOut display(PA_15,PB_7,PC_13,PC_14,PC_15,PH_0,PH_1);//pines en la placa
birda 0:288eb4592f41 12 BusOut Trans(PA_13,PA_14); //pin para los transistores
birda 0:288eb4592f41 13 void ver();
birda 0:288eb4592f41 14 void incre();
birda 0:288eb4592f41 15 int unidad;
birda 0:288eb4592f41 16 int decena;
birda 0:288eb4592f41 17 int conteo;
birda 0:288eb4592f41 18 const char seg[10]= {0x40,0x79,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
birda 0:288eb4592f41 19 Ticker visualizar;
birda 0:288eb4592f41 20 Ticker incrementar;
birda 0:288eb4592f41 21
birda 0:288eb4592f41 22
birda 0:288eb4592f41 23 void ver()
birda 0:288eb4592f41 24 {
birda 0:288eb4592f41 25 switch(conteo) {
birda 0:288eb4592f41 26 case 0:
birda 0:288eb4592f41 27 display =0x00;
birda 0:288eb4592f41 28 Trans =0;
birda 0:288eb4592f41 29 break;
birda 0:288eb4592f41 30 case 1:
birda 0:288eb4592f41 31 display = seg[unidad];
birda 0:288eb4592f41 32 Trans=1;
birda 0:288eb4592f41 33 break;
birda 0:288eb4592f41 34 case 2:
birda 0:288eb4592f41 35 display =0x00;
birda 0:288eb4592f41 36 Trans =0;
birda 0:288eb4592f41 37 break;
birda 0:288eb4592f41 38 case 3:
birda 0:288eb4592f41 39 display = seg[decena];
birda 0:288eb4592f41 40 Trans=2;
birda 0:288eb4592f41 41 break;
birda 0:288eb4592f41 42 }
birda 0:288eb4592f41 43 conteo++;
birda 0:288eb4592f41 44 if(conteo==4) {
birda 0:288eb4592f41 45 conteo=0;
birda 0:288eb4592f41 46 }
birda 0:288eb4592f41 47 }
birda 0:288eb4592f41 48 void incre()
birda 0:288eb4592f41 49 {
birda 0:288eb4592f41 50 if (unidad<9) {
birda 0:288eb4592f41 51 unidad++;
birda 0:288eb4592f41 52 } else {
birda 0:288eb4592f41 53 decena++;
birda 0:288eb4592f41 54 unidad=0;
birda 0:288eb4592f41 55 if(decena==10)decena=0;
birda 0:288eb4592f41 56 }
birda 0:288eb4592f41 57 }
birda 0:288eb4592f41 58
birda 0:288eb4592f41 59
birda 0:288eb4592f41 60
birda 0:288eb4592f41 61 int main()
birda 0:288eb4592f41 62 {
birda 0:288eb4592f41 63 //lcd.cls();
birda 0:288eb4592f41 64 //lcd.printf("Su Voltaje es:");
birda 0:288eb4592f41 65 visualizar.attach(&ver,5.5e-3);
birda 0:288eb4592f41 66 incrementar.attach(&incre,1);
birda 0:288eb4592f41 67
birda 0:288eb4592f41 68
birda 0:288eb4592f41 69
birda 0:288eb4592f41 70 while(1) {
birda 0:288eb4592f41 71 volt_in= entrada.read();
birda 0:288eb4592f41 72 volt_in = volt_in*3300;
birda 0:288eb4592f41 73 voltaje = int(volt_in);
birda 0:288eb4592f41 74 entero = voltaje/1000;
birda 0:288eb4592f41 75 decimal = voltaje%1000;
birda 0:288eb4592f41 76 led=1;
birda 0:288eb4592f41 77 lcd.cls();
birda 0:288eb4592f41 78 lcd.printf("El Voltaje es:");
birda 0:288eb4592f41 79 lcd.locate(1,5);
birda 0:288eb4592f41 80 lcd.printf("%01d,%03d volts", entero,decimal);//de la parte enteraimprime 1 digito y decima imprime 3
birda 0:288eb4592f41 81 wait_us(1e6);
birda 0:288eb4592f41 82 led=1;
birda 0:288eb4592f41 83
birda 0:288eb4592f41 84 }
birda 0:288eb4592f41 85 }