/*****************************************************************************
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 S1 4
#define S2 3
/*****************************************************************************/
/******************************************************************************
Prototipos das funções
******************************************************************************/
void system_init(void);
/*****************************************************************************/
/******************************************************************************
Funcao: int main(void)
Entrada: Nenhuma (void)
Saída: Nenhuma (void)
Descrição: Função principal
*****************************************************************************/
int main()
{
uint8_t estado_s1 = 0;
uint8_t estado_s2 = 0;
stdio_init_all();
printf("Microcontroladores - Aula 18\n");
sleep_ms(250);
system_init();
while(1)
{
estado_s1 = gpio_get(S1);
estado_s2 = gpio_get(S2);
if(estado_s1 == 0)
{
gpio_put(L1, 1);
}
else
{
gpio_put(L1, 0);
}
if(estado_s2 == 0)
{
gpio_put(L2, 1);
}
else
{
gpio_put(L2, 0);
}
}
}
/******************************************************************************
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(L1);
gpio_set_dir(L1, GPIO_OUT);
gpio_put(L1, 0);
gpio_init(L2);
gpio_set_dir(L2, GPIO_OUT);
gpio_put(L2, 0);
gpio_init(S1);
gpio_set_dir(S1, GPIO_IN);
gpio_pull_up(S1); // Enable pull-up resistor
gpio_init(S2);
gpio_set_dir(S2, GPIO_IN);
gpio_pull_up(S2); // Enable pull-up resistor
}S1
S2
S3
L1
L2
L3
L4