Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

HOw to 2 interface 2 LDR into 2x16 Lcd using PIC16F887

Status
Not open for further replies.

syafiq010

Newbie level 2
Joined
Jul 29, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,293
Need some help regarding how to add another port for second LDR.I got 2 LDR,left and right

LDR left = RA0
LDR right = RA1

Im actually still searching on how to add another reading for my LDR.I just done with left LDR to display the voltage in the LCD.Will provide my program after this..

Code:
#include <htc.h>
#include "lcd.h"
#include "adc.h"
#include "system.h"

//   Configuration
//==========================================================================

__CONFIG(HS &			// External Crystal at High Speed
		 WDTDIS &		// Disable Watchdog Timer.
		 PWRTEN &		// Enable Power Up Timer.
		 BORDIS &		// Disable Brown Out Reset.
		 MCLREN &		// MCLR function is enabled
		 LVPDIS);		// Disable Low Voltage Programming.

//	main function
//==========================================================================
void main(void) 
{
	PORTA = 0;										// clear PORT
	PORTB = 0;		
	PORTC = 0;								
	PORTD = 0;										
	
	TRISA = 0b11111111;								// set PORTA as INPUT
	TRISB = 0b00000011; 							        // set PORTB<7:2> AS OUTPUT , PORTB<1:0> as INPUT
	TRISC = 0b00000000;								// set PORTC as output
	TRISD = 0b00000000;								// set PORTD as output

	ANSELH = 0; 									// SET PORTB as DIGITAL I/O for PIC16F887

	lcd_initialize();								// Initialise LCD

	adc_initialize();								// Initialise ADC
	
	lcd_home();
	lcd_putstr("ADC :");							// Put "ADC:" on LDC screen
	lcd_2ndline();
	lcd_putstr("VOLT: .  V");						// Put "VOLT:" on LDC screen

while (1)											// Loop forever
	{
	unsigned int adc_value = 0;
	unsigned int volt_value = 0;
	unsigned char i;

	adc_on();										// ON ADC
	for(i = 0 ; i < 10 ; i++)
		{
		adc_value = adc_value + ui_adc_read();		// take the value for 10 times
		}
	
	adc_value = adc_value/10;						// Devide the final value by 10 to get the average result
	lcd_goto(0x05);
	lcd_bcd(4,adc_value);							// display on LCD with 4 digit number maximun.
	volt_value = (adc_value*50)/102.4;				// if adc_value = 1022.
	lcd_goto(0x45);									// volt_value = (1022*50)/1024 = 499
	lcd_bcd(1,volt_value/100);						// volt_value  = 499/100 = 4 (1st number)
	lcd_goto(0x47);										
	lcd_bcd(1,(volt_value%100)/10); 				// (volt_value = 499%100 = 99). 99/10 = 9(2nd number)
	lcd_bcd(1,volt_value%10);						// (volt_value = 499%100 = 99). 99%10 = 9(last number)		
	}
}


/*******************************************************************************
* PRIVATE FUNCTION: delay_ms
*
* PARAMETERS:
* ~ ui_value	- The period for the delay in miliseconds.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Delay in miliseconds.
*
*******************************************************************************/
void delay_ms(unsigned int ui_value)
{
	while (ui_value-- > 0) {
		__delay_ms(1);	
	}	
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top