Programa en el que se envia por el puerto serial el valor del 1 al 256 correspondiente

Dependencies:   mbed

Committer:
mvillamar
Date:
Sat Feb 01 17:49:02 2020 +0000
Revision:
0:045fa418afc7
UPS; Contador del 1 al 256 el cual muestra el valor decimal, hexadecimal y ascii por el puerto serie

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mvillamar 0:045fa418afc7 1 //ENVIA UNCONTADOR DEL 1 AL 256 Y LO MUESTRA POR EL PUERTO SRIAL EN FORMATO DIGITAL ASCII Y HEXADECIMAL.
mvillamar 0:045fa418afc7 2
mvillamar 0:045fa418afc7 3
mvillamar 0:045fa418afc7 4 #include "mbed.h"
mvillamar 0:045fa418afc7 5
mvillamar 0:045fa418afc7 6 int i = 0; //Inicializa la variable i con el valor de 1
mvillamar 0:045fa418afc7 7 bool a; //Crea la variable a como booleana
mvillamar 0:045fa418afc7 8 //short b=10; //2^8
mvillamar 0:045fa418afc7 9 //int c,d,f,t,u; //2^32
mvillamar 0:045fa418afc7 10 DigitalOut Bled(PD_15); //LED AZUL
mvillamar 0:045fa418afc7 11 DigitalOut Vled(PD_12); //LED VERDE
mvillamar 0:045fa418afc7 12 DigitalOut Nled(PD_13); //LED NARANJA
mvillamar 0:045fa418afc7 13 DigitalOut Rled(PD_14); //LED ROJO
mvillamar 0:045fa418afc7 14
mvillamar 0:045fa418afc7 15 Serial device (PA_2,PA_3);
mvillamar 0:045fa418afc7 16
mvillamar 0:045fa418afc7 17 int avance();
mvillamar 0:045fa418afc7 18 int retroceso();
mvillamar 0:045fa418afc7 19
mvillamar 0:045fa418afc7 20 int main() //Inicializa programa principal
mvillamar 0:045fa418afc7 21 {
mvillamar 0:045fa418afc7 22
mvillamar 0:045fa418afc7 23 while(i<=256) {
mvillamar 0:045fa418afc7 24 //device.printf("Hola \n"); // \n es un enter
mvillamar 0:045fa418afc7 25 //device.printf("e"); //el envio es en ASCII
mvillamar 0:045fa418afc7 26 device.baud(115200);
mvillamar 0:045fa418afc7 27 device.printf("%d",i);
mvillamar 0:045fa418afc7 28 device.printf(" ");
mvillamar 0:045fa418afc7 29 wait(0.03);
mvillamar 0:045fa418afc7 30 //avance();
mvillamar 0:045fa418afc7 31 //retroceso();
mvillamar 0:045fa418afc7 32 i++;
mvillamar 0:045fa418afc7 33 }
mvillamar 0:045fa418afc7 34 device.printf("\n");
mvillamar 0:045fa418afc7 35 i=0;
mvillamar 0:045fa418afc7 36
mvillamar 0:045fa418afc7 37 while(i<=256) {
mvillamar 0:045fa418afc7 38 device.baud(115200);
mvillamar 0:045fa418afc7 39 device.printf("%c",i);
mvillamar 0:045fa418afc7 40 device.printf(" ");
mvillamar 0:045fa418afc7 41 wait(0.03);
mvillamar 0:045fa418afc7 42 i++;
mvillamar 0:045fa418afc7 43 }
mvillamar 0:045fa418afc7 44 device.printf("\r\n");
mvillamar 0:045fa418afc7 45 i=0;
mvillamar 0:045fa418afc7 46
mvillamar 0:045fa418afc7 47 while(i<=256) {
mvillamar 0:045fa418afc7 48 device.baud(115200);
mvillamar 0:045fa418afc7 49 device.printf("%x",i);
mvillamar 0:045fa418afc7 50 device.printf(" ");
mvillamar 0:045fa418afc7 51 wait(0.03);
mvillamar 0:045fa418afc7 52 i++;
mvillamar 0:045fa418afc7 53 }
mvillamar 0:045fa418afc7 54
mvillamar 0:045fa418afc7 55 }
mvillamar 0:045fa418afc7 56
mvillamar 0:045fa418afc7 57 int avance()
mvillamar 0:045fa418afc7 58 {
mvillamar 0:045fa418afc7 59 Bled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 60 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 61 Bled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 62 Vled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 63 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 64 Vled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 65 Nled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 66 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 67 Nled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 68 Rled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 69 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 70 Rled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 71 Bled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 72 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 73 Bled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 74 }
mvillamar 0:045fa418afc7 75
mvillamar 0:045fa418afc7 76 int retroceso()
mvillamar 0:045fa418afc7 77 {
mvillamar 0:045fa418afc7 78 Rled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 79 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 80 Rled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 81 Nled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 82 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 83 Nled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 84 Vled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 85 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 86 Vled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 87 Bled = 1; // NIVEL HIGH
mvillamar 0:045fa418afc7 88 wait(0.1); // ESPERA 1 SEGUNDO
mvillamar 0:045fa418afc7 89 Bled = 0; // NIVEL LOW
mvillamar 0:045fa418afc7 90
mvillamar 0:045fa418afc7 91 }