100% found this document useful (1 vote)
308 views3 pages

PIC16F877 and LDR Example Get Micros

This document provides an example code for connecting a light dependent resistor (LDR) to an analog-to-digital converter (ADC) channel on a PIC16F877 microcontroller. The LDR value is read from the ADC and displayed on a liquid crystal display (LCD) in real-time. The code uses mikroC Pro to interface the LDR, ADC, and LCD on a PIC16F877 microcontroller development board. Links are provided to purchase an evaluation board and LDR components for replicating the example code.

Uploaded by

devchandar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
308 views3 pages

PIC16F877 and LDR Example Get Micros

This document provides an example code for connecting a light dependent resistor (LDR) to an analog-to-digital converter (ADC) channel on a PIC16F877 microcontroller. The LDR value is read from the ADC and displayed on a liquid crystal display (LCD) in real-time. The code uses mikroC Pro to interface the LDR, ADC, and LCD on a PIC16F877 microcontroller development board. Links are provided to purchase an evaluation board and LDR components for replicating the example code.

Uploaded by

devchandar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PIC16F877 and LDR warning example PIC16F877 and ADC example

PIC16F877 and LDR example


Buy IC In Stock - FindChips.cn
PIC16F877A 100% New Original; 100,000 In Stock; 24 Hour Shipping
findchips.cn/PIC16F877A

In this example we connect an LDR to ADC channel 2 which is PA 2. Once again you will get a value in theory between 0 and 1023. The more light that there is the higher
the value.

We will read the value in from the LDR and display this on the LCD

Schematic

PIC16F877 LDR

Code

The example was written using mikroC pro evaluation version

sbit LCD_RS at RB4_bit;


sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
unsigned int adcvalue,value,temp_res;
unsigned char car,x,y;
char *voltage = "00.00";
long temp;

// Routine to show the value of the ADC_read


void ShowADC(int x, int y, unsigned int adcvalue)
{
car = adcvalue / 1000;
LCD_Chr(x,y,48+car);
adcvalue=adcvalue-1000*car;
car = (adcvalue / 100);
LCD_Chr_CP(48+car);
adcvalue=adcvalue-100*car;
car = (adcvalue / 10);
LCD_Chr_CP(48+car);
adcvalue=adcvalue-10*car;
car = adcvalue;
LCD_Chr_CP(48+car);
delay_ms(30);
}

void main()
{
TRISA = 0xFF; // PORTA is input
TRISB = 0;
PORTB = 0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, " ADC :");
do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
adcvalue = temp_res;
ShowADC (1,7,adcvalue);
Delay_ms(300);

} while(1);

} // end main

Links

Microcontroller Programmer Kit Development Board for PIC microcontroller evaluation QL200 PIC

50 pcs Light Dependent Resistors

Be Sociable, Share!

Tweet Like 0 Share


StumbleUpon

Ads by Google LDR Example Code PIC16F877

Related posts:

1. PIC16F877A and RGB LED example

2. PIC16f877 and push button example

3. PIC16F877 and LDR warning example

4. PIC16F877 and 74HC595 shift register example

Comments are closed.

You might also like