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.

c intostring what it is really does?

Status
Not open for further replies.

libyantiger

Member level 5
Joined
Aug 10, 2016
Messages
90
Helped
0
Reputation
0
Reaction score
3
Trophy points
1,288
Activity points
2,269
Code:
/*
 * Project name:  Automatic Temperature Control
 * Copyright:
 *    (c) [url]www.studentcompanion.co.za[/url], 2014.
 * Test configuration:
 *    MCU:             PIC18F45K22
 *                     **broken link removed**
 *    Oscillator:      HS-PLL, 32.00000 MHz
 * Compiler mikroC Pro for PIC v6.5.0
 */
 
// Keypad module connections
char  keypadPort at PORTB;
// End Keypad module connections
 
// LCD module connections
sbit LCD_RS at LATC4_bit;
sbit LCD_EN at LATC5_bit;
sbit LCD_D4 at LATC0_bit;
sbit LCD_D5 at LATC1_bit;
sbit LCD_D6 at LATC2_bit;
sbit LCD_D7 at LATC3_bit;
 
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections
 
#define HEATER PORTD.RD0
#define FAN PORTD.RD1
#define ENTER 15
#define CLEAR 13
#define ON 1
#define OFF 0
 
void main() {
  unsigned short kp,Txt[14];
  unsigned short Temp_Ref ;      //  Reference Temperature
  unsigned char inTemp;
  unsigned int temp;
  float mV, ActualTemp;
  
  Keypad_Init();                           // Initialize Keypad
  ANSELC = 0;                              // Configure PORTC as digital I/O
  ANSELB = 0;                              // Configure PORTB as digital I/O
  ANSELD = 0;                              // Configure PORTD as digital I/O
  TRISA0_bit = 1;                          //Configure AN0 (RA0) as input
  TRISC = 0;                               //PORTC are outputs (LCD)
  TRISD0_bit=0;                            //RD0 is output (Heater)
  TRISD1_bit=0;                            //RD1 is output (Fan)
  
  Lcd_Init();                              // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off
  Lcd_Out(1, 4, "Automatic");
  Lcd_Out(2, 2, "Temp Control");
  delay_ms(2000);                          //2s delay
  
  HEATER = OFF;
  FAN = OFF;
 
  //ON startup, read the Referance Temperature from the Keypad
        START:
       Lcd_Cmd(_LCD_CLEAR);                     // Clear display
       Lcd_Out(1, 1, "Enter Temp Ref");
       Temp_Ref=0;
        Lcd_Out(2, 1, "Temp Ref: ");
        while(1)
        {
         do
         kp = Keypad_Key_Click();             // Store key code in kp variable
         while (!kp);
         if ( kp == ENTER )break;
         if (kp > 3 && kp < 8) kp = kp-1;
         if (kp > 8 && kp < 12) kp = kp-2;
         if (kp ==14)kp = 0;
         if ( kp == CLEAR )goto START;
         Lcd_Chr_Cp(kp + '0');
         Temp_Ref =(10*Temp_Ref) + kp;
       }
      Lcd_Cmd(_LCD_CLEAR);                     // Clear display
      Lcd_Out(1, 1, "Temp Ref: ");
      intToStr( Temp_Ref,Txt);         //Convert to String
      inTemp=Ltrim(Txt);
       Lcd_Out_CP(inTemp);                  //Display Ref Temp
      Lcd_Out(2, 1, "Press # to Cont.");
      //Wait until # is pressed
      kp =0;
      while(kp!=ENTER)
      {
         do
           kp = Keypad_Key_Click();             // Store key code in kp variable
         while(!kp);
      }
       Lcd_Cmd(_LCD_CLEAR);              // Clear display
       
   Lcd_Out(1, 1, "Temp Ref: ");
   Lcd_Chr(1,15,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(1,16,'C');                  // Display "C" for Celsius
   //Program loop
  while(1) {
     //Display Referance Temperature and Actual Temperature
     temp = ADC_Read(0);               //Read temperature from AN0
     mV = temp * 5000.0/1024.0;        //Convert to mV
     ActualTemp = mV/10.0 ;              // Convert to degrees Celcius
     intToStr( Temp_Ref,Txt);         //Convert to String
     inTemp=Ltrim(Txt);
     //Lcd_Out(1, 1, "Temp Ref: ");
     Lcd_Out(1, 11, inTemp);        //Display Ref Temp
     Lcd_Out(2, 1, "Temp= ");
     FloatToStr(ActualTemp,Txt);         //Convert to string
     Txt[4] = 0;
     Lcd_Out(2,7,Txt);
     Lcd_Out(2,12,"   ");
 
      //Compare ref temp with actual emp
      if (Temp_Ref >  ActualTemp)  //If Temp Ref is less than actual Temp, Switch ON Heater
      {
      HEATER = ON,
      FAN = OFF;
      }
       if (Temp_Ref <  ActualTemp)  //If Temp Ref is greater than actual Temp, Switch ON Fan
      {
      HEATER = OFF,
      FAN = ON;
      }
      if (Temp_Ref ==  ActualTemp)  //If Temp Ref is equal to actual Temp, Switch OFF Fan and Heater
      {
      HEATER = OFF,
      FAN = OFF;
      }
      Delay_ms(10000);        //Wait 10 s then repeat
  }
}

when he turn the temp ref to a string using
intToStr( Temp_Ref,Txt); //Convert to String

and store it to txt but next when he dsplayed txt

it was not only the number that tem_ref varible equals it been displayed in an lcd as


tem_ref := 15


so intostr have turned the 15 into str or the entire

temp ref which equals 15 into a

"temp ref 15"

confusion about intostr is it deals with the value of the varible turning it into string or the name and the value of the vraible to be turned intto string?

have look the the project picture



Code:
------------

sbit LCD_RS at LATC4_bit;
sbit LCD_EN at LATC5_bit;
sbit LCD_D4 at LATC0_bit;
sbit LCD_D5 at LATC1_bit;
sbit LCD_D6 at LATC2_bit;
sbit LCD_D7 at LATC3_bit;
 
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections

in this lines he tells the compiler to go to trisac bits to seek the direction of data ,,,if it input or output .... all respect

but i cant see traisa c4 = 0 i mean there is no assignment of direction of 1 which is input or 0 which is output

i cant see where that happens???


------------------------------------------------------------------------------



last question at the end of the loop there is a while 1 loop which is loop forever how the program manages to reach the comparison

lines that are after the while 1 loop ,,,if the while 1 loop simply looops forever ? how that happens?

article-1371251-0B6205FB00000578-734_634x386.jpg
 
Last edited by a moderator:

Instead of guessing you can review the MikroC manual to know what IntToStr() exactly does.

Of course it's not printing variable names, you'll find the respective instruction in the code above.
Code:
Lcd_Out(1, 1, "Temp Ref: ");
 

Instead of guessing you can review the MikroC manual to know what IntToStr() exactly does.

Of course it's not printing variable names, you'll find the respective instruction in the code above.
Code:
Lcd_Out(1, 1, "Temp Ref: ");

thanks for reply
but

that is a comment and not an instruction ?

note that ii am talking about the last part of the program the last while 1 loop

it is within this loop that i find the temp ref appearing on lcd while i cant see when it happened in code

because code is supposed to show it value of the temp ref vairble and not the name of the variable



i made look at the manual it shows nothing
 
Last edited:

that is a comment and not an instruction ?

note that ii am talking about the last part of the program the last while 1 loop
Yes, it's commented out in the last block. However if you see Temp Ref printed on the LCD, be pretty sure that it has been printed out by a Lcd_Out() instruction in the code above.

As for IntToStr(), I don't see what's unclear about it. Here's the description in user manual:
Converts input signed integer number to a string. The output string has fixed width of 7 characters including null character at the end (string termination). The output string is right justified and the remaining positions on the left (if any) are filled with blanks.
 

Yes, it's commented out in the last block. However if you see Temp Ref printed on the LCD, be pretty sure that it has been printed out by a Lcd_Out() instruction in the code above.

As for IntToStr(), I don't see what's unclear about it. Here's the description in user manual:




in the lcd display there are "temp ref: 13 " .... word displayed neatly


i can see from where he gets the 13 he get it from into string function being applied on the

TEM__REF varible and storing it in txt and then storing txt in the inTEMP VARIBLE


AND then displaying out the inetmp yes sir i saw that ....what i cant see is how he on eaith was able to display out the


letter of "temp ref" i saw them on lcd ,,,,,i didnt see the line where did get displayed


thanks
 

"Temp Ref" and "°C" are written once in line 100 - 103 and never cleared.
 

"Temp Ref" and "°C" are written once in line 100 - 103 and never cleared.

CLEVER AND CONFUSING IDEA BUT what about my question about trisa usage i never saw when he assign trisa some value like 1 or 0?
 

what about my question about trisa usage i never saw when he assign trisa some value like 1 or 0?
Which port pins do you particularly worry about? TRISA is actually set in your code for the whole port. PORT B direction registers are probably set in the key input module which isn't included in your code. (I guess it's mikroC built-in functon?).

Also consider that TRIS registers default to 0xFF after reset (all input).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top