I am using picdem 18F4550 with microchip v8.63 and c compiler. The components I am using: - 3 LEDs (red, green, blue); - One LDR (327700 NOPS-12 Fernell).
I added 3 Leeds (red, green and blue) as output to RB4, RB5 and RB6. I also connect LD on RB1.
My question is, when another LED lights are green, how can I get value in my code that the LDR solution?
I included my code:
#include "p18cxxx.h" #pragma config WDT = closed key (zero) {// close all LED lathes LATDbits.LATD0 = 0; LATDbits.LATD1 = 0; LATDbits.LATD2 = 0; // create port d bits which makes the LID drive TRISDbits.TRISD0 = 0; TRISDbits.TRISD1 = 0; TRISDbits.TRISD2 = 0; TRISB = 0; // RB port output PORTB = 0; PORTB = 0b10001111; // 001011010 if (Portbits RB4 == 0) {LATDbits.LATD0 = 1; } If (PORTBbits.RB5 == 0) {LATDbits.LATD1 = 1; } If (portbit.rb6 == 0) {LATDbits.LATD2 = 1; } If (PORTBbits.RB1 == 1) {} while (1) {; Assume that you are connecting the PIN configured as a GPIO with an LDR. The voltage threshold for the GPIO pin is applied. The value read on the pin depends on the resistance of the LDR swing which produces both logic low and logic high. Most likely you want to connect the LDR with the GPIO rather than the PIC A / D pin. Use ADCON to configure ADC Set up A / D for conversion, and wait for A / D completion gaps. Then read the ADRSH and ADRSL which produces an analog voltage of LDR.
Comments
Post a Comment