#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "rom/gpio.h"
// define os nomes dos endereços dos registradores
#define GPIO_ENABLE_REG 0x3FF44020
#define GPIO_OUT_REG 0x3FF44004
#define GPIO_IN1_REG 0x3FF44040
//define os pinos das chaves
#define chave1 34
#define chave2 35
#define chave3 32
#define chave4 33
//cria um vetor com os valores em hexadecimal de 0 a F
uint32_t display[16] = { 0x60035, 0x70004,0x70035,0x20031,0x40004, 0x30025,
0x70025,0x50015,0x50031,0x30035,0x70034,0x30031,0x50025,0x40024, 0x30015,0x30030 };
//cria um vetor com as chaves
uint8_t chave[4] = { chave1, chave2, chave3, chave4 };
void app_main() {
//configura as chaves como entrada
for (uint8_t index = 0; index < 4; index++ ){
gpio_pad_select_gpio( chave[ index ] );
gpio_set_direction ( chave[ index ], GPIO_MODE_INPUT );
gpio_set_pull_mode ( chave[ index ], GPIO_PULLUP_ONLY);
}
//habilita os pinos
REG_WRITE(GPIO_ENABLE_REG, 0b1110000000000110101 );
uint32_t valor_data = REG_READ(GPIO_IN1_REG) & 0xF;
while (true) {
//le o valor do registrador para as chaves
valor_data = REG_READ(GPIO_IN1_REG);
//coloca como saída o valor do vetor dsplay
REG_WRITE(GPIO_OUT_REG, display[valor_data] );
vTaskDelay(200 / portTICK_PERIOD_MS);
}
}CHAVE
Bit0
Bit1
Bit2
Bit3
DISPLAY