I'm using the picdem 18F4550 with microchip v8.63 and the c compiler. components that i'm use are: - 3 leds (red, green, blue); - a LDR (327700 NORPS-12 farnell).
I have connected 3 leds (red, green and blue), on RB4, RB5 and RB6 as output. I also connect the LDR on RB1.
My question is, when the green of another led lights up, how can I retrieve the value in my code that the LDR measures?
I included my code:
#include "p18cxxx.h"
#pragma config WDT = OFF
void main(void) {
// turn off all LED latches
LATDbits.LATD0 = 0;
LATDbits.LATD1 = 0;
LATDbits.LATD2 = 0;
// make port d bits which drive LEDs outputs
TRISDbits.TRISD0 = 0;
TRISDbits.TRISD1 = 0;
TRISDbits.TRISD2 = 0;
TRISB = 0;
// RB port output.
PORTB = 0;
PORTB = 0b10001111;
// 0b01011010
if(PORTBbits.RB4 == 0) {
LATDbits.LATD0 = 1;
}
else if(PORTBbits.RB5 == 0) {
LATDbits.LATD1 = 1;
}
else if(PORTBbits.RB6 == 0) {
LATDbits.LATD2 = 1;
}
if(PORTBbits.RB1 == 1) {
}
while(1) { ; }
}