|
© MCS Electronics, 1995-2007 |
------------ |
|
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 4000000 |
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 |
|
'dimension some variables
Dim B As Byte , I As Integer , L As Long
'the shift statement shift all the bits in a variable one 'place to the left or right
'An optional paramater can be provided for the number of shifts. 'When shifting out then number 128 in a byte, the result will be 0 'because the MS bit is shifted out
B = 1
Shift B , Left Print B
'B should be 2 now
B = 128
Shift B , Left Print B
'B should be 0 now
'The ROTATE statement preserves all the bits
'so for a byte when set to 128, after a ROTATE, LEFT , the value will 'be 1
'Now lets make a nice walking light 'First we use PORTB as an output
Config Portb = Output
'Assign value to portb Portb = 1
Do
For I = 1 To 8 Rotate Portb , Left
'wait for 1 second
Wait 1
Next
'and rotate the bit back to the right
For I = 1 To 8
Rotate Portb , Right Wait 1
Next Loop
End
ROUND
Action
Returns a value rounded to the nearest value.
© MCS Electronics, 1995-2007
Syntax
var = ROUND( x )
Remarks
Var |
A single or double variable that is assigned with the ROUND of |
|
variable x. |
X |
The single or double to get the ROUND of. |
|
|
Round(2.3) = 2 , Round(2.8) = 3
Round(-2.3) = -2 , Round(-2.8) = -3
See Also
INT , FIX , SGN
Example
'----------------------------------------------------------------------------- |
|
------------ |
: round_fix_int.bas |
'name |
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demo : ROUND,FIX |
'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 |
$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 S As Single , Z As Single
For S = -10 To 10 Step 0.5
Print S ; Spc(3) ; Round(s) ; Spc(3) ; Fix(s) ; Spc(3) ; Int(s)
Next
End
RTRIM
Action
Returns a copy of a string with trailing blanks removed
© MCS Electronics, 1995-2007
Syntax
var = RTRIM( org )
Remarks
var |
String that is assigned with the result. |
org |
The string to remove the trailing spaces from |
|
|
See also
TRIM , LTRIM
ASM
NONE
Example
Dim S As String * 6
S =" AB "
Print Ltrim(s)
Print Rtrim(s)
Print Trim(s)
End
SECELAPSED
Action
Returns the elapsed Seconds to a former assigned time-stamp.
Syntax
Target = SECELAPSED(TimeStamp)
Remarks
Target |
A variable (LONG), that is assigned with the elapsed Seconds |
TimeStamp A variable (LONG), which holds a timestamp like the output of an earlier called SecOfDay()
The Function works with the SOFTCLOCK variables _sec, _min and _hour and considers a jump over midnight and gives a correct result within 24 hour between two events.
The Return-Value is in the range of 0 to 86399.
See also
Date and Time Routines , SecOfDay , SysSecElapsed
Partial Example
Lsecofday = Secofday()
© MCS Electronics, 1995-2007
_hour = _hour + 1
Lvar1 = Secelapsed(lsecofday)
Print Lvar1
SECOFDAY
Action
Returns the Seconds of a Day.
Syntax
Target = SECOFDAY()
Target = SECOFDAY(bSecMinHour)
Target = SECOFDAY(strTime)
Target = SECOFDAY(lSysSec)
Remarks
Target |
A variable (LONG), that is assigned with the Seconds of the Day |
bSecMinHour |
A Byte, which holds the Second-value followed by Minute(Byte) and |
|
Hour(Byte) |
strTime |
A String, which holds the time in the format „hh:mm:ss" |
LSysSec |
A Variable (Long) which holds the System Second |
|
|
The Function can be used with 4 different kind of inputs:
1.Without any parameter. The internal Time of SOFTCLOCK (_sec, _min, _hour) is used.
2.With a user defined time array. It must be arranged in same way (Second, Minute, Hour) as the internal SOFTCLOCK time. The first Byte (Second) is the input by this kind of usage. So the Second of Day can be calculated of every time.
3.With a time-String. The time-string must be in the Format „hh:mm:ss".
4.With a System Second Number (LONG)
The Return-Value is in the range of 0 to 86399 from 00:00:00 to 23:59:59. No validity-check of input is made.
See also
Date and Time Routines , SysSec
Partial Example
'================= Second of Day
=============================================
'Example 1 with internal RTC-Clock
_sec = 12 : _min = 30 : _hour = 18 |
' Load RTC-Clock |
for example - testing |
|
Lsecofday = Secofday() |
|
|
page -623- |