Jump to content
Fórum Script Brasil
  • 0

Ajuda com Contador de fluxo de pessoas. Prova! Faço PIX


Question

//INICIO
#include <xc.h>
// CONFIG
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config BOREN = OFF
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config CP = OFF
#define _XTAL_FREQ 4000000
int display(int numero);
int C1 = 0, C2 = 0;
void __interrupt() tratamento_interrupcao(void)
{
static int contador = 0;
static int led = 1, sel_display = 1;
if (INTCONbits.TMR0IF == 1)
{
// Reset flag after overflow
INTCONbits.TMR0IF = 0;
TMR0 = 131;
contador++;
if (contador == 125)
{
contador = 0;
led = !led;
PORTDbits.RD0 = led;
}
//Atualização dos Displays
sel_display = !sel_display;
if (sel_display == 1)
{
PORTDbits.RD1 = 1;
PORTDbits.RD2 = 0;
PORTC = display(C2);
}
else
{
PORTDbits.RD1 = 0;
PORTDbits.RD2 = 1;
PORTC = display(C1);
}
}
if (INTCONbits.INTF == 1)
{
INTCONbits.INTF = 0;
C1++;
if (C1 == 10) {
C1 = 0;
C2++;
}
if (C2 == 10) {
C1 = 0;
C2 = 0;
}
__delay_ms(50);
}
}
void main(void) 
{
//Inicialização e configuração
TRISC = 0x00; //Saídas
TRISD = 0X00; //Saídas
TRISBbits.TRISB0 = 1; //Entrada
TRISBbits.TRISB1 = 1; //Entrada
// Configuração do Timer0
// Select timer mode
OPTION_REGbits.T0CS = 0;
OPTION_REGbits.PSA = 0;
// Set Prescaler to 64
OPTION_REGbits.PS = 0b101;
// Configura o valor inicial
TMR0 = 131;
// Habilita Timer0 interrupt
INTCONbits.TMR0IE = 1;
// Habilita External interrupt
INTCONbits.INTF = 1;
INTCONbits.INTF = 0;
// Habilita global interrupt
INTCONbits.GIE = 1;
while(1){
}
}
int display(int numero)
{
switch (numero)
{
case 0:
return 0x3F;
break;
case 1:
return 0x06;
break;
case 2:
return 0x5B;
break;
case 3:
return 0x4F;
break;
case 4:
return 0x66;
break;
case 5:
return 0x6D;
break;
case 6:
return 0x7D;
break;
case 7:
return 0x07;
break;
case 8:
return 0x7F;
break;
case 9:
return 0x6F;
break;
defaut:
return 0x00;
break;
}
}

 

Quem pode me ajudar, preciso implementar um contador de fluxo de pessoas, com incremento quando entra uma pessoa por um porta e decremento quando sai por outra porta.

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149405
    • Total Posts
      645894
×
×
  • Create New...