plantilla mejorada

Dependencies:   mbed

Committer:
Antulius
Date:
Fri Sep 06 19:35:20 2019 +0000
Revision:
2:ed30bbd12e22
Parent:
1:c0ed6c52c441
Plantilla para la STM32F103C8T6 "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 1:c0ed6c52c441 33 #include "stm32f103c8t6.h"
Antulius 0:9f7581d1af6f 34 #include "mbed.h"
Antulius 0:9f7581d1af6f 35 //#include "AnalogIn.h"
Antulius 0:9f7581d1af6f 36 //#include "Led_RGB.h"
Antulius 1:c0ed6c52c441 37 #include "Serial.h"
Antulius 0:9f7581d1af6f 38 //#include "stdio.h"
Antulius 0:9f7581d1af6f 39
Antulius 0:9f7581d1af6f 40 /*
Antulius 0:9f7581d1af6f 41 :...............................................................................
Antulius 0:9f7581d1af6f 42 : Definiciones
Antulius 0:9f7581d1af6f 43 :...............................................................................
Antulius 0:9f7581d1af6f 44 */
Antulius 0:9f7581d1af6f 45 #define on 0 // Estado para boton presionado
Antulius 0:9f7581d1af6f 46 #define off 1 // Estado para boton sin presionar
Antulius 0:9f7581d1af6f 47 #define hold 2 // Estado para boton mantenido
Antulius 0:9f7581d1af6f 48 #define release 3 // Estado para boton liberado
Antulius 1:c0ed6c52c441 49 #define FALSE 0 // Estado FALSO
Antulius 1:c0ed6c52c441 50 #define TRUE 1 // Estado VERDADERO
Antulius 0:9f7581d1af6f 51 #define Ticker_Rate 1000 // Periodo de interrupción (us)
Antulius 0:9f7581d1af6f 52 /*
Antulius 0:9f7581d1af6f 53 +-------------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 54 | Configuración de Puertos
Antulius 0:9f7581d1af6f 55 +-------------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 56 */
Antulius 0:9f7581d1af6f 57 //confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock)
Antulius 0:9f7581d1af6f 58 Ticker TimerInt; // Inicializa la Interrupción por Timer
Antulius 0:9f7581d1af6f 59 DigitalOut led_monitor(LED1); // Inicializa el LED Monitor
Antulius 1:c0ed6c52c441 60 DigitalOut led_testigo(PB_1); // Inicializa el LED Testigo
Antulius 0:9f7581d1af6f 61 Serial terminal(PA_2, PA_3); // Inicializa la Comunicación Serial a la PC
Antulius 0:9f7581d1af6f 62 PwmOut servo(PA_7); // Inicializa el PWM
Antulius 0:9f7581d1af6f 63 AnalogIn sensor1 (PB_0); // Inicializa Canal Analógico para sensor 1
Antulius 0:9f7581d1af6f 64 /*
Antulius 0:9f7581d1af6f 65 +-------------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 66 | Variables Globales de Usuario
Antulius 0:9f7581d1af6f 67 +-------------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 68 */
Antulius 0:9f7581d1af6f 69 uint16_t Rate=Ticker_Rate/2; // Velocidad de barrido (500us = 0.5ms)
Antulius 0:9f7581d1af6f 70 uint16_t counter=250; // Cuenta inicial de 250us
Antulius 0:9f7581d1af6f 71 /* END variables */
Antulius 0:9f7581d1af6f 72
Antulius 0:9f7581d1af6f 73 /*
Antulius 0:9f7581d1af6f 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antulius 0:9f7581d1af6f 75 | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
Antulius 0:9f7581d1af6f 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antulius 0:9f7581d1af6f 77 */
Antulius 0:9f7581d1af6f 78 // Las Definiciones de Funciones Prototipo
Antulius 0:9f7581d1af6f 79 // y Apuntadores a Vectores de Interrupciones van aquí !
Antulius 0:9f7581d1af6f 80 void TimerInt_OnInterrupt(void);
Antulius 0:9f7581d1af6f 81 void Blinking_Led(void);
Antulius 0:9f7581d1af6f 82 /* END prototypes */
Antulius 0:9f7581d1af6f 83
Antulius 0:9f7581d1af6f 84 /* END definitions */
Antulius 0:9f7581d1af6f 85 /*
Antulius 0:9f7581d1af6f 86 #===============================================================================
Antulius 0:9f7581d1af6f 87 |
Antulius 0:9f7581d1af6f 88 | P R O G R A M A P R I N C I P A L
Antulius 0:9f7581d1af6f 89 |
Antulius 0:9f7581d1af6f 90 #===============================================================================
Antulius 0:9f7581d1af6f 91 */
Antulius 0:9f7581d1af6f 92 int main()
Antulius 0:9f7581d1af6f 93 { // Inicialización de variables, puertos e interrupciones
Antulius 0:9f7581d1af6f 94 confSysClock(); // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock)
Antulius 0:9f7581d1af6f 95 TimerInt.attach_us(&TimerInt_OnInterrupt, Ticker_Rate); // Le asigna el periodo de interrupción de 1ms (Ticker_Rate=1000)
Antulius 0:9f7581d1af6f 96
Antulius 0:9f7581d1af6f 97 terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial.
Antulius 0:9f7581d1af6f 98 terminal.printf(" System is Wake Up!.\n\r");
Antulius 0:9f7581d1af6f 99
Antulius 0:9f7581d1af6f 100 while (true) // El Lazo del Programa principal está aquí !!!
Antulius 0:9f7581d1af6f 101 {
Antulius 0:9f7581d1af6f 102 Blinking_Led(); // Parapadeo del LED por Software
Antulius 0:9f7581d1af6f 103 servo = sensor1.read(); //
Antulius 0:9f7581d1af6f 104 terminal.printf("Blink \r\n");
Antulius 0:9f7581d1af6f 105 }
Antulius 0:9f7581d1af6f 106 }
Antulius 0:9f7581d1af6f 107 /* END main */
Antulius 0:9f7581d1af6f 108
Antulius 0:9f7581d1af6f 109 /*
Antulius 0:9f7581d1af6f 110 ................................................................................
Antulius 0:9f7581d1af6f 111 : Rutinas de los Vectores de Interrupción
Antulius 0:9f7581d1af6f 112 ................................................................................
Antulius 0:9f7581d1af6f 113 */
Antulius 0:9f7581d1af6f 114 // Las Rutinas de Atención a Interrupciones van aquí !
Antulius 0:9f7581d1af6f 115 void TimerInt_OnInterrupt() // Rutina de Atención al Ticker
Antulius 0:9f7581d1af6f 116 {
Antulius 0:9f7581d1af6f 117 counter--; // Aquí va la Rutina de Servicio !
Antulius 0:9f7581d1af6f 118 if (!counter)
Antulius 0:9f7581d1af6f 119 {
Antulius 0:9f7581d1af6f 120 terminal.printf("Counter Finish! \r\n");
Antulius 0:9f7581d1af6f 121 led_monitor = !led_monitor; // Parapadeo del LED por Interrupción (LED Toggled)
Antulius 0:9f7581d1af6f 122 counter = Rate; // Restablece el contador, Le asigna el periodo de 0.5ms (Rate=500)
Antulius 0:9f7581d1af6f 123 }
Antulius 0:9f7581d1af6f 124 }
Antulius 0:9f7581d1af6f 125 /* END Events */
Antulius 0:9f7581d1af6f 126 /*
Antulius 0:9f7581d1af6f 127 ________________________________________________________________________________
Antulius 0:9f7581d1af6f 128 |
Antulius 0:9f7581d1af6f 129 | Funciones Prototipo
Antulius 0:9f7581d1af6f 130 |_______________________________________________________________________________
Antulius 0:9f7581d1af6f 131 */
Antulius 0:9f7581d1af6f 132 // Las Funciones Prototipo van aquí !
Antulius 0:9f7581d1af6f 133 void Blinking_Led() // Software Blinking routine for LED
Antulius 0:9f7581d1af6f 134 {
Antulius 0:9f7581d1af6f 135 // The on-board LED is connected, via a resistor, to +3.3V (not to GND).
Antulius 0:9f7581d1af6f 136 // So to turn the LED on or off we have to set it to 0 or 1 respectively
Antulius 0:9f7581d1af6f 137 led_testigo = 1; // turn the LED on (using Positive Logic)
Antulius 0:9f7581d1af6f 138 wait_ms(200); // 200 millisecond
Antulius 0:9f7581d1af6f 139 led_testigo = 0; // turn the LED off (using Positive Logic)
Antulius 0:9f7581d1af6f 140 wait_ms(1000); // 1000 millisecond
Antulius 0:9f7581d1af6f 141 }
Antulius 0:9f7581d1af6f 142 /* END functions */
Antulius 0:9f7581d1af6f 143
Antulius 0:9f7581d1af6f 144 /* END program */
Antulius 0:9f7581d1af6f 145
Antulius 0:9f7581d1af6f 146 /*+-----------------------------------------------------------------------------
Antulius 1:c0ed6c52c441 147 *+ La documentación va aquí!:
Antulius 1:c0ed6c52c441 148 *+-----------------------------------------------------------------------------
Antulius 0:9f7581d1af6f 149 *+ Conexión al Led Testigo:
Antulius 0:9f7581d1af6f 150 *+
Antulius 0:9f7581d1af6f 151 *+ Los leds se pueden conectar a cualquier pin que se declare como DigitalOut.
Antulius 0:9f7581d1af6f 152 *+ El dispositivo puede drenar hasta 20ma por todas sus salidas a un voltaje de
Antulius 0:9f7581d1af6f 153 *+ 3.3V, pero se recomienda no exceder de 1mA por salida.
Antulius 0:9f7581d1af6f 154 *+ Esto se logra poniendo una resistencia limitadora de mínimo 330 Ohms.
Antulius 0:9f7581d1af6f 155 *+
Antulius 0:9f7581d1af6f 156 *+ 3.3V o 5V
Antulius 0:9f7581d1af6f 157 *+ O
Antulius 0:9f7581d1af6f 158 *+ |
Antulius 0:9f7581d1af6f 159 *+ |
Antulius 0:9f7581d1af6f 160 *+ /
Antulius 0:9f7581d1af6f 161 *+ \ 1K
Antulius 0:9f7581d1af6f 162 *+ /
Antulius 0:9f7581d1af6f 163 *+ \ UTILIZANDO LÓGICA NEGATIVA
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 *+ |
Antulius 0:9f7581d1af6f 171 *+ |__________________________ PIN (Digital Out)
Antulius 0:9f7581d1af6f 172 *+
Antulius 0:9f7581d1af6f 173 *+
Antulius 0:9f7581d1af6f 174 *+
Antulius 0:9f7581d1af6f 175 *+
Antulius 0:9f7581d1af6f 176 *+ 1K
Antulius 0:9f7581d1af6f 177 *+
Antulius 0:9f7581d1af6f 178 *+ _________/\ /\ /\ _____ PIN (Digital Out)
Antulius 0:9f7581d1af6f 179 *+ | \/ \/ \/
Antulius 0:9f7581d1af6f 180 *+ |
Antulius 0:9f7581d1af6f 181 *+ |
Antulius 0:9f7581d1af6f 182 *+ ___|___
Antulius 0:9f7581d1af6f 183 *+ \ /
Antulius 0:9f7581d1af6f 184 *+ \ /
Antulius 0:9f7581d1af6f 185 *+ \ / UTILIZANDO LÓGICA POSITIVA
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 *+
Antulius 0:9f7581d1af6f 195 *+ GND
Antulius 0:9f7581d1af6f 196 *+
Antulius 0:9f7581d1af6f 197 *+----------------------------------------------------------------------------*
Antulius 0:9f7581d1af6f 198 *+
Antulius 0:9f7581d1af6f 199 *+ Powered by
Antulius 0:9f7581d1af6f 200 *+
Antulius 0:9f7581d1af6f 201 *+ T H E A N T U L I U ' S T E A M R&D Unltd
Antulius 0:9f7581d1af6f 202 *+
Antulius 0:9f7581d1af6f 203 *+ Research, Development, Systems, Equipment, Support & Spare Parts.
Antulius 0:9f7581d1af6f 204 *+ (C) Copyright 1989-2019, All Rights Reserved
Antulius 0:9f7581d1af6f 205 *+
Antulius 0:9f7581d1af6f 206 *+ Welcome to The Beaners Proyect Community!
Antulius 0:9f7581d1af6f 207 *+----------------------------------------------------------------------------*/
Antulius 0:9f7581d1af6f 208
Antulius 0:9f7581d1af6f 209 /* END Mbed */