Example Bugs ...

Beta Testing discussion on mikroC.
Author
Message
User avatar
milan
mikroElektronika team
Posts: 1013
Joined: 04 May 2006 16:36
Contact:

#16 Post by milan » 06 Mar 2009 11:35

Hi,

yes it was a misunderstanding.

Our example is made without configuring the 18B20 sensor resolution.

Sensor resolution is set to default (12bit in case of 18B20).

TEMP_RESOLUTION constant is introduced for switching between the different sensors (1820, 18S20, 18B20...).

You misunderstood this constant and you treated is as a constant for
configuring 12bit sensor 18B20 measuring resolution.

We were talking about different things :D
and there is no bug in the example.

One tip:
If you want to form CONF_WORD value, you don't need case

Code: Select all

              switch (TEMP_RESOLUTION)
              {
                case 9 : CONF_WORD = 0b00011111 ; break;
                case 10: CONF_WORD = 0b00111111 ; break;
                case 11: CONF_WORD = 0b01011111 ; break;
                case 12: CONF_WORD = 0b01111111 ; break;
              } 
this could be written with less code:

Code: Select all

CONF_WORD = ((TEMP_RESOLUTION - 9) << 5) | 0b00011111;
One more tip:
Try to organize your code in functions and avoid GOTOs in C.
(If you are migrating from Basic to C this could be hard, but it is worth trying :) )

If you have some other question in the future feel free to ask on forum, mE team and other users will be happy to help you :D
(Try to avoid to name topic "Example bugs" if you aren't 100% sure in that statement, as we saw - there is no bug in this example)
SmartADAPT2 rules !

Acetronics
Posts: 715
Joined: 27 Dec 2006 14:33
Location: Le Tréport , FRANCE

#17 Post by Acetronics » 06 Mar 2009 16:24

Hi, Milan

Thanks for the tips ... and your patience.

from post 6
unsigned short CONF_WORD = 0b00011111 + (( TEMP_RESOLUTION - 9 ) << 5 );
I was the first ... but forgot to copy it !!! :lol:


I had also have noted that

if ( ----) blah blah; else goto ---

Was " not so good " !!!



Migration from Basic to "C" is not so easy !!!

Basic says: " try not to jump around too much " ... C says : use functions ... :lol:

Alain

Pipls
Posts: 12
Joined: 07 Sep 2009 19:52

#18 Post by Pipls » 12 Oct 2009 22:21

Interesting

Post Reply

Return to “mikroC Beta Testing”