as sbit and using of true/false

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

as sbit and using of true/false

#1 Post by Bytex » 13 Apr 2009 00:05

Hi Me team,
New compiler is fantastic but very young.
Here a problem with sbit using.
The problem is: true assigning doesn't work.

Example:

Code: Select all

program Test_Pro_release

dim LED as sbit at PORTB.7

main:

     '// Compile OK
     LED = false
     
     '// 12 305 Argument is out of range "_TRUE" to "sbit"
     '// Test_Pro_release.mbas
     while true
        if LED = false then
           LED = true
        else
           LED = false
        end if
     wend

     '// Compile OK
     while true
        if LED = false then
           LED = 1
        else
           LED = false
        end if
     wend

end.
Thank you in advance

Best regards,
Max

http://www.b-vu.com

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#2 Post by Dany » 13 Apr 2009 07:38

Hi, a bit is not a boolean.
Bits can have the values "0" and "1", booleans can have the values "false" and "true". Both types are in principle incompatible.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#3 Post by Bytex » 13 Apr 2009 08:40

Thank you Dany.
So, what about the old

Code: Select all

Symbol LED = PORTB.7
?
I'm so :cry:

Best regards,
Max

http://www.b-vu.com

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#4 Post by Dany » 13 Apr 2009 11:19

Bytex wrote:Thank you Dany.
So, what about the old

Code: Select all

Symbol LED = PORTB.7
?
I'm so :cry:
Hi, I do not know about symbols (I am a mikroPascal addict), but as far as I can see "PortB.7" is also a bit, so you should assign it 0 or 1, not true of false.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#5 Post by Bytex » 13 Apr 2009 16:37

No, no.
This is a programming style problem.
In the past, with the old compiler (V7.2) it was possible:

Code: Select all

Symbol LED = PORTB.7

main:
    TRISB.7 = 0 ' output
    LED = false ' assign 0 output
    while true 
        if LED = false then
            LED = true
        else
            LED = false
        end if
    wend

end.
So, with true/false assignement you was able to manage everything (PINs, boolean variables and more else).

Regards,

Best regards,
Max

http://www.b-vu.com

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#6 Post by Dany » 13 Apr 2009 17:06

Bytex wrote:No, no.
This is a programming style problem.
:roll:
Bytex wrote:In the past, with the old compiler (V7.2) it was possible:

Code: Select all

Symbol LED = PORTB.7
main:
    TRISB.7 = 0 ' output
    LED = false ' assign 0 output
    while true 
        if LED = false 
        then LED = true
        else LED = false
        end if
    wend
end.
So, with true/false assignement you was able to manage everything (PINs, boolean variables and more else).
Everything of course depends on the implicite type conversion rules from boolean to something else (e.g. bit).
Perhaps something has changed there since V7.2?
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroBasic PRO for PIC General”