OBJETIVO
Desarrollar un programa que muestre los siete colores (black, red, green, ambar, blue, magenta, cyan, white) imprima en pantalla el color que se observe.
DESCRIPCIÓN DEL PROGRAMA
En el programa principal dentro de while(1) se llama a las funciones LED_RGB (color), Printf_Color (color) y delay(), que son las encargadas de hacer las combinaciones para generar los colores, mandar a imprimir en pantalla el color que se esté observando y el retardo para poder visualizar el cambio en los colores, respectivamente.
Dentro de este bucle se incrementa la variable color (color++), si color es mayor a siete o a White entonces color se hace cero o black y comienza nuevamente el conteo.
Código.
#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "rgb.h"
int color = BLUE;
/*!
* @brief Application entry point.
*/
void delay(void)
{
volatile uint32_t i = 0;
for (i = 0; i < 9624060; ++i)
{
__asm("NOP"); /* delay */
}
}
int main(void) {
/* Init board hardware. */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
/* Add your code here */
Ini_RGB();
while(1)
{
LED_RGB (color);
Printf_Color(color);
delay();
color++;
if(color>WHITE){
color=BLACK;
}
}
}
#ifndef SOURCE_RGB_H_
#define SOURCE_RGB_H_
#include <string.h>
#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_debug_console.h"
#include "fsl_device_registers.h"
#include "fsl_port.h"
enum {RED_BIT=1,GREEN_BIT=2,BLUE_BIT=4};
enum {BLACK,RED,GREEN,AMBAR,BLUE,MAGENTA,CYAN,WHITE};
void Ini_RGB(void);
void LED_RGB(int);
void Printf_Color( int cont);
#endif /* SOURCE_RGB_H_ */
#include "rgb.h"
void Ini_RGB(void)
{
// Enable the clock to the PORT module that the LED is on.
CLOCK_EnableClock(kCLOCK_PortB);
// Setup the red LED pin as GPIO
PORT_SetPinMux(BOARD_LED_RED_GPIO_PORT,
BOARD_LED_RED_GPIO_PIN,
kPORT_MuxAsGpio);
LED_RED_INIT(LOGIC_LED_OFF);
// Setup the blue LED pin as GPIO
PORT_SetPinMux(BOARD_LED_BLUE_GPIO_PORT,
BOARD_LED_BLUE_GPIO_PIN,
kPORT_MuxAsGpio);
LED_BLUE_INIT(LOGIC_LED_OFF);
CLOCK_EnableClock(kCLOCK_PortE);
// Setup the green LED pin as GPIO
PORT_SetPinMux(BOARD_LED_GREEN_GPIO_PORT,
BOARD_LED_GREEN_GPIO_PIN,
kPORT_MuxAsGpio);
LED_GREEN_INIT(LOGIC_LED_OFF);
}
void LED_RGB(int color)
{
if(color&RED_BIT)
LED_RED_ON();
else
LED_RED_OFF();
if(color&GREEN_BIT)
LED_GREEN_ON();
else
LED_GREEN_OFF();
if(color&BLUE_BIT)
LED_BLUE_ON();
else
LED_BLUE_OFF();
}
void Printf_Color( int color)
{
char *color_names[] = {"Black","Red","Green","Yellow","Blue","Magenta","Cyan","White"};
char *aux_pointer =color_names[color];
PRINTF("Color Led %s\r\n",aux_pointer);
}
a continuación se muestra la operación del programa.
No hay comentarios:
Publicar un comentario