Hector Rodriguez / Mbed 2 deprecated STM32F103C8_Adivina_Examen

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* ###########################################################################
00002 **    Archivo        : main.c
00003 **    Proyecto       : STM32-103C8_Adivina_Examen
00004 **    Procesador     : STM32F103C8
00005 **    Herramienta    : Mbed
00006 **    Version        : Driver 01.01
00007 **    Compilador     : GNU C Compiler
00008 **    Fecha/Hora     : 14-07-2015, 11:48, # CodeGen: 0
00009 **    Descripción    :
00010 **         Este proyecto muestra la configuración y uso de la Terminal Serial
00011 **         This module contains user's application code.
00012 **   Componentes     : Timer, etc .
00013 **   Configuraciones : Se puede seleccionar entre diferentes velocodades de 
00014 **                     transmisión
00015 **   Autores         :
00016 **         ATEAM Development Group:
00017 **          - Antulio Morgado Valle
00018 **          - Héctor Rodríguez Altamirano
00019 **
00020 **   Versión        : Beta
00021 **   Revisión       : A
00022 **   Release        : 0
00023 **   Bugs & Fixes   :
00024 **   Date           : 20/10/2019
00025 **                    Programa adivina Modificado para examen
00026 **                    27/09/2010 
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 #include "iostream" //Para usar cout
00041 //#include "stdlib.h"
00042 /*
00043 :...............................................................................
00044 :  Definiciones
00045 :...............................................................................
00046 */
00047 #define on              0               // Estado para boton presionado
00048 #define off             1               // Estado para boton sin presionar
00049 #define hold            2               // Estado para boton mantenido
00050 #define release         3               // Estado para boton liberado
00051 #define FALSE           0               // Estado FALSO
00052 #define TRUE            1               // Estado VERDADERO
00053 /*
00054 +-------------------------------------------------------------------------------
00055 |  Configuración de Puertos 
00056 +-------------------------------------------------------------------------------
00057 */
00058 DigitalOut verde (LED1);    // PC_13    (Green_Led)
00059 DigitalOut rojo  (PB_1);    // NC       (Red_Led)
00060 
00061 // *****    Host PC Terminal Communication channels
00062 Serial      terminal (PA_2, PA_3);          // Inicializa la comunicación serial a la PC (Tx,Rx)
00063 //Serial      terminal(USBTX, USBRX,115200);// Tx, Rx  Baud Rate - Terminal Serial por USB @ 115,200 Bauds
00064 
00065 /*
00066 +-------------------------------------------------------------------------------
00067 |  Variables Globales de Usuario 
00068 +-------------------------------------------------------------------------------
00069 */
00070 //uint32_t Baud_Rate = 9600;                // Velocidad de Transmisión (Bauds)
00071 /*
00072 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00073 |  Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
00074 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00075 */
00076 void Setup(void);  
00077 void portada(void);
00078 /* END definitions */ 
00079 
00080 /*
00081 #===============================================================================
00082 |
00083 |               P R O G R A M A     P R I N C I P A L
00084 |
00085 #=============================================================================== 
00086 */
00087 int main()          
00088 {                   // Inicialización de variables, puertos e interrupciones
00089 confSysClock();     // Configure system clock (72MHz HSE clock, 48MHz USB clock)
00090 Setup();            // Inicialización del sistema
00091     portada();
00092     terminal.printf ("ADIVINA\n\r");
00093     rojo  = off;
00094     verde = off;
00095     int intentos=0;
00096     char secreto;
00097     while(TRUE) 
00098     {
00099 Inicio:     /*******************************************************************
00100                do{
00101                terminal.printf(" DIGITE UN NUMERO SECRETO DE 0 A 9 \r\n");
00102                secreto = terminal.getc();
00103                rojo = on;
00104                verde = on;          
00105                }while(secreto < '0' || secreto > '9');
00106                Codigo de la version anterioe en la cual el numero secreto era
00107                introducido por el usuario
00108                ****************************************************************/
00109             secreto=rand()%10+48; //Genera un numero aleatorio
00110             terminal.printf("SE GENERO UN NUMERO SECRETO ALEATORIO \r\n");
00111  Intenta:   intentos++;
00112             terminal.printf(" INTENTO NUMERO %d \r\n",intentos);
00113             terminal.printf(" ADIVINA EL NUMERO: \r\n");
00114             char respuesta = terminal.getc();
00115             terminal.printf(" Tu respuesta es: %c \r\n",respuesta);
00116             if( secreto < respuesta  ) 
00117             {
00118                 terminal.printf(" Es mas Bajo  \r\n");
00119                 rojo = on;
00120                 verde = off;               
00121                 goto Intenta;
00122             }
00123             if( secreto > respuesta  ) 
00124             {
00125                 terminal.printf(" Es mas Alto  \r\n");
00126                 rojo  = off;
00127                 verde = on;
00128                 goto Intenta;
00129             }
00130             if( secreto == respuesta ) 
00131             {
00132                 intentos=0;
00133                 terminal.printf(" CORRECTO!, Es igual a: %c \r\n",secreto);
00134                 rojo  = off;
00135                 verde = on;
00136                 wait(1.0);
00137                 rojo  = off;
00138                 verde = off;
00139                 wait(1.0);
00140                 rojo  = off;
00141                 verde = on;
00142                 wait(1.0);
00143                 terminal.printf(" Eres un Genio !!!  \r\n");
00144                 wait(1.0);
00145                 rojo  = on;
00146                 verde = off;
00147                 wait(1.0);
00148                 rojo  = off;
00149                 verde = on;
00150             }
00151         terminal.printf(" Quieres intentarlo de nuevo?  \r\n");
00152         terminal.printf(" 0 = No \r\n 1 = Si  \r\n");
00153             char opcion = terminal.getc();
00154             if( opcion == '1' ) goto Inicio;
00155             else if( opcion == '0' )
00156             {
00157                 terminal.printf(" Eso es todo Amigos!  \r\n");
00158                 break;
00159             }
00160         }
00161 }
00162 
00163 /* END main */
00164 
00165 /*
00166 ................................................................................
00167 :  Rutinas de los Vectores de Interrupción
00168 ................................................................................
00169 */
00170  
00171 /* END Events */ 
00172 /*
00173 ________________________________________________________________________________
00174 |
00175 |  Funciones Prototipo
00176 |_______________________________________________________________________________
00177 */
00178                 // Las Funciones Prototipo van aquí !
00179 void Setup()
00180 {
00181 //  terminal.baud(Baud_Rate);         // Se configura la velocidad de transmisión e inicia la comunicación serial.    
00182   terminal.baud(115200);         // Se configura la velocidad de transmisión e inicia la comunicación serial.  
00183   terminal.printf(" System is Wake Up!.\n\r");
00184 }              
00185 
00186 void portada(void) // Implementacion de la portada
00187 {
00188     //cout necesita la biblioteca "iostream"
00189     cout << "\t\t\t\t\t\tISTITUTO POLITECNICO NACIONAL\n\n\n";
00190     cout << "\t\t\t\t ESCUELA SUPERIOR DE INGENIERIA MECNICA Y "
00191          << "ELECTRICA\n\n\n";
00192     cout << "\t\t\t\t\tEXAMEN DE ANALISIS NUMERICO\n\n\n";
00193     cout << "\t\t\t\t\tPROFESOR: MORGADO VALLE ANTULIO\n\n\n";
00194     cout << "\t\t\t\t\tALUMNO: RODRIGUEZ ALTAMIRANO HECTOR"
00195          << "\n\n\n\n\n" << endl;
00196 }
00197 /* END routines */   
00198  
00199 /* END program */                
00200 
00201 /* END documentation */ 
00202 /*
00203 +--------------------------------------------------------------------------------
00204 |                               EJERCICIO
00205 |
00206 | 1.-   Este programa tambien acepta letras o caracteres?
00207 | 2.-   Modificar este programa para: 
00208 |       a) Que solo acepte números
00209 |       b) Agregar un contador de Número de Intentos 
00210 |       
00211 +--------------------------------------------------------------------------------
00212 |
00213 |                               EXAMEN
00214 |
00215 | 1.-   Modificar el programa para que despliegue el número de intentos para 
00216 |       adivinar el número secreto.
00217 | 2.-   Modificar el programa para haga eco con la respuesta que le introducimos.
00218 |
00219 | 3.-   Modificar el programa para que el número secreto sea generado aleatoriamente.
00220 |       a) Generar un Número Pseudo Aleatorio Mediante el Ticker
00221 |       b) Utilizando la función RANDOMIZE
00222 | Suerte!
00223 +--------------------------------------------------------------------------------
00224 |
00225 |                     T H E     A N T U L I U S   T E A M
00226 |  Research, Development, Systems Equipment, Support & Spare Parts    I n c.
00227 |                (C) Copyright 1989-2014, All rigths Reserved
00228 |
00229 | This program is licensed under rules of
00230 | THE BEANERS TECHNOLOGIES PROYECT
00231 +-------------------------------------------------------------------------------
00232 */
00233 /* END Mbed */