IR Sensor Interface With PIC18F4550
IR Sensor Interface With PIC18F4550
Concept
The output from the IR sensor circuit will be connected
to pins of a PIC18f4550 microcontroller and the
microcontroller will regard it as digital input to read
either 1 or 0. According to the output from the IR
sensor module, the PIC18F4550 will respond by
glowing led. Since we just want to read some voltage in
the microcontroller as input (either High or low) hence
we are going to configure input pins as digital to read
just 1 or 0 from the sensor.
Source Code:
MPLAB IDE and C18 Compiler is used for compiling the
source code, however MPLAB X IDE and XC8 Compiler
can be also used with no difficulty. Download the entire
project at the end of the source code below with
compiled firmware.
*/
#include <p18f4550.h>
LATDbits.LATD7
// led1
#define led2
LATDbits.LATD6
#define led3
LATBbits.LATB0 // led3
#define led4
LATBbits.LATB1
// led4
#define led5
LATBbits.LATB2
// led5
// led2
OSCCONbits.IRCF1 = 1;
debouncing problem
OSCCONbits.IRCF2= 1;
//
from IR sensor
TRISDbits.TRISD7 = 0;
TRISDbits.TRISD6 = 0;
TRISBbits.TRISB0 = 0;
TRISBbits.TRISB1 = 0;
TRISBbits.TRISB2 = 0;
CMCON = 0x07;
// Disable Comparator
ADCON1bits.PCFG0 = 1;
ADCON1bits.PCFG3 = 1;
//Turn led ON
led1 = 1;
led2 = 1;
led3 = 1;
led4 = 1;
led5 = 1;
}
}