Last active
May 2, 2017 14:07
-
-
Save pablodz/337a89b6fbdf5daed5638187e9148db8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Proyecto2_rev1.21 | |
* Nombre: Tarea 2 - Sistemas Digitales | |
* Módulo: Tiva Launchpad EK-TM4C123GXL | |
* Descripción: | |
* -Al presionar SW1 formar una "X" con 8 Leds | |
* -Al presionar SW2 formar una "Y" | |
* -Al presionar SW3 formar una "I" | |
* -Al presionar SW4 formar una "l" Una linea vertical de 3 leds al medio | |
* -Al presionar SW2 con SW4 formar una "L" pegado a la izquierda | |
* | |
* LEDS ORDENADOS DE LA SIGUIENTE MANERA | |
* D1 D2 D3 | |
* D4 D5 | |
* D6 D7 D8 | |
* Autor: Pablo Díaz V | |
* Fecha: Semestre 2017-1 | |
*/ | |
#include <stdint.h> // Para determinar el tipo de dato | |
#include "tm4c123gh6pm.h" // libreria de controlador del microprocesador | |
// ****************** Vamos a configurar los switches *********************** // | |
//Activamos reloj de puertos B y C | |
void config_sw1234(void){ //void | |
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R0; | |
//Activamos el sw1 que esta en el puerto | |
while( (SYSCTL_PRGPIO_R & SYSCTL_RCGCGPIO_R )==0) { } // Realmente activado | |
// SW1 esta en el puerto PA 4 | |
// SW2 PA3 | |
// SW3 PA2 | |
// SW4 PA5 | |
GPIO_PORTA_DIR_R &= ~(0x3A); // Todos los switches (1,2,3,4) son de entrada en el puerto A | |
GPIO_PORTA_AFSEL_R &= ~(0x3A); // no usamos función alternativa | |
GPIO_PORTA_PUR_R |= 0x3A; // activamos resistencia de pull-up en pines del puerto A | |
GPIO_PORTA_DEN_R |= 0x3A; // Puertos A en digital | |
} // end void | |
// ****************** Fin Configurar Switches ***********************// | |
//*******************************************************************// | |
// ****************** Vamos a configurar los LEDS ***************// | |
void config_Leds(void){ | |
//Se activa la señan de los relojes correspondientes a Puerto B y C | |
SYSCTL_RCGCGPIO_R |= 0x06; | |
// Esperamos la real activación | |
while( (SYSCTL_PRGPIO_R & 0x06)==0) { } | |
//Configuramos puertos de E/S para PB y PC como salidas | |
GPIO_PORTB_DIR_R |= 0xF0; // Configura el bit del puerto B como salida | |
GPIO_PORTB_DR8R_R |=0xF0; // se activa el driver de 8 mA . | |
GPIO_PORTB_DEN_R |=0xF0; // se activa el pin como salida digital. | |
GPIO_PORTB_DATA_R &= ~(0xF0); // apagamos el led | |
GPIO_PORTC_DIR_R |= 0xF0; // Configura el bit del puerto C como salida | |
GPIO_PORTC_DR8R_R |=0xF0; // se activa el driver de 8 mA en el pin. | |
GPIO_PORTC_DEN_R |=0xF0; // se activa el pin como salida digital. | |
GPIO_PORTC_DATA_R &= ~(0xF0); // apagamos el led | |
} | |
// ****************** Fin configurar los LEDS ***************// | |
//*******************************************************************// | |
//**********Codificamos el algoritmos presentado en el diagrama de flujo******// | |
void main(void) { | |
uint32_t n; | |
config_Leds(); | |
config_sw1234(); | |
while (1){ | |
//Aquí verificamos que el interruptor 1 esta prendido | |
//Apagamos todos los leds | |
GPIO_PORTB_DATA_R &= ~(0xF0); // apagamos el leds 1,2,3,4 | |
GPIO_PORTC_DATA_R &= ~(0xF0); // apagamos el leds 5,6,7,8 | |
for(n = 0; n < 10000; n++);//Esperar para no tener efecto rebote | |
//-----------------------SW2 & SW4 presionados,sw2 y sw4-------------------------// | |
if (GPIO_PORTA_DATA_R ==0x28){ | |
//Formamos L | |
while((GPIO_PORTA_DATA_R & 0x28) != 0 ){ | |
GPIO_PORTB_DATA_R |= 0x90;//pb4,pb7 | |
GPIO_PORTC_DATA_R |= 0xE0;//PC5,pc6,pc7 | |
for(n = 0; n < 300000; n++);//Esperar para no tener efecto rebote | |
} | |
while ((GPIO_PORTA_DATA_R & 0x28) == 0 );//Se deja de presionar | |
GPIO_PORTB_DATA_R &= ~(0x90); //apagamos los leds PB | |
GPIO_PORTC_DATA_R &= ~(0xE0);// Apagamos los leds PC | |
else (GPIO_PORTA_DATA_R ==0x08); | |
//SW2 presionado pero SW4 no | |
//Formamos Y | |
while((GPIO_PORTA_DATA_R & 0x08) != 0 ){ | |
GPIO_PORTB_DATA_R |= 0x50;//PB4,PB6 | |
GPIO_PORTC_DATA_R |= 0x50;//PC4,PC6 | |
for(n = 0; n < 300000; n++);//Esperar para no tener efecto rebote | |
} | |
while ((GPIO_PORTA_DATA_R & 0x08) == 0 );//Se deja de presionar | |
GPIO_PORTB_DATA_R &= ~(0x50); //apagamos los leds PB | |
GPIO_PORTC_DATA_R &= ~(0x50);// Apagamos los leds PC | |
else (GPIO_PORTA_DATA_R !=0x20); | |
//SW4 presionado pero SW2 no | |
//Formamos l | |
while((GPIO_PORTA_DATA_R & 0x20) != 0 ){ | |
GPIO_PORTB_DATA_R |= 0x20;//PB5 | |
GPIO_PORTC_DATA_R |= 0x50;//PC4,PC6 | |
for(n = 0; n < 300000; n++);//Esperar para no tener efecto rebote | |
} | |
while ((GPIO_PORTA_DATA_R & 0x20) == 0 );//Se deja de presionar | |
GPIO_PORTB_DATA_R &= ~(0x20); //apagamos los leds PB | |
GPIO_PORTC_DATA_R &= ~(0x50);// Apagamos los leds PC | |
}//End IF | |
//-----------------------SW1 presionado---------------------------// | |
if ((GPIO_PORTA_DATA_R ==0x10){ | |
while((GPIO_PORTA_DATA_R & 0x10) != 0 ){ | |
GPIO_PORTB_DATA_R |= 0x50;//pb4,pb6 | |
GPIO_PORTC_DATA_R |= 0xB0;//PC4,pc5,pc7 | |
for(n = 0; n < 300000; n++);//Esperar para no tener efecto rebote | |
} | |
while ((GPIO_PORTA_DATA_R & 0x10) == 0 );//Se deja de presionar | |
GPIO_PORTB_DATA_R &= ~(0x50); //apagamos los leds PB | |
GPIO_PORTC_DATA_R &= ~(0xB0);// Apagamos los leds PC | |
}// end if | |
//-----------------------SW3 presionado---------------------------// | |
if ((GPIO_PORTA_DATA_R ==0x04){ | |
while((GPIO_PORTA_DATA_R & 0x04) != 0 ){ | |
GPIO_PORTB_DATA_R |= 0x70;//pb4,pb5,pb6 | |
GPIO_PORTC_DATA_R |= 0xF0;//PC4,pc5,pc6,pc7 | |
for(n = 0; n < 300000; n++);//Esperar para no tener efecto rebote | |
} | |
while ((GPIO_PORTA_DATA_R & 0x04) == 0 );//Se deja de presionar | |
GPIO_PORTB_DATA_R &= ~(0x70); //apagamos los leds PB | |
GPIO_PORTC_DATA_R &= ~(0xF0);// Apagamos los leds PC | |
}// end if | |
} | |
//End While interruptor | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Without interruptor that conmute of on to off and viceverse
Sin interruptor que conmute