8 Programming with NanoJ
Note
In the NanoJ program, only global variables are permitted and they may only be initialized within code.
It then follows:
●
No
new
operator
●
No constructors
●
No initialization of global variables outside of code
Examples:
The global variable is to be initialized within the
void user()
function:
unsigned int i;
void user(){
i = 1;
i += 1;
}
The following assignment is not correct:
unsigned int i = 1;
void user() {
i += 1;
}
8.1.7 NanoJ program example
The example shows the programming of a square wave signal in object 2500
h
:01
h
.
// file main.cpp
map S32 outputReg1 as inout 0x2500:1
#include "wrapper.h"
// user program
void user()
{
U16 counter = 0;
while( 1 )
{
++counter;
if( counter < 100 )
InOut.outputReg1 = 0;
else if( counter < 200 )
InOut.outputReg1 = 1;
else
counter = 0;
// yield() 5 times (delay 5ms)
for(U08 i = 0; i < 5; ++i )
yield();
}
}// eof
You can find other examples at us.nanotec.com
8.2 Mapping in the NanoJ program
With this method, a variable in the NanoJ program is linked directly with an entry in the object dictionary.
The creation of the mapping must be located at the start of the file here, even before the
#include
"wrapper.h"
instruction. A comment is permitted above the mapping.
Version: 2.0.1 / FIR-v1650
98