Forum - MCS Electronics
 FAQ Search Register Log in

 SELECT CASE END SELECT Equals IF THEN? Goto page 1, 2  Next
Author Message
Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

Posted: Mon May 01, 2017 7:26 pm    Post subject: SELECT CASE END SELECT Equals IF THEN?

Helo all!!

I'm doing an exercise just about SELECT-CASE with IF THEN correct me if I'm wrong.

 Code: Do   Lightlevel = Getadc(0)   Select Case Lightlevel    Case 102 To 199 : Portb = &B01111111    Case 200 To 399 : Portb = &B10111111    Case 400 To 499 : Portb = &B11011111    Case 500 To 599 : Portb = &B11101111    Case 600 To 699 : Portb = &B11110111    Case 700 To 799 : Portb = &B11111011    Case 800 To 899 : Portb = &B11111101    Case 900 To 1023 : Portb = &B11111110   End Select Loop End

Do not mark me a mistake, correct me if you're okay or not?

 Code: Do   Lightlevel = Getadc(0)    If Lightlevel > 199 Then Portb = &B01111111    Else    If Lightlevel > 200 And Lightlevel < 399 Then Portb = &B10111111    Else    If Lightlevel > 400 And Lightlevel < 499 Then Portb = &B11011111    Else    If Lightlevel > 500 And Lightlevel < 599 Then Portb = &B11101111    Else    If Lightlevel > 600 And Lightlevel < 699 Then Portb = &B11110111    Else    If Lightlevel > 700 And Lightlevel < 799 Then Portb = &B11111011    Else    If Lightlevel > 800 And Lightlevel < 899 Then Portb = &B11111101    Else    If Lightlevel < 1023 Then Portb = &B11111110    End If Loop End

albertsm

Joined: 09 Apr 2004
Posts: 5205
Location: Holland

 Posted: Mon May 01, 2017 8:06 pm    Post subject: code like this : Select Case Lightlevel Case 102 To 199 : Portb = &B01111111 Case 200 To 399 : Portb = &B10111111 translates to: if Lightlevel >=102 and LightLevel <200 then Portb = &B0111_1111 elseif lightlevel >=200 and lightlevel <400 then Portb = &B1011_1111 etc. you should check the help and samples._________________Mark
Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

Posted: Tue May 02, 2017 2:59 am    Post subject:

Hello!!
I already read Bascom's help.

These are the results but it does not work is this or are you wrong?

 Code: Do   Lightlevel = Getadc(0)    If Lightlevel > 102 And Lightlevel < 200 Then    Portb = &B01111111    Elseif Lightlevel > 199 And Lightlevel < 400 Then    Portb = &B10111111    Elseif Lightlevel > 399 And Lightlevel < 500 Then    Portb = &B11011111    Elseif Lightlevel > 499 And Lightlevel < 600 Then    Portb = &B11101111    Elseif Lightlevel > 599 And Lightlevel < 700 Then    Portb = &B11110111    Elseif Lightlevel > 699 And Lightlevel < 800 Then    Portb = &B11111011    Elseif Lightlevel > 799 And Lightlevel < 900 Then    Portb = &B11111101    Elseif Lightlevel < 899 And Lightlevel > 1022 Then    Portb = &B11111110    Else    End If Loop End

Is it right or not? Do not arrest Leds_0

 Code: Elseif Lightlevel < 899 And Lightlevel > 1022 Then    Portb = &B11111110    Else    End If
Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

Posted: Tue May 02, 2017 3:27 am    Post subject:

Hi!! Albertsm

 Code: Elseif Lightlevel > 899 And Lightlevel > 1022 Then    Portb = &B11111110    Else    End If

I already corrected ... It works !!! Question?

Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

Posted: Tue May 02, 2017 1:24 pm    Post subject:

Hi

I have a question which of the two is correct without ELSE or ELSE?

Without ELSE?

 Code: Elseif Lightlevel > 899 And Lightlevel > 1022 Then    Portb = &B11111110    End If Loop End

With ELSE?

 Code: Elseif Lightlevel > 899 And Lightlevel > 1022 Then    Portb = &B11111110    Else    End If Loop End

Both works fine !!
six1

Joined: 27 Feb 2009
Posts: 553

Posted: Tue May 02, 2017 2:07 pm    Post subject:

this is absolutly nonsense...

 Code: Elseif Lightlevel > 899 And Lightlevel > 1022 Then

_________________
For technical reasons, the signature is on the back of this message.
Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

 Posted: Tue May 02, 2017 2:27 pm    Post subject: Why? But it works fine !!
six1

Joined: 27 Feb 2009
Posts: 553

 Posted: Tue May 02, 2017 2:58 pm    Post subject: You didn't understand the working of "if", "elseif", "else" and maybe also not "boolean operators". something like: if 1=0 then.... else ... endif is working or better: will be compiled, but makes no sense at all._________________For technical reasons, the signature is on the back of this message.
Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

 Posted: Tue May 02, 2017 3:07 pm    Post subject: is working or better: will be compiled, but makes no sense at all.
Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

Posted: Tue May 02, 2017 3:12 pm    Post subject:

 Printpix52 wrote: is working or better: will be compiled, but makes no sense at all.

So correct me I want to see them working fine.
Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

Posted: Tue May 02, 2017 5:16 pm    Post subject:

Printpix52 wrote:
Hi

I have a question which of the two is correct without ELSE or ELSE?

Without ELSE?

 Code: Elseif Lightlevel > 899 And Lightlevel > 1022 Then    Portb = &B11111110    End If Loop End

With ELSE?

 Code: Elseif Lightlevel > 899 And Lightlevel > 1022 Then    Portb = &B11111110    Else    End If Loop End

Both works fine !!

For more conditions is this.

 Code: If Condicion_0 Then      Instrucion_0   Elseif Condicion_1 Then      Instrucion_1   Elseif Condicion_2 Then      Instruccion_2      .....      .....      .....      .....   Elseif Condicion_7 Then     Instruccion_7   End If

So that's the way it is written.

 Code: Do   Lightlevel = Getadc(0)    If Lightlevel > 102 And Lightlevel < 200 Then    Portb = &B01111111    Elseif Lightlevel > 199 And Lightlevel < 400 Then    Portb = &B10111111    Elseif Lightlevel > 399 And Lightlevel < 500 Then    Portb = &B11011111    Elseif Lightlevel > 499 And Lightlevel < 600 Then    Portb = &B11101111    Elseif Lightlevel > 599 And Lightlevel < 700 Then    Portb = &B11110111    Elseif Lightlevel > 699 And Lightlevel < 800 Then    Portb = &B11111011    Elseif Lightlevel > 799 And Lightlevel < 900 Then    Portb = &B11111101    Elseif Lightlevel > 899 And Lightlevel > 1022 Then    Portb = &B11111110    End If Loop End

Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

Posted: Thu May 04, 2017 2:59 am    Post subject: Re: SELECT CASE END SELECT Equals IF THEN?

Printpix52 wrote:
Helo all!!

I'm doing an exercise just about SELECT-CASE with IF THEN correct me if I'm wrong.

 Code: Do   Lightlevel = Getadc(0)   Select Case Lightlevel    Case 102 To 199 : Portb = &B01111111    Case 200 To 399 : Portb = &B10111111    Case 400 To 499 : Portb = &B11011111    Case 500 To 599 : Portb = &B11101111    Case 600 To 699 : Portb = &B11110111    Case 700 To 799 : Portb = &B11111011    Case 800 To 899 : Portb = &B11111101    Case 900 To 1023 : Portb = &B11111110   End Select Loop End

Do not mark me a mistake, correct me if you're okay or not?

 Code: Do   Lightlevel = Getadc(0)    If Lightlevel > 199 Then Portb = &B01111111    Else    If Lightlevel > 200 And Lightlevel < 399 Then Portb = &B10111111    Else    If Lightlevel > 400 And Lightlevel < 499 Then Portb = &B11011111    Else    If Lightlevel > 500 And Lightlevel < 599 Then Portb = &B11101111    Else    If Lightlevel > 600 And Lightlevel < 699 Then Portb = &B11110111    Else    If Lightlevel > 700 And Lightlevel < 799 Then Portb = &B11111011    Else    If Lightlevel > 800 And Lightlevel < 899 Then Portb = &B11111101    Else    If Lightlevel < 1023 Then Portb = &B11111110    End If Loop End

Helo all!!

I already solved this, I can do it, I'm very happy !!

 Code: Do   Lightlevel = Getadc(0)    If Lightlevel > 102 And Lightlevel < 200 Then    Portb = &B01111111    End If    If Lightlevel > 199 And Lightlevel < 400 Then    Portb = &B10111111    End If    If Lightlevel > 399 And Lightlevel < 500 Then    Portb = &B11011111    End If    If Lightlevel > 499 And Lightlevel < 600 Then    Portb = &B11101111    End If    If Lightlevel > 599 And Lightlevel < 700 Then    Portb = &B11110111    End If    If Lightlevel > 699 And Lightlevel < 800 Then    Portb = &B11111011    End If    If Lightlevel > 799 And Lightlevel < 900 Then    Portb = &B11111101    End If    If Lightlevel > 899 And Lightlevel > 1022 Then    Portb = &B11111110    End If Loop End

I am very happy I like bascom avr !!!
Duval JP

Joined: 22 Jun 2004
Posts: 987
Location: France

 Posted: Thu May 04, 2017 1:54 pm    Post subject: the big difference between if--endif and select case let us suppose your level is 103 your program read all line and spend a lot of time for nothing with if--- endif or if ---elseif --endif You can do that but add "Exit do" after each choice with select case the program goes directly to the good line and exit of the loop after. JP
Printpix52

Joined: 18 Jun 2014
Posts: 245
Location: D.F.

 Posted: Thu May 04, 2017 3:37 pm    Post subject: Hello!! Dubai and the probe does not work.
Duval JP

Joined: 22 Jun 2004
Posts: 987
Location: France

 Posted: Thu May 04, 2017 6:04 pm    Post subject: would you like explain what you want to do jp
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 HourGoto page 1, 2  Next Page 1 of 2

 Jump to: Select a forum BASCOM AVR/8051----------------BASCOM-AVRBASCOM-8051BASCOM-ARDUINOShare your working BASCOM-8051 code hereShare your working BASCOM-AVR code hereBASCOM BETA-SLA BASCOM Related----------------EASY TCP/IPAVR-DOSAR7212KokkeKat FAT-free SD card libBASCOM Project Blog Other Stuff----------------VariousPCB'sRoboticsNew WebSiteAnnouncementsAVR Archive----------------BASCOM-AVR ArchiveBASCOM-8051 ArchiveBASCOM-AVR Unsupported versionsEasy TCP/IP ArchiveBASCOM-EDB
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum