0% encontró este documento útil (0 votos)
68 vistas31 páginas

Práctica de Interrupciones en Tiva C

Este documento presenta tres códigos en C para el controlador Tiva C series TM4C123G utilizando interrupciones y temporizadores. El primer código enciende y apaga un LED cada 80 ms usando una interrupción de temporizador. El segundo código programa un semáforo que cambia entre verde, amarillo y rojo en diferentes intervalos de tiempo y puede ser interrumpido por un botón peatonal. El tercer código implementa un cronómetro de 0 a 9 segundos con botones de inicio, pausa y paro.

Cargado por

XavierZIT
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
68 vistas31 páginas

Práctica de Interrupciones en Tiva C

Este documento presenta tres códigos en C para el controlador Tiva C series TM4C123G utilizando interrupciones y temporizadores. El primer código enciende y apaga un LED cada 80 ms usando una interrupción de temporizador. El segundo código programa un semáforo que cambia entre verde, amarillo y rojo en diferentes intervalos de tiempo y puede ser interrumpido por un botón peatonal. El tercer código implementa un cronómetro de 0 a 9 segundos con botones de inicio, pausa y paro.

Cargado por

XavierZIT
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd

UNIVERSIDAD TECNOLÓGICA

DE QUERÉTARO
Dispositivos Digitales Programables
Javier Zion Ramírez García

PRACTICA 2

Materia: Dispositivos Digitales Programables

Profesor: Tito Villalobos Cruz

Grupo: ITA57

Carrera: Ingeniería en Tecnologías De Automatización


Objetivo.
El alumno aprenderá el uso de interrupciones y temporizadores de la tarjeta de
desarrollo Tiva C series TM4C123G.
a) Investigar la descripción de las siguientes funciones de la librería Tivaware
(debe estar en español):
a. TimerConfigure
b. TimerLoadSet
c. IntEnable
d. TimerIntEnable
e. IntMasterEnable
f. TimerEnable
g. GPIOPadConfigSet
h. GPIOIntEnable
i. GPIOIntTypeSet
j. IntPrioritySet
k. IntRegister
b) Realizar los siguientes 3 códigos en CCS para el Tiva C series, con una breve
explicación de 1 párrafo de 5 líneas por cada código y un diagrama de flujo por cada
código.

a. Encender y apagar un led cada 80 ms usando una interrupción tipo timmer.

b. Realiza la programación de un semáforo usando timmers. El semáforo estará en


verde durante 8 segundos, parpadeará durante 2 segundos para cambiar a ámbar
durante 2 segundos y finalizará a rojo por 5 segundos y este ciclo se repetirá
sucesivamente. Habrá un botón de pase peatonal, que si se llegase a presionar
mientras el semáforo está en verde empezará a parpadear por 2 segundos, pasará
a ámbar por 2 segundos y se mantendrá en rojo por 5 segundos. Terminando este
tiempo regresará a verde. Usando una interrupción de señales externas

c. Realizar un cronómetro de 0 a 9 segundos con botones de inicio, pausa y Stop.


Desarrollo.
TimerConfigure

Esta función configura el modo de funcionamiento de los temporizadores. El módulo


temporizador se desactiva antes de ser configurado y se deja en estado desactivado

TimerLoadSet

Esta función configura el valor de carga del temporizador; si el temporizador está en


marcha, el valor se carga inmediatamente en el temporizador

IntEnable

La interrupción especificada está habilitada en el controlador de interrupciones

TimerIntEnable

Esta función habilita las fuentes de interrupción del temporizador indicadas. Sólo las
fuentes habilitadas pueden reflejarse en la interrupción del procesador; las fuentes
deshabilitadas no tienen efecto en el procesador.

IntMasterEnable

Esta función permite al procesador responder a las interrupciones. Esta función no


afecta al conjunto de conjunto de interrupciones habilitadas en el controlador de
interrupciones; sólo cierra la única interrupción del del controlador al procesador.

TimerEnable

Esta función permite el funcionamiento del módulo temporizador. El temporizador


debe ser configurado antes de ser habilitarlo.

GPIOPadConfigSet

Esta función establece la intensidad y el tipo de accionamiento de los pines


especificados en el puerto GPIO seleccionado. Para los pines configurados como
puertos de entrada, el pad se configura como se solicita, pero el único efecto real
efecto en la entrada es la configuración de la terminación pull-up o pull-down.
GPIOIntEnable

Esta función habilita las fuentes de interrupción GPIO indicadas. Sólo las fuentes
habilitadas pueden reflejarse en la interrupción del procesador; las fuentes
deshabilitadas no tienen efecto en el procesador.

GPIOIntTypeSet

Esta función configura los distintos mecanismos de activación de interrupciones


para los pines especificados en el puerto GPIO seleccionado.

IntPrioritySet

Esta función se utiliza para establecer la prioridad de una interrupción.

IntRegister

Esta función se utiliza para especificar la función manejadora que se llamará cuando
la interrupción dada se afirma en el procesador.

Primer Código

Para el primer código se necesitaba encender un led cada 80 ms, para esto se
utilizaron las libreras de interrupción tipo timer y se configuro todo lo que se necesita
para activar las interrupciones tipo timer, en la siguiente figura se tiene una parte de
la programación y una pequeña explicación.

Figura 1.Parte del primer código

Explicación

En la primera línea se tiene la habilitación del puerto C, debajo de esta línea es


donde activamos los pines B4,B5 y B6 como salida, en la siguiente línea se tiene la
habilitación del Timer 0, luego se tiene la configuración del timer que será que
cuando el periodo termine se reinicie y siga, después se tiene el tiempo de
activación del timer con una variable donde será igual a la división entre el reloj
interno del Tiva y 12.5,donde 12.5Hz es 80 ms por la fórmula de
t=1/f(T=1/0.08s=12.Hz), en la siguiente se tiene para generar la interrupción del
periodo deseado, luego se tiene la habilitación de la interrupción y a su vez debajo
de este se tiene habilitación del Timer0 y luego se tiene también la habilitación
maestra de las interrupciones y al final se tiene la habilitación del temporizador.

En seguida se tiene el Diagrama de flujo del primer código.


Segundo Código

Para este segundo código se tuvo que realizar un semáforo con un botón peatonal
que acortaba el tiempo del semáforo, en la siguiente figura se tiene una parte de la
programación y una pequeña explicación.

Figura 2.Parte del segundo código

Explicación

En esta parte de segundo código es en donde esta un while donde siempre se va a


ejecutar lo que esta dentro, y lo que esta adentro en una estructura if, donde
pregunta que si el contador es menor a 8 y si es el caso entonces mandara a escribir
con el GPIOPinWrite en el pin C4 mandará un 16 ósea lo activará y para el C5 y C6
mandará a escribir un 0 ósea que los tendra apagados y si ese if no se cumple
entonces preguntará si el contador es mayor a 8 y menor a 11, si es el caso se tiene
adentro otro if que preguntará por el pin 4 y mandará a escribir en ese pin C4 un 0
y de otro modo mandará a escribir en ese mismo pin C4 un 16 y afuera de ese if se
escribió en el pin C5 y C6 un 0, al final se tiene un delay de 150ms y luego se tiene
otro else if donde pregunta que si no es el caso de los 2 anteriores y si el contador
es mayor o igual a 11 y el contador es menor a 13 y si es el caso mandará a escribir
un 0 en el pin C4 Y C6 y en el pin C5 mandará a escribir un 32 y lo activará, después
se tiene otro else if que pregunta que si no cumplió lo demás entonces pregunta que
si el contador es mayor o igual a 13 y el contador es menor a 18,si es el caso
entonces mandará a escribir un 0 en el pin C4 y C5 y en el pin C5 mandará a escribir
un 64 y lo activará, eso sería la explicación de esas líneas del segundo código.
En seguida se tiene el Diagrama de flujo del segundo código.
Tercer Código

Para el tercer código, lo que se tiene que hacer es el conteo de 0 a 9 en un display


de 7 segmentos que debe de tener 3 botones, uno para pausar, otro es Stop y uno
de inicio cuando se presione otro de los 2.

En la siguiente figura se tiene una parte de la programación y una pequeña


explicación de la parte de la programación.

Figura 3.Parte del tercer código


Explicación

En este código se tiene un switch donde va a evaluar el contador y de acuerdo a la


variable sé que se tiene va a elegir el caso que sea igual a esa variable, cuando el
contador este en 0 va a escribir desde el pin 0 hasta el pin 5 del puerto C un 0 y en
el pin 6 un 64, lo que esto va hacer es activar a, b, c, d, e y f y va a desactivar el g,
esto pasa porque el 7 segmentos es de ánodo común esto quiere decir que sus leds
se activan con un 0 y se desactivan con un 1 o en su caso para el enmascaramiento
un 64 para el pin 6, esto va hacer igual en todos los casos, si es el caso 1, los que
van a estar en 0 seria b, c y d y los demás estarían a=1, d=8, e=16, f=32 y g=64 y
con eso mostraría un 2 en el display de 7 segmentos, en los demás case va a
suceder lo mismo pero se van a mandar a 0 o su respectivo enmascaramiento
dependiendo el numero que tendra que mostrar el display.

En seguida se tiene el Diagrama de flujo del tercer código.


Conclusiones.

Esta practica es de gran ayuda, para conocer cómo funcionan las interrupciones y
los times que tiene la Tiva, fue algo complicado entender al 100% como
funcionaban, pero con esto se pudo entender no al 100% su funcionamiento, pero
se pudo entender lo mas relevante de este tema.
Anexos.

CODIGO 1

#include <stdint.h>

#include <stdbool.h>

#include "inc/tm4c123gh6pm.h"

#include "inc/hw_memmap.h"

#include "inc/hw_types.h"

#include "driverlib/sysctl.h"

#include "driverlib/interrupt.h"

#include "driverlib/gpio.h"

#include "driverlib/timer.h"

int main(void)

uint32_t ui32Period;

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ
|SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE,
GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);///HABILITAMOS EL TIMER
0

TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);// DECIMOS QUE EL


CONTEO VA HACER POR SIEMPRE
ui32Period = (SysCtlClockGet() / 12.5 ) ;// ELEGIR EL TIEMPO DE PARPADEO //
1/0.08s=12.5Hz

TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period-1);//

IntEnable(INT_TIMER0A);

TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

IntMasterEnable();

TimerEnable(TIMER0_BASE, TIMER_A);

while(1)

{}

void Timer0IntHandler(void)

// Clear the timer interrupt

TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

// Read the current state of the GPIO pin and

// write back the opposite state

if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4))

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, 0);

else

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4, 16);


}

CODIGO 2

#include <stdint.h>

#include <stdbool.h>

#include "inc/hw_memmap.h"

#include "inc/hw_types.h"

#include "inc/tm4c123gh6pm.h"

#include "driverlib/sysctl.h"

#include "driverlib/gpio.h"

#include "driverlib/interrupt.h"

#include "driverlib/timer.h"

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

// VARIABLES

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

uint32_t ui32Period;

uint8_t CONTADOR;

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

// DECLARACIONES

//-----------------------------------------------------------------------------
void initClock(void);

void initGPIO(void);

void GPIOIntHandler(void);

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

// MAIN RUTINE

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

int main(void) {

initClock();

initGPIO();

while(1)

if(CONTADOR<8)

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,16);

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,0);

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,0);

else if(CONTADOR>8 && CONTADOR<11)

{
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4))

GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_4, 0);

else

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,16);

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,0);

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,0);

SysCtlDelay(2000000);

else if(CONTADOR>=11 && CONTADOR<13)

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,0);

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,32);

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,0);

else if(CONTADOR>=13 && CONTADOR<18)

{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,0);

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,0);

GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,64);

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

// INICIALIZACIÓN DEL RELOJ

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

void initClock(void){

SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ |
SYSCTL_USE_PLL | SYSCTL_SYSDIV_5);

void initGPIO(void){

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

// HABILITAR PUERTO C Y B

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

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE,
GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);

GPIOPinTypeGPIOInput(GPIO_PORTB_BASE,GPIO_PIN_0);

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

// HABILITAR Y CONFIGURAR LA INTERRUPCIÓN

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

GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_INT_PIN_0,
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

GPIOIntEnable(GPIO_PORTB_BASE, GPIO_INT_PIN_0);

GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_INT_PIN_0,
GPIO_LOW_LEVEL);

IntPrioritySet(INT_GPIOB, 0);

IntRegister(INT_GPIOB, GPIOIntHandler);

IntEnable(INT_GPIOB);

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

// HABILITAR Y CONFIGURAR TIMER 0

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

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);///HABILITAMOS EL
TIMER 0
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);// DECIMOS QUE EL
CONTEOEO VA HACER POR SIEMPRE

ui32Period = (SysCtlClockGet() / 1 ) ;// ELEGIR EL TIEMPO DE PARPADEO //


1/0.08s=12.5Hz

TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period-1);//

IntEnable(INT_TIMER0A);

TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

TimerEnable(TIMER0_BASE, TIMER_A);

IntMasterEnable();

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

// Timer0IntHandler

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

void Timer0IntHandler(void)

// Clear the timer interrupt

TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

// Read the current state of the GPIO pin and

// write back the opposite state

CONTADOR++;
if(CONTADOR==18) CONTADOR=0;

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

// GPIOIntHandler(INTERRUPCIÓN)

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

void GPIOIntHandler(void){

GPIOIntClear(GPIO_PORTB_BASE, GPIO_INT_PIN_0);

int state=GPIOIntStatus(GPIO_PORTB_BASE, true);

if(state==1){

CONTADOR = 9;

CODIGO 3

#include <stdint.h>

#include <stdbool.h>

#include "inc/hw_memmap.h"

#include "inc/hw_types.h"

#include "inc/tm4c123gh6pm.h"

#include "driverlib/sysctl.h"

#include "driverlib/gpio.h"

#include "driverlib/interrupt.h"

#include "driverlib/timer.h"

//-----------------------------------------------------------------------------
// VARIABLES

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

uint32_t ui32Period;

uint8_t CONTADOR=0;

uint8_t BOTONES=0;

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

// DECLARACIONES

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

void initClock(void);

void initGPIO(void);

void GPIOIntHandler(void);

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

// MAIN RUTINE

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

int main(void) {

initClock();

initGPIO();

while(1){
switch(CONTADOR){

case 0:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,0);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,0);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,0);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,64);//G

break;

case 1:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,1);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,8);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,16);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,32);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,64);//G

break;

case 2:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,4);//C
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,0);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,0);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,32);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,0);//G

break;

case 3:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,0);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,16);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,32);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,0);//G

break;

case 4:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,1);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,8);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,16);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,0);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,0);//G

break;
case 5:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,1);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,0);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,16);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,0);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,0);//G

break;

case 6:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,2);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,8);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,16);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,32);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,64);//G

break;

case 7:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,8);//D
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,16);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,32);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,64);//G

break;

case 8:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,0);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,0);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,0);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,0);//G

break;

case 9:

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);//A

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);//B

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);//C

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,0);//D

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4,16);//E

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,0);//F

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,0);//G

break;

}
}

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

// INICIALIZACIÓN DEL RELOJ

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

void initClock(void){

SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ |
SYSCTL_USE_PLL | SYSCTL_SYSDIV_5);

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

// HABILITAR PUERTO C Y B

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

void initGPIO(void){

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0|
GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6)
;

GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 |


GPIO_PIN_3);
//-----------------------------------------------------------------------------

// HABILITAR Y CONFIGURAR LA INTERRUPCIÓN

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

GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 |


GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

GPIOIntEnable(GPIO_PORTF_BASE,
GPIO_INT_PIN_1|GPIO_INT_PIN_2|GPIO_INT_PIN_3);

GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 |


GPIO_PIN_3, GPIO_LOW_LEVEL);

IntPrioritySet(INT_GPIOF, 0);

IntRegister(INT_GPIOF, GPIOIntHandler);

IntEnable(INT_GPIOF);

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

// HABILITAR Y CONFIGURAR LA INTERRUPCIÓN

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

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

ui32Period = (SysCtlClockGet() / 1);

TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);

IntEnable(INT_TIMER0A);

TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);

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

// Timer0IntHandler

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

void Timer0IntHandler(void)

TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

if(BOTONES==0) CONTADOR++;

if(CONTADOR==10) CONTADOR=0;

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

// GPIOIntHandler(INTERRUPCIÓN)

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

void GPIOIntHandler(void){

GPIOIntClear(GPIO_PORTF_BASE,
GPIO_INT_PIN_1|GPIO_INT_PIN_2|GPIO_INT_PIN_3);

int state = GPIOIntStatus(GPIO_PORTF_BASE, true);

switch (state){

case 2:
BOTONES=0;

break;

case 4:

BOTONES=2;

CONTADOR=CONTADOR;

break;

case 8:

BOTONES=2;

CONTADOR=0;

break;

También podría gustarte