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.
Dependencies: mbed
main.cpp
00001 /* ########################################################################### 00002 ** Archivo : main.c 00003 ** Proyecto : STM32-103C8_AdivinaV2 00004 ** Procesador : STM32F103C8 00005 ** Herramienta : Mbed 00006 ** Version : Driver 01.01 00007 ** Compilador : GNU C Compiler 00008 ** Fecha/Hora : 13-09-2019 01:30, # CodeGen: 0 00009 ** Descripción : 00010 ** Este proyecto recibe un numero predefinido por el administrador para 00011 ** que despues un usuario intente adivinarlo con un limite de intetos 00012 ** los cuales ya estas preestablecidos por el administrador. 00013 ** Componentes : Timer, etc . 00014 ** Configuraciones : Se puede seleccionar entre diferentes velocodades de 00015 ** transmisión 00016 ** Autores : 00017 ** ATEAM Development Group: 00018 ** - Antulio Morgado Valle. 00019 ** - Marcelo Padron Javier 4CV2. 00020 ** 00021 ** Versión : Beta 00022 ** Revisión : B 00023 ** Release : 0 00024 ** Bugs & Fixes : 00025 ** Date : 13/09/2019 00026 ** 00027 ** 00028 ** 00029 ** ###########################################################################*/ 00030 /* 00031 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 00032 : Includes 00033 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 00034 */ 00035 00036 #include "stm32f103c8t6.h" 00037 #include "mbed.h" 00038 #include "Serial.h" 00039 #include "stdio.h" 00040 /* 00041 :............................................................................... 00042 : Definiciones 00043 :............................................................................... 00044 */ 00045 #define on 0 // Estado para boton presionado 00046 #define off 1 // Estado para boton sin presionar 00047 #define hold 2 // Estado para boton mantenido 00048 #define release 3 // Estado para boton liberado 00049 #define FALSE 0 // Estado FALSO 00050 #define TRUE 1 // Estado VERDADERO 00051 /* 00052 +------------------------------------------------------------------------------- 00053 | Configuración de Puertos 00054 +------------------------------------------------------------------------------- 00055 */ 00056 DigitalOut verde (LED1); // PC_13 (Green_Led) 00057 DigitalOut rojo (PB_1); // NC (Red_Led) 00058 00059 // ***** Host PC Terminal Communication channels 00060 Serial terminal (PA_2, PA_3); // Inicializa la comunicación serial a la PC (Tx,Rx) 00061 //Serial terminal(USBTX, USBRX,115200);// Tx, Rx Baud Rate - Terminal Serial por USB @ 115,200 Bauds 00062 00063 /* 00064 +------------------------------------------------------------------------------- 00065 | Variables Globales de Usuario 00066 +------------------------------------------------------------------------------- 00067 */ 00068 //uint32_t Baud_Rate = 9600; // Velocidad de Transmisión (Bauds) 00069 /* 00070 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00071 | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción 00072 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00073 */ 00074 void Setup(void); 00075 /* END definitions */ 00076 00077 /* 00078 #=============================================================================== 00079 | 00080 | P R O G R A M A P R I N C I P A L 00081 | 00082 #=============================================================================== 00083 */ 00084 int main() 00085 { // Inicialización de variables, puertos e interrupciones 00086 confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock) 00087 Setup(); // Inicialización del sistema 00088 while(TRUE) 00089 { 00090 Primero: int numero = 5; //Primero vamos a limitar el numero de intentos 00091 if( numero > 0) //Colocaremos un condicional al inicio de nuestro programa para que estemos regresando a este punto. 00092 { 00093 terminal.printf("\n DIGITE UN NUMERO SECRETO DE 0 A 9 \r\n"); 00094 int secreto = terminal.getc(); 00095 rojo = on; 00096 verde = on; 00097 Intenta: terminal.printf("\n Solo tienes %i intentos para adividnar!\r\n", numero); 00098 terminal.printf("\nADIVINA EL NUMERO: \r\n"); 00099 int respuesta = terminal.getc(); 00100 terminal.printf("\nEL NUMERO QUE INGRESASTE FUE \r\n"); //Imprimimos la respuesta como parte de las condiciones que nos pide el profesor. 00101 terminal.putc ( respuesta ); 00102 if( secreto < respuesta ) 00103 { 00104 terminal.printf(" \n\nEl numero que ingresaste es mas alto! \r\n"); 00105 rojo = on; 00106 verde = off; 00107 numero = numero - 1; 00108 goto Intenta; 00109 } 00110 if( secreto > respuesta ) 00111 { 00112 terminal.printf(" \n\nEl numero que ingresaste es mas bajo! \r\n"); 00113 rojo = off; 00114 verde = on; 00115 numero = numero - 1 ; 00116 goto Intenta; 00117 } 00118 if( secreto == respuesta ) 00119 { 00120 terminal.printf(" \n\nFelicidades!, La respuesta es: %i \r\n",secreto); 00121 rojo = off; 00122 verde = on; 00123 wait(1.0); 00124 rojo = off; 00125 verde = off; 00126 wait(1.0); 00127 rojo = off; 00128 verde = on; 00129 wait(1.0); 00130 terminal.printf("Felicidades, realmente eres un genio! \r\n"); 00131 wait(1.0); 00132 rojo = on; 00133 verde = off; 00134 wait(1.0); 00135 rojo = off; 00136 verde = on; 00137 } 00138 00139 terminal.printf(" Quieres intentarlo de nuevo? \r\n"); 00140 terminal.printf(" 0 = No \r\n 1 = Si \r\n"); 00141 char opcion = terminal.getc(); 00142 if( opcion == '1' ) 00143 { 00144 numero = numero - 1; 00145 goto Primero; 00146 } 00147 else if( opcion == '0' ) 00148 { 00149 terminal.printf("El numero de intentos realizados fueron %i!\r\n", numero); 00150 break; 00151 } 00152 } 00153 else if ( numero == 0) 00154 { 00155 terminal.printf(" Lo lamento, excediste el numero de intentos!\r\n"); 00156 } 00157 } 00158 } 00159 00160 /* END main */ 00161 00162 /* 00163 ................................................................................ 00164 : Rutinas de los Vectores de Interrupción 00165 ................................................................................ 00166 */ 00167 00168 /* END Events */ 00169 /* 00170 ________________________________________________________________________________ 00171 | 00172 | Funciones Prototipo 00173 |_______________________________________________________________________________ 00174 */ 00175 // Las Funciones Prototipo van aquí ! 00176 void Setup() 00177 { 00178 // terminal.baud(Baud_Rate); // Se configura la velocidad de transmisión e inicia la comunicación serial. 00179 terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial. 00180 terminal.printf(" Bienvenido Amo!\n\r"); 00181 } 00182 00183 /* END routines */ 00184 00185 /* END program */ 00186 00187 /* END documentation */ 00188 /* 00189 +-------------------------------------------------------------------------------- 00190 | 00191 | EXAMEN 00192 | 00193 | 1.- Modificar el programa para que despliegue el número de intentos para 00194 | adivinar el número secreto. 00195 | 2.- Modificar el programa para haga eco con la respuesta que le introducimos. 00196 | 00197 | 3.- Modificar el programa para que te limite el numero de intentos. 00198 | Suerte! 00199 +-------------------------------------------------------------------------------- 00200 | 00201 | T H E A N T U L I U S T E A M 00202 | Research, Development, Systems Equipment, Support & Spare Parts I n c. 00203 | (C) Copyright 1989-2014, All rigths Reserved 00204 | 00205 | This program is licensed under rules of 00206 | THE BEANERS TECHNOLOGIES PROYECT 00207 +------------------------------------------------------------------------------- 00208 */ 00209 /* END Mbed */
Generated on Thu Jul 14 2022 15:22:52 by
1.7.2