Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SELECT CASE END SELECT Equals IF THEN?
Goto page Previous  1, 2
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Fri May 05, 2017 2:33 am    Post subject: Reply with quote

Duval JP wrote:
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 Wink


Hello DUVAL JP!!

Trying out the ones you said these:

You can do that but add "Exit do" after each choice

greetings from Mexico
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri May 05, 2017 10:25 am    Post subject: Reply with quote

that is working well with the bascom simulator
you have to use 2 loop
here I use a for--next loop, replace it by do--loop and remove the ' before ' Lightlevel = Getadc(0)
you make a mistake somewhere with > and < too



$regfile = "M168def.dat"
$crystal = 11052000
$hwstack = 32
$swstack = 32
$framesize = 32
'$baud = 19200 ' whit this statement port D.0 et D.1 are unuable as I/O port
' to generate one time-----------------------------------------------------------

$sim


Dim Lightlevel As Word


'*************remarque on blck or the other one*****************************************
'(
For Lightlevel = 103 To 1003 Step 100

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

Loop
Print Portb
Print Lightlevel
Next
')
'**********************************************************************************

For Lightlevel = 103 To 1003 Step 100
Do
' Lightlevel = Getadc(0)
Select Case Lightlevel
Case 103 To 199
Portb = &B01111111
Exit Do
Case 200 To 399
Portb = &B10111111
Exit Do
Case 400 To 499
Portb = &B11011111
Exit Do
Case 500 To 599
Portb = &B11101111
Exit Do
Case 600 To 699

Portb = &B11110111
Exit Do
Case 700 To 799

Portb = &B11111011
Exit Do
Case 800 To 899

Portb = &B11111101
Exit Do
Case 900 To 1023

Portb = &B11111110
Exit Do
End Select

Loop
Print Portb
Print Lightlevel
Next
End


jp Wink
Back to top
View user's profile Visit poster's website
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 553

germany.gif
PostPosted: Fri May 05, 2017 11:24 am    Post subject: Reply with quote

...and in contrast to your work, a short form of what you want to do...

Code:

$regfile = "m16adef.dat"
$crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
$baud = 19200


Config Portb = Output

Config Adc = Single , Prescaler = Auto
Start Adc

Dim Lightlevel As Word
Dim Shift_byte As Byte
Dim Out_byte As Byte


Do
  Lightlevel = Getadc(0)
  Shift_byte = Lightlevel / 146
  Out_byte = 1
  Shift Out_byte , Left , Shift_byte
  Portb = Not Out_byte
Loop
End
 

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Fri May 05, 2017 2:55 pm    Post subject: Reply with quote

Very Happy Very Happy Thanks to all my friends!! Very Happy Very Happy
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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