Manejo de liberia "*.h" "*.cpp", clases para el la manejo de salidas en terminal y torre de 8 leds.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
janzaldo
Date:
Sun Jun 21 02:57:50 2020 +0000
Parent:
0:9f7581d1af6f
Commit message:
Please check and comment

Changed in this revision

SysClockConf.cpp Show diff for this revision Revisions of this file
SysClockConf.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
stm32_janzaldo.cpp Show annotated file Show diff for this revision Revisions of this file
stm32_janzaldo.h Show annotated file Show diff for this revision Revisions of this file
stm32f103c8t6.h Show diff for this revision Revisions of this file
--- a/SysClockConf.cpp	Wed Jun 26 18:54:11 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
-  ******************************************************************************
-  * @file    SysClockConf.c
-  * @version 
-  * @date    05-July-2016
-  * @brief   System Clock configuration for STM32F103C8T6
-  *****************************************************************************
-  *
-  * All rights reserved.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
-  */
-
-#include "SysClockConf.h"
-#include "mbed.h"
-
-void HSE_SystemClock_Config(void) {
-    RCC_OscInitTypeDef        RCC_OscInitStruct;
-    RCC_ClkInitTypeDef        RCC_ClkInitStruct;
-    RCC_PeriphCLKInitTypeDef  PeriphClkInit;
-
-    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
-    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
-    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
-    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
-    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
-    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
-    HAL_RCC_OscConfig(&RCC_OscInitStruct);
-    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
-    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
-    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
-    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
-    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
-    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
-    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB;
-    PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
-    PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
-    HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
-}
-
-void confSysClock(void) {
-    HAL_RCC_DeInit();
-    HSE_SystemClock_Config();
-    SystemCoreClockUpdate();
-}
\ No newline at end of file
--- a/SysClockConf.h	Wed Jun 26 18:54:11 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-#pragma once
-void confSysClock(void);
\ No newline at end of file
--- a/main.cpp	Wed Jun 26 18:54:11 2019 +0000
+++ b/main.cpp	Sun Jun 21 02:57:50 2020 +0000
@@ -1,28 +1,28 @@
-/* ###########################################################################
-**    Archivo        : main.c
-**    Proyecto       : STM32-F103C8_Plantilla
-**    Procesador     : STM32F103C8
-**    Herramienta    : Mbed
+/* #############################################################################
+**    Archivo        : main.cpp
+**    Proyecto       : STM32F103C8_Practica 7 POO
+**    Procesador     : STM32F103C8T6
+**    Plataforma     : Blue Pill
+**    Herramienta    : Mbed Compiler
 **    Version        : Driver 01.01
 **    Compilador     : GNU C Compiler
-**    Fecha/Hora     : 14-07-2015, 11:48, # CodeGen: 0
+**    Fecha/Hora     : 20-06-2020, 11:48, # CodeGen: 0
 **    Descripción    :
-**         Este proyecto hace...
-**         This module contains user's application code.
+**         Practica 7 de tarjeta SMET32F103C8
+ **        Utilizando liberia "stm32_janzaldo.h"
+**
 **   Componentes     : GPIO, Timer, etc .
-**   Configuraciones : Includes, Stacks y Drivers externos
+**   Configuraciones : 
 **   Autores         :
-**         ATEAM Development Group:
-**          - Antulio Morgado Valle
+**         ATIC:
+**          - By Jorge Anzaldo
 **
-**   Versión        : Beta
+**   Versión        : 1
 **   Revisión       : A
 **   Release        : 0
 **   Bugs & Fixes   :
-**   Date           : 20/10/2019
-**                    Added support for Led_RGB
-**                    22/09/2018 
-**                    Added LCD Menu, Beta version (with bugs)
+**   Date           : 19/07/2020
+**                    
 **
 ** ###########################################################################*/
 /*
@@ -30,59 +30,7 @@
 :  Includes
 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 */
-#include "mbed.h"
-#include "stm32f103c8t6.h"
-//#include "stm32f10x.h"
-#include "PinNames.h"
-//#include "SysClockConf.h"
-//#include "AnalogIn.h"
-//#include "Led_RGB.h"
-//#include "Serial.h"
-//#include "stdio.h"
-
-/*
-:...............................................................................
-:  Definiciones
-:...............................................................................
-*/
-#define  on             0               // Estado para boton presionado
-#define off             1               // Estado para boton sin presionar
-#define hold            2               // Estado para boton mantenido
-#define release         3               // Estado para boton liberado
-#define Ticker_Rate     1000            // Periodo de interrupción (us)
-/*
-+-------------------------------------------------------------------------------
-|  Configuración de Puertos 
-+-------------------------------------------------------------------------------
-*/
-//confSysClock();     // Configure system clock (72MHz HSE clock, 48MHz USB clock)
-Ticker      TimerInt;               // Inicializa la Interrupción por Timer
-DigitalOut  led_monitor(LED1);      // Inicializa el LED Monitor
-DigitalOut  led_testigo(PA_1);      // Inicializa el LED Testigo
-Serial      terminal(PA_2, PA_3);   // Inicializa la Comunicación Serial a la PC
-PwmOut      servo(PA_7);            // Inicializa el PWM
-AnalogIn    sensor1 (PB_0);         // Inicializa Canal Analógico para sensor 1
-/*
-+-------------------------------------------------------------------------------
-|  Variables Globales de Usuario 
-+-------------------------------------------------------------------------------
-*/
-uint16_t Rate=Ticker_Rate/2;        // Velocidad de barrido (500us = 0.5ms)
-uint16_t counter=250;               // Cuenta inicial de 250us
-/* END variables */
-
-/*
-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-|  Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-*/
-        // Las Definiciones de Funciones Prototipo 
-        // y Apuntadores a Vectores de Interrupciones van aquí !
-void TimerInt_OnInterrupt(void);  
-void Blinking_Led(void);
-/* END prototypes */
-
-/* END definitions */  
+#include "stm32_janzaldo.h"
 /*
 #===============================================================================
 |
@@ -90,119 +38,26 @@
 |
 #=============================================================================== 
 */
-int main()          
-{                           // Inicialización de variables, puertos e interrupciones
-confSysClock();             // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock)
-TimerInt.attach_us(&TimerInt_OnInterrupt, Ticker_Rate);   // Le asigna el periodo de interrupción de 1ms (Ticker_Rate=1000)
-
-terminal.baud(115200);      // Se configura la velocidad de transmisión e inicia la comunicación serial.    
-terminal.printf(" System is Wake Up!.\n\r"); 
-
-    while (true)                // El Lazo del Programa principal está aquí !!!
-    {
-        Blinking_Led();             // Parapadeo del LED por Software
-        servo = sensor1.read();       // 
-        terminal.printf("Blink \r\n");                           
+int main(){   
+    Stm32T Torreta;  // Creamos el objeto Torreta de la clase Stm32T
+    Torreta.Lp();    // limpiar pantalla
+    Torreta.Pausa();  // Pausa - oprimir una tecla para continuar.
+    Torreta.Mensaje("\t\t >>> Uso de liberia stm32_janzaldo <<< ");
+    Torreta.Mensaje("\t Manejando 8 LED's como una torreta ");
+    Torreta.Mensaje("\t by Jorge Anzaldo ");
+    while(true){
+       for(int i=0;i<4;i++){
+           Torreta.Testigo(true);
+           Torreta.Ascendente();
+           Torreta.Testigo(false);
+           Torreta.Descendente();
+       }
+       for(int i=0;i<2;i++){
+           Torreta.Testigo(true);
+           Torreta.Adentro();
+           Torreta.Testigo(false);
+           Torreta.Afuera(); 
+        }
     }
 }
-/* END main */
-
-/*
-................................................................................
-:  Rutinas de los Vectores de Interrupción
-................................................................................
-*/
-                // Las Rutinas de Atención a Interrupciones van aquí !
-void TimerInt_OnInterrupt()          // Rutina de Atención al Ticker
-{
-    counter--;                      // Aquí va la Rutina de Servicio !
-    if (!counter)
-    {
-        terminal.printf("Counter Finish! \r\n");
-        led_monitor = !led_monitor; // Parapadeo del LED por Interrupción (LED Toggled)
-        counter = Rate;           // Restablece el contador, Le asigna el periodo de 0.5ms (Rate=500)
-    } 
-}
-/* END Events */   
-/*
-________________________________________________________________________________
-|
-|  Funciones Prototipo
-|_______________________________________________________________________________
-*/
-                // Las Funciones Prototipo van aquí !
-void Blinking_Led()             // Software Blinking routine for LED 
-{
-        // The on-board LED is connected, via a resistor, to +3.3V (not to GND). 
-        // So to turn the LED on or off we have to set it to 0 or 1 respectively
-    led_testigo = 1;        // turn the LED on (using Positive Logic)
-    wait_ms(200);           // 200 millisecond
-    led_testigo = 0;        // turn the LED off (using Positive Logic)
-    wait_ms(1000);          // 1000 millisecond
-}
-/* END functions */    
-                
-/* END program */
-
-/*+-----------------------------------------------------------------------------       
-*+  Conexión al Led Testigo:
-*+ 
-*+  Los leds se pueden conectar a cualquier pin que se declare como DigitalOut. 
-*+  El dispositivo puede drenar hasta 20ma por todas sus salidas a un voltaje de 
-*+  3.3V, pero se recomienda no exceder de 1mA por salida.
-*+  Esto se logra poniendo una resistencia limitadora de mínimo 330 Ohms.
-*+  
-*+    3.3V o 5V
-*+       O
-*+       |
-*+       |
-*+       /
-*+       \   1K
-*+       /
-*+       \                         UTILIZANDO LÓGICA NEGATIVA
-*+       |
-*+    ___|___
-*+    \      /
-*+     \    /
-*+      \  /
-*+     __\/__
-*+       |
-*+       |__________________________  PIN (Digital Out)
-*+
-*+      
-*+      
-*+       
-*+                    1K
-*+                   
-*+        _________/\  /\  /\  _____    PIN (Digital Out)
-*+       |           \/  \/  \/
-*+       |      
-*+       |
-*+    ___|___
-*+    \      /
-*+     \    /
-*+      \  /                       UTILIZANDO LÓGICA POSITIVA
-*+     __\/__
-*+       |
-*+       |
-*+       |
-*+    ___|___
-*+     _____
-*+      ___
-*+       _
-*+
-*+      GND
-*+
-*+----------------------------------------------------------------------------*
-*+
-*+   Powered by
-*+
-*+          T H E     A N T U L I U ' S   T E A M   R&D  Unltd 
-*+
-*+  Research, Development, Systems, Equipment, Support & Spare Parts.
-*+  (C) Copyright 1989-2019, All Rights Reserved            
-*+
-*+  Welcome to The Beaners Proyect Community!                   
-*+----------------------------------------------------------------------------*/
-
-/* END Mbed */ 
\ No newline at end of file
+/* FIN main - Programa principal */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stm32_janzaldo.cpp	Sun Jun 21 02:57:50 2020 +0000
@@ -0,0 +1,107 @@
+#include "mbed.h"
+#include "PinNames.h"
+#include "stm32_janzaldo.h"
+/*
+:...............................................................................
+:  Definiciones  by Jorge Anzaldo 
+:...............................................................................
+*/
+/*
++-------------------------------------------------------------------------------
+|  Configuración de Puertos 
++-------------------------------------------------------------------------------
+*/
+
+DigitalOut  led_monitor(LED1);      // Inicializa el LED Monitor
+DigitalOut  led_testigo(PB_1);      // Inicializa el LED Testigo
+
+BusOut Salida(PA_8,PA_9,PA_10,PA_11, PB_4, PB_5, PB_6, PB_7); // Identificando LED's
+
+Serial      terminal(PA_2, PA_3);  // Inicializa la Comunicación Serial a la PC
+
+/*
++-------------------------------------------------------------------------------
+|  Variables Globales de Usuario 
++-------------------------------------------------------------------------------
+*/
+int tiempo = 100;
+
+/* FIN Definiciones*/  
+/*
++-------------------------------------------------------------------------------
+|  Desarrollo de metodos / funciones miembro de las clases
++-------------------------------------------------------------------------------
+*/
+Stm32::Stm32(void){
+    terminal.baud(115200);    
+    led_monitor=0;   
+    terminal.printf("\r\n\t\t >>> Terminal Conectada <<< \r\n");  
+}
+void Stm32::Lp(void){
+    printf("\033[2J"); // limpiar   
+}
+void Stm32::Mensaje(const char *txt){
+    terminal.printf("\r\n %s \r\n",txt); 
+}
+void Stm32::Pausa(void){
+    terminal.printf("\r\n Oprime cualquier tecla para continuar \r\n"); 
+    getchar();
+}
+void Stm32::Testigo(bool status){
+    if(status){ led_testigo=1;}
+    else{led_testigo=0;}}
+void Stm32::Intermitente(int veces){
+    int i=0;
+    while(i<veces){
+        Testigo(true);
+        wait_ms(200);
+        Testigo(false);
+        wait_ms(200);
+        i++;
+    }
+}
+void Stm32::Leer(const char *txt, int &valor){
+    terminal.printf("\r\n %s ",txt); 
+    terminal.scanf("%d",&valor);
+}
+void Stm32::Ver(const char *txt, int valor){
+    terminal.printf("\r\n %s %d",txt,valor); 
+}
+void Stm32T::Encender(int v){
+    Salida[v]=1; 
+    wait_ms(tiempo);  
+}
+void Stm32T::Apagar(int v){
+    Salida[v]=0;
+}
+void Stm32T::Ascendente(void){
+    for(int i=0;i<8;i++){
+        Encender(i);
+        Apagar(i);
+    }
+}
+void Stm32T::Descendente(void){
+    for(int i=7;i>=0;i--){
+        Encender(i);
+        Apagar(i);
+    }    
+}
+void Stm32T::Afuera(void){
+    for(int i=3,j=4;i>=0;i--,j++){
+        Encender(i);
+        Encender(j);
+        wait_ms(tiempo);
+    }
+    Salida=0;
+  
+}
+void Stm32T::Adentro(void){
+    for(int i=0,j=7;i<4;i++,j--){
+        Encender(i);
+        Encender(j);
+        wait_ms(tiempo);
+    }
+    Salida=0;
+    
+}
+/* FIN */  
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stm32_janzaldo.h	Sun Jun 21 02:57:50 2020 +0000
@@ -0,0 +1,34 @@
+/*
+:...............................................................................
+:  Definiciones de clases  by Jorge Anzaldo 
+:...............................................................................
+*/
+#ifndef PRUEBA_H
+#define PRUEBA_H
+class Stm32{    // Clase Stm32
+    private:
+    
+    public:
+        Stm32(void);                // Construcor por default
+        void Mensaje(const char  *);
+        void Pausa(void);
+        void Testigo(bool);
+        void Intermitente(int); 
+        void Leer(const char *, int &);
+        void Ver(const char *, int );
+        void Lp(void);
+};
+
+class Stm32T: public Stm32{
+    private:
+    
+    public:
+        void Encender(int);
+        void Apagar(int);
+        void Ascendente();
+        void Descendente();
+        void Adentro();
+        void Afuera();
+};
+#endif 
+/* FIN */  
\ No newline at end of file
--- a/stm32f103c8t6.h	Wed Jun 26 18:54:11 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-#pragma once
-#include "PinNames.h"
-#include "SysClockConf.h"
-