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.

PIC16f877 and temperature sensor Lm35 interface via pic adc

Status
Not open for further replies.

rahulkrrish

Newbie level 2
Joined
Jan 19, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,306
temperature sensor lm35

I am using MPLAB IDE for simulating...can u give me a c source code for PIC16f877 and Lm35 interface
 

temperature sensors lm35

rahulkrrish said:
I am using MPLAB IDE for simulating...can u give me a c source code for PIC16f877 and Lm35 interface
hi..what exactly are you making?a temperature sensor?can u send me the schematic diagram of your project?
 

Re: PIC16f877 and temperature sensor Lm35 interface via pic

Hello! This is a great project and I want to build too!
I have the 16f877 running with the 3310 LCD...but I don't know how to build the code for the LM35.I use MPlab .
I tried using the code here but it doesn't work.

#include <pic.h>

//config bits
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES PROTECT //Code protected from reads
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD

//10-bit adc output
#device adc=10

#use delay(clock=20000000)
#byte lcdport = 0x06 // PORTB

#include "3310.c" //3310 files here!

void main()
{
unsigned long adc_val;
char adc_val_string[10];
float temp_val;
char temp_val_string[10];

set_tris_b(0x00);
setup_adc_ports(AN0_AN1_VSS_VREF);
setup_adc(ADC_CLOCK_DIV_32);


//LM35 connected to RA1/AN1
set_adc_channel(1);
delay_us(50);

nokia_init();

while(1)
{
nokia_clean_ddram(); //clear lcd screen
adc_val = read_adc(); //read adc

//display 10-bit adc
nokia_gotoxy(2,1);
printf(nokia_printchar, "ADC value:");
sprintf(adc_val_string, "%Lu" , adc_val);
nokia_gotoxy(4,2);
printf(nokia_printchar, adc_val_string);

//display calculated temperature value
temp_val = (adc_val / 1024.0) * 100.0;
nokia_gotoxy(2,3);
printf(nokia_printchar, "Temperature:");
sprintf(temp_val_string, "%0.2f" , temp_val);
nokia_gotoxy(4,4);
printf(nokia_printchar, temp_val_string);
printf(nokia_printchar, " deg.");

delay_ms(1000);
}
}


Could anyone pls translate this code into C so I can compile it in MPlab?
I also attached a photo with the scheme in proteus...but I think I need another cmponent instead of that Rv.
Thank you in advance!
 

    V

    Points: 2
    Helpful Answer Positive Rating
Re: PIC16f877 and temperature sensor Lm35 interface via pic

here is the 3310 library for Proteus...maybe more need it....
But is there no one to help me??...I am sorry if I am posting in the wrong section...or if I did something wrong...
 

Attachments

  • proteus-model-nokia3310lcd_1765.zip
    426.9 KB · Views: 289
Re: PIC16f877 and temperature sensor Lm35 interface via pic

I have solved the problem...I am going to post here the project just in case someone else needs it.Hoping that this is not a forum based on monologues...can anyone help me with a piece of code for using the pressure sensor MPX 4115?
 
Re: PIC16f877 and temperature sensor Lm35 interface via pic

Thank you for this project. im doing a similar project but im not going to use the LCD, im using the an array of 8 LEDs to show the ADC output... how can i go about doing that? (i mean how do you configure the PIC to take the ADC result to the PORT?) :?:
 

Re: PIC16f877 and temperature sensor Lm35 interface via pic

Sorry Dante...but I am a newbie too...I don't think I can help you much...unless you have to use an array of 8LEDs I suggest using a 7seg ...and u just connect that to a port...and send the value to that port...
But I have a problem too...I added a pressure sensor...an MPX4115 to the project...and I get the same value every time..could someone take a look at my code and tell me what's wrong?
Code:
// PIC16F877 + Nokia 3310 LCD
// Hi-Tech C 

#include <pic.h>
__CONFIG( WDTDIS & PWRTEN & BORDIS & LVPDIS & DUNPROT & WRTEN & DEBUGEN & UNPROTECT);
#include "delay.h"
#include "stdlib.h"
#include "lcd3310.c"

void initialize(void)
{
	GIE=0;			// disable interrupts
	ADCS1 = 0;		//select Fosc/8
	ADCS0 = 1;
	ADCON1=0;		// A/D port configuration 0
	ADFM = 1;		//right justified result
	ADON=1;			// turn on the AD conversion module	
	lcd_init();		//initialize 3310LCD
	lcd_clear();	//clear screen	
}
/* return a 10-bit result */
unsigned int read_adc(unsigned char channel)
{
	channel&=0x07;			// truncate channel to 3 bits
	ADCON0&=0xC5;			// clear current channel select
	ADCON0|=(channel<<3);	// apply the new channel select
	ADGO=1;					// initiate conversion on the selected channel
	while(ADGO)continue;
	return(((ADRESH&0x03)<<8)+ADRESL);	// return the 10-bit result
}


float mpx4115a_read(void)                // for pressure sensor MPX4115A
{
int p_an,adc_sample;
float p_hPa_float,pres_mmHg;			

p_an=0;											// reset value
DelayMs(5);					
adc_sample = read_adc(1);

// 10 bits ADC is 1024 steps --> -Vref is 0 V and +Vref is 5 V  
// 760 mmHg = 101.325 kPa-->1 pascal is 0.0075006168 mm Hg at 0 degrees Celsius. 
// 1 mm Hg at 0 degrees Celsius is 133.3223684218 pascals.
// so ADC range goes from 0V (0 hPa) to 5 V (1223 hPa) --> each step is 1.12 hPa

if (adc_sample>1023)return;				// error detection
p_an=adc_sample; 						// 
p_hPa_float=((float)p_an*(5.0*100/1023.0));	
pres_mmHg=p_hPa_float*133.3223684218;
return (pres_mmHg);
}

void main(void)
{
	long int temp,pres;
	initialize();
	lcd_gotoxy(0,0);lcd_puts("Temp: ");   
	lcd_gotoxy(70,0);lcd_puts("C");
	lcd_gotoxy(0,3);
	lcd_puts("Pres: ");   
	lcd_gotoxy(60,3);
	lcd_puts("mmHg");
	while(1)
	{
		temp =read_adc(0)*((5.0*100.0)/1023.0);
		if (temp>99)
			{
			display_digit(1,31,(temp/100)%10);                //hundreds
			display_digit(1,40,(temp/10)%10);                 //tenths
			display_digit(1,50,temp%10);                      //ones 
			}
		else
			{
			lcd_gotoxy(30,0); lcd_puts("  ");
			lcd_gotoxy(30,1); lcd_puts("  ");                
			display_digit(1,40,(temp/10)%10);             //tenths
			display_digit(1,50,temp%10);                 //ones 
			}
		DelayMs(2500);      
		pres =mpx4115a_read();
		if (pres>99)
			{
			display_digit(3,30,(pres/100)%10);                //hundreds
			display_digit(3,40,(pres/10)%10);                 //tenths
			display_digit(3,50,pres%10);                      //ones 
			}
		else
			{
			lcd_gotoxy(30,3); lcd_puts("  ");
			lcd_gotoxy(30,4); lcd_puts("  ");                
			display_digit(3,40,(pres/10)%10);             //tenths
			display_digit(3,50,pres%10);                 //ones 
			}
		DelayMs(2500);      
	}
}

It's the same project...and I would be very happy if someone could help me...because I have to add a SHT11 too...and make a RF transmission...
Thank you in advance!
 
Re: PIC16f877 and temperature sensor Lm35 interface via pic

This is a very fun forum...full of monologues:D
Anyway...I solved this problem too...not thanks to anyone here...here are the results...maybe someone else need it too.
Now to proceed to the humidity sensor and the wireless transmission.
Code:
// PIC16F877 + Nokia 3310 LCD
// Hi-Tech C 

#include <pic.h>
__CONFIG( WDTDIS & PWRTEN & BORDIS & LVPDIS & DUNPROT & WRTEN & DEBUGEN & UNPROTECT);
#include "delay.h"
#include "stdlib.h"
#include "lcd3310.c"

void initialize(void)
{
	GIE=0;			// disable interrupts
	ADCS1 = 0;		//select Fosc/8
	ADCS0 = 1;
	ADCON1=0;		// A/D port configuration 0
	ADFM = 1;		//right justified result
	ADON=1;			// turn on the AD conversion module	
	lcd_init();		//initialize 3310LCD
	lcd_clear();	//clear screen	
}
/* return a 10-bit result */
unsigned int read_adc(unsigned char channel)
{
	channel&=0x07;			// truncate channel to 3 bits
	ADCON0&=0xC5;			// clear current channel select
	ADCON0|=(channel<<3);	// apply the new channel select
	DelayMs(10);
	ADGO=1;					// initiate conversion on the selected channel
	while(ADGO)continue;
	return(((ADRESH&0x03)<<8)+ADRESL);	// return the 10-bit result
}


float mpx4115a_read(void)                // for pressure sensor MPX4115A
{
	int p_an,adc_sample;
	float pres_mmHg;			

		p_an=0;											// reset value
		DelayMs(5);					
		adc_sample = read_adc(1);
		DelayMs(10);

// 10 bits ADC is 1024 steps --> -Vref is 0 V and +Vref is 5 V  
// 760 mmHg = 101.325 kPa  
// Vout = VDD*(0.009*P - 0.095) it's a linear ecuation --> y = mX + b
// m = Prange / ADrange = 100 / 920 and b = Pmax - (m * ADmax) = 115 - (0.1087 * 975)
// P = 0.1087 * ADval + 9.0175

		if (adc_sample>1023)return;				// error detection
		p_an=adc_sample; 						
		pres_mmHg=0.1087*p_an+9.0175;
		return (pres_mmHg);
}

void main(void)
{
	long int temp,pres;
	initialize();
	lcd_gotoxy(0,0);lcd_puts("Temp: ");   
	lcd_gotoxy(70,0);lcd_puts("C");
	lcd_gotoxy(0,3);
	lcd_puts("Pres: ");   
	lcd_gotoxy(60,3);
	lcd_puts("mmHg");
	while(1)
	{
		temp =read_adc(0)*((5.0*100.0)/1023.0);
		if (temp>99)
			{
			display_digit(1,31,(temp/100)%10);                //hundreds
			display_digit(1,40,(temp/10)%10);                 //tenths
			display_digit(1,50,temp%10);                      //ones 
			}
		else
			{
			lcd_gotoxy(30,0); lcd_puts("  ");
			lcd_gotoxy(30,1); lcd_puts("  ");                
			display_digit(1,40,(temp/10)%10);             //tenths
			display_digit(1,50,temp%10);                 //ones 
			}
		DelayMs(250);      
		pres =mpx4115a_read();
		if (pres>99)
			{
			display_digit(3,30,(pres/100)%10);                //hundreds
			display_digit(3,40,(pres/10)%10);                 //tenths
			display_digit(3,50,pres%10);                      //ones 
			}
		else
			{
			lcd_gotoxy(30,3); lcd_puts("  ");
			lcd_gotoxy(30,2); lcd_puts("  ");                
			display_digit(3,40,(pres/10)%10);             //tenths
			display_digit(3,50,pres%10);                 //ones 
			}
		DelayMs(250);      
	}
}
 
Re: PIC16f877 and temperature sensor Lm35 interface via pic

Thank you for the reply superman2009...you are the first one!:)
I already managed to configure the temp sensor.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Re: PIC16f877 and temperature sensor Lm35 interface via pic

plz could any body help me with schematic and source code for room control using lm35 and 16f877a ???
 

Re: PIC16f877 and temperature sensor Lm35 interface via pic

dahroug...just look up...I put the code there...you can just delete the part with the mpx4115
 

i want to make 7 segment as read out and all seven segments from one port
and plz i want the schematic cuz i have some problems in connections
 

Re: PIC16f877 and temperature sensor Lm35 interface via pic

ok ok i saw the images it is a perfect work i will do it
thanx alot
 
Hi Guy,

May somebody help me to send a full schimatic diagram and the 16F877 source code and im need it in my FYP....Thanks
 
Hi all,
Here is a code I wrote to read off of MPX4115 and send to 16x2 LCD:
Code:
program PressureSensor
'Microcontroller:ATMEGA88
'Compiler: mikroBASIC PRO for AVR
'Programmer: Syed Tahmid Mahbub

dim LCD_RS as sbit at PORTB2_bit
dim LCD_EN as sbit at PORTB3_bit
dim LCD_D4 as sbit at PORTB4_bit
dim LCD_D5 as sbit at PORTB5_bit
dim LCD_D6 as sbit at PORTB6_bit
dim LCD_D7 as sbit at PORTB7_bit

dim LCD_RS_Direction as sbit at DDB2_bit
dim LCD_EN_Direction as sbit at DDB3_bit
dim LCD_D4_Direction as sbit at DDB4_bit
dim LCD_D5_Direction as sbit at DDB5_bit
dim LCD_D6_Direction as sbit at DDB6_bit
dim LCD_D7_Direction as sbit at DDB7_bit

dim Pressure as longword
dim Vout as longword
dim vString as string[7]
dim vWord as word[3]

main:
     LCD_Init()
     LCD_Cmd(_LCD_CLEAR)
     LCD_Cmd(_LCD_CURSOR_OFF)
     LCD_Out(1, 1, "Pressure:")
     vString = "115kPa"
     while true
           Vout = (ADC_Read(0) * 500) >> 10 'Get Vout
           Pressure = ( (2 * Vout) + 95 ) div 9  'Formula for getting Pressure, as stated in datasheet
           vWord[0] = (Pressure div 100) + 48
           vWord[1] = ( (Pressure div 10) mod 10) + 48
           vWord[2] = (Pressure mod 10) + 48
           vString[0] = vWord[0]
           vString[1] = vWord[1]
           vString[2] = vWord[2]
           LCD_Out(1, 11, vString)
     wend
end.
MPX4115 pin 1 connected to PC0 (pin 23) of ATMEGA88.

LCD connections:
RW - gnd
RS - PB2
E - PB3
D4...D7 - PB4...PB7

Hope this helps someone here.
Tahmid.
 

can somebody send me the schematic diagram for the wireless temp sensor.. tnx..
 

can someone plzzz send the same code in assembly language plzzzzz

---------- Post added at 17:20 ---------- Previous post was at 17:07 ----------

actuallt i am making project on temprature control in which i have to set the reference temprature ,let say 30,on value less than 30 heater starts and on value gr8ter than 30 cooler starts. i can also change the reference temprature from keypad!!! i also have to interface lcd on which i can see the temprature variations....guyzzz plz plz send me the code on assembly language of pic 16f877a...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top