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.

Temperature Sensor (LM35 + PIC16F877A)

Status
Not open for further replies.

Mr.Khiros

Junior Member level 3
Joined
Aug 25, 2013
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
176
Hi ;
i'm using PIC16F877A with temperature sensor LM35 . I refered to this work
https://forum.allaboutcircuits.com/blog.php?b=513
but i'm not able to unterstand those instructions :
ADRead = (ADC_Get_Sample(0) * 500) >> 10;
vDisp[0] = ADRead / 100;
vDisp[1] = (ADRead / 10) % 10;
vDisp[2] = ADRead % 10;
Display[1] = vDisp[0] + 48;
Display[2] = vDisp[1] + 48;
Display[3] = vDisp[2] + 48;
NEED YOUR HELP.
 

ADRead = (ADC_Get_Sample(0) * 500) >> 10;

// consider and ADRead value of 123
vDisp[0] = ADRead / 100; // vDisp[0] will become 1. i.e. integer left dividing 123/100 = 1 (most significant digit)

vDisp[1] = (ADRead / 10) % 10; // vDisp[1] will become 7. i.e. 123/10 = 12, and 12 % 10 is the remained times i.e. 2 (middle digit)

vDisp[2] = ADRead % 10; // vDisp[2] will become remainder of 567/10 i.e. 567/10 = 16 and the remainder is 7 (least significant digit)

The following converts the numbers to ASCII for display on a serial terminal etc. So for 123 above
Display[1] = vDisp[0] + 48; // = 49
Display[2] = vDisp[1] + 48; // = 50
Display[3] = vDisp[2] + 48; // = 51

For ASCII look at https://www.asciitable.com/ and you will see decimal 48 displays character '0'

Hope that helps with the understanding of integer division, remainders and ASCII. Nice question.
 
Max value of adc is 1023 for 5V input. Max o/p of LM35 is 1.5V. So, max adc value will be 306.9

0 to 306.9 is multiplied by 500

eg:

306.9 * 500 = 153450

153450 >> 10 = 149

149 is approx 150 max temperature of LM35.


Code C - [expand]
1
2
3
4
5
6
vDisp[0] = ADRead / 100;
vDisp[1] = (ADRead / 10) % 10;
vDisp[2] = ADRead % 10;
Display[1] = vDisp[0] + 48;
Display[2] = vDisp[1] + 48;
Display[3] = vDisp[2] + 48;



These are for extracting digits of the number


Code C - [expand]
1
2
3
vDisp[0] = ADRead / 100;
vDisp[1] = (ADRead / 10) % 10;
vDisp[2] = ADRead % 10;



149/100 = 1 //hundredths digit
149/10 = 14
14%10 = 4 //tens digit
149%10 = 9 //units digit

Converting int value to ascii charcaters by adding 48 or 0x30


Code C - [expand]
1
2
3
Display[1] = vDisp[0] + 48;
Display[2] = vDisp[1] + 48;
Display[3] = vDisp[2] + 48;



1 + 0x30 = 0x31 = '1'
4 + 0x30 = 0x34 = '4'
9 + 0x30 = 0x39 = '9'

Display[] = "149"

You can replace the above with


Code C - [expand]
1
2
3
Display[1] = ADRead / 100 + 48;
Display[2] = (ADRead / 10) % 10 + 48;
Display[3] = ADRead % 10 + 48;



or


Code C - [expand]
1
IntToStr(ADRead, strADRead); //strADRead is a string (unsigned char strADRead[23];

 
It's work know ... but there is a little prob , after the conversion to string
Code:
IntToStr(ADRead, strADRead); //strADRead is a string (unsigned char strADRead[23];
the LCD shows the digit far of it's place ?
 

This code change integer to string:
- number 0 is referred to character '0' in ASCII table ('0' has index is 48).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top