+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Newbie level 3
    Points: 40, Level: 1

    Join Date
    May 2019
    Posts
    3
    Helped
    0 / 0
    Points
    40
    Level
    1

    Automatic temperature controller using pic 16f877a [MOVED]

    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

    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;
          }
    }
    }

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 2
    Points: 2,819, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    559
    Helped
    49 / 49
    Points
    2,819
    Level
    12

    Re: Automatic temperature controller using pic 16f877a [MOVED]

    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;
          }
    }



  3. #3
    Advanced Member level 4
    Points: 7,540, Level: 20

    Join Date
    Jan 2015
    Posts
    1,061
    Helped
    333 / 333
    Points
    7,540
    Level
    20

    Re: Automatic temperature controller using pic 16f877a [MOVED]

    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


    1 members found this post helpful.

  4. #4
    Advanced Member level 3
    Points: 4,911, Level: 16
    Achievements:
    7 years registered
    PA3040's Avatar
    Join Date
    Aug 2011
    Posts
    865
    Helped
    44 / 44
    Points
    4,911
    Level
    16

    Re: Automatic temperature controller using pic 16f877a [MOVED]

    What is the value the LCD is showing

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



    •   AltAdvertisement

        
       

  5. #5
    Newbie level 4
    Points: 2,846, Level: 12

    Join Date
    Dec 2003
    Posts
    6
    Helped
    1 / 1
    Points
    2,846
    Level
    12

    Re: Automatic temperature controller using pic 16f877a [MOVED]

    try define like
    #define HEATER RD2_bit;
    and in main give TRISD=0;


    1 members found this post helpful.

  6. #6
    Newbie level 3
    Points: 40, Level: 1

    Join Date
    May 2019
    Posts
    3
    Helped
    0 / 0
    Points
    40
    Level
    1

    Re: Automatic temperature controller using pic 16f877a [MOVED]

    Quote Originally Posted by Aussie Susan View Post
    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



  7. #7
    Advanced Member level 2
    Points: 2,819, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    559
    Helped
    49 / 49
    Points
    2,819
    Level
    12

    Re: Automatic temperature controller using pic 16f877a [MOVED]

    You have to change this,

    Code:
    volt=result*4.88;
    to this

    Code:
    volt=(float)result*4.88;



  8. #8
    Newbie level 3
    Points: 40, Level: 1

    Join Date
    May 2019
    Posts
    3
    Helped
    0 / 0
    Points
    40
    Level
    1

    Re: Automatic temperature controller using pic 16f877a [MOVED]

    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 green led is ON and the heater is OFF. But i don't find this functions.



    •   AltAdvertisement

        
       

  9. #9
    Advanced Member level 2
    Points: 2,819, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    559
    Helped
    49 / 49
    Points
    2,819
    Level
    12

    Re: Automatic temperature controller using pic 16f877a [MOVED]

    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.



--[[ ]]--