Javier Marcelo
/
STM32F103C8_Biseccion
Programa para calcular la raíz de una función por el método de Bisección.
main.cpp@6:57457ad17880, 2019-10-25 (annotated)
- Committer:
- JavierMarcelo98
- Date:
- Fri Oct 25 15:05:26 2019 +0000
- Revision:
- 6:57457ad17880
- Parent:
- 5:7bd28f4ca12b
Programa Biseccion.
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 |
ArturoRiosRamos | 3:7d496863c448 | 3 | ** Proyecto : STM32-103C8_Portada |
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 |
JavierMarcelo98 | 4:e8498d695fc2 | 18 | ** - Marcelo Padron Javier |
Antulius | 0:f680c41c1640 | 19 | ** |
Antulius | 0:f680c41c1640 | 20 | ** Versión : Beta |
Antulius | 0:f680c41c1640 | 21 | ** Revisión : A |
Antulius | 0:f680c41c1640 | 22 | ** Release : 0 |
Antulius | 0:f680c41c1640 | 23 | ** Bugs & Fixes : |
JavierMarcelo98 | 4:e8498d695fc2 | 24 | ** Date : 22/10/2019 |
JavierMarcelo98 | 4:e8498d695fc2 | 25 | ** |
ArturoRiosRamos | 3:7d496863c448 | 26 | ** |
Antulius | 0:f680c41c1640 | 27 | ** |
Antulius | 0:f680c41c1640 | 28 | ** |
Antulius | 0:f680c41c1640 | 29 | ** ###########################################################################*/ |
Antulius | 0:f680c41c1640 | 30 | /* |
Antulius | 0:f680c41c1640 | 31 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
Antulius | 0:f680c41c1640 | 32 | : Includes |
Antulius | 0:f680c41c1640 | 33 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
Antulius | 0:f680c41c1640 | 34 | */ |
Antulius | 0:f680c41c1640 | 35 | |
Antulius | 0:f680c41c1640 | 36 | #include "stm32f103c8t6.h" |
Antulius | 0:f680c41c1640 | 37 | #include "mbed.h" |
Antulius | 0:f680c41c1640 | 38 | #include "Serial.h" |
Antulius | 0:f680c41c1640 | 39 | #include "stdio.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 |
JavierMarcelo98 | 4:e8498d695fc2 | 51 | #define Ticker_Rate 1000 // Tiempo del Ticker |
JavierMarcelo98 | 6:57457ad17880 | 52 | #define RAIZ(x) ((x)+2) |
JavierMarcelo98 | 4:e8498d695fc2 | 53 | ////////////////////////////////////////// Definimos las notas notas musicales y su frecuencia. |
Antulius | 0:f680c41c1640 | 54 | /* |
Antulius | 0:f680c41c1640 | 55 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 56 | | Configuración de Puertos |
Antulius | 0:f680c41c1640 | 57 | +------------------------------------------------------------------------------- |
JavierMarcelo98 | 4:e8498d695fc2 | 58 | */ |
JavierMarcelo98 | 5:7bd28f4ca12b | 59 | DigitalOut verde (LED1); // NC (Green_Led) |
JavierMarcelo98 | 4:e8498d695fc2 | 60 | DigitalOut Led_Monitor (PB_1); // Led monitor de la Tarjeta STM32F103C8 |
JavierMarcelo98 | 4:e8498d695fc2 | 61 | Serial terminal (PA_2, PA_3); // Inicializa la comunicación serial a la PC (Tx,Rx) |
JavierMarcelo98 | 4:e8498d695fc2 | 62 | //Serial terminal(USBTX, USBRX,115200);// Tx, Rx Baud Rate - Terminal Serial por USB @ 115,200 Bauds |
Antulius | 0:f680c41c1640 | 63 | |
Antulius | 0:f680c41c1640 | 64 | /* |
Antulius | 0:f680c41c1640 | 65 | +------------------------------------------------------------------------------- |
JavierMarcelo98 | 4:e8498d695fc2 | 66 | | Variables Globales de Usuario |
JavierMarcelo98 | 4:e8498d695fc2 | 67 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
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 | */ |
ArturoRiosRamos | 3:7d496863c448 | 73 | void Portada(); |
JavierMarcelo98 | 5:7bd28f4ca12b | 74 | void Calculos(); |
Antulius | 0:f680c41c1640 | 75 | void Setup(void); |
Antulius | 0:f680c41c1640 | 76 | /* END definitions */ |
Antulius | 0:f680c41c1640 | 77 | |
Antulius | 0:f680c41c1640 | 78 | /* |
Antulius | 0:f680c41c1640 | 79 | #=============================================================================== |
Antulius | 0:f680c41c1640 | 80 | | |
Antulius | 0:f680c41c1640 | 81 | | P R O G R A M A P R I N C I P A L |
Antulius | 0:f680c41c1640 | 82 | | |
Antulius | 0:f680c41c1640 | 83 | #=============================================================================== |
Antulius | 0:f680c41c1640 | 84 | */ |
Antulius | 0:f680c41c1640 | 85 | int main() |
JavierMarcelo98 | 6:57457ad17880 | 86 | { |
JavierMarcelo98 | 6:57457ad17880 | 87 | |
Antulius | 0:f680c41c1640 | 88 | Setup(); // Inicialización del sistema |
JavierMarcelo98 | 6:57457ad17880 | 89 | Portada(); |
JavierMarcelo98 | 5:7bd28f4ca12b | 90 | Calculos(); //Mandar a llamar a la funcion Calculos. |
ArturoRiosRamos | 3:7d496863c448 | 91 | } |
Antulius | 0:f680c41c1640 | 92 | /* END main */ |
Antulius | 0:f680c41c1640 | 93 | |
Antulius | 0:f680c41c1640 | 94 | /* |
Antulius | 0:f680c41c1640 | 95 | ................................................................................ |
Antulius | 0:f680c41c1640 | 96 | : Rutinas de los Vectores de Interrupción |
Antulius | 0:f680c41c1640 | 97 | ................................................................................ |
Antulius | 0:f680c41c1640 | 98 | */ |
Antulius | 0:f680c41c1640 | 99 | |
Antulius | 0:f680c41c1640 | 100 | /* END Events */ |
Antulius | 0:f680c41c1640 | 101 | /* |
Antulius | 0:f680c41c1640 | 102 | ________________________________________________________________________________ |
Antulius | 0:f680c41c1640 | 103 | | |
Antulius | 0:f680c41c1640 | 104 | | Funciones Prototipo |
Antulius | 0:f680c41c1640 | 105 | |_______________________________________________________________________________ |
Antulius | 0:f680c41c1640 | 106 | */ |
Antulius | 0:f680c41c1640 | 107 | // Las Funciones Prototipo van aquí ! |
Antulius | 0:f680c41c1640 | 108 | void Setup() |
Antulius | 0:f680c41c1640 | 109 | { |
Antulius | 0:f680c41c1640 | 110 | // terminal.baud(Baud_Rate); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
JavierMarcelo98 | 4:e8498d695fc2 | 111 | terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
JavierMarcelo98 | 5:7bd28f4ca12b | 112 | } |
JavierMarcelo98 | 5:7bd28f4ca12b | 113 | void Portada()//Funcion Portada |
JavierMarcelo98 | 4:e8498d695fc2 | 114 | { |
JavierMarcelo98 | 5:7bd28f4ca12b | 115 | terminal.printf("\n\r\t\e[1;32m0101 0101 010101 01 10 0101 0101 0101 0101 0101 0101 0101 01 10 0101 0101\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 116 | terminal.printf("\n\r\t\e[1;32m01 01 01 010 010 01 0 0 1 01 0 1 10 01 010 10 01 0 1\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 117 | terminal.printf("\n\r\t\e[1;32m0101 0101 01 01 1 10 0101 1 0101 01 0101 10 0101 01 1 10 01 0 1\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 118 | terminal.printf("\n\r\t\e[1;32m01 01 01 01 10 01 0 0 1 01 0 1 10 01 01 010 01 0 1\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 119 | terminal.printf("\n\r\t\e[1;32m0101 0101 010101 01 10 0101 0101 0 1 0101 0 1 10 0101 01 10 0101 0101\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 120 | terminal.printf("\n\n\r\t\e[1;32m \'NUESTROS COLORES VERDE \e[0m\e[1;37mY BLANCO, POR QUE EL\e[0m\e[1;31m ROJO LO LLEVAMOS EN LA SANGRE!!!\'\e[0m\n\n"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 121 | terminal.printf("\n\r\t\t\e[1;37m ESCUELA SUPERIOR DE INGENIERIA MECANICA Y ELECTRICA\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 122 | terminal.printf("\n\n\r\t\t\e[1;37m INGENIERIA EN COMUNICACIONES Y ELECTRONICA\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 123 | terminal.printf("\n\n\r\t\t\e[1;37m ANALISIS NUMERICO\e[0m"); |
JavierMarcelo98 | 6:57457ad17880 | 124 | terminal.printf("\n\n\r\t\t\e[1;37m PROGRAMA: METODO DE BISECCION\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 125 | terminal.printf("\n\n\r\t\t\e[1;37m ALUMNO: MARCELO PADRON JAVIER\e[0m"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 126 | terminal.printf("\n\n\r\t\t\e[1;37m GRUPO: 4CV2\e[0m\n\n"); |
JavierMarcelo98 | 5:7bd28f4ca12b | 127 | wait(3.0);//Retardo de 3 segundos |
JavierMarcelo98 | 4:e8498d695fc2 | 128 | } |
JavierMarcelo98 | 5:7bd28f4ca12b | 129 | void Calculos() |
JavierMarcelo98 | 4:e8498d695fc2 | 130 | { |
JavierMarcelo98 | 6:57457ad17880 | 131 | |
JavierMarcelo98 | 6:57457ad17880 | 132 | float xi, xu, xr, xa, ea; |
JavierMarcelo98 | 6:57457ad17880 | 133 | int iteraciones; |
JavierMarcelo98 | 6:57457ad17880 | 134 | terminal.printf("Limite superior de la raiz: "); |
JavierMarcelo98 | 6:57457ad17880 | 135 | xi=terminal.getc(); |
JavierMarcelo98 | 6:57457ad17880 | 136 | terminal.printf("Limite inferior de la raiz: "); |
JavierMarcelo98 | 6:57457ad17880 | 137 | xu=terminal.getc(); |
JavierMarcelo98 | 6:57457ad17880 | 138 | terminal.printf("%12s %10s %10s %10s %10s\n", "Iteraciones", "Xi", "Xu", "Xr", "Ea"); |
JavierMarcelo98 | 6:57457ad17880 | 139 | iteraciones=0; |
JavierMarcelo98 | 6:57457ad17880 | 140 | xa = 0.0; |
JavierMarcelo98 | 6:57457ad17880 | 141 | ea = 0; |
JavierMarcelo98 | 6:57457ad17880 | 142 | do{ |
JavierMarcelo98 | 6:57457ad17880 | 143 | iteraciones++; |
JavierMarcelo98 | 6:57457ad17880 | 144 | xr = (xi + xu) / 2; |
JavierMarcelo98 | 6:57457ad17880 | 145 | if(iteraciones >= 2) |
JavierMarcelo98 | 6:57457ad17880 | 146 | { |
JavierMarcelo98 | 6:57457ad17880 | 147 | ea = ((xr - xa) / xr) * 100; // Calculamos el error aproximado a partir de la segunda iteración |
JavierMarcelo98 | 6:57457ad17880 | 148 | } |
JavierMarcelo98 | 6:57457ad17880 | 149 | ea = fabs(ea); // Calculamos el valor absoluto del número |
JavierMarcelo98 | 6:57457ad17880 | 150 | terminal.printf("%12d %10f %10f %10f %10f\n", iteraciones, xi, xu, xr, fabs(ea)); |
JavierMarcelo98 | 6:57457ad17880 | 151 | xa = xr; |
JavierMarcelo98 | 6:57457ad17880 | 152 | if(RAIZ(xr) > 0) |
JavierMarcelo98 | 6:57457ad17880 | 153 | { |
JavierMarcelo98 | 6:57457ad17880 | 154 | xi = xr; |
JavierMarcelo98 | 5:7bd28f4ca12b | 155 | } |
JavierMarcelo98 | 6:57457ad17880 | 156 | else{ |
JavierMarcelo98 | 6:57457ad17880 | 157 | xu = xr; |
JavierMarcelo98 | 6:57457ad17880 | 158 | } |
JavierMarcelo98 | 6:57457ad17880 | 159 | } |
JavierMarcelo98 | 6:57457ad17880 | 160 | while(ea > 0.5 || (ea == 0.0 && iteraciones == 1)); |
JavierMarcelo98 | 6:57457ad17880 | 161 | terminal.printf("\nLa raiz es de f(x) = x + 2; es: \n", xr); |
JavierMarcelo98 | 6:57457ad17880 | 162 | } |
Antulius | 0:f680c41c1640 | 163 | /* END routines */ |
Antulius | 0:f680c41c1640 | 164 | |
Antulius | 0:f680c41c1640 | 165 | /* END program */ |
Antulius | 0:f680c41c1640 | 166 | |
Antulius | 0:f680c41c1640 | 167 | /* END documentation */ |
Antulius | 0:f680c41c1640 | 168 | /* |
ArturoRiosRamos | 3:7d496863c448 | 169 | |
Antulius | 0:f680c41c1640 | 170 | +-------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 171 | | |
Antulius | 0:f680c41c1640 | 172 | | T H E A N T U L I U S T E A M |
Antulius | 0:f680c41c1640 | 173 | | Research, Development, Systems Equipment, Support & Spare Parts I n c. |
Antulius | 0:f680c41c1640 | 174 | | (C) Copyright 1989-2014, All rigths Reserved |
Antulius | 0:f680c41c1640 | 175 | | |
Antulius | 0:f680c41c1640 | 176 | | This program is licensed under rules of |
Antulius | 0:f680c41c1640 | 177 | | THE BEANERS TECHNOLOGIES PROYECT |
Antulius | 0:f680c41c1640 | 178 | +------------------------------------------------------------------------------- |
Antulius | 0:f680c41c1640 | 179 | */ |
Antulius | 0:f680c41c1640 | 180 | /* END Mbed */ |