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.

LM35 simulating in proteus

Status
Not open for further replies.

dabby21

Advanced Member level 4
Joined
Aug 8, 2011
Messages
114
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Philippines
Activity points
2,232
sirs,

good day,

im working a simulation on LM35 through pic and output the results in LCD.

Code:
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

float temp;
char i,txt[15];
unsigned int temp_res;

unsigned int quanta=0.488;

void Move_Delay() {                  // Function used for text moving
  Delay_ms(500);                     // You can change the moving speed here
}


void main(){

  ADCON1 = 0x0E;
  ADCON0 = 0x00;                     // Set PORTA.0 To analog And all others digital
  ADCON2 = 0x8A;                     // Set PORTA analog And right justify result

  TRISA = 0xFF;
  TRISB = 0x00;
  PORTB = 0x00;
  LATB = 0x00;
  

  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

  Lcd_Out(1, 1, "Temperature :");
  Lcd_Chr(2,8,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(2,9,'C');                  // Display "C" for Celsius
  ADC_Init();                        // Initialize ADC

 do{

           temp_res = ADC_Read(0);
           temp= temp_res * quanta;
           FloatToStr(temp, txt);            // Convert temperature to string
           Lcd_Out(2,3,txt);
           Delay_Ms(300);

           } while(1);

  

  
/*  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt3);                 // Write text in first row

  Lcd_Out(2,6,txt4);                 // Write text in second row
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Out(1,1,txt1);                 // Write text in first row
  Lcd_Out(2,5,txt2);                 // Write text in second row

  Delay_ms(2000);

  // Moving text
  for(i=0; i<4; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }

  while(1) {                         // Endless loop
    for(i=0; i<8; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();
    }

    for(i=0; i<8; i++) {             // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      Move_Delay();
    }
  }   */

}

upon researching, i have come up the above code, outputting the string temperature and character to the LCD was good, but when i try to change the result of LM35 in protues, it does not change the result on the LCD.\


heres my simulation on proteus sirs. thanks in advance
 

hello,

Does temp_res follow the LM35 value change ?
you better had to write :
Temp=(float)temp_res * quanta;
 

hello,

Does temp_res follow the LM35 value change ?
you better had to write :
Temp=(float)temp_res * quanta;

thanks for the reply, but unfortunately, it didn't work. The results are still the same.

is there something i miss in my program? or on my hardware?
 
Last edited:

hello,

When you change the value on LM35 , value is in °C ?
does the AN0 in mV value change also ?
Try to display the temp_res value on lcd instead of the float value.
WordToStr(temp_res,txt);

also, Initialize the quanta value in the main . or declare it as constant value.
 

hello,

When you change the value on LM35 , value is in °C ?
does the AN0 in mV value change also ?
Try to display the temp_res value on lcd instead of the float value.
WordToStr(temp_res,txt);

also, Initialize the quanta value in the main . or declare it as constant value.

hi,

I made changes on the program like you told me to ,but unfortunately sir, the output on LCD is still the same.
Code:
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

void main(){

     float temp;
     char txt[15];
     unsigned int temp_res;
     const int quanta=0.488;


  ADCON1 = 0x0E;
  ADCON0 = 0x00;                     // Set PORTA.0 To analog And all others digital
  ADCON2 = 128;                     // Set PORTA analog And right justify result

  TRISA = 0xFF;
  TRISB = 0x00;
  PORTB = 0x00;

  

  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

  Lcd_Out(1, 1, "Temperature :");
  Lcd_Chr(2,8,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(2,9,'C');                  // Display "C" for Celsius
  ADC_Init();                        // Initialize ADC

 do{

           temp_res = ADC_Read(0);
           temp= temp_res * quanta;
           WordToStr(temp, txt);            // Convert temperature to string
           Lcd_Out( 2, 3 , txt);
           Delay_Ms(500);

           } while(1);
}
 

const int quanta=0.488;
it's a float value , not integer!


try

Code:
float quanta;

quanta=0.488;
....
CMCON=0;
ADCON0=0x01; //enable ADC ,Set PORTA.0 To analog And all others digital
ADCON1 = 0x0E;
ADCON2 = 128;                     // Set PORTA analog And right justify result

etc ....

do{
           Lcd_Cmd(_LCD_CLEAR); 
           temp_res = 1000;
           temp= (float) temp_res * quanta;
           FloatToStr(temp, txt);            // Convert temperature to string
           Lcd_Out(1,3,txt);

           temp_res =ADC_Read(0);
           temp= (float) temp_res * quanta;
           FloatToStr(temp, txt);            // Convert temperature to string
           Lcd_Out(2,3,txt);

           Delay_Ms(2000);

           } while(1);

check if you get 48.8 on LCD on 1rst line..
Connect a voltmeter on ADC0 input proteus to show voltage input...
 

Hi,

i did copy the codes you've showed above, yup i get 48.8 on the first line of LCD, but still 0 on the second line
 

hello,

Are you sure about the input voltage on Ra0 analog input.?

try to replace lm35 by a fix value ex: 2935mv
273.5°K+20°K ,so, simulate 20°C.
 

Hi,

Yup, i already configure the ADCON1=0x0E, which puts the AN0 to analog and the rest is digital.

i am replacing the lm35 with resistors and potentio sir, and i did get some reading of it. but why is it when i used the LM35, all it reads is 0.
 

Maybe,it 's a probleme of simulator (Proteus problem)
try to put a resistor of 6,8K betwwen Lm35 output and +5V , and add a proteus tools Voltmeter to see what you get as lm35 output value.
what kind of value do you enter inside lm35
is it °C or °K
try to use °K , so 2735 for 0°C or 2935 for 20°C !
 

sirs,

good day,

im working a simulation on LM35 through pic and output the results in LCD.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
 
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
 
float temp;
char i,txt[15];
unsigned int temp_res;
 
unsigned int quanta=0.488;
 
void Move_Delay() {                  // Function used for text moving
  Delay_ms(500);                     // You can change the moving speed here
}
 
 
void main(){
 
  ADCON1 = 0x0E;
  ADCON0 = 0x00;                     // Set PORTA.0 To analog And all others digital
  ADCON2 = 0x8A;                     // Set PORTA analog And right justify result
 
  TRISA = 0xFF;
  TRISB = 0x00;
  PORTB = 0x00;
  LATB = 0x00;
  
 
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
 
  Lcd_Out(1, 1, "Temperature :");
  Lcd_Chr(2,8,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(2,9,'C');                  // Display "C" for Celsius
  ADC_Init();                        // Initialize ADC
 
 do{
 
           temp_res = ADC_Read(0);
           temp= temp_res * quanta;
           FloatToStr(temp, txt);            // Convert temperature to string
           Lcd_Out(2,3,txt);
           Delay_Ms(300);
 
           } while(1);
 
  
 
  
/*  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt3);                 // Write text in first row
 
  Lcd_Out(2,6,txt4);                 // Write text in second row
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
 
  Lcd_Out(1,1,txt1);                 // Write text in first row
  Lcd_Out(2,5,txt2);                 // Write text in second row
 
  Delay_ms(2000);
 
  // Moving text
  for(i=0; i<4; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }
 
  while(1) {                         // Endless loop
    for(i=0; i<8; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();
    }
 
    for(i=0; i<8; i++) {             // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      Move_Delay();
    }
  }   */
 
}


upon researching, i have come up the above code, outputting the string temperature and character to the LCD was good, but when i try to change the result of LM35 in protues, it does not change the result on the LCD.\


heres my simulation on proteus sirs. thanks in advance

There are some errors present in your code.

For example in line #21 unsigned int quanta=0.488;
Rectify those errors

---------- Post added at 21:55 ---------- Previous post was at 21:37 ----------

Also see ADC Conversion Clock Select bit setting for PIC16F87XA, 18F2x2, 18F4x microcontroller https://www.edaboard.com/blog/1542/

see Display temperature on LCD 16x2 display using LM35 and Pic16F876A https://www.edaboard.com/blog/1486/

Also use advance search option to search Tahmid's Blog entries (https://www.edaboard.com/members/172910/). They are really good
 
Code:
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
 void main(){
     float temp;
     char txt[15];
     unsigned int temp_res;
     float quanta=0.488;

  ADCON1 = 0x0E;
  ADCON0 = 0x00;                     // Set PORTA.0 To analog And all others digital

   /*
      ADCON2

      *ADC Result Right Justified.
      *Acquisition Time = 2TAD
      *Conversion Clock = 32 Tosc
   */
  ADCON2=0b10001010;

  CMCON = 0x07 ;                     // Disbale comparators

  TRISA = 0xFF;
  TRISB = 0x00;
  PORTB = 0x00;


ADCON0.ADON=1;


  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

  Lcd_Out(1, 1, "Temperature :");
  Lcd_Chr(2,8,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(2,9,'C');                  // Display "C" for Celsius
  ADC_Init();                        // Initialize ADC

 do{


           temp_res = ADC_Read(0);
           temp= (temp_res) * (quanta);
           FloatToStr(temp, txt);            // Convert temperature to string
           Lcd_Out( 2, 3 , txt);
           Delay_Ms(1000);

           } while(1);
}

Sirs,

Good day, thanks for the replies regarding my problem.

Above code is modified changing int to float. but still the same results and i also add up the adcon2 configurations for acquisition tme and clock conversion. still the same results.



but when i interface it on real, i manage to output the results of LM35, why on protues it will not work?

and i have encountered ANSELH syntax considered to be error on microC.... anyone can help me out? TIA
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top