#include <stdio.h>
#include "pico/stdlib.h"
#include "display_lcd.h"
#include <string.h>
#include "hardware/gpio.h"
#include "hardware/timer.h"
#include "hardware/irq.h"
#define ALARM_NUM 0
#define ALARM_IRQ TIMER_IRQ_0
#define DELAY 100000
void system_init(void);
void alarm_irq(void);
void init_timer_irq(void);
uint16_t contador = 0;
int main() {
stdio_init_all();
uint8_t aluno_atual =1;
unsigned char texto_linha_um[17] = "FATEC S.A. 2024";
unsigned char texto_linha_dois[17] = " Teste Display ";
unsigned char texto_linha_tres[17] = "RODRIGO SILVA";
unsigned char texto_linha_quatro[17] = "RA:3027";
unsigned char texto_linha_cinco[17] = "DENNER SANTOS";
unsigned char texto_linha_seis[17] = "RA:3039";
unsigned char texto_linha_sete[17] = "LEANDRO CORREA";
unsigned char texto_linha_oito[17] = "RA:3032";
unsigned char texto_linha_nove[17] = "MOHAMED MAGID";
unsigned char texto_linha_dez[17] = "RA:13011";
unsigned char texto_linha_onze[17] = "PAULO ARAGAO";
unsigned char texto_linha_doze[17] = "RA: OOOO";
system_init();
sleep_ms(500);
DesligaCursor();
LIMPA_DISPLAY();
while (true) {
printf("Hello, Wokwi!\n");
sleep_ms(250);
if ((aluno_atual==1) && (contador==0))
{
printf("aluno atual = 1\n");
posicao_cursor_lcd(1,1);
escreve_frase_ram_lcd(texto_linha_tres);
posicao_cursor_lcd(2,1);
escreve_frase_ram_lcd(texto_linha_quatro);
contador = 30;
aluno_atual++;
}
else if((aluno_atual==2) && (contador==0))
{
LIMPA_DISPLAY();
posicao_cursor_lcd(1,1);
escreve_frase_ram_lcd(texto_linha_cinco);
posicao_cursor_lcd(2,1);
escreve_frase_ram_lcd(texto_linha_seis);
contador = 30;
aluno_atual++;
}
else if((aluno_atual==3) && (contador==0))
{
LIMPA_DISPLAY();
posicao_cursor_lcd(1,1);
escreve_frase_ram_lcd(texto_linha_sete);
posicao_cursor_lcd(2,1);
escreve_frase_ram_lcd(texto_linha_oito);
contador = 30;
aluno_atual++;
}
else if((aluno_atual==4) && (contador==0))
{
LIMPA_DISPLAY();
posicao_cursor_lcd(1,1);
escreve_frase_ram_lcd(texto_linha_nove);
posicao_cursor_lcd(2,1);
escreve_frase_ram_lcd(texto_linha_dez);
contador = 30;
aluno_atual++;
}
else if((aluno_atual==5) && (contador==0))
{
LIMPA_DISPLAY();
posicao_cursor_lcd(1,1);
escreve_frase_ram_lcd(texto_linha_onze);
posicao_cursor_lcd(2,1);
escreve_frase_ram_lcd(texto_linha_doze);
contador = 30;
if(aluno_atual>=4)
{
aluno_atual = 1;
}
}
sleep_ms(500);
}
}
/******************************************************************************
* Funcao: void system_init(void)
* Entrada: Nenhuma (void)
* Saída: Nenhuma (void)
* Descrição: Inicializa sistema (microcontrolador e periféricos)
*****************************************************************************/
void system_init(void)
{
sleep_ms(250);
init_timer_irq();
init_lcd();
}
void alarm_irq(void)
{
static bool toggle = false;
static bool toggle_led_dois = false;
static uint8_t contagem = 0;
printf("SysTick interrupt occurred!\n");
// Clear the alarm irq
hw_clear_bits(&timer_hw->intr, 1u << ALARM_NUM);
uint64_t target = timer_hw->timerawl + DELAY;
// Write the lower 32 bits of the target time to the alarm register, arming it.
timer_hw->alarm[ALARM_NUM] = (uint32_t) target;
if(contador) contador--;
}
void init_timer_irq(void)
{
// Enable the interrupt for the alarm (we're using Alarm 0)
hw_set_bits(&timer_hw->inte, 1u << ALARM_NUM) ;
// Associate an interrupt handler with the ALARM_IRQ
irq_set_exclusive_handler(ALARM_IRQ, alarm_irq) ;
// Enable the alarm interrupt
irq_set_enabled(ALARM_IRQ, true) ;
uint64_t target = timer_hw->timerawl + DELAY;
// Write the lower 32 bits of the target time to the alarm register, arming it.
timer_hw->alarm[ALARM_NUM] = (uint32_t) target;
}