Arturo Rios Ramos
/
STM32F103C8_Adivina
El programa cuenta los intentos ingresados por el usuario para adivinar el numero
main.cpp@0:f680c41c1640, 2019-09-05 (annotated)
- Committer:
- Antulius
- Date:
- Thu Sep 05 23:29:04 2019 +0000
- Revision:
- 0:f680c41c1640
- Child:
- 1:b5216422f915
- Child:
- 2:f7a3163071b1
Adivina
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Antulius | 0:f680c41c1640 | 1 | /* ########################################################################### |
Antulius | 0:f680c41c1640 | 2 | ** Archivo : main.c |
Antulius | 0:f680c41c1640 | 3 | ** Proyecto : STM32-103C8_Adivina |
Antulius | 0:f680c41c1640 | 4 | ** Procesador : STM32F103C8 |
Antulius | 0:f680c41c1640 | 5 | ** Herramienta : Mbed |
Antulius | 0:f680c41c1640 | 6 | ** Version : Driver 01.01 |
Antulius | 0:f680c41c1640 | 7 | ** Compilador : GNU C Compiler |
Antulius | 0:f680c41c1640 | 8 | ** Fecha/Hora : 14-07-2015, 11:48, # CodeGen: 0 |
Antulius | 0:f680c41c1640 | 9 | ** Descripción : |
Antulius | 0:f680c41c1640 | 10 | ** Este proyecto muestra la configuración y uso de la Terminal Serial |
Antulius | 0:f680c41c1640 | 11 | ** This module contains user's application code. |
Antulius | 0:f680c41c1640 | 12 | ** Componentes : Timer, etc . |
Antulius | 0:f680c41c1640 | 13 | ** Configuraciones : Se puede seleccionar entre diferentes velocodades de |
Antulius | 0:f680c41c1640 | 14 | ** transmisión |
Antulius | 0:f680c41c1640 | 15 | ** Autores : |
Antulius | 0:f680c41c1640 | 16 | ** ATEAM Development Group: |
Antulius | 0:f680c41c1640 | 17 | ** - Antulio Morgado Valle |
Antulius | 0:f680c41c1640 | 18 | ** |
Antulius | 0:f680c41c1640 | 19 | ** Versión : Beta |
Antulius | 0:f680c41c1640 | 20 | ** Revisión : A |
Antulius | 0:f680c41c1640 | 21 | ** Release : 0 |
Antulius | 0:f680c41c1640 | 22 | ** Bugs & Fixes : |
Antulius | 0:f680c41c1640 | 23 | ** Date : 20/10/2019 |
Antulius | 0:f680c41c1640 | 24 | ** Ejemplpo del Hola Mundo |
Antulius | 0:f680c41c1640 | 25 | ** 27/09/2010 |
Antulius | 0:f680c41c1640 | 26 | ** |
Antulius | 0:f680c41c1640 | 27 | ** |
Antulius | 0:f680c41c1640 | 28 | ** ###########################################################################*/ |
Antulius | 0:f680c41c1640 | 29 | /* |
Antulius | 0:f680c41c1640 | 30 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
Antulius | 0:f680c41c1640 | 31 | : Includes |
Antulius | 0:f680c41c1640 | 32 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
Antulius | 0:f680c41c1640 | 33 | */ |
Antulius | 0:f680c41c1640 | 34 | |
Antulius | 0:f680c41c1640 | 35 | #include "stm32f103c8t6.h" |
Antulius | 0:f680c41c1640 | 36 | #include "mbed.h" |
Antulius | 0:f680c41c1640 | 37 | #include "Serial.h" |
Antulius | 0:f680c41c1640 | 38 | #include "stdio.h" |
Antulius | 0:f680c41c1640 | 39 | /* |
Antulius | 0:f680c41c1640 | 40 | :............................................................................... |
Antulius | 0:f680c41c1640 | 41 | : Definiciones |
Antulius | 0:f680c41c1640 | 42 | :............................................................................... |
Antulius | 0:f680c41c1640 | 43 | */ |
Antulius | 0:f680c41c1640 | 44 | #define on 0 // Estado para boton presionado |
Antulius | 0:f680c41c1640 | 45 | #define off 1 // Estado para boton sin presionar |
Antulius | 0:f680c41c1640 | 46 | #define hold 2 // Estado para boton mantenido |
Antulius | 0:f680c41c1640 | 47 | #define release 3 // Estado para boton liberado |
Antulius | 0:f680c41c1640 | 48 | #define FALSE 0 // Estado FALSO |
Antulius | 0:f680c41c1640 | 49 | #define TRUE 1 // Estado VERDADERO |
Antulius | 0:f680c41c1640 | 50 | /* |
Antulius | 0:f680c41c1640 | 51 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 52 | | Configuración de Puertos |
Antulius | 0:f680c41c1640 | 53 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 54 | */ |
Antulius | 0:f680c41c1640 | 55 | DigitalOut verde (LED1); // PC_13 (Green_Led) |
Antulius | 0:f680c41c1640 | 56 | DigitalOut rojo (PB_1); // NC (Red_Led) |
Antulius | 0:f680c41c1640 | 57 | |
Antulius | 0:f680c41c1640 | 58 | // ***** Host PC Terminal Communication channels |
Antulius | 0:f680c41c1640 | 59 | Serial terminal (PA_2, PA_3); // Inicializa la comunicación serial a la PC (Tx,Rx) |
Antulius | 0:f680c41c1640 | 60 | //Serial terminal(USBTX, USBRX,115200);// Tx, Rx Baud Rate - Terminal Serial por USB @ 115,200 Bauds |
Antulius | 0:f680c41c1640 | 61 | |
Antulius | 0:f680c41c1640 | 62 | /* |
Antulius | 0:f680c41c1640 | 63 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 64 | | Variables Globales de Usuario |
Antulius | 0:f680c41c1640 | 65 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 66 | */ |
Antulius | 0:f680c41c1640 | 67 | //uint32_t Baud_Rate = 9600; // Velocidad de Transmisión (Bauds) |
Antulius | 0:f680c41c1640 | 68 | /* |
Antulius | 0:f680c41c1640 | 69 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Antulius | 0:f680c41c1640 | 70 | | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción |
Antulius | 0:f680c41c1640 | 71 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Antulius | 0:f680c41c1640 | 72 | */ |
Antulius | 0:f680c41c1640 | 73 | void Setup(void); |
Antulius | 0:f680c41c1640 | 74 | /* END definitions */ |
Antulius | 0:f680c41c1640 | 75 | |
Antulius | 0:f680c41c1640 | 76 | /* |
Antulius | 0:f680c41c1640 | 77 | #=============================================================================== |
Antulius | 0:f680c41c1640 | 78 | | |
Antulius | 0:f680c41c1640 | 79 | | P R O G R A M A P R I N C I P A L |
Antulius | 0:f680c41c1640 | 80 | | |
Antulius | 0:f680c41c1640 | 81 | #=============================================================================== |
Antulius | 0:f680c41c1640 | 82 | */ |
Antulius | 0:f680c41c1640 | 83 | int main() |
Antulius | 0:f680c41c1640 | 84 | { // Inicialización de variables, puertos e interrupciones |
Antulius | 0:f680c41c1640 | 85 | confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock) |
Antulius | 0:f680c41c1640 | 86 | Setup(); // Inicialización del sistema |
Antulius | 0:f680c41c1640 | 87 | terminal.printf ("ADIVINA\n\r"); |
Antulius | 0:f680c41c1640 | 88 | rojo = off; |
Antulius | 0:f680c41c1640 | 89 | verde = off; |
Antulius | 0:f680c41c1640 | 90 | |
Antulius | 0:f680c41c1640 | 91 | while(TRUE) |
Antulius | 0:f680c41c1640 | 92 | { |
Antulius | 0:f680c41c1640 | 93 | Inicio: terminal.printf(" DIGITE UN NUMERO SECRETO DE 0 A 9 \r\n"); |
Antulius | 0:f680c41c1640 | 94 | char secreto = terminal.getc(); |
Antulius | 0:f680c41c1640 | 95 | rojo = on; |
Antulius | 0:f680c41c1640 | 96 | verde = on; |
Antulius | 0:f680c41c1640 | 97 | Intenta: terminal.printf(" ADIVINA EL NUMERO: \r\n"); |
Antulius | 0:f680c41c1640 | 98 | char respuesta = terminal.getc(); |
Antulius | 0:f680c41c1640 | 99 | if( secreto < respuesta ) |
Antulius | 0:f680c41c1640 | 100 | { |
Antulius | 0:f680c41c1640 | 101 | terminal.printf(" Es mas Bajo \r\n"); |
Antulius | 0:f680c41c1640 | 102 | rojo = on; |
Antulius | 0:f680c41c1640 | 103 | verde = off; |
Antulius | 0:f680c41c1640 | 104 | goto Intenta; |
Antulius | 0:f680c41c1640 | 105 | } |
Antulius | 0:f680c41c1640 | 106 | if( secreto > respuesta ) |
Antulius | 0:f680c41c1640 | 107 | { |
Antulius | 0:f680c41c1640 | 108 | terminal.printf(" Es mas Alto \r\n"); |
Antulius | 0:f680c41c1640 | 109 | rojo = off; |
Antulius | 0:f680c41c1640 | 110 | verde = on; |
Antulius | 0:f680c41c1640 | 111 | goto Intenta; |
Antulius | 0:f680c41c1640 | 112 | } |
Antulius | 0:f680c41c1640 | 113 | if( secreto == respuesta ) |
Antulius | 0:f680c41c1640 | 114 | { |
Antulius | 0:f680c41c1640 | 115 | terminal.printf(" CORRECTO!, Es igual a: %c \r\n",secreto); |
Antulius | 0:f680c41c1640 | 116 | rojo = off; |
Antulius | 0:f680c41c1640 | 117 | verde = on; |
Antulius | 0:f680c41c1640 | 118 | wait(1.0); |
Antulius | 0:f680c41c1640 | 119 | rojo = off; |
Antulius | 0:f680c41c1640 | 120 | verde = off; |
Antulius | 0:f680c41c1640 | 121 | wait(1.0); |
Antulius | 0:f680c41c1640 | 122 | rojo = off; |
Antulius | 0:f680c41c1640 | 123 | verde = on; |
Antulius | 0:f680c41c1640 | 124 | wait(1.0); |
Antulius | 0:f680c41c1640 | 125 | terminal.printf(" Eres un Genio !!! \r\n"); |
Antulius | 0:f680c41c1640 | 126 | wait(1.0); |
Antulius | 0:f680c41c1640 | 127 | rojo = on; |
Antulius | 0:f680c41c1640 | 128 | verde = off; |
Antulius | 0:f680c41c1640 | 129 | wait(1.0); |
Antulius | 0:f680c41c1640 | 130 | rojo = off; |
Antulius | 0:f680c41c1640 | 131 | verde = on; |
Antulius | 0:f680c41c1640 | 132 | } |
Antulius | 0:f680c41c1640 | 133 | terminal.printf(" Quieres intentarlo de nuevo? \r\n"); |
Antulius | 0:f680c41c1640 | 134 | terminal.printf(" 0 = No \r\n 1 = Si \r\n"); |
Antulius | 0:f680c41c1640 | 135 | char opcion = terminal.getc(); |
Antulius | 0:f680c41c1640 | 136 | if( opcion == '1' ) goto Inicio; |
Antulius | 0:f680c41c1640 | 137 | else if( opcion == '0' ) |
Antulius | 0:f680c41c1640 | 138 | { |
Antulius | 0:f680c41c1640 | 139 | terminal.printf(" Eso es todo Amigos! \r\n"); |
Antulius | 0:f680c41c1640 | 140 | break; |
Antulius | 0:f680c41c1640 | 141 | } |
Antulius | 0:f680c41c1640 | 142 | } |
Antulius | 0:f680c41c1640 | 143 | } |
Antulius | 0:f680c41c1640 | 144 | |
Antulius | 0:f680c41c1640 | 145 | /* END main */ |
Antulius | 0:f680c41c1640 | 146 | |
Antulius | 0:f680c41c1640 | 147 | /* |
Antulius | 0:f680c41c1640 | 148 | ................................................................................ |
Antulius | 0:f680c41c1640 | 149 | : Rutinas de los Vectores de Interrupción |
Antulius | 0:f680c41c1640 | 150 | ................................................................................ |
Antulius | 0:f680c41c1640 | 151 | */ |
Antulius | 0:f680c41c1640 | 152 | |
Antulius | 0:f680c41c1640 | 153 | /* END Events */ |
Antulius | 0:f680c41c1640 | 154 | /* |
Antulius | 0:f680c41c1640 | 155 | ________________________________________________________________________________ |
Antulius | 0:f680c41c1640 | 156 | | |
Antulius | 0:f680c41c1640 | 157 | | Funciones Prototipo |
Antulius | 0:f680c41c1640 | 158 | |_______________________________________________________________________________ |
Antulius | 0:f680c41c1640 | 159 | */ |
Antulius | 0:f680c41c1640 | 160 | // Las Funciones Prototipo van aquí ! |
Antulius | 0:f680c41c1640 | 161 | void Setup() |
Antulius | 0:f680c41c1640 | 162 | { |
Antulius | 0:f680c41c1640 | 163 | // terminal.baud(Baud_Rate); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
Antulius | 0:f680c41c1640 | 164 | terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
Antulius | 0:f680c41c1640 | 165 | terminal.printf(" System is Wake Up!.\n\r"); |
Antulius | 0:f680c41c1640 | 166 | } |
Antulius | 0:f680c41c1640 | 167 | |
Antulius | 0:f680c41c1640 | 168 | /* END routines */ |
Antulius | 0:f680c41c1640 | 169 | |
Antulius | 0:f680c41c1640 | 170 | /* END program */ |
Antulius | 0:f680c41c1640 | 171 | |
Antulius | 0:f680c41c1640 | 172 | /* END documentation */ |
Antulius | 0:f680c41c1640 | 173 | /* |
Antulius | 0:f680c41c1640 | 174 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 175 | | EJERCICIO |
Antulius | 0:f680c41c1640 | 176 | | |
Antulius | 0:f680c41c1640 | 177 | | 1.- Este programa tambien acepta letras o caracteres? |
Antulius | 0:f680c41c1640 | 178 | | 2.- Modificar este programa para: |
Antulius | 0:f680c41c1640 | 179 | | a) Que solo acepte números |
Antulius | 0:f680c41c1640 | 180 | | b) Agregar un contador de Número de Intentos |
Antulius | 0:f680c41c1640 | 181 | | |
Antulius | 0:f680c41c1640 | 182 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 183 | | |
Antulius | 0:f680c41c1640 | 184 | | EXAMEN |
Antulius | 0:f680c41c1640 | 185 | | |
Antulius | 0:f680c41c1640 | 186 | | 1.- Modificar el programa para que despliegue el número de intentos para |
Antulius | 0:f680c41c1640 | 187 | | adivinar el número secreto. |
Antulius | 0:f680c41c1640 | 188 | | 2.- Modificar el programa para haga eco con la respuesta que le introducimos. |
Antulius | 0:f680c41c1640 | 189 | | |
Antulius | 0:f680c41c1640 | 190 | | 3.- Modificar el programa para que el número secreto sea generado aleatoriamente. |
Antulius | 0:f680c41c1640 | 191 | | a) Generar un Número Pseudo Aleatorio Mediante el Ticker |
Antulius | 0:f680c41c1640 | 192 | | b) Utilizando la función RANDOMIZE |
Antulius | 0:f680c41c1640 | 193 | | Suerte! |
Antulius | 0:f680c41c1640 | 194 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 195 | | |
Antulius | 0:f680c41c1640 | 196 | | T H E A N T U L I U S T E A M |
Antulius | 0:f680c41c1640 | 197 | | Research, Development, Systems Equipment, Support & Spare Parts I n c. |
Antulius | 0:f680c41c1640 | 198 | | (C) Copyright 1989-2014, All rigths Reserved |
Antulius | 0:f680c41c1640 | 199 | | |
Antulius | 0:f680c41c1640 | 200 | | This program is licensed under rules of |
Antulius | 0:f680c41c1640 | 201 | | THE BEANERS TECHNOLOGIES PROYECT |
Antulius | 0:f680c41c1640 | 202 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 203 | */ |
Antulius | 0:f680c41c1640 | 204 | /* END Mbed */ |