I read the port RB7, and in the if a check the value. if there is output on RB7 I want that the led on my chip light up (led D1), but it burns all the time even when there is nothing connected to RB7. What i'm doing wrong? That's the PIC 18F4550 It's written in mplab v8.63 and the C18 compiler.
void main (void)
{
TRISD = 0x00; // PORTD als uitgang
TRISB = 0b00110000; // RB4 en RB5 als ingang
RCONbits.IPEN = 0; // prioriteit uit
INTCONbits.GIE = 1; // enable interrupt
INTCONbits.RBIE = 1; // interrupt portB aan
TRISBbits.TRISB7 = 0;
TRISBbits.TRISB6 = 0;
TRISBbits.TRISB3 = 0;
while(1)
{
_asm sleep _endasm
}
}
#pragma interrupt ISR
void ISR (void)
{
if (INTCONbits.RBIF==1)
{
if(LATBbits.LATB7 == 1) // value on RB7 ?
{
LATDbits.LATD1 ^= 1; // D2 togglen
}
}
INTCONbits.RBIF = 0;
}