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.

Automatic temperature controller using pic 16f877a [MOVED]

Status
Not open for further replies.

abirm

Newbie level 3
Newbie level 3
Joined
May 1, 2019
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
61
hi !
I have to realize a temperature controller using pic 16f877a . normali, the microcontroller reads the temperature continuously and compares it to the desired value. when the desired value is higher than the measured value, the relay and the red LED are activated. when the desired value is equal to the measured value, the green LED is activated. but i dont find this faction (the relay and the leds do not work ). this is my code on micrc please helpe me to find the
fault :sad:


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
// 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
char display[16]="";
 
void Move_Delay() { // Function used for text moving
Delay_ms(2000); // You can change the moving speed here
}
#define HEATER PORTD.RD2
#define LED_RED  PORTD.RD3
#define LED_GREEN PORTD.RC5
#define ButtonPlus PORTD.RD0
#define Buttonmoins  PORTD.RD1
#define ON 1
#define OFF 0
 
void main() {
unsigned int result;
float volt,temp;
float temp_ref=50;
 
trisb=0;
trisa=0xff;
adcon1=0x80;
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_LCD_CURSOR_OFF);
while(1)
{
  result=adc_read(0);
  volt=result*4.88;
  temp=volt/10;
 
  lcd_out(1,1,"Temp =");
 
  floattostr(temp,display);
  lcd_out_cp(display);
  lcd_chr(1,15,223); //print at pos(row=1,col=13) "°" =223 =0xdf
  lcd_out_cp("C"); //celcius
 
   if(ButtonPlus == 1) {
      temp_ref +=5;
      if(temp_ref >100)
      temp_ref = 50;
      }
 
       if(Buttonmoins == 1) {
      temp_ref -=5;
      if(temp_ref < 10)
      temp_ref = 50;
      }
 
  lcd_out(2,1,"T. Ref =");
 
  floattostr(temp_ref,display);
  lcd_out_cp(display);
  lcd_chr(2,15,223); //print at pos(row=1,col=13) "°" =223 =0xdf
  lcd_out_cp("C");
 
 
  Delay_ms(500);
 
    if (temp_ref < Temp)
        {
        HEATER = 1;
        LED_RED = 1;
        LED_GREEN = 0;
       }
        if (temp_ref >= Temp)
        {
        HEATER =0;
        LED_RED = 0;
        LED_GREEN = 1;
      }
}
}

 

In mikroC code if you use assign integer value to float or double type variable then that doesn't work.

Try this.


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
// 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
char display[23]="";
 
void Move_Delay() { // Function used for text moving
Delay_ms(2000); // You can change the moving speed here
}
#define HEATER PORTD.RD2
#define LED_RED  PORTD.RD3
#define LED_GREEN PORTD.RC5
#define ButtonPlus PORTD.RD0
#define Buttonmoins  PORTD.RD1
#define ON 1
#define OFF 0
 
void main() {
unsigned int result;
float volt = 0.0,temp = 0.0;
float temp_ref=50.0;
 
trisb=0;
trisa=0xff;
adcon1=0x80;
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_LCD_CURSOR_OFF);
while(1)
{
  result=adc_read(0);
  volt=result*4.88;
  temp=volt/10.0;
 
  lcd_out(1,1,"Temp =");
 
  floattostr(temp,display);
  lcd_out_cp(display);
  lcd_chr(1,15,223); //print at pos(row=1,col=13) "°" =223 =0xdf
  lcd_out_cp("C"); //celcius
 
   if(ButtonPlus == 1) {
      temp_ref +=5.0;
      if(temp_ref >100.0)
      temp_ref = 50.0;
      }
 
       if(Buttonmoins == 1) {
      temp_ref -=5.0;
      if(temp_ref < 10.0)
      temp_ref = 50.0;
      }
 
  lcd_out(2,1,"T. Ref =");
 
  floattostr(temp_ref,display);
  lcd_out_cp(display);
  lcd_chr(2,15,223); //print at pos(row=1,col=13) "°" =223 =0xdf
  lcd_out_cp("C");
 
 
  Delay_ms(500);
 
    if (temp_ref < Temp)
        {
        HEATER = 1;
        LED_RED = 1;
        LED_GREEN = 0;
       }
        if (temp_ref >= Temp)
        {
        HEATER =0;
        LED_RED = 0;
        LED_GREEN = 1;
      }
}

 

I think that 'PORTC.RC5' is wrong is this PORTD.RD5 or PORTC.RC5?
I can't see where you are setting TRISD to make pins 2, 3 and 5 as outputs.
Depending on the load on the lines to the relay and LEDs, you could well be suffering the RMW problem that MCUs with only a PORT register can have. It would be better to create a shadow register for the output bits, set that how you want then and then write that shadow register to the PORT.
Susan
 
  • Like
Reactions: abirm

    abirm

    Points: 2
    Helpful Answer Positive Rating
What is the value the LCD is showing

Is value of the LCD changing when the temperature increasing and decreasing
 

try define like
#define HEATER RD2_bit;
and in main give TRISD=0;
 
  • Like
Reactions: abirm

    abirm

    Points: 2
    Helpful Answer Positive Rating
I think that 'PORTC.RC5' is wrong is this PORTD.RD5 or PORTC.RC5?
I can't see where you are setting TRISD to make pins 2, 3 and 5 as outputs.
Depending on the load on the lines to the relay and LEDs, you could well be suffering the RMW problem that MCUs with only a PORT register can have. It would be better to create a shadow register for the output bits, set that how you want then and then write that shadow register to the PORT.
Susan

it is PORTC.RC5
 

You have to change this,

Code:
volt=result*4.88;

to this

Code:
volt=(float)result*4.88;
 

When i run the code in the micro c software, i have no errors, but when i run the code in the appropriate schematic in isis, i don't find the operation that i wont. Because, when i compare the temperature of the sensor with the static telmperature that i put in the program(50), normally, if temp<temp_ref, the red led and the heater operates (ON), and if temp>=temp_ref, the green led is ON and the heater is OFF. But i don't find this functions.
 

Zip and post the complete mikroC PRO PIC project files and also the Proteus file so that I can test it here and fix it if needed.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top