Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help me plz

Status
Not open for further replies.

parjun

New Member
hey friend i was going thru a tutorial for PIC16F877A programming when i had one doubt in the below program....

#include<pic.h>
#include<stdio.h>
#include<delay.c>
#include<lcd.c>

/* Function to wait */

void wait_a_second()
{
unsigned int j;
for (j=0; j<4;j++)
DelayMs(250);
}

/* Main Program */

main(void)
{
const float lsb = 5000.0/1024.0; (i have doubt in this line)
float mV,temp, templ, temph;
unsigned int tempc;
unsigned char disp[]=" TEMP = ";

TRISA=1;/* RA0 is input and others output */
TRISB=0;/* Port B is output */

RBPU=0; /* Trigger the internal pullup registers */

ADCON1 = 0X8E;/* RA0 is analog and RA2 and RA3 are digital */
ADCON0 = 0X41; /* Configure A/D clock and select channel 0 */

for(;;)
{
ADCON0 = 0X45;/* Start Analog to Digital convertion */
while (ADCON0 !=0);/* wait for convertion */
temph = ADRESH;/* Upper 2 bits */
templ = ADRESL;/* Lower 8 bits */
temp = 256.0*temph+templ;/* In digital mode */
mV = temp*lsb; /* Temperature in mV */
tempc = mV/10.0; /* Temperature in centigrade since Vo is 10 mV/C hence if temperature is 30degree it is represented as 300mV/C*/
sprintf (disp+7, "%d",tempc); /* Display temperature as string */
lcd_puts(tempc);
wait_a_second();
lcd_clear();/* clear display screen of LCD*/
}
}

/* End of Program */



Questions :

1. what is the line " const float lsb =5000.0/1024.0 " means?
2. why is he multiplying 256 * temph +templ to get digital code?


THis program is for interfacing LCD with PIC16F877.....

Source:

10 EMI 05 Programming PIC Micro Controllers in C

Page no.39 of that tutorial
So help me plz
 

3v0

Coop Build Coordinator
Forum Supporter
No one here named Plz !

When you make a post please use a meaningful title. For all the info your title gives you underwear could be on fire !

When you post code use the # icon to place
Code:
tags around the code. They will preserve the formating.

OK on to your questions.
1. what is the line " const float lsb =5000.0/1024.0 " means?
declare a constant of the type float
The constant in named lsb which is short for least segnificant byte.
The compiler will calculate (5000.0/1024.0) and assigne it to the constant.

2. why is he multiplying 256 * temph +templ to get digital code?
I think the comment "In digital mode" means the sensor is not analog. Mostly just confusing here.

This is a common method of converting a value stored in 2 bytes to a 16 bit word. temph is the high byte and templ is the low byte. Multiplying temph by 256 is the same as shifting it 8 bits left.

The data was read into the sensor. The 2 high order bits were stored in temph and the 8 low order bits were stored int templ.

You want to combine temph and templ to get the 10 bit value. The temph bits are shifte right 8 bits and added to templ to get
HHLLLLLLLL

3v0
 

parjun

New Member
I want more clarification

I can understand that lsb stands for that..but what is the purpose of that in the program? we can see that lsb is being multiplied with temp for something tell me that part clearly....more over sorry for the wrong title and this program is abt interfacing LM35 with PIC16F877 and not LCD .... The sensor is LM35 which provides analog o/p

Can u give more clarity while explaining that temph and templ thing ( i mean i can understand that ADC in PIC 16F877 is 10bit one but why we need it in 10 bit format).... here we are displaying room temperature in the LCD... and also in the hyperlink attached in PAGE 38 can u tell me why we are connecting RB0-RB3 to D4-D7 in the diagram?
 
Last edited:
Status
Not open for further replies.
Top