Javier Marcelo
/
STM32F103C8_Minimos
Programa de Minimos.
main.cpp@1:b5216422f915, 2019-09-13 (annotated)
- Committer:
- ArturoRiosRamos
- Date:
- Fri Sep 13 15:45:52 2019 +0000
- Revision:
- 1:b5216422f915
- Parent:
- 0:f680c41c1640
- Child:
- 3:7d496863c448
El programa cuenta el numero de intentos
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 |
ArturoRiosRamos | 1:b5216422f915 | 65 | |
Antulius | 0:f680c41c1640 | 66 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 67 | */ |
ArturoRiosRamos | 1:b5216422f915 | 68 | int intentos=0; |
ArturoRiosRamos | 1:b5216422f915 | 69 | int respuesta; |
ArturoRiosRamos | 1:b5216422f915 | 70 | int secreto; |
Antulius | 0:f680c41c1640 | 71 | //uint32_t Baud_Rate = 9600; // Velocidad de Transmisión (Bauds) |
Antulius | 0:f680c41c1640 | 72 | /* |
Antulius | 0:f680c41c1640 | 73 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Antulius | 0:f680c41c1640 | 74 | | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción |
Antulius | 0:f680c41c1640 | 75 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Antulius | 0:f680c41c1640 | 76 | */ |
Antulius | 0:f680c41c1640 | 77 | void Setup(void); |
Antulius | 0:f680c41c1640 | 78 | /* END definitions */ |
Antulius | 0:f680c41c1640 | 79 | |
Antulius | 0:f680c41c1640 | 80 | /* |
Antulius | 0:f680c41c1640 | 81 | #=============================================================================== |
Antulius | 0:f680c41c1640 | 82 | | |
Antulius | 0:f680c41c1640 | 83 | | P R O G R A M A P R I N C I P A L |
Antulius | 0:f680c41c1640 | 84 | | |
Antulius | 0:f680c41c1640 | 85 | #=============================================================================== |
Antulius | 0:f680c41c1640 | 86 | */ |
Antulius | 0:f680c41c1640 | 87 | int main() |
Antulius | 0:f680c41c1640 | 88 | { // Inicialización de variables, puertos e interrupciones |
Antulius | 0:f680c41c1640 | 89 | confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock) |
Antulius | 0:f680c41c1640 | 90 | Setup(); // Inicialización del sistema |
Antulius | 0:f680c41c1640 | 91 | terminal.printf ("ADIVINA\n\r"); |
Antulius | 0:f680c41c1640 | 92 | rojo = off; |
Antulius | 0:f680c41c1640 | 93 | verde = off; |
ArturoRiosRamos | 1:b5216422f915 | 94 | |
Antulius | 0:f680c41c1640 | 95 | |
Antulius | 0:f680c41c1640 | 96 | while(TRUE) |
Antulius | 0:f680c41c1640 | 97 | { |
Antulius | 0:f680c41c1640 | 98 | Inicio: terminal.printf(" DIGITE UN NUMERO SECRETO DE 0 A 9 \r\n"); |
ArturoRiosRamos | 1:b5216422f915 | 99 | secreto = terminal.getc(); |
Antulius | 0:f680c41c1640 | 100 | rojo = on; |
ArturoRiosRamos | 1:b5216422f915 | 101 | verde = on; |
ArturoRiosRamos | 1:b5216422f915 | 102 | do{ |
Antulius | 0:f680c41c1640 | 103 | Intenta: terminal.printf(" ADIVINA EL NUMERO: \r\n"); |
ArturoRiosRamos | 1:b5216422f915 | 104 | respuesta = terminal.getc(); |
Antulius | 0:f680c41c1640 | 105 | if( secreto < respuesta ) |
Antulius | 0:f680c41c1640 | 106 | { |
Antulius | 0:f680c41c1640 | 107 | terminal.printf(" Es mas Bajo \r\n"); |
Antulius | 0:f680c41c1640 | 108 | rojo = on; |
Antulius | 0:f680c41c1640 | 109 | verde = off; |
Antulius | 0:f680c41c1640 | 110 | goto Intenta; |
Antulius | 0:f680c41c1640 | 111 | } |
Antulius | 0:f680c41c1640 | 112 | if( secreto > respuesta ) |
Antulius | 0:f680c41c1640 | 113 | { |
Antulius | 0:f680c41c1640 | 114 | terminal.printf(" Es mas Alto \r\n"); |
Antulius | 0:f680c41c1640 | 115 | rojo = off; |
Antulius | 0:f680c41c1640 | 116 | verde = on; |
Antulius | 0:f680c41c1640 | 117 | goto Intenta; |
Antulius | 0:f680c41c1640 | 118 | } |
ArturoRiosRamos | 1:b5216422f915 | 119 | } while ( secreto != respuesta ); |
ArturoRiosRamos | 1:b5216422f915 | 120 | intentos ++; |
Antulius | 0:f680c41c1640 | 121 | if( secreto == respuesta ) |
Antulius | 0:f680c41c1640 | 122 | { |
ArturoRiosRamos | 1:b5216422f915 | 123 | terminal.printf(" CORRECTO!, Es igual a: %i \r\n",secreto); |
Antulius | 0:f680c41c1640 | 124 | rojo = off; |
Antulius | 0:f680c41c1640 | 125 | verde = on; |
Antulius | 0:f680c41c1640 | 126 | wait(1.0); |
Antulius | 0:f680c41c1640 | 127 | rojo = off; |
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 | wait(1.0); |
Antulius | 0:f680c41c1640 | 133 | terminal.printf(" Eres un Genio !!! \r\n"); |
Antulius | 0:f680c41c1640 | 134 | wait(1.0); |
Antulius | 0:f680c41c1640 | 135 | rojo = on; |
Antulius | 0:f680c41c1640 | 136 | verde = off; |
Antulius | 0:f680c41c1640 | 137 | wait(1.0); |
Antulius | 0:f680c41c1640 | 138 | rojo = off; |
Antulius | 0:f680c41c1640 | 139 | verde = on; |
ArturoRiosRamos | 1:b5216422f915 | 140 | terminal.printf(" El numero de intentos fue de: %d", intentos); |
Antulius | 0:f680c41c1640 | 141 | } |
Antulius | 0:f680c41c1640 | 142 | terminal.printf(" Quieres intentarlo de nuevo? \r\n"); |
Antulius | 0:f680c41c1640 | 143 | terminal.printf(" 0 = No \r\n 1 = Si \r\n"); |
ArturoRiosRamos | 1:b5216422f915 | 144 | int opcion = terminal.getc(); |
Antulius | 0:f680c41c1640 | 145 | if( opcion == '1' ) goto Inicio; |
Antulius | 0:f680c41c1640 | 146 | else if( opcion == '0' ) |
Antulius | 0:f680c41c1640 | 147 | { |
Antulius | 0:f680c41c1640 | 148 | terminal.printf(" Eso es todo Amigos! \r\n"); |
Antulius | 0:f680c41c1640 | 149 | break; |
Antulius | 0:f680c41c1640 | 150 | } |
Antulius | 0:f680c41c1640 | 151 | } |
Antulius | 0:f680c41c1640 | 152 | } |
Antulius | 0:f680c41c1640 | 153 | |
Antulius | 0:f680c41c1640 | 154 | /* END main */ |
Antulius | 0:f680c41c1640 | 155 | |
Antulius | 0:f680c41c1640 | 156 | /* |
Antulius | 0:f680c41c1640 | 157 | ................................................................................ |
Antulius | 0:f680c41c1640 | 158 | : Rutinas de los Vectores de Interrupción |
Antulius | 0:f680c41c1640 | 159 | ................................................................................ |
Antulius | 0:f680c41c1640 | 160 | */ |
Antulius | 0:f680c41c1640 | 161 | |
Antulius | 0:f680c41c1640 | 162 | /* END Events */ |
Antulius | 0:f680c41c1640 | 163 | /* |
Antulius | 0:f680c41c1640 | 164 | ________________________________________________________________________________ |
Antulius | 0:f680c41c1640 | 165 | | |
Antulius | 0:f680c41c1640 | 166 | | Funciones Prototipo |
Antulius | 0:f680c41c1640 | 167 | |_______________________________________________________________________________ |
Antulius | 0:f680c41c1640 | 168 | */ |
Antulius | 0:f680c41c1640 | 169 | // Las Funciones Prototipo van aquí ! |
Antulius | 0:f680c41c1640 | 170 | void Setup() |
Antulius | 0:f680c41c1640 | 171 | { |
Antulius | 0:f680c41c1640 | 172 | // terminal.baud(Baud_Rate); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
Antulius | 0:f680c41c1640 | 173 | terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
Antulius | 0:f680c41c1640 | 174 | terminal.printf(" System is Wake Up!.\n\r"); |
Antulius | 0:f680c41c1640 | 175 | } |
Antulius | 0:f680c41c1640 | 176 | |
Antulius | 0:f680c41c1640 | 177 | /* END routines */ |
Antulius | 0:f680c41c1640 | 178 | |
Antulius | 0:f680c41c1640 | 179 | /* END program */ |
Antulius | 0:f680c41c1640 | 180 | |
Antulius | 0:f680c41c1640 | 181 | /* END documentation */ |
Antulius | 0:f680c41c1640 | 182 | /* |
Antulius | 0:f680c41c1640 | 183 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 184 | | EJERCICIO |
Antulius | 0:f680c41c1640 | 185 | | |
Antulius | 0:f680c41c1640 | 186 | | 1.- Este programa tambien acepta letras o caracteres? |
Antulius | 0:f680c41c1640 | 187 | | 2.- Modificar este programa para: |
Antulius | 0:f680c41c1640 | 188 | | a) Que solo acepte números |
Antulius | 0:f680c41c1640 | 189 | | b) Agregar un contador de Número de Intentos |
Antulius | 0:f680c41c1640 | 190 | | |
Antulius | 0:f680c41c1640 | 191 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 192 | | |
Antulius | 0:f680c41c1640 | 193 | | EXAMEN |
Antulius | 0:f680c41c1640 | 194 | | |
Antulius | 0:f680c41c1640 | 195 | | 1.- Modificar el programa para que despliegue el número de intentos para |
Antulius | 0:f680c41c1640 | 196 | | adivinar el número secreto. |
Antulius | 0:f680c41c1640 | 197 | | 2.- Modificar el programa para haga eco con la respuesta que le introducimos. |
Antulius | 0:f680c41c1640 | 198 | | |
Antulius | 0:f680c41c1640 | 199 | | 3.- Modificar el programa para que el número secreto sea generado aleatoriamente. |
Antulius | 0:f680c41c1640 | 200 | | a) Generar un Número Pseudo Aleatorio Mediante el Ticker |
Antulius | 0:f680c41c1640 | 201 | | b) Utilizando la función RANDOMIZE |
Antulius | 0:f680c41c1640 | 202 | | Suerte! |
Antulius | 0:f680c41c1640 | 203 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 204 | | |
Antulius | 0:f680c41c1640 | 205 | | T H E A N T U L I U S T E A M |
Antulius | 0:f680c41c1640 | 206 | | Research, Development, Systems Equipment, Support & Spare Parts I n c. |
Antulius | 0:f680c41c1640 | 207 | | (C) Copyright 1989-2014, All rigths Reserved |
Antulius | 0:f680c41c1640 | 208 | | |
Antulius | 0:f680c41c1640 | 209 | | This program is licensed under rules of |
Antulius | 0:f680c41c1640 | 210 | | THE BEANERS TECHNOLOGIES PROYECT |
Antulius | 0:f680c41c1640 | 211 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 212 | */ |
Antulius | 0:f680c41c1640 | 213 | /* END Mbed */ |