© MCS Electronics, 1995-2007
variables |
'declare the SUB |
Declare Sub Test(b1 As Byte , Byval B2 As Byte) |
program |
'assign a value to |
A = 65 |
variable A |
|
Call Test(a , 5)'call test with parameter A and constant |
'alternative call |
Test A , 5 |
Print A |
'now print the new |
value |
|
End |
|
Sub Test(b1 As Byte , Byval B2 As Byte) |
'use the same |
variable names as 'the declared one |
'print it |
Print B1 |
Print Bcd(b2) |
'reassign the |
B1 = 10 |
variable |
'reassign the |
B2 = 15 |
variable |
|
End Sub |
|
One important thing to notice is that you can change b2 but that the change wil not be reflected to the calling program!
Variable A is changed however.
This is the difference between the BYVAL and BYREF argument in the DECLARE ration of the SUB program.
When you use BYVAL, this means that you will pass the argument by its value. A copy of the variable is made and passed to the SUB program. So the SUB program can use the value and modify it, but the change will not be reflected to the calling parameter. It would be impossible too when you pass a numeric constant for example.
If you do not specify BYVAL, BYREF will be used by default and you willpass the address of the variable. So when you reassign B1 in the above example, you are actually changing parameter A.
CHECKSUM
Action
Returns a checksum of a string.
Syntax
PRINT Checksum(var)
b = Checksum(var)
Remarks
BA numeric variable that is assigned with the checksum.
© MCS Electronics, 1995-2007
The checksum is computed by counting all the bytes of the string variable. Checksums are often used with serial communication.
The checksum is a byte checksum. The following VB code is equivalent :
Dim Check as Byte
Check = 255
For x = 1 To Len(s$)
Check = check – ASC(mid$(s$,x,1))
Next
See also
CRC8 , CRC16 , CRC32
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 S As String * 10 |
'dim variable |
S = "test" |
'assign variable |
Print Checksum(s) |
'print value (192) |
End |
|
CHR
Action
Convert a numeric variable or a constant to a string with a length of 1 character. The character represents the ASCII value of the numeric value.
Syntax
PRINT CHR(var)
s = CHR(var)
Remarks
Var |
Numeric variable or numeric constant. |
S |
A string variable. |
|
|
When you want to print a character to the screen or the LCDdisplay, you must convert it with the CHR() function.
© MCS Electronics, 1995-2007
When you use PRINT numvar, the value will be printed.
When you use PRINT Chr(numvar), the ASCII character itself will be printed.
The Chr() function is handy in combination with the LCD custom characters where you can redefine characters 0-7 of the ASCII table.
See also
ASC
Example
'----------------------------------------------------------------------------- |
|
------------ |
: chr.bas |
'name |
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: shows how to use the CHR() and BCD() function and |
' |
HEX() function in combination with a PRINT |
statement |
: Mega48 |
'micro |
'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 |
|
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Dim K As Byte
K = 65
Print K ; Chr(k) ; K ; Chr(66) ; Bcd(k) ; Hex(k)
End
CIRCLE
Action
Draws a circle on a graphic display.
Syntax
CIRCLE(x0,y0) , radius, color
Remarks
X0 |
Starting horizontal location of the line. |
page -298-
|
© MCS Electronics, 1995-2007 |
|
|
|
Y0 |
Starting vertical location of the line. |
|
Radius |
Radius of the circle |
|
Color |
Color of the circle |
|
|
|
|
See Also
LINE
Example
'----------------------------------------------------------------------------- |
|
|
------------ |
: t6963_240_128.bas |
'name |
|
'copyright |
|
: (c) 1995-2005, MCS Electronics |
'purpose |
|
: T6963C graphic display support demo 240 * 128 |
'micro |
|
: Mega8535 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'----------------------------------------------------------------------------- |
|
|
------------ |
|
$regfile = "m8535.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 |
|
'----------------------------------------------------------------- |
(c) |
2001-2003 MCS Electronics |
' |
' |
T6963C graphic display support demo 240 * 128 |
'----------------------------------------------------------------- |
|
|
'The connections of the LCD used in this demo |
'LCD pin |
GND |
connected to |
' 1 |
GND |
'2 |
GND |
GND |
'3 |
+5V |
+5V |
'4 |
-9V |
-9V potmeter |
'5 |
/WR |
PORTC.0 |
'6 |
/RD |
PORTC.1 |
'7 |
/CE |
PORTC.2 |
'8 |
C/D |
PORTC.3 |
'9 |
NC |
not conneted |
'10 |
RESET |
PORTC.4 |
'11-18 |
D0-D7 |
PA |
'19 |
FS |
PORTC.5 |
'20 |
NC |
not connected |
'First we define that we use a graphic LCD ' Only 240*64 supported yet
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 8
'The dataport is the portname that is connected to the data lines of the LCD 'The controlport is the portname which pins are used to control the lcd 'CE, CD etc. are the pin number of the CONTROLPORT.
' For example CE =2 because it is connected to PORTC.2