| View previous topic :: View next topic |
| Author |
Message |
bittersweet
Joined: 23 Apr 2008 Posts: 22
|
|
Posted: Sun May 11, 2008 3:42 pm |
|
|
And there is still a problem in my circuit on board shows the seconds 0-90 instead of 0-60  |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun May 11, 2008 6:41 pm |
|
|
| bittersweet wrote: | And there is still a problem in my circuit on board shows the seconds 0-90 instead of 0-60  | The DS1302 chip is using BCD coded data, you will have to convert this to an integer first (59 in BCD == 89 in decimal).
The old v3.182 driver you are using does not do the BCD conversion, this was added to the driver somewhere between v3.226 and v3.249.
| Code: | /-----------------------------------------------------------------------------
// Convert a BCD number to an int8.
//-----------------------------------------------------------------------------
int8 Bcd2Int(int8 BCD)
{
return (10 * (BCD >> 4)) + (BCD & 0x0F);
}
//-----------------------------------------------------------------------------
// Convert an int8 to a packed BCD value.
//
// This code is equivalent to, but shorter than:
// return ((val / 10) << 4) + (val % 10);
//-----------------------------------------------------------------------------
int8 Int2Bcd(int8 BinaryValue)
{
int8 Tens = 0;
// Get the tens digit by doing subtractions of 10 from the binary value.
while (BinaryValue >= 10)
{
BinaryValue -= 10;
Tens += 0x10;
}
// Get the ones digit by adding the remainder.
return Tens + BinaryValue;
} |
|
|
 |
bittersweet
Joined: 23 Apr 2008 Posts: 22
|
|
Posted: Mon May 12, 2008 8:17 am |
|
|
| thanks a lot for u'r help, I convert BCD to integer, but there is a problem when bcd number is over 15, the Bcd2toInt function cant convert correctly, how can i correct this? |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 12, 2008 9:01 am |
|
|
| bittersweet wrote: | | is there any way to write them on the same line | I don't have v3.182 so I can't check if it is a bug in the lcd driver. v3.226 is the oldest version I have and that is working great, displaying both items at the same line. The lcd.c from v3.226 is a lot older, maybe the same as in your version, dated 23-6-2003.
Which display are you using (type number)?
How many characters on a line and how many lines? |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 12, 2008 9:22 am |
|
|
| Quote: | | secondly,ds18b20 temperature sensor shows 180-200 celcius degree. when i heat it with my hand degree is increasing... | By default the DS18B20 works in 12-bit mode while your code assumes the chip is working with a 9 bit resolution, most likely the code was copied from a DS1820 chip. That's why your temperature reading is 8 times too high.
You have two options:
1) Change the driver to use the full 12-bits. | Code: | | result = (float) temp3 / 2.0; <<- change this to '/ 16.0' | or
2) On startup configure the DS18B20 to work in 9-bit mode just like the DS1820. This has the advantage that the temperature conversion goes much faster (94ms instead of 750ms). |
|
 |
bittersweet
Joined: 23 Apr 2008 Posts: 22
|
|
Posted: Mon May 12, 2008 9:23 am |
|
|
problem is about Bcd2Int function.i tried numbers till 15,it worked correctly for these numbers.But the numbers over 15 can't been converted.
for ex: 20 -> 0010 0000
after 4 shifting to right ->0000 0010 = 2
multiply with 10-> 20 = 0010 0000
adding first nibble (BCD & 0F)
totally -> 0000 1110 = 14
so if the number is AB,the function returns 10*A+B.But the problem is A can be max. 15 (1111)....
how can i fix this problem?? |
|
 |
bittersweet
Joined: 23 Apr 2008 Posts: 22
|
|
Posted: Mon May 12, 2008 9:25 am |
|
|
| ckielstra wrote: | | Quote: | | secondly,ds18b20 temperature sensor shows 180-200 celcius degree. when i heat it with my hand degree is increasing... | By default the DS18B20 works in 12-bit mode while your code assumes the chip is working with a 9 bit resolution, most likely the code was copied from a DS1820 chip. That's why your temperature reading is 8 times too high.
You have two options:
1) Change the driver to use the full 12-bits. | Code: | | result = (float) temp3 / 2.0; <<- change this to '/ 16.0' | or
2) On startup configure the DS18B20 to work in 9-bit mode just like the DS1820. This has the advantage that the temperature conversion goes much faster (94ms instead of 750ms). |
i got and corrected it, ds18b20 is working truely now. |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 12, 2008 2:23 pm |
|
|
| Quote: | so if the number is AB,the function returns 10*A+B.But the problem is A can be max. 15 (1111)....
how can i fix this problem?? | Do some more reading on BCD.
In BCD the maximum value for A and B is 9, not 15. The maximum BCD value you can store in an int8 = 99.
Your example with an 'A' of 15 is an invalid value. |
|
 |
|