Francisco Sarabia / Mbed 2 deprecated STM32F103C8T6_IntegracionNumerica

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       : STM32F103C8_Caratula
00004 **    Procesador     : STM32F103C8T6
00005 **    Plataforma     : Blue Pill
00006 **    Herramienta    : Mbed Compiler
00007 **    Version        : Driver 01.01
00008 **    Compilador     : GNU C Compiler
00009 **    Fecha/Hora     : 17-02-2020, 22:53, # CodeGen: 0
00010 **    Descripción    :
00011 **         Este proyecto hace una carátula para mostrar la presentación
00012 **         This module contains user's application code.
00013 **   Componentes     : GPIO, Timer, etc .
00014 **   Configuraciones : Includes, Stacks y Drivers externos
00015 **   Autores         :
00016 **         ATEAM Development Group:
00017 **          -  Francisco Sarabia López, Antulio Morgado Valle(plantilla)
00018 **
00019 **   Versión        : Alpha
00020 **   Revisión       : A
00021 **   Release        : 0
00022 **   Bugs & Fixes   :
00023 **   Date           : 
00024 **
00025 ** ###########################################################################*/
00026 /*
00027 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00028 :  Includes
00029 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00030 */
00031 #include "stm32f103c8t6.h"
00032 #include "mbed.h"
00033 #include "Serial.h"
00034 //#include "LedRGB.h"
00035 //#include "stdio.h"
00036 
00037 /*
00038 :...............................................................................
00039 :  Definiciones
00040 :...............................................................................
00041 */
00042 #define  on             0           // Estado para boton presionado
00043 #define off             1           // Estado para boton sin presionar
00044 #define hold            2           // Estado para boton mantenido
00045 #define release         3           // Estado para boton liberado
00046 #define FALSE           0           // Estado FALSO
00047 #define TRUE            1           // Estado VERDADERO
00048 #define Ticker_Rate     1000        // Periodo de interrupción Ticker (us)
00049 #define Baud_Rate       115200      // Velocidad de Transmisión de la Terminal
00050 /*
00051 +-------------------------------------------------------------------------------
00052 |  Configuración de Puertos 
00053 +-------------------------------------------------------------------------------
00054 */
00055 Ticker      TimerInt;               // Inicializa la Interrupción por Timer
00056 DigitalOut  led_monitor(LED1);      // Inicializa el LED Monitor
00057 DigitalOut  led_testigo(PB_1);      // Inicializa el LED Testigo
00058 PwmOut      led_pwm(PA_7);          // Inicializa el LED PWM
00059 AnalogIn    sensor1(PB_0);          // Inicializa Canal Analógico para sensor 1
00060 Serial      terminal(PA_2, PA_3);   // Inicializa la Comunicación Serial a la PC
00061 /*
00062 +-------------------------------------------------------------------------------
00063 |  Variables Globales de Usuario 
00064 +-------------------------------------------------------------------------------
00065 */
00066 uint16_t Rate=Ticker_Rate/2;        // Velocidad de barrido (500us = 0.5ms)
00067 uint16_t counter=250;               // Cuenta inicial de 250us
00068 /* END variables */
00069 
00070 /*
00071 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00072 |  Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
00073 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00074 */
00075         // Las Definiciones de Funciones Prototipo 
00076         // y Apuntadores a Vectores de Interrupciones van aquí !
00077 void TimerInt_OnInterrupt(void);  
00078 void Blinking_Led(void);
00079 double funcion(float x);
00080 
00081 /* END prototypes */
00082 
00083 /* END definitions */  
00084 /*
00085 #===============================================================================
00086 |
00087 |               P R O G R A M A     P R I N C I P A L
00088 |
00089 #=============================================================================== 
00090 */
00091 int main()          
00092 {                           // Inicialización de variables, puertos e interrupciones
00093 confSysClock();             // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock)
00094 TimerInt.attach_us(&TimerInt_OnInterrupt, Ticker_Rate);   // Le asigna el periodo de interrupción de 1ms (Ticker_Rate=1000)
00095 
00096 terminal.baud(Baud_Rate);      // Se configura la velocidad de transmisión e inicia la comunicación serial.    
00097 terminal.printf(" System is Wake Up!.\n\r"); 
00098 
00099     while (true)                // El Lazo del Programa principal está aquí !!!
00100     {
00101         Blinking_Led();             // Parapadeo del LED por Software
00102         led_pwm = sensor1.read();   // El Led se encenderá de acuerdo al valor del sensor
00103         terminal.printf("INSTITUTO POLITECNICO NACIONAL \r\n");
00104         terminal.printf("\n EEEEEEE       SSSS      IIIIIII     M      M    EEEEEEE \r\n");
00105         terminal.printf(  " E            S             I        M M  M M    E \r\n");
00106         terminal.printf(  " EEEEEEE       SSSS         I        M  MM  M    EEEEEEE \r\n");
00107         terminal.printf(  " E                 S        I        M      M    E \r\n"); 
00108         terminal.printf(  " EEEEEEE       SSSS      IIIIIII     M      M    EEEEEEE \r\n");
00109         terminal.printf(  "\n Francisco Sarabia Lopez\r\n"); 
00110         terminal.printf(  "\n Ingenieria en Comunicaciones y Electronica\r\n"); 
00111 
00112 
00113     int n;
00114     float i, a, b;
00115     double fa, fx, fb, dx, area;
00116 
00117     printf("Ingresa el valor del limite inferior\n");
00118     scanf("%f", &a);
00119     printf("Ingresa el valor del limite superior\n");
00120     scanf("%f", &b);
00121     printf("Ingresa el numero de particiones\n");
00122     scanf("%d", &n);
00123 
00124     fx = 0.0;
00125     fa = funcion(a);
00126     fb = funcion(b);
00127     dx = (b - a)/(float)n;
00128     for (i = a; i < b; i += dx)
00129     {
00130         fx = fx + funcion(i);
00131     }
00132     area = (fx + (fa + fb) / 2) * dx;
00133     printf("%0.10f\n", area);
00134     return 0;
00135                            
00136     }
00137 }
00138 /* END main */
00139 
00140 /*
00141 ................................................................................
00142 :  Rutinas de los Vectores de Interrupción
00143 ................................................................................
00144 */
00145                 // Las Rutinas de Atención a Interrupciones van aquí !
00146 void TimerInt_OnInterrupt()          // Rutina de Atención al Ticker
00147 {
00148     
00149 }
00150 /* END Events */   
00151 /*
00152 ________________________________________________________________________________
00153 |
00154 |  Funciones Prototipo
00155 |_______________________________________________________________________________
00156 */
00157                 // Las Funciones Prototipo van aquí !
00158 void Blinking_Led()     // Software Blinking routine for LED 
00159 {
00160         // The on-board LED is connected, via a resistor, to +3.3V (not to GND). 
00161         // So to turn the LED on or off we have to set it to 0 or 1 respectively
00162     led_testigo = 1;        // turn the LED on (using Positive Logic)
00163     wait_ms(200);           // 200 millisecond
00164     led_testigo = 0;        // turn the LED off (using Positive Logic)
00165     wait_ms(1000);          // 1000 millisecond
00166 }
00167 
00168 // Definicion de la funcion matematica a evaluar
00169 double funcion(float x)
00170 {
00171     double r;
00172     r=exp(x*x);//funcion e^(x^2)
00173     return r;
00174 }
00175 /* END functions */    
00176                 
00177 /* END program */
00178 
00179 /*+-----------------------------------------------------------------------------       
00180 *+ La documentación va aquí!:
00181 *+-----------------------------------------------------------------------------       
00182 *+
00183 *+
00184 *+----------------------------------------------------------------------------*
00185 *+
00186 *+   Powered by
00187 *+
00188 *+          T H E     A N T U L I U ' S   T E A M   R&D  Unltd 
00189 *+
00190 *+  Research, Development, Systems, Equipment, Support & Spare Parts.
00191 *+  (C) Copyright 1989-2019, All Rights Reserved            
00192 *+
00193 *+  Welcome to The Beaners Proyect Community!                   
00194 *+----------------------------------------------------------------------------*/
00195 
00196 /* END documentation */ 
00197 
00198 /* END Mbed */