0
votes

Iwould be most grateful if your experts on using the C18 compiler could give me a pointer as to what I am doing wrong. To become familiar I started a simple thermometer project:- NTC thermistor --> 18F2520 --> HD44780.

After getting the chain debugged and producing the code to convert the AN0 input voltage , mid range 2.5V = 10000 ohm, all was well including the needed routines to get the TºC onto the LCD.

The above was bare bones but working nicely producing a new LCD dispay of TºC every second.

Next step was to become a little more sofhisticated,

At the beginning of the tcalc function I put in an out of range test. If as I had initially decided, the application was going to measure water temperature. Then Rntc greater than 28000 would be ice, (out of range above ) At the other end of valid values <1900 is getting almost to steam. The routine I was calling to give an error message was being igmored.

Here is the tcalc code to change Rntc into a temperature TºC

    /**************************************************
                Start tcalc
***************************************************/
void tcalc(unsigned char value) // does Rntc to T maths
{
     // start read AN0 for ADRESH ADRESL
  ADCON0 = 0x03;
  while(   ADCON0 == 0x03);// loop A/D 11 bits
    // notes at end  explain 11bit convert in 5 us

   Delay10TCYx(20); // +20us saftey margin
   ADRESH =0x02; //Dummy we use 512 as test value
   ADRESL =0x00;// Dummy 0x200 = d512
   Vin= ADRESH*256+ADRESL; 
   Rntc = (1024.0*Rref)/Vin -Rref;
 //  Rntc = 29000;//DUMMY test 2hi

/***********************************************
 Rntc MUST be valid (in range) test above/below
***********************************************/

if ( Rntc>28000) // Rntc too high
{
 Rntc_out; //jump to Show HIGH error message

}

dly1sec;

if (Rntc<1900) // Rntc too low
{
   Rntc_out; //jump to Show LOW error message
}


/***********************************************
Pairing Rntc value, with T equation coefficients
***********************************************/

if (Rntc>14706) //case 1
   {
    a = 19.67,b = -1136.15, c = 27335.25 ;
    goto Trange_1thru5 ;
   }
if (Rntc>8310.8) //case 2
   {
    a = 9.228,b = -840.85, c =25236.82 ;
    goto Trange_1thru5 ;
   }
if (Rntc>4910.6) //case 3
   {
    a = 4.554,b =-567.886, c = 21246.2 ;
    goto Trange_1thru5 ;
   }
if (Rntc>3019.7) //case 4
   {
    a = 2.358,b = -373.486, c = 16941.29 ;
    goto Trange_1thru5 ;
   }
if (Rntc>1924.6) //case 5
   {
    a = 1.275,b = -245.047, c = 13131.885 ;
    goto Trange_1thru5 ;
   }





Trange_1thru5:
  c= c-Rntc; 
  T = (-b - sqrt(-b*-b -4*a*c))/(2*a);
      /* Quadratic T result chosen has to be lowest */

}
/******************************************************
               END tcalc
*******************************************************/

The called routine 'Rntc_out' is as follows

/******************************************************* 
           ****** Start Rntc_outofrange ******
********************************************************/

void Rntc_out (unsigned char value) 
{
 lcdcmd(0x80);//move to top line of LCD
// RntcHL =Rntc;
if (Rntc<1900) //Rntc too low
 {
 lcddata('R');  
 lcddata('n');
 lcddata('t');
 lcddata('c');
 lcddata(' ');
 lcddata('t');
 lcddata('o');
 lcddata('o');
 lcddata(' ');
 lcddata('L');
 lcddata('o');
 lcddata('w');
 lcdcmd(0xC0);//Bottom line of LCD
 T = Rntc;
float_to_char;
 dly1sec;
 dly1sec;
 dly1sec;
 dly1sec;
 dly1sec;//  Rntc low  on screen 5 seconds 

 }

if ( Rntc>27500) // Rntc too high
 {
 lcddata('R'); 
 lcddata('n');
 lcddata('t');
 lcddata('c');
 lcddata(' ');
 lcddata('t');
 lcddata('o');
 lcddata('o');
 lcddata(' ');
 lcddata('H');
 lcddata('i');
 lcddata('g');
 lcddata('h');
 lcdcmd(0xC0);//Bottom line of LCD
 T = Rntc;
float_to_char;
 dly1sec;
 dly1sec;
 dly1sec;
 dly1sec;
 dly1sec; // Rntc high  on screen 5 seconds */

 }

}


/******************************************************* 
           ****** End Rntc_outofrange ******
********************************************************/

Basically my question is when testing for out of range Rntc. The code is skipped as if it were not there.

PS If I put the Rntc module's code as a Label : and goto the code, then yes the test for out of range is not ignored and the condition can be serviced.

Of course the 'goto' ploy has a little problem. The outof range reading means that after a few seconds, the thermistor has to be read again. meaning another goto to tcalc. meaning calling itself. C18 doesn't seem to like this.

I would be very happy if some kind soul could point out the error of my code at least in general.

1

1 Answers

1
votes

To call a function, you need to use parentheses and pass it its argument, and you'll probably want to follow that up with a return:

Rntc_out(Rntc); // I'm guessing this is the parameter you want?
return;

I see a number of other function calls in your program with missing parentheses. You'll need to fix these too.