© MCS Electronics, 1995-2007
'this function can be used to display an IP number in normal format
Function Ipnum(ip As Long) As String
Local T As Byte , J As Byte
Ipnum = ""
For J = 1 To 4 T = Ip And 255
Ipnum = Ipnum + Str(t)
If J < 4 Then Ipnum = Ipnum + "."
Shift Ip , Right , 8
Next
End Function End
UPPERLINE
Action
Reset LCD cursor to the upperline.
Syntax
UPPERLINE
Remarks
Optional you can also use the LOCATE statement.
See also
LOWERLINE , THIRDLINE , FOURTHLINE , LCD, CLS , LOCATE
Example
Dim A As Byte
A = 255
Cls
Lcd A
Thirdline
Lcd A
Upperline
End
VAL
Action
Converts a string representation of a number into a number.
Syntax
var = VAL( s)
|
© MCS Electronics, 1995-2007 |
Remarks |
Var |
A numeric variable that is assigned with the value of s. |
|
S |
Variable of the string type. |
|
|
|
|
It depends on the variable type which conversion routine will be used. Single and Double conversion will take more code space.
When you use INPUT, internal the compiler also uses the VAL routines.
In order to safe code, there are different conversion routines. For example BINVAL and HEXVAL are separate routines.
While they could be added to the compiler, it would mean a certain overhead as they might never be needed.
With strings as input or the INPUT statement, the string is dynamic and so all conversion routines would be needed.
See also
STR , HEXVAL , HEX , BIN , BINVAL
Example
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 8000000 |
frequency |
' use baud rate |
$baud = 19200 |
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
for the SW stack |
' default use 40 |
$framesize = 40 |
for the frame space |
|
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits |
= 8 , Clockpol = 0 |
|
Dim A As Byte , S As String * 10 |
|
S = "123" |
'convert string |
A = Val(s) |
Print A |
' 123 |
S = "12345678" |
|
Dim L As Long |
|
L = Val(s) |
|
Print L |
|
End |
|
VARPTR
Action
Retrieves the memory-address of a variable.
Syntax
var = VARPTR( var2 ) var = VARPTR( "var3" )
|
© MCS Electronics, 1995-2007 |
Remarks |
Var |
The variable that receives the address of var2. |
|
Var2 |
A variable to retrieve the address from. |
|
var3 |
A constant |
|
|
|
|
Sometimes you need to know the address of a variable, for example when you like to peek at it's memory content.
The VARPTR() function assigns this address.
See also
NONE
Example
Dim W As Byte
Print Hex(varptr(w)) ' 0060
VER
Action
Returns the AVR-DOS version
Syntax
result = VER()
Remarks
Result |
A numeric variable that is assigned with the AVR-DOS version. The version |
|
number is a byte and the first release is version 1. |
|
|
When you have a problem, MCS can ask you for the AVR-DOS version number. The VER() function can be used to return the version number then.
See also
INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FREEFILE , FILEATTR , SEEK , BSAVE , BLOAD , KILL , DISKFREE , GET , PUT , FILEDATE , FILETIME , FILEDATETIME , DIR , WRITE , INPUT
The VERSION() function is something different. It is intended to include compile time info into the program.
ASM
Calls |
_AVRDOSVer |
|
|
Input |
- |
Output |
R16 loaded with value |
|
|
© MCS Electronics, 1995-2007
Example
Print Ver()
VERSION
Action
Returns a string with the date and time of compilation.
Syntax
Var = VERSION(frm)
Remarks
Var is a string variable that is assigned with a constant. This version constant is set at compilation time to MM-DD-YY hh:nn:ss
Where MM is the month, DD the day of the month, YY the year.
hh is the hour is 24-hour format, nn the minutes, and ss the seconds.
When frm is set to 1, the format date will be shown in eurpean DD-MM-YY hh:nn:ss format.
While it is simple to store the version of your program in the source code, it is harder to determine which version was used for a programmed chip.
The Version() function can print this information to the serial port, or to an LCDdisplay.
See Also
VER
Example
Print Version()
WAIT
Action
Suspends program execution for a given time.
Syntax
WAIT seconds
Remarks
seconds The number of seconds to wait.
© MCS Electronics, 1995-2007
No accurate timing is possible with this command.
When you use interrupts, the delay may be extended.
See also
DELAY , WAITMS
Example
WAIT 3 'wait for three seconds
Print "*"
WAITKEY
Action
Wait until a character is received.
Syntax
var = WAITKEY()
var = WAITKEY(#channel)
Remarks
var |
Variable that receives the ASCII value of the serial buffer. |
|
Can be a numeric variable or a string variable. |
#channel |
The channel used for the software UART. |
|
|
While Inkey() returns a character from the serial buffer too, INKEY() continues when there is no character. Waitkey() waits until there is a character received. This blocks your program.
See also
INKEY , ISCHARWAITING
Example
'----------------------------------------------------------------------------- |
|
------------ |
: inkey.bas |
'name |
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demo: INKEY , WAITKEY |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 4000000 |
frequency |
' use baud rate |
$baud = 19200 |
© MCS Electronics, 1995-2007 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
for the SW stack |
' default use 40 |
$framesize = 40 |
for the frame space |
|
Dim A As Byte , S As String * 2 |
|
Do |
'get ascii value |
A = Inkey() |
from serial port |
|
's = Inkey() |
'we got something |
If A > 0 Then |
Print "ASCII code " ; A ; " from serial" |
|
End If |
'until ESC is |
Loop Until A = 27 |
pressed |
|
A = Waitkey() |
'wait for a key |
's = waitkey() |
|
Print Chr(a) |
|
'wait until ESC is pressed |
|
Do |
|
Loop Until Inkey() = 27 |
|
'When you need to receive binary data and the bibary value 0 , 'you can use the IScharwaiting() function.
'This will return 1 when there is a char waiting and 0 if there is no char waiting.
'You can get the char with inkey or waitkey then.
End
WAITMS
Action
Suspends program execution for a given time in mS.
Syntax
WAITMS mS
Remarks
Ms The number of milliseconds to wait. (1-65535)
No accurate timing is possible with this command.
In addition, the use of interrupts can slow this routine.
See also
DELAY , WAIT , WAITUS
ASM
WaitMS will call the routine _WAITMS. R24 and R25 are loaded with the number of milliseconds to wait.