Last active
August 29, 2015 14:16
-
-
Save samirfor/9068da000430f392c3ed to your computer and use it in GitHub Desktop.
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
/** | |
* Ferramenta SanUSB: http://sanusb.site50.net/ | |
* Compilar com MPLABX+C18: https://drive.google.com/open?id=0B5332OAhnMe2N3czQWxVX0JVSkE&authuser=0 | |
* | |
* Este programa semáforo com LEDs com sinalização de tempo para pedestres (cronometro regressivo). | |
* | |
* Foto da placa: https://drive.google.com/file/d/0BwIZj8djOAj2dnJGZ3FKUFM2NFE/view?usp=sharing | |
* Esquema: https://drive.google.com/file/d/0BwIZj8djOAj2U2RjSHdXdDBfTXM/view?usp=sharing | |
* Vídeo: https://www.youtube.com/watch?v=6erQAws2SIU | |
*/ | |
#include "SanUSB48.h" | |
#define v_vermelho pin_a0 | |
#define v_amarelo pin_a1 | |
#define v_verde pin_a2 | |
#define p_vermelho pin_a4 | |
#define p_verde pin_a5 | |
short int requisicao_pedestre = 0; | |
int i; | |
unsigned char set_seg[10] = {0x6F, 0x7F, 0x07, 0x7D, 0x6D, 0x66, 0x4F, 0x5B, 0x06, 0x3F}; | |
#pragma interrupt interrupcao //Tem que estar aqui ou dentro do firmware.c | |
void interrupcao() { | |
} | |
void checar_botao(int z) { | |
int i = 0; | |
for (i = 0; i <= z; i++) { | |
tempo_ms(100); | |
if (!entrada_pin_e3) { | |
requisicao_pedestre = 1; | |
} | |
} | |
} | |
/** | |
* Semaforo com tempo para pedestre | |
*/ | |
void main() { | |
clock_int_48MHz(); | |
TRISA = 0; // saida | |
TRISB = 0; // saida | |
// Luzes dos semáforos | |
PORTAbits.RA0 = 1; | |
PORTAbits.RA1 = 0; | |
PORTAbits.RA2 = 0; | |
PORTAbits.RA4 = 1; | |
PORTAbits.RA5 = 0; | |
// Display de 7 seg | |
PORTBbits.RB0 = 0; | |
PORTBbits.RB1 = 0; | |
PORTBbits.RB2 = 0; | |
PORTBbits.RB3 = 0; | |
PORTBbits.RB4 = 0; | |
PORTBbits.RB5 = 0; | |
PORTBbits.RB6 = 0; | |
while (1) { | |
nivel_baixo(v_vermelho); | |
nivel_baixo(v_amarelo); | |
nivel_alto(v_verde); | |
checar_botao(40); | |
nivel_baixo(v_vermelho); | |
nivel_alto(v_amarelo); | |
nivel_baixo(v_verde); | |
tempo_ms(1500); | |
nivel_alto(v_vermelho); | |
nivel_baixo(v_amarelo); | |
nivel_baixo(v_verde); | |
tempo_ms(2000); | |
if (requisicao_pedestre == 1) { | |
nivel_baixo(p_vermelho); | |
nivel_alto(p_verde); | |
for (i = 0; i < 10; i++) { | |
PORTB = set_seg[i]; | |
if (i > 6) { | |
nivel_baixo(p_verde); | |
inverte_saida(p_vermelho); | |
tempo_ms(500); | |
inverte_saida(p_vermelho); | |
tempo_ms(500); | |
} else { | |
tempo_ms(1000); | |
} | |
} | |
PORTB = 0; | |
nivel_alto(p_vermelho); | |
requisicao_pedestre = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment