Bom dia pessoal. Estou programando um PCI 16F628A, mas tenho um problema com ele. Em certo momento do código preciso fazer um acionamento somente se as portas RB0 e RA3, que são entradas, estiverem em 1 ou somente a porta RA3 estiver em nível alto, porém o uC parece não reconhecer o sinal nessa porta. Este é código, se puderem me mostrar onde estou errando ficaria muito grato.

#include <xc.h>

// CONFIG
#pragma config FOSC = INTOSCCLK
#pragma config WDTE = OFF
#pragma config PWRTE = ON
#pragma config MCLRE = OFF
#pragma config BOREN = OFF
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config CP = OFF

#define _XTAL_FREQ 4000000

#define p1 PORTBbits.RB0
#define TRIS_p1 TRISBbits.TRISB0 //int p1 = 7;
//int p2 = 8;

#define faca PORTBbits.RB5
#define TRIS_faca TRISBbits.TRISB5 //int faca = 2;

#define foto PORTAbits.RA3
#define TRIS_foto TRISAbits.TRISA3 //int foto = 6;

//int estadoFoto;//

#define imapedal PORTBbits.RB1
#define TRIS_imapedal TRISBbits.TRISB1 //int imapedal = 9;

#define negocio PORTAbits.RA0
#define TRIS_negocio TRISAbits.TRISA0 //int negocio = 3;

#define up PORTBbits.RB2
#define TRIS_up TRISBbits.TRISB2 //int up = 10;

#define down PORTBbits.RB3
#define TRIS_down TRISBbits.TRISB3 //int down = 11;

#define imamotor PORTAbits.RA4
#define TRIS_imamotor TRISAbits.TRISA4 //int imamotor = 12;

unsigned int um = 1;
unsigned int rpm = 5;
unsigned int motor = 0;

void main()
{
while(1)
{

TRIS_p1 = 1;
TRIS_foto = 1;
TRIS_imapedal = 1;
TRIS_up = 1;
TRIS_down = 1;
TRIS_imamotor = 1;

TRIS_faca = 0;
TRIS_negocio = 0;

faca = 0;
negocio = 0;
do {

if (PORTBbits.RB2 == 1)
{
rpm = rpm + 1;
}
if (PORTBbits.RB3 == 1)
{
rpm = rpm - um;

}
if (rpm < 0)
{
rpm = rpm + !rpm;

}
if (PORTAbits.RA4 == 1)
{
motor = motor + 1;

}
if(PORTAbits.RA4 == 0)
{
motor = motor ;

}

} while ((motor) != (rpm));

faca = 0;
if (PORTBbits.RB1 == 1)
{
negocio = 1;
}

else
{
negocio = 0;
}

if ((PORTBbits.RB0 == 1) && (PORTAbits.RA3 == 1))
{
motor = 0;

faca = 1;
__delay_ms (200);
}

else if ((PORTBbits.RB0 == 0) & (TRISAbits.TRISA3 == 1))
{
faca = 1;
motor = 0;

__delay_ms (200);
}

else
{
faca = 0;
}

faca = 0;

}
}

Exibições: 140

Anexos

As respostas para este tópico estão encerradas.

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço