Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:13 01 Aug 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 : Micromite V5.04.09 Beta 3

     Page 1 of 2    
Author Message
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 10:33am 11 Jan 2018
Copy link to clipboard 
Print this post

I have a new beta version of the Micromite firmware available. It can be downloaded from: http://geoffg.net/Downloads/Micromite/Micromite_V5.04.09_Beta.zip

This includes the fix for issues with corrupted 5" displays (discussed in another thread) and adds the ability to write display drivers in BASIC (rather than just using CFunctions). Peter Mather is planning some new display drivers using this facility and it will be fascinating to see what he comes up with.

My plan for future beta versions is to keep adding small improvements (incrementing the beta number) and keep the beta open for some months until it has accumulated enough changes and is stable enough to warrant a full release. If you find any bugs please let me know.

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

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 01:00pm 11 Jan 2018
Copy link to clipboard 
Print this post

Would that mean that the console would also use that display driver?

Microblocks. Build with logic.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 01:57pm 11 Jan 2018
Copy link to clipboard 
Print this post

No, using an LCD panel as the console on the MM+ requires a SSD1963 based panel. This is because the SSD1963 supports hardware scrolling.

Other than this a driver written in BASIC looks like a built in driver, you can select fonts, draw lines, use MM+ controls, etc. However it will be slower so it is best suited to small displays (ie, 128x32 pixels).
Geoff Graham - http://geoffg.net
 
LewW
Newbie

Joined: 16/01/2018
Location: Australia
Posts: 15
Posted: 10:37pm 19 Jan 2018
Copy link to clipboard 
Print this post

Hi Geoff,

Thanks for V5.04.09_Beta_9

I have just installed it on my E100, and it has resolved all my 5" SSD1963 display problems.

Note that when I reset the E100, it indicates V5.04.09 Beta 4.

Best wishes,

Lew.

 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 11:19pm 19 Jan 2018
Copy link to clipboard 
Print this post

  LewW said  Note that when I reset the E100, it indicates V5.04.09 Beta 4.

Yes, my plan is too keep updating the beta, if it is a significant change I will announce it on this forum.
Geoff Graham - http://geoffg.net
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 01:19am 17 Feb 2018
Copy link to clipboard 
Print this post

There is a new beta version (Beta 10) for anyone who would like to experiment with it:
http://geoffg.net/Downloads/Micromite/Micromite_V5.04.09_Beta.zip

It includes a new command STATIC. This is similar to LOCAL except that the variables created will retain their value between calls to the subroutine or function. The syntax is exactly the same as DIM.

This version also includes the bug fixes of all previous betas... see the change log for the details.

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

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 12:18pm 17 Feb 2018
Copy link to clipboard 
Print this post

I know this STATIC command was on the list for some time. I am happy that you found a way to do it. This will make programming so much easier and tidier (especially library functions).
A big thanks from me!

Microblocks. Build with logic.
 
PicFan
Senior Member

Joined: 18/03/2014
Location: Austria
Posts: 133
Posted: 02:01pm 17 Feb 2018
Copy link to clipboard 
Print this post

Hello Geoff!
Thanks for the new version, the "static" command is very important! Unfortunately I have a little problem:



1.) Problem: (MX170 and MX470)

DIM x = 1


RUN>

ERROR: variable name


2.) Problem: (MX170, 44pol.)


OPTION AUTORUN ON

DIM x = 1

RUN>

CPU exception # 7 at adress 0x9D03DE78
Processor restarteä

CPU exception # 7 at adress 0x9D03DE78
Processor restarteä

CPU exception # 7 at adress 0x9D03DE78
Processor restarteä
. . . . .


The system hangs up, Ctrl-C, as well as Reset has no effect. USB is no longer recognized, reprogramming with the PICKIT is required.

2.) Problem: (MX470)

OPTION AUTORUN ON

DIM x = 1

RUN>




The system hangs up, Ctrl-C, as well as Reset has no effect. USB is no longer recognized, reprogramming with the PICKIT is required.


Thank you !

WolfgangEdited by PicFan 2018-02-19
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 11:18pm 17 Feb 2018
Copy link to clipboard 
Print this post

Can one of you in the know, explain to me why STATIC is so useful?
LOCAL is local to the sub - I get that. They are disposed of when the sub exits.
If STATIC remains between calls, isn't that exactly the same a just having a global DIM variable that is visible to everything in the code at any time?

I know I am missing something, but I just don't know what at this point.
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 01:09am 18 Feb 2018
Copy link to clipboard 
Print this post

  Grogster said   Can one of you in the know, explain to me why STATIC is so useful?

LOCAL is useful because you don't have to worry about functions that use variables with the same name. This is usually a problem when you reuse subs/functions.

If you have to use global's to retain values, you loose that advantage.

STATIC saves the dilemma. It's not a common 'must have' but it is very handy when making reusable functions.

I will have to experiment to see what happens to STATIC variables in functions in the library. Will the values survive program restarts?

Jim
VK7JH
MMedit
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 02:02am 18 Feb 2018
Copy link to clipboard 
Print this post

I have run a few tests.
If the FUNCTION that uses STATIC in saved in the LIBRARY, any STATIC variables are reinitialised with program start/stop so that is OK.

The problem with DIM occurs on 28 pin micromites but NOT in DOS_MMBasic
  Quote   DIM x = 500 ' works OK in DOS_MMBASIC
DO
PRINT x," ",addit()
PAUSE 1000
LOOP

FUNCTION addit()
static x
x = x +
1
addit = x
END FUNCTION

This program errors on the micromite MX170 with DIM, runs OK on DOS as is and runs OK on micromite with DIM removed.

Jim
VK7JH
MMedit
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 01:59pm 18 Feb 2018
Copy link to clipboard 
Print this post

Thanks guys. Something has seriously gone wrong.
Give me a day and I try to find out what the problem is.

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

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 11:00pm 18 Feb 2018
Copy link to clipboard 
Print this post

So, is STATIC a variable that is ONLY visible to subs and functions, and is not visible to the rest of the running code? Some kind of 'Static variable' that will remain across calls to a sub or function?

Could you not do that with CONST?

Sorry - still don't really understand this....
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 01:13am 19 Feb 2018
Copy link to clipboard 
Print this post

A LOCAL variable is reset to zero (or "") whenever the SUB/Function is called.
A STATIC variable is the same as LOCAL except it's value is NOT reset each time the SUB/FUNCTION is called. It retains the value it had when the SUB/FUNCTION was last exited.

You could do it all with global variables, just as you could do without LOCAL variables, but this way produces more modular code.

It is not like a CONST. The STATIC name refers to it remaining static between subsequent calls to the SUB, not static all the time.

Jim
VK7JH
MMedit
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 02:38am 19 Feb 2018
Copy link to clipboard 
Print this post

With a CONST you cannot change its value. A STATIC is a variable that you can change (like a LOCAL) but will retain its value (like a global variable created by DIM).

Say, for example, that you need a function to detect a switch press and print a suitable message. This function will be called repeatedly from various parts of your program.

Your code could look like this:

SUB SwPressed
IF PIN(xxx) = 0 THEN ' if switch pressed
PRINT "Switch has been pressed"
ENDIF
END SUB


The problem with this is that while your finger is held down on the switch the message will rapidly repeat and scroll up the screen. Not good, you wanted just one message.

So you could rewrite it like this (we are ignoring debounce issues):

DIM SwState = 0 'define a global var to keep track of the switch

SUB SwPressed
IF PIN(xxx) = 0 THEN ' if switch pressed
IF SwState = 0 THEN ' if we have not seen this before
PRINT "Switch has been pressed"
SwState = 1 ' show that we have seen the press
ENDIF
ELSE
SwState = 0 ' record that the switch has been released
ENDIF
END SUB


Now you are using the global variable SwState to track if the message has been printed and only print it once. But using a global variable is messy and if you are monitoring many switches you will need many global variables. You will also have the chance of clashing with other globals and tearing out what remaining hair that you have.

STATIC fixes that:

SUB SwPressed
STATIC SwState = 0 'define a static var to keep track of the switch
IF PIN(xxx) = 0 THEN ' if switch pressed
IF SwState = 0 THEN ' if we have not seen this before
PRINT "Switch has been pressed"
SwState = 1 ' show that we have seen the press
ENDIF
ELSE
SwState = 0 ' record that the switch has been released
ENDIF
END SUB


Now the subroutine is neatly self contained.

In a more general sense you normally use STATIC to keep track of the state of something while inside a sub/fun. For example, is this com port open or closed? Have we received this message or not? What steps in a sequence have we completed? All of these involve the state of the program.

In the past you would use DIM to create global variables to keep track of the state, now you can use STATIC. Just like LOCAL the use of STATIC helps to make your subroutines and functions more self contained and portable but its use is not mandatory.

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

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 03:04am 22 Feb 2018
Copy link to clipboard 
Print this post

I have fixed the bug in Beta 10 that stopped STATIC and DIM from working. Anyone interested in playing with the new version (Beta 11) can download it from: http://geoffg.net/Downloads/Micromite/Micromite_V5.04.09_Beta.zip

When you get used to them STATIC variables can be quite useful, especially as they reduce the need for global variables created with DIM.

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

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 04:36am 22 Feb 2018
Copy link to clipboard 
Print this post

So, using your example above, I don't see the difference between:


SUB SwPressed
STATIC SwState = 0 'define a static var to keep track of the switch
IF PIN(xxx) = 0 THEN ' if switch pressed
IF SwState = 0 THEN ' if we have not seen this before
PRINT "Switch has been pressed"
SwState = 1 ' show that we have seen the press
ENDIF
ELSE
SwState = 0 ' record that the switch has been released
ENDIF
END SUB


....and this one:


SUB SwPressed
LOCAL SwState = 0 'define a static var to keep track of the switch
IF PIN(xxx) = 0 THEN ' if switch pressed
IF SwState = 0 THEN ' if we have not seen this before
PRINT "Switch has been pressed"
SwState = 1 ' show that we have seen the press
ENDIF
ELSE
SwState = 0 ' record that the switch has been released
ENDIF
END SUB


In the lower example using LOCAL, the value of SwState will be lost when the sub exits - I get that fine. But if STATIC is supposed to remain across calls to subs and functions, then STATIC SwState=0 will clear it anyway, so LOCAL would be a more usual choice would it not?

In this example:


SUB BLAH1
LOCAL A
...
END SUB


...the variable 'A' will exist inside the sub, and vanish once the sub exits - also returning any memory it was using to the memory pool. That is fine. I understand LOCAL.

In this example:


SUB BLAH2
STATIC A
A=1
...
END SUB


...the variable 'A' will remain with the value of 1 even when the sub exits, correct?
This static variable is NOT visible to the rest of the code, correct?
If you call this sub again, A will still be equal to 1 unless you change it, correct?

Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 04:41am 22 Feb 2018
Copy link to clipboard 
Print this post

  Grogster said  
In this example:


SUB BLAH2
STATIC A
A=1
...
END SUB


...the variable 'A' will remain with the value of 1 even when the sub exits, correct?
This static variable is NOT visible to the rest of the code, correct?
If you call this sub again, A will still be equal to 1 unless you change it, correct?

Yes

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 04:45am 22 Feb 2018
Copy link to clipboard 
Print this post

Ahhhhh, OK, thanks.
I think I have cottoned on to what that is all about now.
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 05:11am 22 Feb 2018
Copy link to clipboard 
Print this post

This example might make things clearer
Run it for a while with the occasional keypress

  Quote   ' returns the elapsed time between keypresses
PRINT timebetweendrinks()

DO
IF INKEY$<>"" THEN
PRINT timebetweendrinks(), TIME$
ENDIF
LOOP


FUNCTION timebetweendrinks()
STATIC bottomsup
' we need to remember the last drink
LOCAL drinktime ' temporary variable
drinktime = VAL(MID$(TIME$,7,2))+VAL(MID$(TIME$,4,2))*60+VAL(MID$(TIME$,1,2))*3600
IF bottomsup = 0 THEN
timebetweendrinks =
0 ' gives a zero time if it is the first call to the function
ELSE
timebetweendrinks = drinktime - bottomsup
ENDIF
bottomsup = drinktime
' save the new drink time
END FUNCTION


I often need to measure elapsed time so STATIC will be handy

Jim
VK7JH
MMedit
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025