Arturo Rios Ramos
/
STM32F103C8_Formula_Gral1
Formula general con interacción en los seriales de la tarjeta
main.cpp@1:49bacc76f02d, 2019-09-13 (annotated)
- Committer:
- ArturoRiosRamos
- Date:
- Fri Sep 13 15:48:11 2019 +0000
- Revision:
- 1:49bacc76f02d
- Parent:
- 0:f680c41c1640
Formula General, con entradas y salidas a la terminal
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: |
ArturoRiosRamos | 1:49bacc76f02d | 17 | ** - Arturo Rios Ramos |
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 : |
ArturoRiosRamos | 1:49bacc76f02d | 23 | ** Date : 13/09/2019 |
ArturoRiosRamos | 1:49bacc76f02d | 24 | ** Formula General |
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" |
ArturoRiosRamos | 1:49bacc76f02d | 39 | #include "math.h" |
Antulius | 0:f680c41c1640 | 40 | /* |
Antulius | 0:f680c41c1640 | 41 | :............................................................................... |
Antulius | 0:f680c41c1640 | 42 | : Definiciones |
Antulius | 0:f680c41c1640 | 43 | :............................................................................... |
Antulius | 0:f680c41c1640 | 44 | */ |
Antulius | 0:f680c41c1640 | 45 | #define on 0 // Estado para boton presionado |
Antulius | 0:f680c41c1640 | 46 | #define off 1 // Estado para boton sin presionar |
Antulius | 0:f680c41c1640 | 47 | #define hold 2 // Estado para boton mantenido |
Antulius | 0:f680c41c1640 | 48 | #define release 3 // Estado para boton liberado |
Antulius | 0:f680c41c1640 | 49 | #define FALSE 0 // Estado FALSO |
Antulius | 0:f680c41c1640 | 50 | #define TRUE 1 // Estado VERDADERO |
Antulius | 0:f680c41c1640 | 51 | /* |
Antulius | 0:f680c41c1640 | 52 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 53 | | Configuración de Puertos |
Antulius | 0:f680c41c1640 | 54 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 55 | */ |
Antulius | 0:f680c41c1640 | 56 | DigitalOut verde (LED1); // PC_13 (Green_Led) |
Antulius | 0:f680c41c1640 | 57 | DigitalOut rojo (PB_1); // NC (Red_Led) |
Antulius | 0:f680c41c1640 | 58 | |
Antulius | 0:f680c41c1640 | 59 | // ***** Host PC Terminal Communication channels |
Antulius | 0:f680c41c1640 | 60 | Serial terminal (PA_2, PA_3); // Inicializa la comunicación serial a la PC (Tx,Rx) |
Antulius | 0:f680c41c1640 | 61 | //Serial terminal(USBTX, USBRX,115200);// Tx, Rx Baud Rate - Terminal Serial por USB @ 115,200 Bauds |
Antulius | 0:f680c41c1640 | 62 | |
Antulius | 0:f680c41c1640 | 63 | /* |
Antulius | 0:f680c41c1640 | 64 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 65 | | Variables Globales de Usuario |
Antulius | 0:f680c41c1640 | 66 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 67 | */ |
Antulius | 0:f680c41c1640 | 68 | //uint32_t Baud_Rate = 9600; // Velocidad de Transmisión (Bauds) |
Antulius | 0:f680c41c1640 | 69 | /* |
Antulius | 0:f680c41c1640 | 70 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Antulius | 0:f680c41c1640 | 71 | | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción |
Antulius | 0:f680c41c1640 | 72 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Antulius | 0:f680c41c1640 | 73 | */ |
Antulius | 0:f680c41c1640 | 74 | void Setup(void); |
Antulius | 0:f680c41c1640 | 75 | /* END definitions */ |
Antulius | 0:f680c41c1640 | 76 | |
Antulius | 0:f680c41c1640 | 77 | /* |
Antulius | 0:f680c41c1640 | 78 | #=============================================================================== |
Antulius | 0:f680c41c1640 | 79 | | |
Antulius | 0:f680c41c1640 | 80 | | P R O G R A M A P R I N C I P A L |
Antulius | 0:f680c41c1640 | 81 | | |
Antulius | 0:f680c41c1640 | 82 | #=============================================================================== |
Antulius | 0:f680c41c1640 | 83 | */ |
Antulius | 0:f680c41c1640 | 84 | int main() |
Antulius | 0:f680c41c1640 | 85 | { // Inicialización de variables, puertos e interrupciones |
Antulius | 0:f680c41c1640 | 86 | confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock) |
Antulius | 0:f680c41c1640 | 87 | Setup(); // Inicialización del sistema |
ArturoRiosRamos | 1:49bacc76f02d | 88 | float _a,_b,_c,x1,x2; //Declaracion de variables |
ArturoRiosRamos | 1:49bacc76f02d | 89 | |
ArturoRiosRamos | 1:49bacc76f02d | 90 | terminal.printf("Valor de A: "); |
ArturoRiosRamos | 1:49bacc76f02d | 91 | terminal.scanf("%f",&_a); |
ArturoRiosRamos | 1:49bacc76f02d | 92 | terminal.printf("Valor de B: "); |
ArturoRiosRamos | 1:49bacc76f02d | 93 | terminal.scanf("%f",&_b); |
ArturoRiosRamos | 1:49bacc76f02d | 94 | terminal.printf("Valor de C: "); |
ArturoRiosRamos | 1:49bacc76f02d | 95 | terminal.scanf("%f",&_c); |
ArturoRiosRamos | 1:49bacc76f02d | 96 | |
ArturoRiosRamos | 1:49bacc76f02d | 97 | |
ArturoRiosRamos | 1:49bacc76f02d | 98 | if(((_b*_b)-(4*_a*_c))>0){ |
ArturoRiosRamos | 1:49bacc76f02d | 99 | |
ArturoRiosRamos | 1:49bacc76f02d | 100 | x1=(float)(((-1)*_b)+(sqrt((_b*_b)-(4*_a*_c))))/2; |
ArturoRiosRamos | 1:49bacc76f02d | 101 | x2=(float)(((-1)*_b)-(sqrt((_b*_b)-(4*_a*_c))))/2; |
ArturoRiosRamos | 1:49bacc76f02d | 102 | printf("X1 = %.2fn",x1); |
ArturoRiosRamos | 1:49bacc76f02d | 103 | printf("X2 = %.2fn",x2); |
ArturoRiosRamos | 1:49bacc76f02d | 104 | |
ArturoRiosRamos | 1:49bacc76f02d | 105 | } |
ArturoRiosRamos | 1:49bacc76f02d | 106 | else{ |
ArturoRiosRamos | 1:49bacc76f02d | 107 | printf("ERROR: La ecuacion no tiene resultado."); |
ArturoRiosRamos | 1:49bacc76f02d | 108 | } |
Antulius | 0:f680c41c1640 | 109 | } |
Antulius | 0:f680c41c1640 | 110 | |
Antulius | 0:f680c41c1640 | 111 | /* END main */ |
Antulius | 0:f680c41c1640 | 112 | |
Antulius | 0:f680c41c1640 | 113 | /* |
Antulius | 0:f680c41c1640 | 114 | ................................................................................ |
Antulius | 0:f680c41c1640 | 115 | : Rutinas de los Vectores de Interrupción |
Antulius | 0:f680c41c1640 | 116 | ................................................................................ |
Antulius | 0:f680c41c1640 | 117 | */ |
Antulius | 0:f680c41c1640 | 118 | |
Antulius | 0:f680c41c1640 | 119 | /* END Events */ |
Antulius | 0:f680c41c1640 | 120 | /* |
Antulius | 0:f680c41c1640 | 121 | ________________________________________________________________________________ |
Antulius | 0:f680c41c1640 | 122 | | |
Antulius | 0:f680c41c1640 | 123 | | Funciones Prototipo |
Antulius | 0:f680c41c1640 | 124 | |_______________________________________________________________________________ |
Antulius | 0:f680c41c1640 | 125 | */ |
Antulius | 0:f680c41c1640 | 126 | // Las Funciones Prototipo van aquí ! |
Antulius | 0:f680c41c1640 | 127 | void Setup() |
Antulius | 0:f680c41c1640 | 128 | { |
Antulius | 0:f680c41c1640 | 129 | // terminal.baud(Baud_Rate); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
Antulius | 0:f680c41c1640 | 130 | terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
Antulius | 0:f680c41c1640 | 131 | terminal.printf(" System is Wake Up!.\n\r"); |
Antulius | 0:f680c41c1640 | 132 | } |
Antulius | 0:f680c41c1640 | 133 | |
Antulius | 0:f680c41c1640 | 134 | /* END routines */ |
Antulius | 0:f680c41c1640 | 135 | |
Antulius | 0:f680c41c1640 | 136 | /* END program */ |
Antulius | 0:f680c41c1640 | 137 | |
Antulius | 0:f680c41c1640 | 138 | /* END documentation */ |
Antulius | 0:f680c41c1640 | 139 | /* |
Antulius | 0:f680c41c1640 | 140 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 141 | | EJERCICIO |
Antulius | 0:f680c41c1640 | 142 | | |
Antulius | 0:f680c41c1640 | 143 | | 1.- Este programa tambien acepta letras o caracteres? |
Antulius | 0:f680c41c1640 | 144 | | 2.- Modificar este programa para: |
Antulius | 0:f680c41c1640 | 145 | | a) Que solo acepte números |
Antulius | 0:f680c41c1640 | 146 | | b) Agregar un contador de Número de Intentos |
Antulius | 0:f680c41c1640 | 147 | | |
Antulius | 0:f680c41c1640 | 148 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 149 | | |
Antulius | 0:f680c41c1640 | 150 | | EXAMEN |
Antulius | 0:f680c41c1640 | 151 | | |
Antulius | 0:f680c41c1640 | 152 | | 1.- Modificar el programa para que despliegue el número de intentos para |
Antulius | 0:f680c41c1640 | 153 | | adivinar el número secreto. |
Antulius | 0:f680c41c1640 | 154 | | 2.- Modificar el programa para haga eco con la respuesta que le introducimos. |
Antulius | 0:f680c41c1640 | 155 | | |
Antulius | 0:f680c41c1640 | 156 | | 3.- Modificar el programa para que el número secreto sea generado aleatoriamente. |
Antulius | 0:f680c41c1640 | 157 | | a) Generar un Número Pseudo Aleatorio Mediante el Ticker |
Antulius | 0:f680c41c1640 | 158 | | b) Utilizando la función RANDOMIZE |
Antulius | 0:f680c41c1640 | 159 | | Suerte! |
Antulius | 0:f680c41c1640 | 160 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 161 | | |
Antulius | 0:f680c41c1640 | 162 | | T H E A N T U L I U S T E A M |
Antulius | 0:f680c41c1640 | 163 | | Research, Development, Systems Equipment, Support & Spare Parts I n c. |
Antulius | 0:f680c41c1640 | 164 | | (C) Copyright 1989-2014, All rigths Reserved |
Antulius | 0:f680c41c1640 | 165 | | |
Antulius | 0:f680c41c1640 | 166 | | This program is licensed under rules of |
Antulius | 0:f680c41c1640 | 167 | | THE BEANERS TECHNOLOGIES PROYECT |
Antulius | 0:f680c41c1640 | 168 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 169 | */ |
Antulius | 0:f680c41c1640 | 170 | /* END Mbed */ |