plantilla mejorada

Dependencies:   mbed

Committer:
Antulius
Date:
Wed Jun 26 18:54:11 2019 +0000
Revision:
0:9f7581d1af6f
Child:
1:c0ed6c52c441
Plantilla para la Tarjeta STM32-F103C8T6 mejor conocida como "Blue Pill"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Antulius 0:9f7581d1af6f 1 /* ###########################################################################
Antulius 0:9f7581d1af6f 2 ** Archivo : main.c
Antulius 0:9f7581d1af6f 3 ** Proyecto : STM32-F103C8_Plantilla
Antulius 0:9f7581d1af6f 4 ** Procesador : STM32F103C8
Antulius 0:9f7581d1af6f 5 ** Herramienta : Mbed
Antulius 0:9f7581d1af6f 6 ** Version : Driver 01.01
Antulius 0:9f7581d1af6f 7 ** Compilador : GNU C Compiler
Antulius 0:9f7581d1af6f 8 ** Fecha/Hora : 14-07-2015, 11:48, # CodeGen: 0
Antulius 0:9f7581d1af6f 9 ** Descripción :
Antulius 0:9f7581d1af6f 10 ** Este proyecto hace...
Antulius 0:9f7581d1af6f 11 ** This module contains user's application code.
Antulius 0:9f7581d1af6f 12 ** Componentes : GPIO, Timer, etc .
Antulius 0:9f7581d1af6f 13 ** Configuraciones : Includes, Stacks y Drivers externos
Antulius 0:9f7581d1af6f 14 ** Autores :
Antulius 0:9f7581d1af6f 15 ** ATEAM Development Group:
Antulius 0:9f7581d1af6f 16 ** - Antulio Morgado Valle
Antulius 0:9f7581d1af6f 17 **
Antulius 0:9f7581d1af6f 18 ** Versión : Beta
Antulius 0:9f7581d1af6f 19 ** Revisión : A
Antulius 0:9f7581d1af6f 20 ** Release : 0
Antulius 0:9f7581d1af6f 21 ** Bugs & Fixes :
Antulius 0:9f7581d1af6f 22 ** Date : 20/10/2019
Antulius 0:9f7581d1af6f 23 ** Added support for Led_RGB
Antulius 0:9f7581d1af6f 24 ** 22/09/2018
Antulius 0:9f7581d1af6f 25 ** Added LCD Menu, Beta version (with bugs)
Antulius 0:9f7581d1af6f 26 **
Antulius 0:9f7581d1af6f 27 ** ###########################################################################*/
Antulius 0:9f7581d1af6f 28 /*
Antulius 0:9f7581d1af6f 29 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Antulius 0:9f7581d1af6f 30 : Includes
Antulius 0:9f7581d1af6f 31 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Antulius 0:9f7581d1af6f 32 */
Antulius 0:9f7581d1af6f 33 #include "mbed.h"
Antulius 0:9f7581d1af6f 34 #include "stm32f103c8t6.h"
Antulius 0:9f7581d1af6f 35 //#include "stm32f10x.h"
Antulius 0:9f7581d1af6f 36 #include "PinNames.h"
Antulius 0:9f7581d1af6f 37 //#include "SysClockConf.h"
Antulius 0:9f7581d1af6f 38 //#include "AnalogIn.h"
Antulius 0:9f7581d1af6f 39 //#include "Led_RGB.h"
Antulius 0:9f7581d1af6f 40 //#include "Serial.h"
Antulius 0:9f7581d1af6f 41 //#include "stdio.h"
Antulius 0:9f7581d1af6f 42
Antulius 0:9f7581d1af6f 43 /*
Antulius 0:9f7581d1af6f 44 :...............................................................................
Antulius 0:9f7581d1af6f 45 : Definiciones
Antulius 0:9f7581d1af6f 46 :...............................................................................
Antulius 0:9f7581d1af6f 47 */
Antulius 0:9f7581d1af6f 48 #define on 0 // Estado para boton presionado
Antulius 0:9f7581d1af6f 49 #define off 1 // Estado para boton sin presionar
Antulius 0:9f7581d1af6f 50 #define hold 2 // Estado para boton mantenido
Antulius 0:9f7581d1af6f 51 #define release 3 // Estado para boton liberado
Antulius 0:9f7581d1af6f 52 #define Ticker_Rate 1000 // Periodo de interrupción (us)
Antulius 0:9f7581d1af6f 53 /*
Antulius 0:9f7581d1af6f 54 +-------------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 55 | Configuración de Puertos
Antulius 0:9f7581d1af6f 56 +-------------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 57 */
Antulius 0:9f7581d1af6f 58 //confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock)
Antulius 0:9f7581d1af6f 59 Ticker TimerInt; // Inicializa la Interrupción por Timer
Antulius 0:9f7581d1af6f 60 DigitalOut led_monitor(LED1); // Inicializa el LED Monitor
Antulius 0:9f7581d1af6f 61 DigitalOut led_testigo(PA_1); // Inicializa el LED Testigo
Antulius 0:9f7581d1af6f 62 Serial terminal(PA_2, PA_3); // Inicializa la Comunicación Serial a la PC
Antulius 0:9f7581d1af6f 63 PwmOut servo(PA_7); // Inicializa el PWM
Antulius 0:9f7581d1af6f 64 AnalogIn sensor1 (PB_0); // Inicializa Canal Analógico para sensor 1
Antulius 0:9f7581d1af6f 65 /*
Antulius 0:9f7581d1af6f 66 +-------------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 67 | Variables Globales de Usuario
Antulius 0:9f7581d1af6f 68 +-------------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 69 */
Antulius 0:9f7581d1af6f 70 uint16_t Rate=Ticker_Rate/2; // Velocidad de barrido (500us = 0.5ms)
Antulius 0:9f7581d1af6f 71 uint16_t counter=250; // Cuenta inicial de 250us
Antulius 0:9f7581d1af6f 72 /* END variables */
Antulius 0:9f7581d1af6f 73
Antulius 0:9f7581d1af6f 74 /*
Antulius 0:9f7581d1af6f 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antulius 0:9f7581d1af6f 76 | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
Antulius 0:9f7581d1af6f 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antulius 0:9f7581d1af6f 78 */
Antulius 0:9f7581d1af6f 79 // Las Definiciones de Funciones Prototipo
Antulius 0:9f7581d1af6f 80 // y Apuntadores a Vectores de Interrupciones van aquí !
Antulius 0:9f7581d1af6f 81 void TimerInt_OnInterrupt(void);
Antulius 0:9f7581d1af6f 82 void Blinking_Led(void);
Antulius 0:9f7581d1af6f 83 /* END prototypes */
Antulius 0:9f7581d1af6f 84
Antulius 0:9f7581d1af6f 85 /* END definitions */
Antulius 0:9f7581d1af6f 86 /*
Antulius 0:9f7581d1af6f 87 #===============================================================================
Antulius 0:9f7581d1af6f 88 |
Antulius 0:9f7581d1af6f 89 | P R O G R A M A P R I N C I P A L
Antulius 0:9f7581d1af6f 90 |
Antulius 0:9f7581d1af6f 91 #===============================================================================
Antulius 0:9f7581d1af6f 92 */
Antulius 0:9f7581d1af6f 93 int main()
Antulius 0:9f7581d1af6f 94 { // Inicialización de variables, puertos e interrupciones
Antulius 0:9f7581d1af6f 95 confSysClock(); // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock)
Antulius 0:9f7581d1af6f 96 TimerInt.attach_us(&TimerInt_OnInterrupt, Ticker_Rate); // Le asigna el periodo de interrupción de 1ms (Ticker_Rate=1000)
Antulius 0:9f7581d1af6f 97
Antulius 0:9f7581d1af6f 98 terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial.
Antulius 0:9f7581d1af6f 99 terminal.printf(" System is Wake Up!.\n\r");
Antulius 0:9f7581d1af6f 100
Antulius 0:9f7581d1af6f 101 while (true) // El Lazo del Programa principal está aquí !!!
Antulius 0:9f7581d1af6f 102 {
Antulius 0:9f7581d1af6f 103 Blinking_Led(); // Parapadeo del LED por Software
Antulius 0:9f7581d1af6f 104 servo = sensor1.read(); //
Antulius 0:9f7581d1af6f 105 terminal.printf("Blink \r\n");
Antulius 0:9f7581d1af6f 106 }
Antulius 0:9f7581d1af6f 107 }
Antulius 0:9f7581d1af6f 108 /* END main */
Antulius 0:9f7581d1af6f 109
Antulius 0:9f7581d1af6f 110 /*
Antulius 0:9f7581d1af6f 111 ................................................................................
Antulius 0:9f7581d1af6f 112 : Rutinas de los Vectores de Interrupción
Antulius 0:9f7581d1af6f 113 ................................................................................
Antulius 0:9f7581d1af6f 114 */
Antulius 0:9f7581d1af6f 115 // Las Rutinas de Atención a Interrupciones van aquí !
Antulius 0:9f7581d1af6f 116 void TimerInt_OnInterrupt() // Rutina de Atención al Ticker
Antulius 0:9f7581d1af6f 117 {
Antulius 0:9f7581d1af6f 118 counter--; // Aquí va la Rutina de Servicio !
Antulius 0:9f7581d1af6f 119 if (!counter)
Antulius 0:9f7581d1af6f 120 {
Antulius 0:9f7581d1af6f 121 terminal.printf("Counter Finish! \r\n");
Antulius 0:9f7581d1af6f 122 led_monitor = !led_monitor; // Parapadeo del LED por Interrupción (LED Toggled)
Antulius 0:9f7581d1af6f 123 counter = Rate; // Restablece el contador, Le asigna el periodo de 0.5ms (Rate=500)
Antulius 0:9f7581d1af6f 124 }
Antulius 0:9f7581d1af6f 125 }
Antulius 0:9f7581d1af6f 126 /* END Events */
Antulius 0:9f7581d1af6f 127 /*
Antulius 0:9f7581d1af6f 128 ________________________________________________________________________________
Antulius 0:9f7581d1af6f 129 |
Antulius 0:9f7581d1af6f 130 | Funciones Prototipo
Antulius 0:9f7581d1af6f 131 |_______________________________________________________________________________
Antulius 0:9f7581d1af6f 132 */
Antulius 0:9f7581d1af6f 133 // Las Funciones Prototipo van aquí !
Antulius 0:9f7581d1af6f 134 void Blinking_Led() // Software Blinking routine for LED
Antulius 0:9f7581d1af6f 135 {
Antulius 0:9f7581d1af6f 136 // The on-board LED is connected, via a resistor, to +3.3V (not to GND).
Antulius 0:9f7581d1af6f 137 // So to turn the LED on or off we have to set it to 0 or 1 respectively
Antulius 0:9f7581d1af6f 138 led_testigo = 1; // turn the LED on (using Positive Logic)
Antulius 0:9f7581d1af6f 139 wait_ms(200); // 200 millisecond
Antulius 0:9f7581d1af6f 140 led_testigo = 0; // turn the LED off (using Positive Logic)
Antulius 0:9f7581d1af6f 141 wait_ms(1000); // 1000 millisecond
Antulius 0:9f7581d1af6f 142 }
Antulius 0:9f7581d1af6f 143 /* END functions */
Antulius 0:9f7581d1af6f 144
Antulius 0:9f7581d1af6f 145 /* END program */
Antulius 0:9f7581d1af6f 146
Antulius 0:9f7581d1af6f 147 /*+-----------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 148 *+ Conexión al Led Testigo:
Antulius 0:9f7581d1af6f 149 *+
Antulius 0:9f7581d1af6f 150 *+ Los leds se pueden conectar a cualquier pin que se declare como DigitalOut.
Antulius 0:9f7581d1af6f 151 *+ El dispositivo puede drenar hasta 20ma por todas sus salidas a un voltaje de
Antulius 0:9f7581d1af6f 152 *+ 3.3V, pero se recomienda no exceder de 1mA por salida.
Antulius 0:9f7581d1af6f 153 *+ Esto se logra poniendo una resistencia limitadora de mínimo 330 Ohms.
Antulius 0:9f7581d1af6f 154 *+
Antulius 0:9f7581d1af6f 155 *+ 3.3V o 5V
Antulius 0:9f7581d1af6f 156 *+ O
Antulius 0:9f7581d1af6f 157 *+ |
Antulius 0:9f7581d1af6f 158 *+ |
Antulius 0:9f7581d1af6f 159 *+ /
Antulius 0:9f7581d1af6f 160 *+ \ 1K
Antulius 0:9f7581d1af6f 161 *+ /
Antulius 0:9f7581d1af6f 162 *+ \ UTILIZANDO LÓGICA NEGATIVA
Antulius 0:9f7581d1af6f 163 *+ |
Antulius 0:9f7581d1af6f 164 *+ ___|___
Antulius 0:9f7581d1af6f 165 *+ \ /
Antulius 0:9f7581d1af6f 166 *+ \ /
Antulius 0:9f7581d1af6f 167 *+ \ /
Antulius 0:9f7581d1af6f 168 *+ __\/__
Antulius 0:9f7581d1af6f 169 *+ |
Antulius 0:9f7581d1af6f 170 *+ |__________________________ PIN (Digital Out)
Antulius 0:9f7581d1af6f 171 *+
Antulius 0:9f7581d1af6f 172 *+
Antulius 0:9f7581d1af6f 173 *+
Antulius 0:9f7581d1af6f 174 *+
Antulius 0:9f7581d1af6f 175 *+ 1K
Antulius 0:9f7581d1af6f 176 *+
Antulius 0:9f7581d1af6f 177 *+ _________/\ /\ /\ _____ PIN (Digital Out)
Antulius 0:9f7581d1af6f 178 *+ | \/ \/ \/
Antulius 0:9f7581d1af6f 179 *+ |
Antulius 0:9f7581d1af6f 180 *+ |
Antulius 0:9f7581d1af6f 181 *+ ___|___
Antulius 0:9f7581d1af6f 182 *+ \ /
Antulius 0:9f7581d1af6f 183 *+ \ /
Antulius 0:9f7581d1af6f 184 *+ \ / UTILIZANDO LÓGICA POSITIVA
Antulius 0:9f7581d1af6f 185 *+ __\/__
Antulius 0:9f7581d1af6f 186 *+ |
Antulius 0:9f7581d1af6f 187 *+ |
Antulius 0:9f7581d1af6f 188 *+ |
Antulius 0:9f7581d1af6f 189 *+ ___|___
Antulius 0:9f7581d1af6f 190 *+ _____
Antulius 0:9f7581d1af6f 191 *+ ___
Antulius 0:9f7581d1af6f 192 *+ _
Antulius 0:9f7581d1af6f 193 *+
Antulius 0:9f7581d1af6f 194 *+ GND
Antulius 0:9f7581d1af6f 195 *+
Antulius 0:9f7581d1af6f 196 *+----------------------------------------------------------------------------*
Antulius 0:9f7581d1af6f 197 *+
Antulius 0:9f7581d1af6f 198 *+ Powered by
Antulius 0:9f7581d1af6f 199 *+
Antulius 0:9f7581d1af6f 200 *+ T H E A N T U L I U ' S T E A M R&D Unltd
Antulius 0:9f7581d1af6f 201 *+
Antulius 0:9f7581d1af6f 202 *+ Research, Development, Systems, Equipment, Support & Spare Parts.
Antulius 0:9f7581d1af6f 203 *+ (C) Copyright 1989-2019, All Rights Reserved
Antulius 0:9f7581d1af6f 204 *+
Antulius 0:9f7581d1af6f 205 *+ Welcome to The Beaners Proyect Community!
Antulius 0:9f7581d1af6f 206 *+----------------------------------------------------------------------------*/
Antulius 0:9f7581d1af6f 207
Antulius 0:9f7581d1af6f 208 /* END Mbed */