Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:00 15 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM2: Select Case vs CPU Restart...

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 12:27pm 28 Sep 2020
Copy link to clipboard 
Print this post

Hi all.

MMBASIC 5.04.08


SELECT CASE CODE
 CASE ONE
   ...
   ...
   ...
 CASE ELSE
   CPU RESTART
END SELECT


The CPU RESTART command is never executed.

The work-around is easy enough:


SELECT CASE CODE
 CASE ONE
   ...
   ...
   ...
 CASE ELSE
   Y=1
END SELECT
IF Y THEN CPU RESTART


...but why does the first code example not work?

There are newer versions of MMBASIC then 5.04.08 now, so perhaps it has been addressed already.  I have a fix for it as shown above, but I am curious as to why the first version won't work.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 02:31pm 28 Sep 2020
Copy link to clipboard 
Print this post

That just does not seem right.  I am not near any hardware at this time so I cannot test it but the ELSE part of the SELECT command works perfectly and also CPU RESTART works perfectly.  I cannot see why the two together will not work.

I don't think that the version could be the issue as nothing has changed in this area since 5.04.08.

Could you please recheck this, it could be something in your test setup.

Geoff
Geoff Graham - http://geoffg.net
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 04:00pm 28 Sep 2020
Copy link to clipboard 
Print this post

Put some PRINTs around the CPU RESTART

PRINT "before"
CPU RESTART
PRINT "after"
Micromites and Maximites! - Beginning Maximite
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1116
Posted: 12:56am 29 Sep 2020
Copy link to clipboard 
Print this post

@grogster

Not sure I understand your code, but

  Quote  MMBASIC 5.04.08


SELECT CASE CODE
CASE ONE
  ...
  ...
  ...
CASE ELSE
  CPU RESTART
END SELECT


The CPU RESTART command is never executed.

..your SELECT CASE is based on the variable CODE, but your CASE statement is using the value in variable(or constant) ONE, in which case there is no relationship for any of the CASE statements to evaluate.

If you change your program to this, it works (version 5.05.06)

CODE = 1
SELECT CASE CODE
 CASE 1
   PRINT "CASE 1 WITH CODE  = 1"
 CASE ELSE
   PRINT "CASE ELSE"
   PAUSE 2000
END SELECT
PRINT " now try the else route"
PAUSE 2000
CODE = 99
SELECT CASE CODE
 CASE 1
   PRINT "CASE 1 WITH CODE = 99 - DOESN'T HAPPEN"
 CASE ELSE
   PRINT "CASE ELSE - HAPPENING!"
   PAUSE 2000
   CPU RESTART
END SELECT


The pause statements are in there so you can see what is happening.

Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 02:10am 29 Sep 2020
Copy link to clipboard 
Print this post

Original code is working now.  Perhaps it was just that the chip got a bit upset with lots of download and test cycles, without cycling the power?

Came back today, put the code back as it was originally, and it is working fine.  

@ panky: Yes, I am working on the SELECT CASE part of the code now.  In the example, there was nothing for the select case to evaluate as you say, so it was just supposed to simply CPU RESTART as CODE had not had the routines defined yet.  The "..." lines just mean lines of my code, which I omitted as they were not relevant to the issue, cos I was only wanting to make sure the the CASE ELSE took effect on any OTHER key-press then one of the valid ones - which are being defined in the CASE's now.

CODE is returned by the IR remote-control receiver interrupt, and SELECT CASE decides which button was pressed, but not all of them are used, so I wanted the system to just restart on any non-valid button press.

It is working now, which is odd, but perhaps it was just that cos I did so many program-new-program cycles on the chip last night(was up to 2AM) without ever cycling the main power, that something got a little upset?  Possible?
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 09:05am 29 Sep 2020
Copy link to clipboard 
Print this post

  Grogster said  Perhaps it was just that the chip got a bit upset with lots of download and test cycles, without cycling the power?

It is working now, which is odd, but perhaps it was just that cos I did so many program-new-program cycles on the chip last night(was up to 2AM) without ever cycling the main power, that something got a little upset?  Possible?

No (sorry).  Everytime you load/edit/run a program MMBasic completely resets itself.  Also, it could not be a stray gamma ray flipping a bit as that would have crashed MMBasic.

Most likely it was a bug in your code which you did not notice and was not present when you reentered the test code... it happens to all of us - especially at 2AM.

Geoff
Edited 2020-09-29 19:10 by Geoffg
Geoff Graham - http://geoffg.net
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 02:00pm 30 Sep 2020
Copy link to clipboard 
Print this post

@Grogster



Dunno why, Graeme but that logic just cracked me up:

This?
Or this?
Or this?
Oh f**k it!  
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025