Example #1
0
int main(void)
{
Puerto_inicia();
Led_inicia();
InicializarTeclas();
UART_Init();
ADC_Init();

int tecla;
int old_tecla=0;
while(1) {
  tecla = EscanearTeclado();

  if(tecla!=old_tecla) {
  switch(tecla) {
	case 1:
			Led_invierte(LED_1);
			EnviarCadena();
			break;
			    }

  old_tecla=tecla;
  }

}
return 0;
}
Example #2
0
int main(void)
{
   	Puerto_inicia();
	Led_inicia();
	InicializarTeclas();
    DAC_Init();
    timer_interrupcion(1);

   while(1) {
   }
   return 0;
}
Example #3
0
int main(void)
{
	int valor_Analogico;

   /* perform the needed initialization here */
   /*Inicializa los Leds*/
   InicializarLeds();
   /*Inicaliza Teclado*/
   InicializarTeclas();
   /*Inicaliza Timer*/
   InicializarTimer();
   /*Inicializa conADC*/
   InicializarADC();
   /*Configurar tiempo 250mseg*/
   ConfigurarTiempo(750);
   /*Habilita interrupcion*/
   SetInterrup();

   while(1) {
      /* add your code here */
	   valor_Analogico= EntradaADC();
	   if (valor_Analogico>800){
		   PrenderLed(LED3);
		    ApagarLed(LED2);
		   /*ApagarLed(LED3);*/
	   }
	   /*if (valor_Analogico<900){
		   	   	   PrenderLed(LED3);
	   	   		   ApagarLed(LED1);
	   	   		   ApagarLed(LED2);
	   	   	   }*/

	    if (valor_Analogico<30){
		   PrenderLed(LED2);
		    ApagarLed(LED3);
		   /*ApagarLed(LED3);*/
	    }
	    /*if (valor_Analogico>40){
	   		   PrenderLed(LED3);
	   		   ApagarLed(LED1);
	   		   ApagarLed(LED2);
	   	   }*/
	     }
   return 0;
}
int main(void)
{
   /* perform the needed initialization here */
	uint8_t INICIOLEDS;
	uint8_t INICIOTECLAS;
	uint8_t INICIOTIMERS;
	uint8_t ESTADOESCANEO;


	//VARIABLES DE TECLAS
	uint8_t PRENDIDO = 1;
	uint8_t APAGADO = 0;
	uint8_t PULSADO = 0;
	uint8_t NO_PULSADO = 1;


	//Instancaimos el struc de TECLAS
	TECLAS_1_2_3_4 TECLAS;

	//Inicializamos los puertos de TECLAS
	INICIOTECLAS = InicializarTeclas();

	//----------------------------------
	//VARIABLES DEL TIMER RTI
	uint32_t DURACION_DEL_CICLO_COLOR=100;//Es una variable que se usa para determina cuantas cuentas del RTI dura un ciclo del color. En este caso la duración de un color es igual a 100 cuentas del RTI
	uint32_t TIEMPO_TIMER_RTI=1;//Tiempo en milisegundo del contador RTI
	uint32_t Cuenata_color=0;//Es una variable que cuenta la cantidad de ciclos que se va a mostrar un color determinado
	uint32_t TIEMPO_DEL_COLOR=5;//Es una variable que determina el tiempo total que va a durar un color. Se determina con la cantidad de ciclos que se va a mostrar de un color

	//Inicializamos los TIMERS y definimos el intervalo
	INICIOTIMERS = InicializarTimers();

	DefinirIntervaloRTI(TIEMPO_TIMER_RTI);


	//----------------------------------
	//VARIABLES DE LEDS
	//Inicializamos los puertos de LED
	INICIOLEDS = inicializarPuertos();

	//Instancaimos el struc de LED
	LED_1_2_3_RGB LEDS;

	//VARIABLES DEL RGB
	//Instancaimos el struc de COLORES DE RGB
	COLORES_LEDRGB COLORES_RGB;
	GenerarColoresRGB();

	//DEFINIMOS LOS INTERVALOS DE TIEMPO INICIALES QUE LO VAMOS A DEJAR PRENDIDO A CADA COLOR DEL RGB

	COLORES_RGB.color_ledR=DURACION_DEL_CICLO_COLOR;
	COLORES_RGB.color_ledG=DURACION_DEL_CICLO_COLOR;
	COLORES_RGB.color_ledB=DURACION_DEL_CICLO_COLOR;

	//----------------------------------

	do
	{//GENERAMOS EL ARCOIRIS
		if(!EstadoTecla(TEC1))
		{

			do
			{
				//Seleccionamos lo que vamos a cambiar de estado. En este caso los tres R-G-B
				LEDS.ledR = PRENDIDO;
				LEDS.ledG = PRENDIDO;
				LEDS.ledB = PRENDIDO;
				LEDS.LED_UNO = APAGADO;
				LEDS.LED_DOS = APAGADO;
				LEDS.LED_TRES = APAGADO;

				//CAMBIAMOS EL ESTAD
				cambiarEstado(&LEDS);

				//INICIALIZAMOS a CERO EL CONTADOR DEL TIMER
				SetContadorRGB(CERO);

				//ARRANCAMOS UN CICLO DE COLOR EL CUAL DURA UNA CANTIDAD IGUAL A DURACION_DEL_CICLO_COLOR. EN ESTE CASO SE DEFINIO EN 100 mseg

				//Obtenemos el valor del contador
				uint32_t tiempoPrendido = GetContadorRGB();

				do
				{
					tiempoPrendido = GetContadorRGB();

					if(COLORES_RGB.color_ledR <= tiempoPrendido)
					{
						apagarLed(LEDR);
					}
					if(COLORES_RGB.color_ledG <= tiempoPrendido)
					{
						apagarLed(LEDG);
					}
					if(COLORES_RGB.color_ledB <= tiempoPrendido)
					{
						apagarLed(LEDB);
					}
				}
				while(tiempoPrendido<=DURACION_DEL_CICLO_COLOR);

				//LUEGO DE CUMPLIDO UN CICLO DE VISUALIZACIÓN DE UN COLOR

				//Aumentamos el contador de ciclos
				Cuenata_color++;

			}while(TIEMPO_DEL_COLOR>=Cuenata_color);

			//INICIALIZAMOS A CERO EL CONTADOR DE COLOR
			Cuenata_color=CERO;
			//CAMBIAMOS EL COLOR, MEDIANTE EL CAMBIO DE LA DURACIÓN DE LOS RGB
			CambiarColorRGB(&COLORES_RGB,DURACION_DEL_CICLO_COLOR);
		}
		else
		{
			//Seleccionamos el que vamos a cambiar de estado. PRIMERO EL LED1
			LEDS.ledR = APAGADO;
			LEDS.ledG = APAGADO;
			LEDS.ledB = APAGADO;
			LEDS.LED_UNO = PRENDIDO;
			LEDS.LED_DOS = APAGADO;
			LEDS.LED_TRES = APAGADO;

			//CAMBIAMOS EL LED1
			cambiarEstado(&LEDS );

			//Esperamos un intervalo


			SetContadorRGB(CERO);

			uint32_t INTERVALO=250;//Definimos un intervalo de 250 milisegundos entre el ensendido de cada color

			uint32_t tiempoDeEspera = CERO;

			do
			{
				tiempoDeEspera= GetContadorRGB();
			}
			while(tiempoDeEspera<INTERVALO);
			//Apagamos el LED1
			apagarLed(LED1);

			//Seleccionamos el SIGUEINTE, EL LED2
			LEDS.ledR = APAGADO;
			LEDS.ledG = APAGADO;
			LEDS.ledB = APAGADO;
			LEDS.LED_UNO = APAGADO;
			LEDS.LED_DOS = PRENDIDO;
			LEDS.LED_TRES = APAGADO;

			//CAMBIAMOS EL LED2
			cambiarEstado(&LEDS );

			//Esperamos otro intervalo de 250 ms
			SetContadorRGB(CERO);

			do
			{
				tiempoDeEspera= GetContadorRGB();
			}
			while(tiempoDeEspera<INTERVALO);
			//Apagamos el LED2
			apagarLed(LED2);
		}

	}while(1);

}
int main(void)
{
	uint8_t LedSelecionado = 1;
	int8_t Periodo = 0;
		/* perform the needed initialization here */
		InicializarLeds();
		InicializarTeclas();
		InicializarTimer(250);

		while(1){
			/* Consigna 3.1 b) */
			if(LeerTecla(TECLA1)){
				delayNoelegante(MAXDELAY);
				LedSelecionado--;
				if(LedSelecionado == 0) LedSelecionado = 4;
			}
			if(LeerTecla(TECLA2)){
				delayNoelegante(MAXDELAY);
				LedSelecionado ++;
				if(LedSelecionado == 5) LedSelecionado = 1;
			}
			if(LeerTecla(TECLA3)){
				delayNoelegante(MAXDELAY);
				Periodo -=2;
				if(Periodo == -200) Periodo = -200; // SAturacion de seguridad
				InicializarTimer(250 + Periodo);
			}
			if(LeerTecla(TECLA4)){
				delayNoelegante(MAXDELAY);
				Periodo +=2;
				if(Periodo == 200) Periodo = 200; // SAturacion de seguridad
				InicializarTimer(250 + Periodo);
			}
			if (FlagCounter == 1){
				FlagCounter =0;
				switch(LedSelecionado){
				case 1:
					ToogleLed(LED0R);
					ApagaLed(LED1);
					ApagaLed(LED2);
					ApagaLed(LED3);
					ApagaLed(LED0G);
					break;
				case 2:
					ToogleLed(LED1);
					ApagaLed(LED0R);
					ApagaLed(LED2);
					ApagaLed(LED3);
					ApagaLed(LED0G);
					break;
				case 3:
					ToogleLed(LED2);
					ApagaLed(LED1);
					ApagaLed(LED0R);
					ApagaLed(LED3);
					ApagaLed(LED0G);
					break;
				case 4:
					ToogleLed(LED3);
					ApagaLed(LED1);
					ApagaLed(LED2);
					ApagaLed(LED0R);
					ApagaLed(LED0G);
					break;
				default:
					ApagaLed(LED1);
					ApagaLed(LED2);
					ApagaLed(LED3);
					ApagaLed(LED0R);
					break;
				}
			}
		}
    return 0;
}
Example #6
0
int main(void)

{
	/*Inicializaciones */
	uint8_t tecla;                         	/* Tecla pulsada*/


	InicializarLeds();  				 	 /* Inicializa Leds */
	InicializarTeclas();					 /* Inicializa teclado */
	InicializarTimerRIT();               	 /* Inicializa Timers RIT*/
	InicializarDAC();                        /* Inicializa DAC*/

	ledsRGB.rojo=RANGO-1;                	 /* Valor inicial para los leds del RGB */
	ledsRGB.verde=RANGO-2;
	ledsRGB.azul=APAGAR;
	ledsRGB.intensidad=RANGO-1;

	CargarValorDAC(200);

	cicloTotal=RANGO*RANGO;  /* Calcula el numero de intervalos totales por ciclo*/

/* Ciclo infinito principal */
while (VERDADERO){

	tecla = TeclaPulsada();


	switch (tecla){
		case NOTECLA:
			                                       /* Si no se pulsa Tecla  */
			ApagarLed(LEDROJO);
			ApagarLed(LEDAMARILLO);
			ApagarLed(LEDVERDE);
			//CargarValorDAC (200);
			break;

		case TECLA1:
			if (ledsRGB.rojo>= RANGO)
			{
				ledsRGB.rojo=APAGAR;
					PrenderLed(LEDAMARILLO);        /* Indica paso por cero*/
					PrenderLed(LEDVERDE);
					RetardoAsmNop(RETARDOxCERO);    /* Retardo extendido */

			}else ledsRGB.rojo++;                   /* Tecla 1 aumenta RGB rojo*/
			ConmutaLed(LEDROJO);
			//CargarValorDAC (100);
			break;

		case TECLA2:
			if (ledsRGB.verde>= RANGO)
			{
				ledsRGB.verde=APAGAR;
					PrenderLed(LEDAMARILLO);        /* Indica paso por cero*/
					PrenderLed(LEDROJO);
					RetardoAsmNop (RETARDOxCERO);   /* Retardo extendido */
			}else ledsRGB.verde++;                  /* Tecla 2 aumenta RGB verde*/
			ConmutaLed(LEDVERDE);
			//CargarValorDAC (500);
			break;

		case TECLA3:
			if (ledsRGB.azul>= RANGO)
			{
				ledsRGB.azul=APAGAR;
					PrenderLed(LEDROJO);            /* Indica paso por cero*/
					PrenderLed(LEDVERDE);
					RetardoAsmNop (RETARDOxCERO);   /* Retardo extendido */
			}else ledsRGB.azul++;                   /* Tecla 3 aumenta RGB azul*/
			ConmutaLed(LEDAMARILLO);                /* acusa incremento azul RGB */
			//CargarValorDAC (700);
			break;

		case TECLA4:
			if (ledsRGB.intensidad>= RANGO)
			{
				ledsRGB.intensidad=APAGAR;
					ConmutaLed(LEDAMARILLO);       /* Indica paso por cero*/
					ConmutaLed(LEDVERDE);
					RetardoAsmNop (RETARDOxCERO);  /* Retardo extendido */
				}else ledsRGB.intensidad++;        /* Tecla 4 aumenta la intensidad*/
			ConmutaLed(LEDROJO);                   /* acusa incremento*/
			//CargarValorDAC (1000);
			break;
	 }/*switch */

	RetardoAsmNop (RETARDO);                    /* Retardo entre lectura de teclado */


  }return FALSO; /*while */
} /*main*/
Example #7
0
int main(void)

{

	/*Inicializaciones */

	InicializarLeds();  				 	 /* Inicializa Leds */
	InicializarTeclas();                     /* Inicializa Teclas*/
	InicializarADC();                        /* Inicializa DAC -> CH1*/
	InicializarDAC();                        /* Inicializa Dac*/
	InicializarSerie();                      /* Inicializa Puerto Serie*/
	InicializarTimerRIT();					 /* Inicializa Timer RIT*/



	uint32_t nc;                           /* contador auxiliar para mensaje*/

	/* Ciclo infinito principal */
	while (VERDADERO){

		tecla = TeclaPulsada ();
			switch (tecla){
				case NOTECLA:               /* Si no se pulsa Tecla */

					break;
				case TECLA1:                /* Tecla 1 Aumenta ganancia*/
					if (ganancia<=10)
					  {
						ganancia++;
					  }
					for(nc=0; nc!=22; nc++) /* Envio mensaje */
						{
						 Enviar_Byte_Serie (mensaje1[nc]);
						} /*for nc */
					Enviar_Byte_Serie (10); /*Linea nueva*/
					Enviar_Byte_Serie (13); /*Retorno de carro*/
    				ConmutaLed(LEDAMARILLO);
					break;
				case TECLA2:                /* Tecla 2 Disminuye ganancia*/
					if (ganancia >=2)
					  {
						ganancia--;
					  }
					for(nc=0; nc!=22; nc++) /* Envio mensaje */
					  {
						Enviar_Byte_Serie (mensaje2[nc]);
    					} /*for nc */

					Enviar_Byte_Serie (10); /*Linea nueva*/
					Enviar_Byte_Serie (13); /*Retorno de carro*/
					ConmutaLed(LEDAMARILLO);
					break;
				case TECLA3:                /* Tecla 3 Mute*/
					ganancia=0;
					for(nc=0; nc!=22; nc++) /* Envio mensaje */
					  {
						Enviar_Byte_Serie (mensaje3[nc]);
    					} /*for nc */
					Enviar_Byte_Serie (10); /*Linea nueva*/
					Enviar_Byte_Serie (13); /*Retorno de carro*/
					ConmutaLed(LEDAMARILLO);
					break;
				case TECLA4:                /* Tecla 4 Setea Ganancia en 1 */
					ganancia=1;

					for(nc=0; nc!=22; nc++) /* Envio mensaje */
						{
						 Enviar_Byte_Serie (mensaje4[nc]);
						} /*for nc */
					Enviar_Byte_Serie (10); /*Linea nueva*/
					Enviar_Byte_Serie (13); /*Retorno de carro*/


					ConmutaLed(LEDAMARILLO);
					break;
			}

			RetardoAsmNop (5000000);


      //  Enviar_Byte_Serie (dataADC/4+32);    /* Prueba de comunicación*/

	}return FALSO; /*while */
} /*main*/