/*****************************************************************************
Nome do Arquivo : main.c
Descrição : Arquivo principal prova P2, exercicio 1
Ambiente : WOKWI e RP2040 C/C++ SDK
Responsável : Weslley M. Torres
Versão/Data : 1.0.0 - 25/03/2024 - Initial version
*****************************************************************************/
/******************************************************************************
HEADER-FILES (Somente os arquivos necessários nesse arquivo)
******************************************************************************/
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
/*****************************************************************************/
/******************************************************************************
Variaveis Globais
******************************************************************************/
#define L1 8
#define L2 7
#define L3 6
#define L4 5
#define S1 4
#define S2 3
#define S3 2
/*****************************************************************************/
/******************************************************************************
Prototipos das funções
******************************************************************************/
void system_init(void);
void button_callback(uint gpio);
/*****************************************************************************/
/******************************************************************************
Funcao: int main(void)
Entrada: Nenhuma (void)
Saída: Nenhuma (void)
Descrição: Função principal
*****************************************************************************/
int main()
{
stdio_init_all();
sleep_ms(250);
system_init();
while(1)
{
sleep_ms(50);
}
}
/******************************************************************************
Funcao: void system_init(void)
Entrada: Nenhuma (void)
Saída: Nenhuma (void)
Descrição: Inicializa sistema (microcontrolador e periféricos)
*****************************************************************************/
void system_init(void)
{
printf("Init Hardware ....\n");
sleep_ms(10);
gpio_init(L3);
gpio_set_dir(L3, GPIO_OUT);
gpio_put(L3, 0);
gpio_init(L4);
gpio_set_dir(L4, GPIO_OUT);
gpio_put(L4, 0);
gpio_init(S3);
gpio_set_dir(S3, GPIO_IN);
gpio_pull_up(S3); // Enable pull-up resistor
gpio_set_irq_enabled_with_callback(S3, GPIO_IRQ_EDGE_FALL, true, (gpio_irq_callback_t)&button_callback);
}
/******************************************************************************
Funcao: void button_callback(void)
Entrada: Nenhuma (void)
Saída: Nenhuma (void)
Descrição: Função tratamento interrupcao do botao
*****************************************************************************/
void button_callback(uint gpio)
{
static uint8_t estado = 0;
printf("Valor de estado na entrada = %d\n", estado);
estado = !estado;
printf("Valor de estado invertido = %d\n", estado);
gpio_put(L3, estado);
gpio_put(L4, estado);
}S1
S2
S3
L1
L2
L3
L4