Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Atmega328p and Arduino Nano

Status
Not open for further replies.
Out of curiosity, does Oshonsoft have scope? I've noticed in code I've seen here that all variables seem to be global, is that the case?

Mike.
It's kinda laughable... You can declare local variables, but when you look at the assembled version they are static... They just appear local.. I must have a closer look... I'm wondering if a local byte is declared whether its can be used In other functions.... I can see how as Vlad doesn't use a software stack..
 
Out of curiosity, does Oshonsoft have scope? I've noticed in code I've seen here that all variables seem to be global, is that the case?

Mike.
There is no "scope" in the Oshonsoft basic, at least not in the 16F compilers. By default, most variables are global. However, in a "Procedure", the variables can be local to that procedure only. If arguments are passed with a "ByRef" in the argument list , one can return values but the procedure still defines the same name locally. For example:
Code:
Proc chkband(buf As Byte, ByRef band As Byte, ByRef newband As Byte, ByRef change As Bit)
    If buf = 0 Then newband = 1
    If buf = 1 Then newband = 2
    ..... rest of code
End Proc
All 4 variables are given independent storage in ram flagged as under "chkband", even though buf, band,newband and change are also defined in the main program in separate ram locations. Without the ByRef declaration, the variable in the procedure cannot be returned to main program.

However, if using gosub or functions, the variables are global. It is a real mix, one has to check the compile/variable locations to make sure data is passed and returned properly. I find the Procedure routine the only one that creates new storage for same variable names, even though they can be passed back and forth via the argument list (if so declared).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top