Está en la página 1de 15

IT-8-ACM-03-R02

UNIVERSIDAD AUTÓNOMA DE NUEVO LEÓN


FACULTAD DE INGENIERÍA MECÁNICA Y ELÉCTRICA

TIPO DE EXAMEN: MEDIO CURSO ENERO JUNIO


MATERIA: DISEÑO DE SISTEMAS EMBEBIDOS
SEMESTRE: SEPTIMO
ACADEMIA: ELECTRONICA

Nombre: __Cardiel Cortes Janeth Jamilet __________________Fecha_08_/_10_/2023

Matricula __1867586__Hora __V4__ Salón __7215__ Tiempo: Inicio ______ Final ______

INSTRUCCIONES:

a) Lea cuidadosamente este examen y resuelva los problemas propuestos en las hojas anexas, encierre los resultados en un
rectángulo, no despegue las hojas. Favor de dejar su celular apagado y dentro de su mochila.
b) Es un examen individual a libro cerrado, no está permitido el uso de notas, apuntes, calculadoras.
c) No se arriesgue, será considerado como copia, ver el examen de su compañero o el uso de notas.
d) Confirme los resultados obtenidos, de un ingeniero esperan que proporcione resultados correctos y soluciones concretas.
e) Concéntrese en su examen, tiene 2 horas 30 minutos para resolverlo.

1. Se requiere decodificar un teclado hexadecimal matricial de membrana, y desplegar la tecla presionada de


derecha a izquierda.

0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 2
0 0 0 0 0 1 2 3
0 0 0 0 1 2 3 4
0 0 0 1 2 3 4 5
0 0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
2 3 4 5 6 7 8 9
3 4 5 6 7 8 9 1

2.- Objetivo
1. Utilizar interrupciones para generar mediante funciones los valores a 7mostrar
2. Programar el barrido para mostrar los valores programados
3. Generar un código para que el teclado permita generar y mostrar los valores de 0 al 9

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
3.- Diagrama de Flujo Propuesto

INICIO

int D1=0x70;int D2=0x60;int D3=0x50;int D4=0x40;int D5=0x30;int D6=0x20;


int D7=0x10;int D8=0x00;
int numeros[10]={0x0,0x01,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9};
int acumulado = 0, oper = 0, resul = 0, num1 = 0, num2=0;int tecla;int teclado = 0;uint32_t previousMillis =
0;uint32_t currentMillis = 0;

WHILE(1) FIN

displayNumber(teclado);

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

currentMillis = HAL_GetTick();

if (currentMillis -
previousMillis > 500)

switch
(GPIO_Pin)

case case case case DEFAULT


GPIO_PIN_0: GPIO_PIN_1: GPIO_PIN_2: GPIO_PIN3:

2 3 4 5 1

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
2 –

GPIOA->ODR = 0xF0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(GPIOA,
GPIO_PIN_0) == 0)

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOA,


GPIO_PIN_5, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(GPIOA,
GPIO_PIN_0) == 0)

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOA,


GPIO_PIN_6, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(GPIOA,
GPIO_PIN_0) == 0)

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOA,


GPIO_PIN_7, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(GPIOA,
GPIO_PIN_0) == 0)

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
3

GPIOA->ODR = 0xF0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

if
(HAL_GPIO_ReadPin(GPIO
A, GPIO_PIN_1) == 0)

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

if
(HAL_GPIO_ReadPin(GPIO tecla = 9;
A, GPIO_PIN_1) == 0) teclado = (teclado % 10000000) * 10 + tecla;

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);

if
(HAL_GPIO_ReadPin(GPIO tecla = 6;
A, GPIO_PIN_1) == 0) teclado = (teclado % 10000000) * 10 + tecla;

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);

if
(HAL_GPIO_ReadPin(GPIO tecla = 3;
A, GPIO_PIN_1) == 0) teclado = (teclado % 10000000) * 10 + tecla;

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
3

GPIOA->ODR = 0xF0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

if
(HAL_GPIO_ReadPin(GPI
tecla = 0;
OA, GPIO_PIN_2) == 0)
teclado = (teclado % 10000000) * 10 + tecla;

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

if
(HAL_GPIO_ReadPin(GPI
tecla = 8;
OA, GPIO_PIN_2) == 0)
teclado = (teclado % 10000000) * 10 + tecla;

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);

if
(HAL_GPIO_ReadPin(GPI
tecla = 5;
OA, GPIO_PIN_2) == 0)
teclado = (teclado % 10000000) * 10 + tecla;

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);

if
(HAL_GPIO_ReadPin(GPI
tecla = 2;
OA, GPIO_PIN_2) == 0)
teclado = (teclado % 10000000) * 10 + tecla;

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
3

GPIOA->ODR = 0xF0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(GPIOA,
GPIO_PIN_2) == 0)

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(GPIOA,
tecla = 7;
GPIO_PIN_2) == 0)
teclado = (teclado % 10000000) * 10 + tecla;

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(GPIOA,
tecla = 4;
GPIO_PIN_2) == 0)
teclado = (teclado % 10000000) * 10 + tecla;

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(GPIOA,
tecla = 1;
GPIO_PIN_2) == 0)
teclado = (teclado % 10000000) * 10 + tecla;

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
void displayNumber(int valor)

int dig1,dig2,dig3,dig4,dig5,dig6,dig7,dig8;
dig8= numero%10;
dig7= (numero%100)/10;
dig6= (numero%1000)/100;
dig5= (numero%10000)/1000;
dig4= (numero%100000)/10000;
dig3= (numero%1000000)/100000;
dig2= (numero%10000000)/1000000;
dig1= (numero%100000000)/10000000;

setDisplay(dig1, dig2, dig3, dig4, dig5, dig6, dig7, dig8);

GPIOC->ODR=D8+numeros[dig8];
HAL_Delay(1);
GPIOC->ODR=D7+numeros[dig7];
HAL_Delay(1);
GPIOC->ODR=D6+numeros[dig6];
HAL_Delay(1);
GPIOC->ODR=D5+numeros[dig5];
HAL_Delay(1);
GPIOC->ODR=D4+numeros[dig4];
HAL_Delay(1);
GPIOC->ODR=D3+numeros[dig3];
HAL_Delay(1);
GPIOC->ODR=D2+numeros[dig2];
HAL_Delay(1);
GPIOC->ODR=D1+numeros[dig1];
HAL_Delay(1);

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
4.- Diagrama de la Implementación del Circuito

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
5.- Evidencia Grafica

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
6.- Programacion

Función principal while (1):

Este es el bucle principal del programa, que se ejecutará de manera indefinida (while (1) es un bucle infinito).
Dentro del bucle, se llama a la función displayNumber(teclado) repetidamente, pasando el valor actual de la
variable teclado como argumento a la función.
Función HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin):

Esta función se llama cuando se produce una interrupción externa en uno de los pines GPIO del
microcontrolador.
Obtiene el tiempo actual en milisegundos usando currentMillis = HAL_GetTick().
Luego, comprueba si ha pasado más de 500 ms desde la última vez que se llamó a esta función (if
(currentMillis - previousMillis > 500)).
Después, utiliza un switch basado en el pin GPIO que generó la interrupción (GPIO_Pin) para realizar acciones
específicas en función del pin.
Para cada caso (pin GPIO), configura ciertos pines GPIOA en alto o bajo, verifica el estado de ciertos pines y
realiza cálculos en algunos casos.
Finalmente, actualiza el valor de previousMillis para controlar el tiempo.
Función displayNumber(int numero):

Esta función toma un número como argumento y se encarga de descomponer ese número en sus dígitos
individuales.
Utiliza operaciones de módulo y división para dividir el número en sus dígitos individuales (dig1, dig2, dig3, ...,
dig8).
Luego, llama a la función setDisplay() con los dígitos individuales como argumentos para mostrar el número en
un display de siete segmentos.
Función setDisplay(int dig1, int dig2, int dig3, int dig4, int dig5, int dig6, int dig7, int dig8):

Esta función se encarga de configurar las salidas GPIOC para mostrar los dígitos en un display de siete
segmentos.
Utiliza valores predefinidos (D1, D2, ..., D8) para configurar los dígitos en el display.
Utiliza un array llamado numeros para obtener la configuración de segmentos necesaria para representar los
dígitos en el display.
Configura los pines GPIOC uno por uno para mostrar los dígitos y espera 1 milisegundo entre cada cambio de
dígito utilizando HAL_Delay(1).

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
while (1)
{
displayNumber(teclado);
}
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)


{
currentMillis = HAL_GetTick();
if (currentMillis - previousMillis > 500)
{

switch (GPIO_Pin)
{
case GPIO_PIN_0:
GPIOA->ODR = 0xF0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == 0)
{

}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == 0)
{

}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == 0)
{

}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == 0)
{

}
GPIOA->ODR = 0x00;
break;

case GPIO_PIN_1:
GPIOA->ODR = 0xF0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == 0)
{

}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == 0)
{
tecla = 9;
teclado = (teclado % 10000000) * 10 + tecla;
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == 0)
{
tecla = 6;
teclado = (teclado % 10000000) * 10 + tecla;
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == 0)
{
tecla = 3;
teclado = (teclado % 10000000) * 10 + tecla;
}

GPIOA->ODR = 0x00;
break;

case GPIO_PIN_2:
GPIOA->ODR = 0xF0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2) == 0)
{
tecla = 0;
teclado = (teclado % 10000000) * 10 + tecla;
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2) == 0)
{
tecla = 8;
teclado = (teclado % 10000000) * 10 + tecla;
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2) == 0)
{
tecla = 5;
teclado = (teclado % 10000000) * 10 + tecla;
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2) == 0)
{
tecla = 2;
teclado = (teclado % 10000000) * 10 + tecla;
}

GPIOA->ODR = 0x00;
break;

case GPIO_PIN_3:
GPIOA->ODR = 0xF0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_3) == 0)
{
teclado = 00000000;

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_3) == 0)
{
tecla = 7;
teclado = (teclado % 10000000) * 10 + tecla;
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_3) == 0)
{
tecla = 4;
teclado = (teclado % 10000000) * 10 + tecla;
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_3) == 0)
{
tecla = 1;
teclado = (teclado % 10000000) * 10 + tecla;
}

GPIOA->ODR = 0x00;
break;
}

previousMillis = currentMillis;
}
}

void displayNumber(int valor)


{
int dig1, dig2, dig3, dig4, dig5, dig6, dig7, dig8;

dig8 = valor % 10; // unidades


dig7 = (valor % 100) / 10; // decenas
dig6 = (valor % 1000) / 100; // centenas
dig5 = (valor % 10000) / 1000; // unidades de millar
dig4 = (valor % 100000) / 10000; // decenas de millar
dig3 = (valor % 1000000) / 100000; // centenas de millar
dig2 = (valor % 10000000) / 1000000; // unidades de millon
dig1 = (valor % 100000000) / 10000000; // decenas de millon

setDisplay(dig1, dig2, dig3, dig4, dig5, dig6, dig7, dig8);


}

void setDisplay(int dig1, int dig2, int dig3, int dig4, int dig5, int dig6, int dig7, int dig8)
{
GPIOC->ODR = D8 + numeros[dig8];
HAL_Delay(1);
GPIOC->ODR = D7 + numeros[dig7];
HAL_Delay(1);
GPIOC->ODR = D6 + numeros[dig6];
HAL_Delay(1);
GPIOC->ODR = D5 + numeros[dig5];
HAL_Delay(1);

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016
GPIOC->ODR = D4 + numeros[dig4];
HAL_Delay(1);
GPIOC->ODR = D3 + numeros[dig3];
HAL_Delay(1);
GPIOC->ODR = D2 + numeros[dig2];
HAL_Delay(1);
GPIOC->ODR = D1 + numeros[dig1];
HAL_Delay(1);
}

REVISIÓN No.: 7
VIGENTE A PARTIR DE: 01 de Agosto del 2016

También podría gustarte