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 #include "TextLCD.h" 00003 00004 00005 Serial device(PTE0, PTE1); // tx, rx 00006 Serial pc(USBTX,USBRX); // pc 00007 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00008 00009 char buffer[10]; // TAMAÑO DEL BUFER 00010 Timer t; //VALOR DEL TIEMPO 00011 int c=0,d; 00012 00013 DigitalOut ledrojo(LED1); //rojo 00014 DigitalOut ledverde(LED2); //verde 00015 DigitalOut ledazul(LED3); //azul 00016 00017 00018 00019 int readBuffer(char *buffer,int count) //esta funcion lee un bufer de datos 00020 { 00021 int i=0; 00022 t.start(); //CUENTA EL TIEMPO DE CONEXION E INICIA 00023 while(1) { 00024 while (device.readable()) { 00025 char c = device.getc(); 00026 if (c == '\r' || c == '\n') c = '$';//si se envia fin de linea o de caracter inserta $ 00027 buffer[i++] = c;//mete al bufer el caracter leido 00028 if(i > count)break;//sale del loop si ya detecto terminacion 00029 } 00030 if(i > count)break; 00031 if(t.read() > 1) { //MAS DE UN SEGUNDO DE ESPERA SE SALE Y REINICA EL RELOJ Y SE SALE 00032 t.stop(); 00033 t.reset(); 00034 break; 00035 } 00036 } 00037 return 0; 00038 } 00039 00040 void cleanBuffer(char *buffer, int count) //esta funcion limpia el bufer 00041 { 00042 for(int i=0; i < count; i++) { 00043 buffer[i] = '\0'; 00044 } 00045 } 00046 00047 int main() 00048 { 00049 pc.baud(9600); // asigno baudios y configuro puerto serie de la PC 00050 pc.format(8,Serial::None,1); 00051 00052 device.baud(9600); // asigno baudios y configuro device 00053 device.format(8,Serial::None,1); 00054 00055 lcd.printf("ok"); // indica lcd funciona 00056 ledverde=0; 00057 ledrojo=1; 00058 ledazul=1; 00059 wait(1.5); 00060 lcd.cls(); //limpiar lcd 00061 ledverde=1; 00062 00063 while(1) { 00064 if (device.readable()) { 00065 readBuffer(buffer,10); 00066 lcd.cls(); 00067 lcd.printf("%s", buffer); 00068 ledazul=0; 00069 cleanBuffer(buffer, 10); 00070 } 00071 } 00072 }
Generated on Thu Aug 18 2022 08:34:30 by
1.7.2