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