16f877a USART display temp on PC

General discussion on mikroC.
Author
Message
20051050
Posts: 16
Joined: 02 Apr 2010 20:03

16f877a USART display temp on PC

#1 Post by 20051050 » 09 Apr 2010 13:53

Hi guys,
I am new to your forum ,and I hope that you help me ,please.

I want to display the temperature using the LM35DZ on the hyper terminal ,following is the code and does not have errors but I receive incorrect data >>

Any help please
Pic 16f877a hs 8MHz rs232


unsigned temp_value;
char *out="000000";
void main()
{
Usart_Init(9600);
ADCON1 = 0x80;
TRISA = 0xFF; // PORTA as input
while(1)
{
if (USART_Data_Ready()) {

Delay_ms(1000);
temp_value = Adc_Read(0)*5000/1024; // Read analog input
out[0]=temp_value/10;
out[1]= temp_value%10;
ByteToStr(temp_value,out);
Usart_Write("temp is");
Usart_Write(out);
}
}
}


any help ,please

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#2 Post by 20051050 » 09 Apr 2010 13:55

I want to receive data as ASCCi

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#3 Post by 20051050 » 09 Apr 2010 13:56

Any help please :cry: :cry: :cry:

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#4 Post by 20051050 » 09 Apr 2010 15:45

why you do not help me :(

Bigote
Posts: 67
Joined: 09 Aug 2009 12:51
Location: Willemstad

Re: 16f877a USART display temp on PC

#5 Post by Bigote » 10 Apr 2010 05:21

Hi

I think that you are making several mistakes

1. If you want to just send data to the hyper terminal you don't need this method " USART_Data_Ready() ". Delete it and and just leave
everything that needs to be done over and again inside the while(1) loop

2. You are reading the data incorrectly. I know that when you read using the ADC ig gives you 10 bits. The PIC is a 8 bits microcontrellor.
Take a look at the ADC examples programs to see how you should read the analog port.


3. I don't understand the mathematics behind the reading of the value. I think that the sensor gives you 10mV per degree right? How much is
your reference voltage? Lets say you make the reference voltage equal to 1V. When the sensors output is 1V that means that the
temperature is 1/0.01=100 degrees. The ADC output will gives you 1023 counts. That means that the degree/LSB is equal to (in this case)
100/1023= When you read the ADC multiply the counts with (100/1023) and you will get the temperature in degrees. This is of course not
a good example to use but just so you just understand how to calculate the degree/LSB constant.

4. When outputting to USART try to do this. Create a char array like myarray[10]; The calculated temperature must be converted to string. Remember to use the correct form of convert to string.
Inside you put the information and what the information tells you:


myarray[0]='T'
myarray[1]='e'
myarray[2]='m'
myarray[3]='p'
myarray[4]='='
myarray[5]= here comes the first char of the temperature
myarray[6]=here comes the second char of the temperature
myarray[7]=here comes the third char of the temperature
myarray[8]=here comes the fourth char of the temperature

After everything is nicely inside a char you output the whole char via usart. Create e method and give the method this char like this

void Write_String(char *Awo)
{
for (t=0;t<=8;t++)
{
Usart_Write(awo[t]);
}

}

This code is not compleet and untested but at least you have a lot of information of how to do it

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#6 Post by 20051050 » 10 Apr 2010 11:49

Thank you very very much
I will try it now

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#7 Post by 20051050 » 10 Apr 2010 15:49

I get tiered
Can any one please send me a tested code with its hardware connection to try it ,because I have tested what is written in the MikroC manual and in the examples that come with the compiler
and I really do not know the fault where ???

Any help please

The result of the last tries that it is only giving me indication that the com is connected,but with out any data....

please heeeeelp

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#8 Post by 20051050 » 11 Apr 2010 13:26

heeelp :?

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#9 Post by 20051050 » 11 Apr 2010 18:39

I wrote this code ,and I check it on the terminal ,but I can not receive any thing


unsigned int temp_value;
unsigned char out[9];
unsigned int i;
void main()
{
Usart_Init(9600);
ADCON1 = 0x80;
TRISA = 0xFF; // PORTA as input
while(1)
{

Delay_ms(1000);
temp_value = Adc_Read(0)>>2;
temp_value =temp_value *5000/256; // Read analog input
//out[0]=temp_value/10;
//out[1]= temp_value%10;
ByteToStr(temp_value,out);

Usart_Write('T');
Delay_ms(1000);
Usart_Write('E');
Delay_ms(1000);
Usart_Write('M');
Delay_ms(1000);
Usart_Write('P');
Delay_ms(1000);
Usart_Write('=');
Delay_ms(1000);

do
{
Usart_Write(out);
}while (i<9);

}
}



Any help

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#10 Post by 20051050 » 11 Apr 2010 22:19

it is so bad when you see someone saying :heeeeeeeeeeeeeelp
and you ignore him

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: 16f877a USART display temp on PC

#11 Post by tihomir.losic » 12 Apr 2010 17:03

Hello,

here is several links, which might help to you:
- mikroC PRO for PIC
- Examples for EasyPIC6 (mikroC PRO for PIC): http://www.mikroe.com/zip/easypic6/easy ... s_v101.zip
If you follow this link, you can find examples for DS1820 (One Wire) and RS-232 (UART)
Also, here is datasheet for LM35DZ:
http://pdf1.alldatasheet.com/datasheet- ... /LM35.html

I hope that you will find usable information's, and find solution.
For any further assistance, feel free to contact us.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#12 Post by 20051050 » 12 Apr 2010 17:16

Thank you very much ....
But I have already gone through these links ....
And my problem is outputting the LM35 data on the PC ....
I can not receive any thing ....
even wrong data I do not receive >>

what can be the reason behind that ???

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#13 Post by 20051050 » 12 Apr 2010 17:20

Beside that >>>
I have a code >>>
can any one tested using the proteus ....
just testing >>>please because what I have is demo version

any help please

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: 16f877a USART display temp on PC

#14 Post by tihomir.losic » 12 Apr 2010 17:25

Hello,

This can be done by using generated COFF file for importing it in Proteus.
Here is a forum topic where users shared their experience of how this can be done:
http://www.mikroe.com/forum/viewtopic.php?t=21840

Proteus is really not supported mikroElektronika certified environment on which your test can be performed.
So, this is out of our support scope.
Thank you for your understanding.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

20051050
Posts: 16
Joined: 02 Apr 2010 20:03

Re: 16f877a USART display temp on PC

#15 Post by 20051050 » 12 Apr 2010 17:31

ok
Thanks alot for your cooperation

Post Reply

Return to “mikroC General”