Created
February 16, 2023 02:39
-
-
Save diogojorgebasso/b165816441b40e4d9cbeaa0383881cdb to your computer and use it in GitHub Desktop.
Último projeto de Embarcados, sintetizando o aprendizado na sala de aula: piscar LED baseado num intervalômetro ou com o pressionamento botão na Placa, conexão serial e muito mais
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "adc.h" | |
#include "config.h" | |
#include "keypad.h" | |
#include "pic18f4520.h" | |
#include "serial.h" | |
#include "timer.h" | |
#include "lcd.h" | |
#include "ssd.h" | |
const unsigned char nome[] = "Diogo"; | |
const unsigned char matricula[] = "2021123456"; | |
unsigned char x, tecla; | |
unsigned int temp; | |
void leTeclado() { | |
switch (kpRead()) { | |
case 1: | |
lcdCommand(0x80); | |
for (x = 0; x < sizeof (nome) - 1; x++) { | |
lcdData(nome[x]); | |
} | |
break; | |
case 2: | |
lcdCommand(0xC0); | |
for (x = 0; x < sizeof (matricula) - 1; x++) { | |
lcdData(matricula[x]); | |
} | |
break; | |
case 4: | |
BitSet(PORTC, 2); | |
break; | |
case 8: | |
BitClr(PORTC, 2); | |
break; | |
case 16: | |
lcdCommand(0x80); | |
for (x = 0; x < 16; x++) { | |
lcdData(' '); | |
} | |
lcdCommand(0xC0); | |
for (x = 0; x < 16; x++) { | |
lcdData(' '); | |
} | |
break; | |
} | |
} | |
void MostraDisplay(void) { | |
temp = adcRead() / 2; | |
ssdDigit(((temp / 1) % 10), 0); | |
ssdDigit(((temp / 10) % 10), 1); | |
ssdDigit(((temp / 100) % 10), 2); | |
} | |
void Serial() { | |
if (tecla == 0) return; | |
switch (tecla) { | |
case 'A': | |
lcdCommand(0x80); | |
for (x = 0; x<sizeof (nome) - 1; x++) lcdData(nome[x]); | |
break; | |
case 'B': | |
lcdCommand(0xC0); | |
for (x = 0; x<sizeof (matricula) - 1; x++) lcdData(matricula[x]); | |
break; | |
case 'C': | |
BitSet(PORTC, 2); | |
break; | |
case 'D': | |
BitClr(PORTC, 2); | |
break; | |
case '0': | |
lcdCommand(0x80); | |
for (x = 0; x < 16; x++) { | |
lcdData(' '); | |
} | |
lcdCommand(0xC0); | |
for (x = 0; x < 16; x++) { | |
lcdData(' '); | |
} | |
break; | |
} | |
serialSend('T'); | |
serialSend(':'); | |
serialSend((temp / 10) + 48); | |
serialSend((temp % 10) + 48); | |
serialSend(13); | |
} | |
void main(void) { | |
unsigned char serial_data; | |
char slot; | |
kpInit(); | |
lcdInit(); | |
adcInit(); | |
ssdInit(); | |
timerInit(); | |
serialInit(); | |
BitClr(TRISC, 2); | |
for (;;) { | |
timerReset(5000); | |
ssdUpdate(); | |
serial_data = serialRead(); | |
if (serial_data) { | |
tecla = serial_data; | |
} | |
switch (slot) { | |
case 0: | |
leTeclado(); | |
slot = 1; | |
break; | |
case 1: | |
Serial(); | |
slot = 2; | |
break; | |
case 2: | |
kpDebounce(); | |
slot = 3; | |
break; | |
case 3: | |
MostraDisplay(); | |
slot = 0; | |
break; | |
default: | |
slot = 0; | |
break; | |
} | |
timerWait(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment