### Welcome to EDAboard.com

#### Welcome to our site! EDAboard.com is an international Electronic 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.

Status
Not open for further replies.

#### warrior_16th

##### Newbie level 6
i was searching about some temperature sensor code and i get one but actually i didnt understand it well iam just new at this field and this code have alot of function that i actually didn understand it so if anyone could help me and give me an explaination for each line i will be thank full
this the code :

int temp1;
char temp[10];
temp1=temp1*0.245*2;
INTToStr(temp1,temp);}
void main() {
TRISA = 0xFF;
TRISD=0;PORTD=0;
TRISB=0;PORTB=0;
TRISc=1;PORTc=0;
Uart1_init(9600);
Lcd_Init();
lcd_cmd(_LCD_CURSOR_OFF);
while (1) {
lcd_out(1,10,temp);
UART1_Write_Text("temperature");
UART1_Write_Text(temp);UART1_Write(13);UART1_Write(10);;Delay_ms(1000);;
} }

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
int temp1;                      // store ADC value and converted temperature
char temp[10];                  // store up to 9 ASCII characters plus null terminator

// function to read the voltage on port A0

INTToStr(temp1,temp);       // convert binary value to an ASCII string for printing later
}

void main() {
TRISA = 0xFF;               // PORTA all inputs
TRISD=0;                    // PORTD all outputs
PORTD=0;                    // PORTD all low
TRISB=0;                    // PORTB all outputs
PORTB=0;                    // PORTB all low
TRISc=1;                    // PORTC bit0 input, rest output
PORTc=0;

Uart1_init(9600);       // MikroC library function to initialise serial port
Lcd_Init();                 // MikroC library function to initialise 2x16 character LCD
lcd_cmd(_LCD_CURSOR_OFF);   // MIKROC library function to turn off the LCD flashing cursor

while (1) {                              // loop forever
lcd_out(1,10,temp);                  // send temperature to LCD
UART1_Write_Text("temperature");     // send "temperature" to serial port
UART1_Write_Text(temp);              // send value of temperature, converted to text
UART1_Write(13);                     // carriage return
UART1_Write(10);                     // line feed
;
Delay_ms(1000);                      // 1000mS (1 second) delay
;
}

}

Hope this helps

warrior_16th

### warrior_16th

points: 2

#### warrior_16th

##### Newbie level 6

THX BROTHER SO MUCH iam really thankful for u

#### alexan_e

What is the part you don't understand because even if you read it in simple English you will be able to understand what it is doing.

I assume that you know how to declare an array variable char temp[10]; or an integer int temp1;
This is also the case for INTToStr(temp1,temp); integer to string
Lcd_Init(); lcd initialize
lcd_cmd(_LCD_CURSOR_OFF); lcd send command
UART1_Write_Text("temperature"); even in this line, when you see uart write text what do you think it does?

You should be able to understand most of it

Alex

warrior_16th

### warrior_16th

points: 2

#### warrior_16th

##### Newbie level 6

What is the part you don't understand because even if you read it in simple English you will be able to understand what it is doing.

I assume that you know how to declare an array variable char temp[10]; or an integer int temp1;
This is also the case for INTToStr(temp1,temp); integer to string
Lcd_Init(); lcd initialize
lcd_cmd(_LCD_CURSOR_OFF); lcd send command
UART1_Write_Text("temperature"); even in this line, when you see uart write text what do you think it does?

You should be able to understand most of it

Alex
actually there r some lines i didnt understand such like this
int temp1;
char temp[10];
i dont know what does it mean store up to 9 ASCII characters plus null terminator

and INTToStr(temp1,temp); i new that it convert int to string but dont know why
the rest some how i can understand it
sorry for disturbing brother

warrior_16th

### warrior_16th

points: 2

#### alexan_e

actually there r some lines i didnt understand such like this
int temp1;
char temp[10];
i dont know what does it mean store up to 9 ASCII characters plus null terminator

and INTToStr(temp1,temp); i new that it convert int to string but dont know why
the rest some how i can understand it
sorry for disturbing brother
You don't disturb me at all but I though you might say something like that, if you are missing the basic knowledge of the C language (like declaring a variable) then you should really start by reading a C tutorial or book and start with simple blinking led code before you go to something that uses LCD and USART.

Alex

warrior_16th

### warrior_16th

points: 2

#### warrior_16th

##### Newbie level 6

You don't disturb me at all but I though you might say something like that, if you are missing the basic knowledge of the C language (like declaring a variable) then you should really start by reading a C tutorial or book and start with simple blinking led code before you go to something that uses LCD and USART.

Alex
hye brother i read alot about these thing and to good extent i understand the good but still dont know how he used the same variable in the same equation
temp1=temp1*0.245*2 where the variable temp1 at left hand side represnet the temperature value and the temp1 in the right hand side represnt the voltage in binary w.r.t
the temp1 value at left hand side ,how they can be named like each other

another question sorry char temp[10] are we set it up by 10 character to represent just the numbers from 0 to 9 ? like decimal number ? or what

#### andre_teprom

##### Super Moderator
Staff member
It means that operation at this variable ( right side ) is stored at this same variable ( left side ).
After that command line, temp1 contains a value different than before.

+++

warrior_16th

### warrior_16th

points: 2

#### alexan_e

temp1=temp1*0.245*2
this actually tells to the compiler to read the value of temp1 from the ram, multiply it with 0.245 and with 2 and store the result back to the variable temp1
I don't know why you think that this would be a problem to do.

char temp[10]
this declares an array of 10 characters , temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6], temp[7], temp[8], temp[9]
note that when you declare char temp[x] (or any array) you can access temp[0]..... temp[x-1]
it is just a group of 10 char type variables placed in contiguous memory space, you can assign any value to each of them but we usually use this array type as a string to hold some text (as letters in each position)
you can declare any type of array, int temp[10], long int temp[10] etc

In your code you get a result from the ADC, for example 100, then multiply it 100*0.245*2=450
and then use INTToStr function to convert the integer 450 to a string '4' '5' '0' that is stored in the temp array to be shown later in the LCD

Alex

warrior_16th

### warrior_16th

points: 2

#### warrior_16th

##### Newbie level 6
temp1=temp1*0.245*2
this actually tells to the compiler to read the value of temp1 from the ram, multiply it with 0.245 and with 2 and store the result back to the variable temp1
I don't know why you think that this would be a problem to do.

char temp[10]
this declares an array of 10 characters , temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6], temp[7], temp[8], temp[9]
note that when you declare char temp[x] (or any array) you can access temp[0]..... temp[x-1]
it is just a group of 10 char type variables placed in contiguous memory space, you can assign any value to each of them but we usually use this array type as a string to hold some text (as letters in each position)
you can declare any type of array, int temp[10], long int temp[10] etc

In your code you get a result from the ADC, for example 100, then multiply it 100*0.245*2=450
and then use INTToStr function to convert the integer 450 to a string '4' '5' '0' that is stored in the temp array to be shown later in the LCD

Alex
thx bro so much its just a samll part of my project and i am nebwie with this field but i try to learn thx again

Status
Not open for further replies.