Plantilla para la Tarjeta FRDM-KL46Z

Dependencies:   mbed

Committer:
Antulius
Date:
Tue Jun 25 17:49:37 2019 +0000
Revision:
9:e9eddd66920e
Parent:
8:6e3526d25aeb
Plantilla para la Tarjeta FRDM-KL46Z

Who changed what in which revision?

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