Plantilla para la Tarjeta FRDM-KL25Z

Dependencies:   mbed

main.cpp

Committer:
Antulius
Date:
2019-06-26
Revision:
0:f52ce5a32dbc

File content as of revision 0:f52ce5a32dbc:

/* ###########################################################################
**    Archivo        : main.c
**    Proyecto       : FRDM-KL25Z_Plantilla
**    Procesador     : MKL25Z128VLK4
**    Herramienta    : Mbed
**    Version        : Driver 01.01
**    Compilador     : GNU C Compiler
**    Fecha/Hora     : 14-07-2015, 11:48, # CodeGen: 0
**    Descripción    :
**         Este proyecto hace...
**         This module contains user's application code.
**   Componentes     : GPIO, Timer, etc .
**   Configuraciones : Includes, Stacks y Drivers externos
**   Autores         :
**         ATEAM Development Group:
**          - Antulio Morgado Valle
**
**   Versión        : Beta
**   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)
**
** ###########################################################################*/
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:  Includes
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/
#include "mbed.h"

/*
:...............................................................................
:  Definiciones
:...............................................................................
*/
#define Ticker_Rate     1000            // Periodo de interrupción (us)
/*
+-------------------------------------------------------------------------------
|  Configuración de Puertos 
+-------------------------------------------------------------------------------
*/
Ticker      TimerInt;               // Inicializa la Interrupción por Timer
DigitalOut  led_monitor(LED1);      // Inicializa el LED Monitor
DigitalOut  led_testigo(LED2);      // Inicializa el LED Testigo
PwmOut      servo(PTE22);           // Inicializa el PWM
AnalogIn    sensor1 (PTB0);         // Inicializa Canal Analógico para sensor 1
Serial      terminal(USBTX, USBRX); // Inicializa la Comunicación Serial a la PC
/*
+-------------------------------------------------------------------------------
|  Variables Globales de Usuario 
+-------------------------------------------------------------------------------
*/
uint16_t Rate=Ticker_Rate/2;        // Velocidad de barrido (500us = 0.5ms)
uint16_t counter=250;               // Cuenta inicial de 250us
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|  Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
void TimerInt_OnInterrupt(void);  
void Blinking_Led(void); 
/* END Prototypes */

/* END Definitions */ 

/*
#===============================================================================
|
|               P R O G R A M A     P R I N C I P A L
|
#=============================================================================== 
*/
int main()
{
                // Inicialización de variables, puertos e interrupciones
TimerInt.attach_us(&TimerInt_OnInterrupt, Rate);   // Le asigna el periodo de Interrupción de 1ms (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");                           
    }
}
/* END main */

/*
................................................................................
:  Rutinas de los Vectores de Interrupción
................................................................................
*/
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 (Toggle the LED)
        counter = Rate;             // Restablece el contador
    } 
}
/* 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
        wait_ms(200);           // 200 millisecond
        led_testigo = 0;        // turn the LED off
        wait_ms(1000);          // 1000 millisecond
}
/* END Funtions */

/* 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 */