© MCS Electronics, 1995-2007
© MCS Electronics, 1995-2007
© MCS Electronics, 1995-2007
Dear reader.
BASCOM was "invented" in 1995. It was intended for personal usage only. I
decided to make it public as I found no other tool that was so simple to use.
Since that time, a lot of options and extensions were added. Without the help
and patience of the many users, BASCOM would not be what it is today :
"the best and most affordable tool for fast proto typing".
All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or
mechanical, including photocopying, recording, taping, or information storage and retrieval systems - without the
written permission of the publisher.
Products that are referred to in this document may be either trademarks and/or registered trademarks of the
respective owners. The publisher and the author make no claim to these trademarks.
While every precaution has been taken in the preparation of this document, the publisher and the author assume no
responsibility for errors or omissions, or for damages resulting from the use of information contained in this document
or from the use of programs and source code that may accompany it. In no event shall the publisher and the author be
liable for any loss of profit or any other commercial damage caused or alleged to have been caused directly or
indirectly by this document.
Technical Editors
M.C.Alberts
Cover Designer
B.F.de Graaff
4 BASCOM-8051
Table of Contents
Foreword 0
Part I INDEX 13
1 Table of contents
................................................................................................................................... 14
2 Keyword...................................................................................................................................
Reference 17
30 Tools Graphic
...................................................................................................................................
Converter 54
31 Tools LIB...................................................................................................................................
Manager 55
32 Tools Triscent
...................................................................................................................................
Converter 56
33 Tools Export
...................................................................................................................................
to RTF 57
34 Options Compiler
...................................................................................................................................
Output 57
35 Options Compiler
...................................................................................................................................
Communication 58
36 Options Compiler
...................................................................................................................................
I2C 58
37 Options Compiler
...................................................................................................................................
LCD 59
38 Options Compiler
...................................................................................................................................
Misc 60
39 Options Communication
................................................................................................................................... 60
40 Options Environment
................................................................................................................................... 62
41 Options hardware
...................................................................................................................................
simulator 64
42 Options Programmer
................................................................................................................................... 64
43 Options Monitor
................................................................................................................................... 65
44 Options Printer
................................................................................................................................... 66
45 Window cascade
................................................................................................................................... 66
46 Window Tile
................................................................................................................................... 67
47 Window arrange
...................................................................................................................................
icons 67
48 Window minimize
...................................................................................................................................
all 67
49 Help About
................................................................................................................................... 67
50 Help Index
................................................................................................................................... 67
51 Help on help
................................................................................................................................... 67
52 Help Shop
................................................................................................................................... 68
53 Help Forum
................................................................................................................................... 68
54 Help Support
................................................................................................................................... 68
55 Help Credits
................................................................................................................................... 68
13 $DEFAULT
...................................................................................................................................
XRAM 92
14 $EXTERNAL
................................................................................................................................... 92
15 $INCLUDE
................................................................................................................................... 93
16 $IRAMSTART
................................................................................................................................... 94
17 $LARGE ................................................................................................................................... 94
18 $LIB ................................................................................................................................... 95
19 $LCD ................................................................................................................................... 95
20 $LCDRS ................................................................................................................................... 96
21 $MAP ................................................................................................................................... 97
22 $NOBREAK
................................................................................................................................... 97
23 $NOINIT ................................................................................................................................... 98
24 $NONAN................................................................................................................................... 98
25 $NONULL
................................................................................................................................... 99
26 $NORAMCLEAR
................................................................................................................................... 99
27 $NOSP ................................................................................................................................... 100
28 $OBJ ................................................................................................................................... 100
29 $RAMSIZE
................................................................................................................................... 101
30 $RAMTRON
................................................................................................................................... 101
31 $RAMSTART
................................................................................................................................... 103
32 $REGFILE
................................................................................................................................... 104
33 $ROMSTART
................................................................................................................................... 104
34 $SERIALINPUT
................................................................................................................................... 105
35 $SERIALINPUT2LCD
................................................................................................................................... 105
36 $SERIALOUTPUT
................................................................................................................................... 106
37 $SIM ................................................................................................................................... 107
38 $TIMEOUT
................................................................................................................................... 107
39 $WAIT ................................................................................................................................... 108
40 ALIAS ................................................................................................................................... 108
41 ABS ................................................................................................................................... 109
42 ASC ................................................................................................................................... 110
43 AVG ................................................................................................................................... 110
44 BAUD ................................................................................................................................... 111
45 BCD ................................................................................................................................... 112
46 BITWAIT................................................................................................................................... 112
47 BREAK ................................................................................................................................... 113
48 CALL ................................................................................................................................... 113
49 CHR ................................................................................................................................... 114
50 CLS ................................................................................................................................... 115
51 CONST ................................................................................................................................... 116
52 CONFIG................................................................................................................................... 116
53 CONFIG...................................................................................................................................
1WIRE 117
54 CONFIG...................................................................................................................................
ADUC812 117
55 CONFIG...................................................................................................................................
BAUD 119
56 CONFIG...................................................................................................................................
BAUD1 119
57 CONFIG...................................................................................................................................
DEBOUNCE 120
58 CONFIG...................................................................................................................................
I2CDELAY 120
59 CONFIG...................................................................................................................................
GETRC 121
60 CONFIG...................................................................................................................................
GRAPHLCD 121
61 CONFIG...................................................................................................................................
LCDPIN 125
62 CONFIG...................................................................................................................................
LCD 125
63 CONFIG...................................................................................................................................
LCDBUS 126
64 CONFIG...................................................................................................................................
MICROWIRE 127
65 CONFIG...................................................................................................................................
PRINT 127
66 CONFIG...................................................................................................................................
SCL 128
67 CONFIG...................................................................................................................................
SDA 128
68 CONFIG...................................................................................................................................
SERVOS 129
69 CONFIG...................................................................................................................................
SPI 130
70 CONFIG...................................................................................................................................
TIMER0, TIMER1 131
71 CONFIG...................................................................................................................................
WATCHDOG 132
72 COUNTER
................................................................................................................................... 132
73 CPEEK ................................................................................................................................... 134
74 CURSOR
................................................................................................................................... 135
75 DATA ................................................................................................................................... 136
76 DEBOUNCE
................................................................................................................................... 137
77 DECR ................................................................................................................................... 138
78 DECLARE
................................................................................................................................... 139
79 DEF ................................................................................................................................... 140
80 DEFLCDCHAR
................................................................................................................................... 140
81 DELAY ................................................................................................................................... 141
82 DIM ................................................................................................................................... 141
83 DISABLE
................................................................................................................................... 143
84 DISPLAY
................................................................................................................................... 143
85 DO ................................................................................................................................... 144
86 ELSE ................................................................................................................................... 144
87 ENABLE................................................................................................................................... 145
88 END ................................................................................................................................... 146
89 END IF ................................................................................................................................... 146
90 ERASE ................................................................................................................................... 147
91 EXIT ................................................................................................................................... 148
92 FOR ................................................................................................................................... 148
93 FOURTHLINE
................................................................................................................................... 149
94 FUSING................................................................................................................................... 150
95 GET ................................................................................................................................... 151
96 GETAD ................................................................................................................................... 152
97 GETAD2051
................................................................................................................................... 153
98 GETRC ................................................................................................................................... 158
99 GETRC5................................................................................................................................... 160
100 GOSUB................................................................................................................................... 162
101 GOTO ................................................................................................................................... 163
102 HEX ................................................................................................................................... 163
103 HEXVAL................................................................................................................................... 164
104 HIGH ................................................................................................................................... 164
105 HIGHW ................................................................................................................................... 165
106 HOME ................................................................................................................................... 166
107 I2CRECEIVE
................................................................................................................................... 166
108 I2CSEND
................................................................................................................................... 167
109 I2C ................................................................................................................................... 168
110 IDLE ................................................................................................................................... 169
111 IF ................................................................................................................................... 169
112 INCR ................................................................................................................................... 171
113 INKEY ................................................................................................................................... 171
114 INP ................................................................................................................................... 173
115 INPUT ................................................................................................................................... 173
116 INPUTBIN
................................................................................................................................... 175
117 INPUTHEX
................................................................................................................................... 176
118 INSTR ................................................................................................................................... 177
119 LCASE ................................................................................................................................... 178
120 LCD ................................................................................................................................... 178
121 LCDINIT................................................................................................................................... 181
122 LCDHEX................................................................................................................................... 182
123 LEFT ................................................................................................................................... 183
124 LEN ................................................................................................................................... 183
125 LOAD ................................................................................................................................... 184
126 LOCATE................................................................................................................................... 185
127 LOOKUP
................................................................................................................................... 185
128 LOOKUPSTR
................................................................................................................................... 186
129 LOW ................................................................................................................................... 187
130 LOWW ................................................................................................................................... 188
131 LOWERLINE
................................................................................................................................... 188
132 MAKEBCD
................................................................................................................................... 189
133 MAKEDEC
................................................................................................................................... 189
134 MAKEINT
................................................................................................................................... 190
135 MAX ................................................................................................................................... 190
136 MID ................................................................................................................................... 191
137 MIN ................................................................................................................................... 192
138 MOD ................................................................................................................................... 192
11 JPK Systems
...................................................................................................................................
X-programmer 272
12 Peter Averill's
...................................................................................................................................
TAFE programmer 273
13 STK200/300
...................................................................................................................................
ISP Programmer 274
14 Rhombus
...................................................................................................................................
SCE-51 275
15 SE511-SE516
...................................................................................................................................
programmer 276
Index 311
I
INDEX 13
1 INDEX
All software provided with this product package is provided 'AS IS' without any
warranty expressed or implied.
MCS Electronics will not be liable for any damages, costs or loss of profits arising
from the usage of this product package.
BASCOM IDE 38
Updates 27
File
File New 39 , File Open 39 , File Close 40 , File Save 40 , File Save
As... 40
File Print 41 , File Print Preview 40 , File Exit 41
Edit
Edit Undo 42 , Edit Redo 42 , Edit Copy 42 , Edit Cut 42 , Edit Paste
43
Edit Find 43 , Edit Find Next 43 , Edit Replace 44 , Editor Keys 46 , Edit
Goto 44 , Edit Indent 45 , Edit Unindent 45
Program
Compile 47 , Syntax check 47 , Show Result 48 , Simulate 49 , Send
to chip 52
Tools
Terminal Emulator 53 , LCD designer 54 , Graphic Converter 54 , LIB Manager 55
, Export to RTF 57
Options
Compiler Output 57 , Compiler Communication 58 , Compiler I2C 58 , Compiler
LCD 59
Compiler Misc. 60 , Communication 60 , Environment 62
Window
Cascade 66 , Tile 67 , Arrange Icons 67 , Minimize all 67
Help
About 67 , Index 67 , Help on Help 67 , Credits 68 , Forum 68 , Shop 68 , Support
68
BASCOM Statements 77
Language Fundamentals 70
Initialization 248
Errors 279
Programmers 52
Language Reference
-1-
1WRESET, 1WREAD, 1WWRITE 83 , 1WSEARCHFIRST 85 , 1WSEARCHNEXT 87 ,
1WIRECOUNT 84
-COMPILER DIRECTIVES-
#IF 80 , #ELSE 81 , #ENDIF 82 , $ASM - $END ASM 88 ,$INCLUDE 93 , $BAUD 89 ,
$BGF 89 , $CRYSTAL 91 , $DEFAULT XRAM 92 , $IRAMSTART 94 , $LARGE 94 , $LCD
95 , $MAP 97 , $NOBREAK 97 , $NOINIT 98 , $NONAN 98 , $NONULL 99 ,
$NORAMCLEAR 99 , $NOSP 100 , $OBJ 100 , $RAMSIZE 101 , $RAMSTART 103 , $REGFILE
104 , $ROMSTART 104 , $SERIALINPUT 105 , $SERIALINPUT2LCD 105 , $SERIALOUTPUT
106 , $SIM 107
-A-
ABS 109 , ALIAS 108 , ASC 110 , AVG 110
-B-
BITWAIT 112 , BCD 112 , BREAK 113
-C-
CALL 113 , CLOSE 198 , CLS 115 , CHR 114 , CONFIG 116 , CONST 116 ,COUNTER 132 ,
CPEEK 134 , CURSOR 135
-D-
DATA 136 , DEBOUNCE 137 , DECR 138 , DECLARE 139 , DEFINT 140 , DEFBIT 140 ,
DEFBYTE 140 , DEFLCDCHAR 140 , DEFWORD 140 , DELAY 141 , DIM 141 , DISABLE 143 ,
DISPLAY 143 , DO 144
-E-
ELSE 144 , ENABLE 145 , END 146 , END IF 146 , ERASE 147 , EXIT 148
-F-
FOR 148 , FOURTHLINE 149 , FUSING 150
-G-
GET 151 , GETAD 152 , GETAD2051 153 , GETRC 158 , GETRC5 160 , GOSUB 162 , GOTO 163
-H-
HEX 163 , HEXVAL 164 , HIGH 164 , HIGHW 165 , HOME 166
-I-
I2CRECEIVE 166 , I2CSEND 167 , I2CSTART 168 , I2CSTOP 168 , I2CRBYTE 168 ,
I2CWBYTE 168 , IDLE 169 , IF 169 , INCR 171 , INKEY 171 , INP 173 , INPUT 173 , INPUTBIN
175 , INPUTHEX 176 , INSTR 177
-L-
LCASE 178 , LCD 178 , LCDINIT 181 , LCDHEX 182 , LEFT 183 , LEN 183 , LOAD 184 , LOCATE
185 , LOOKUP 185 , LOOKUPSTR 186 , LOOP 144 , LOW 187 , LOWW 188 , LOWERLINE 188
-M-
MAKEDEC 189 , MAKEBCD 189 , MAKEINT 190 , MAX 190 , MID 191 , MIN 192 , MOD 192
-N-
NEXT 196
-O-
ON Interrupt 196 , ON Value 197 , OPEN 198 , OUT 200
-P-
P1,P3 201 , PEEK 202 , POKE 202 , PSET 207 , POWERDOWN 203 , PRINT 203 , PRINTBIN 204
-R-
READ 208 , READMAGCARD 209 , REM 211 , REPLACE 211 , RESET 212 , RESTORE 212 ,
RETURN 213 , RIGHT 214 , RND 214 , ROTATE 215
-S-
SELECT 216 , SET 216 , SHIFT 217 , SHIFTCURSOR 217 , SHIFTIN 218 , SHIFTOUT 218 ,
SHIFTLCD 219 , SHOWPIC 220 , SOUND 220 , SOUNDEXT 221 , SPACE 222 , SPC 223 , SPIIN
224 , SPIOUT 225 , START 225 , STOP 226 , STOP TIMER 226 , STR 228 , STRING 228 , SUB
229 , SWAP 230
-T-
THEN 169 , THIRDLINE 230 , TO 148
-U-
UCASE 231 , UPPERLINE 232
-V-
VAL 232 , VARPTR 233
-W-
WAIT 233 , WAITKEY 234 , WAITMS 234 , WAITMSE 235 , WHILE .. WEND 236
Conditions
Conditions execute a part of the program depending on the condition
IF 169 , ELSE 144 , END IF 146 , EXIT 148 , DO 144 , LOOP 144 , SELECT 216 , FOR 148 , NEXT
196 , TO 148 , THEN 169 , WHILE .. WEND 236
Configuration
Configuration command initialize the hardware to the desired state.
CONFIG 116
Conversion
A conversion routine is a function that converts a number or string.
ASC 110 , BCD 112 , CHR 114 , FUSING 150 , HEX 163 , HEXVAL 164 , HIGH 164 , HIGHW 165 ,
MAKEDEC 189 , MAKEBCD 189 , MAKEINT 190 , STR 228 , VAL 232
Delay
Delay routines delay the program for the specified time.
DELAY 141 , WAIT 233 , WAITMS 234
Directives
Directives are special instructions for the compiler. They can override a setting from
the IDE.
#IF 80 , #ELSE 81 , #ENDIF 82 , $ASM - $END ASM 88 ,$INCLUDE 93 , $BAUD 89 ,
$BGF 89 , $CRYSTAL 91 , $DEFAULT XRAM 92 , $IRAMSTART 94 , $LARGE 94 , $LCD
95 , $MAP 97 , $NOBREAK 97 , $NOINIT 98 , $NONAN 98 , $NONULL 99 ,
$NORAMCLEAR 99 , $NOSP 100 , $OBJ 100 , $RAMSIZE 101 , $RAMSTART 103 , $REGFILE
104 , $ROMSTART 104 , $SERIALINPUT 105 , $SERIALINPUT2LCD 105 , $SERIALOUTPUT
106 , $SIM 107
Graphical LCD
Graphical LCD commands extend the normal text LCD commands.
PSET 207 , SHOWPIC 220
I2C
I2C commands allow you to communicate with I2C chips with the TWI hardware or
with emulated I2C hardware.
I2CRECEIVE 166 , I2CSEND 167 , I2CSTART 168 , I2CSTOP 168 , I2CRBYTE 168 ,
I2CWBYTE 168
Interrups
Interrupt related routines.
ON Interrupt 196 , ENABLE 145 , DISABLE 143 , PRIORITY 206
IO
I/O commands are related to the I/O pins of the processor.
ALIAS 108 , BITWAIT 112 , DEBOUNCE 137 , SET 216 , RESET 212
Math
Math functions
ABS 109 , AVG 110 , MAX 190 , MIN 192 , MOD 192
Micro
Micro statements are highly related to the micro processor.
BREAK 113 , P1,P3 201 , IDLE 169 , END 146 , POWERDOWN 203 , START 225 , STOP 226 ,
STOP TIMER 226
Memory
Memory functions set or read RAM , EEPROM or flash memory.
CPEEK 134 , ERASE 147 , INP 173 , OUT 200 , PEEK 202 , POKE 202 , DIM 141 , READ 208 ,
RESTORE 212 , DATA 136 , VARPTR 233
Remote control
Remote control statements send or receive IR commands for remote control.
GETRC5 160
RS-232
RS-232 are serial routines that use the UART or emulate a UART.
WAITKEY 234 , PRINT 203 , PRINTBIN 204 , PRINTHEX 205 , PUT 207 , OPEN 198 ,SPC 223 ,
INKEY 171 , INPUT 173 , INPUTBIN 175 , INPUTHEX 176 , GET 151 , CLOSE 198
SPI
SPI routines communicate according to the SPI protocol with either hardware SPI or
software emulated SPI.
SPIIN 224 , SPIOUT 225 , SPIINIT 224
String
String routines are used to manipulate strings.
MID 191 , LCASE 178 , INSTR 177 , LEFT 183 , LEN 183 , RIGHT 214 , STRING 228 , REPLACE
211 , SPACE 222 , UCASE 231
Text LCD
Text LCD routines work with the normal text based LCD displays.
CLS , CURSOR 135 , FOURTHLINE 149 , HOME 166 , LCD 178 , LCDINIT 181 , LCDHEX
115
, LOCATE 185 , SHIFTLCD 219 , SHIFTCURSOR 217 ,DISPLAY 143 , LOWERLINE 188 ,
182
Various
This section contains all statements that were hard to put into another group
CALL 113 , CONST 116 , COUNTER 132 , DECR 138 , DECLARE 139 , DEFINT 140 , DEFBIT
140 ,DEFBYTE 140 , DEFLCDCHAR 140 , DEFWORD 140 , GETAD 152 , GETAD2051 153 ,
GETRC 158 , , GOSUB 162 , GOTO 163 , INCR 171 , LOAD 184 , LOOKUP 185 , LOOKUPSTR
186 , LOW 187 , LOWW 188 , ON Value 197 , READMAGCARD 209 , REM 211 , RETURN 213 ,
RND 214 , ROTATE 215 , SHIFT 217 , SHIFTIN 218 , SHIFTOUT 218 , SOUND 220 , SUB 229 ,
SWAP 230
II
Installing BASCOM-8051 21
2 Installing BASCOM-8051
After you have downloaded the software you need to UNZIP the downloaded file.
There is only one file named setup.exe
You may run this setup.exe from within the Windows Shell but it is important to
notice that when you use the commercial version, you MUST UNZIP the setup.exe
since you need to copy the license file to the same directory as setup.exe.
A license agreement will be shown. You need to read it and accept the agreement.
This is a no-nonsense agreement where you are allowed to install/copy on as many
computers as you want, providing that you use only one computer at the same
time.
After clicking the 'I accept the agreeement' option, you need to click the Next-
button again to continue.
You can now select/enter the Program Group name. The default is shown below.
When the files are installed, the installer will install some addiitonal files :
Press the Next-Button to install the additional files. This will go quick in most cases.
When you install from CD-ROM the setup will also copy PDF datasheets. The
installation will take longer then.
You MUST reboot your PC since it will install a driver needed for the programming.
III
Updates 27
3 Updates
The update process is simple.
· Go to the main MCS website at http://www.mcselec.com
· In the left pane under 'Main Menu' you will find a link named 'Registration/
Updates'
Notice that the website uses two different accounts : one for the forum/shop and
one for the registration/updates. You will see the following screen:
You need to provide a username, password, email and full name. Company name is
optional. When you want to receive notifications when updates are available, select
this option.
When you filled in the information, click 'Submit Registration'.
· After you click submit, you can get various error messages. For example that a
username already exists. Press the Back-button in your browser, and correct the
error, then try again
· If the registration is successful you will get a message that the registration
succeeded.
· Now you can login. You will see the following screen :
It is important that you enter a valid serial number. Do not try to enter serial
numbers from cracked versions. When you enter invalid serial numbers, you will
loose support and the ability to update.
The valid serial number is shown in the Help, About box.
When the product is selected, the serial number is entered, and you press 'Register
product' you will see the following message :
At the top you can see which products are registered, and which status they have.
When you want to do a FULL SETUP, you need to download the full version.
You do not need to uninstall a previous version. You can install an update into the
same directory or a new directory.
You can also order the same update on CD-ROM. You will be directed to the on line
shop. Notice that the shop uses a different account/username
The ZIP file you download contains only one setup.exe. You need to run this
executable.
It is also important that you put the license DLL into the same directory as setup.
exe
Setup will copy this file to the bascom application directory. You can also manual
copy this file.
The license file is on CD-ROM, diskette, or the media (email) you received it on. It is
only supplied once.
Without the file, bascom will not run.
The file is named bsc5132L.DLL for BASCOM-8051 and bscavrL.DLL for BASCOM-
AVR
When you got the license by email, it was zipped and probably had a different
extension. Consult the original installation instructions.
The file is only provided once, we can not, and do not provide it again.
It is also possible to do a partial update. For example to update some DAT files, or
to update to a beta which is only available as an update.
For partial updates, you need the Update Wiz.
When you do not have the Update Wiz, you can download it.
Unzip it to the same directory as BASCOM.
The Update Wiz uses LIC files which you can download. A LIC file is a text file, it is
not the LICENSE DLL !
Store the downloaded LIC file in the same directory as the Update Wiz.
When you store the Update Wiz into the same directory as BASCOM, the license DLL
already exist there.
When you put the Update Wiz and the LIC files into a separate directory, you need
to copy the BASCOM license DLL to this directory too.
When you run the Update Wiz, it will check for a new version and will download this
if available. It will then run again.
When the Update Wiz finds a LIC file, it will check if the update/install location is
specified. For new downloaded LIC files, the update wiz does not know the update
directory, and will ask for the directory you want to update. This can be any (new)
directory, but usually is the BASCOM application directory.
After you click Ok, the directory to update is stored in the LIC file.
It will not be asked again.
You need to select the product that you want to update. In the sample there is only
1 choice.
Press the Next-button to continue.
The Wiz will compare files on the web with your local files in the specified directory.
When it finds packages that are newer, they will be shown in a list. By default they
are all selected.
You can unselect the packages you do not want to update.
Press Next to download the selected packages.
IV
BASCOM IDE 37
4 BASCOM IDE
4.1 RUNNING BASCOM-8051
The BASCOM IDE is a so-called multi document application. This means that you can
open more than one source file. The operations that you perform are always done
on the current document, that is, the window with the focus.
File
File New 39
File Open 39
File Close 40
File Save 40
File Print 41
File Exit 41
Edit
Edit Undo 42
Edit Redo 42
Edit Copy 42
Edit Cut 42
Edit Paste 43
Edit Find 43
Edit Replace 44
Editor Keys 46
Program
Compile 47
Syntax check 47
Show Result 48
Simulate 49
Send to chip 52
Tools
Terminal Emulator 53
LCD designer 54
Graphic Converter 54
LIB Manager 55
Options
Compiler Output 57
Compiler Communication 58
Compiler I2C 58
Compiler LCD 59
Compiler Misc. 60
Communication 60
Environment 62
Hardware Simulator 64
Programmer 64
Monitor 65
Printer 66
Window
Cascade 66
Tile 67
Arrange Icons 67
Minimize all 67
Help
About 67
Index 67
Forum 68
Shop 68
Support 68
Credits 68
Note that you must save your program before you can compile it. Newly created
files will have the name [nonameX] in the window caption. Where X is a number
starting with 1 for the first editor window.
Before you can compile your program, you must give it a valid name.
You can specify that BASCOM must reformat the file when it opens the file.
See Options Environment 62 options.
This should only be necessary when loading files made with another editor.
Since saved/closed files are put in a so called 'recent file list' , you can also open a
file by selecting it from the File menu.
By clicking the Setup-button, you can change some printer properties. For margin
settings, you must use the Options Printer settings 66 . For a hardcopy, click the
Print-button.
See also
Print 41
See also
Print preview 40
See also
Edit Redo 42
Shortcut
CTRL+Z
See also
Edit Undo 42
Shortcut
SHIFT+CTRL+Z
Shortcut
CTRL+C and CTRL+INS
Shortcut
CTRL+T
Shortcut
CTRL+ V and SHIFT + INS
You can choose to search forward or backward. Optional you can search case
sensitive and for whole words.
Regular expressions are also supported.
Shortcut
CTRL+F
See Also
Edit Find 43
Shortcut
F3
Enter the text to search for and the text to replace with, and press return.
Shortcut
CTRL+R
The current line number will be shown. You can edit this and press RETURN to jump
You need to select at least one line in order to use this option.
When you have a structure like :
Do
a=a+1
b=b+1
Loop
It is hard to see the structure. You can best indent your code.
Do
a=a+1
b=b+1
Loop
When you have code that is not indented you can indent it by selecting the two line
within the structure and choose 'Edit Indent Block'.
You need to select at least one line in order to use this option.
When you have a structure like :
Do
a=a+1
b=b+1
Loop
It is hard to see the structure. You can best indent your code.
Do
a=a+1
b=b+1
Loop
When you have code that is not indented you can indent it by selecting the two line
within the structure and choose 'Edit Indent Block'. The Unindent option can be used
when the code is too much indented :
Do
a=a+1
b=b+1
Loop
The sample above show that too much indention does not make the program
readable.
xxx.SIM Generated by the simulator to store the variable names of the watch
xxx.PRJ window and the breakpoints.
If an error occurs, you will receive an error message and the compilation will end.
The cursor will be set to the line in which the error occurred. The line will be marked
with a red color too. The red marking color will disappear when you compile the
program again.
Shortcut
F7
Shortcut
CTRL+F7
See the Options Compiler Output 57 for specifying which files must be created.
The files that can be viewed are report and error.
Click the Print button to print the selected file.
Click the Ok button to return to the editor.
Shortcut
or CTRL+W
Variable The name, type and the location in memory of the used
variables
The margin
On the left side a margin is visible. This margin can display the following icons:
a yellow dot, indicating that the line holds executable code
a read dot, indicating that a break line is set. You can only set a breakpoint
on a line that has a
yellow dot.
a yellow arrow. This arrow shows the line currently executing.
To pause execution at a certain line, you can set a breakpoint. Just set the cursor on
that line and press F9. By pressing F9 again, you can remove the breakpoint.
Note that a breakpoint can only be set on a line that contains executable code.
This is visible by the yellow dot. Statements like $romstart don't contain executable
code and won't have a corresponding yellow dot.
You can also run to a specified line by clicking the run to button .
Each segment is named with a letter. To change a port pin, select the segment from
the list and press the spacebar. Now you can enter the desired port pin.
After you are done with assigning/changing, press the Ok button.
Update source
The displaying of the variables and the arrow costs a lot of processor time. To
simulate faster, you can disable the update of these items. Click the button to
enable/disable the update.
Refresh variables
Normally, variables are only refreshed in step mode (F8), because depending on the
used statements, the value would be hard to watch. You can also choose to display
the value during program execution. The default is on.
To end a session close the windows or just set the focus to an editor window.
After you have tested your program you can run one of the supported programmers.
You can also press F4 or click on the button.
Some programmers support the auto flash option from the programmers options.
When you select this option, the programmer window will not be visible, but the
chip will be erased, programmed and verified automatically. The progress will be
visible in the IDE-menu bar.
Different serial comport and parallel printer port based programmers are supported.
You must select one first with the Options Programmers 64 menu.
The terminal emulator supports ANSI, TTY, VT100 and VT220 terminal emulation.
Information you type and information that the computer board sends,
are displayed in the same window.
You must use the same baud rate for the terminal emulator and the program you
compile. If you compiled your program with the Compiler Settings at 4800 baud,
you must set the Communication Settings also to 4800 baud. The setting for the
baud rate is reported in the report file.
File upload
This will upload the current program in HEX format to a monitor program.
With the Options Monitor settings, you can specify an optional header to be sent
before the actual hex file is sent to the monitor.
Also a delay in mS can be specified for a optional delays after each line sent.
When an ALTAIR ROM is selected from the Monitor Options, a binary file will be sent
to the monitor. The baud rate of the terminal emulator will be used.
For an 552 ALTAIR ROM, the terminal baud rate must be set to 115200 baud.
While sending the hex file to the monitor, an extra menu option will be available:
File Escape
This will abort the upload to the monitor program.
File Exit
This will close the terminal emulator window.
By clicking, the Clear All button you can clear all points.
By clicking the Set All button you can set all points.
With the Options Compiler LCD 59 settings you can choose if the 3 most significant
bits must be set high. Some LCD displays require this.
You must replace the ?-sign with a number ranging from 0 to7.
When you want to display the custom character you can use the chr() function.
LCD chr(0) 'will display custom character 0.
The numbers after the custom character are representing the row values.
An empty row is converted to 32 (space) since a zero is used to terminate the bytes.
You can use your favorite graphic tool to create the bitmaps and use the Graphic
converter to convert them into black and white images.
When you click the Save-button the picture will be converted into black and white.
Any non-white color will be converted into black.
By clicking the Add button a dialog box will be shown to select the ASM file that
contains the ASM routine(s).
By clicking on the Delete button the selected Routine will be removed from the
selected library.
Each routine must be preceded by the name of the routine between brackets.
Each routine must be ended with the [END] line.
[_DEC76]
;decrease the register pair r6 and r7 with one
; return zero in ACC when r6r7 is zero
_Dec76:
Dec r6 ; dec LSB
Cjne r6,#255,*+4 ; if it was zero
Dec r7 ; we need to decrease r7 to
Mov a,r7 ; result into a
Orl a,r6 ; OR with r6 to see if it is zero
Ret
[END]
$lib "mylib.lib"
$external _dec76
[XBYTE]
CMAP0_TAR = ff00
CMAP0_ALT = ff01
The 3 lines above show the section and 2 entries. The triscend chips are configured
by writing to locations where normally XRAM is located.
BASCOM handles this automatic for you. So when you assign a value to
CMAP0_TAR, the value is written to location &HFF00 where the CMAP0_TAR register
is located.
Reading this XRAM SFR will do the reverse.
At www.triscend.com you can find all info you need. Look for the E5 line of chips.
These are 8051 compatible chips which can be configured with the Triscend
software. You can for example create 3 UARTS, add I2C, SPI, TIMERS etc.
So the E5 chip is hardware configurable by software!
After you created your ‘chip’ , you create the .H file and this file must be imported
with the Tools Triscend Convert option.
There is an evaluation KIT available from triscend. Another pro is that the chips
have many pins. So when your design needs a lot of I/O pins, I advise to look at
these chips.
Remarks
RTF files can be used in documents such as Word files. RTF files can also be used to
show code with colors on a web page. When your file has the name test.bas , a file
with the name test.rtf will be created in the same directory.
Binary file This will generate a ROM-image of the program. Of course you can
You can also use the CONFIG SDA 128 and CONFIG SCL 128 statements.
In the 4-bit mode, only the highest nibble of the data lines is used.
To spare a pin for the R/W pin, reading from the LCD is not supported and you must
connect the R/W line to ground. See additional hardware 257 for more info.
You can also use the LCD statements in the data bus mode.
Some LCD displays needs the upper 3 bits to be set high. So when you have this
kind of display you must select this option. When you select this option the LCD
designer will set the upper 3 bits high when the DEFLCDCHAR 140 statement is
generated.
Remarks
register file Select the register file which is suitable for your target uP. The
reg51.DAT file is the common file that works for every uP, but
doesn’t have hardware specific registers. You can use this file as a
base for your own DAT file.
byte end Specifies the last location of internal memory that can be used by
the compiler for storing variables. For uP's with 128 bytes of RAM
set it to 70 for example. All space after this value is used for the
stack. With the simulator you can test if you run out of stack
space. For uP's with 256 bytes of internal RAM, you can use a
higher value, F0 for example.
size warning Select this option to enable the compiler to give a warning
message when the code size exceeds the specified size.(decimal)
Option Remark
Comport The comport of you computer to use.
Baud rate The baud rate to use.
Parity The parity to use.
Data bits The number of data bits to use.
Stop bits The number of stop bits to use.
Handshake The handshake to use.
Emulation The terminal emulation to use.
Font Click the button to select the font and font color to use.
Backcolor The background color to use (default blue)
Run emulator modal Runs the terminal emulator in modal mode so you can use all
key combinations that are normally reserved to the IDE.
Note that the baud rate of the terminal emulator and the baud rate setting of the
compiler options, must be the same in order to work correctly.
OPTION DESCRIPTION
Auto indent With auto indent, the cursor will be set to the same left
margin as the current line when you press return.
Don't change case This option will not change the case of your line when you
enabled 'Reformat code'. By default each first characters case
is set to uppercase.
Reformat BAS files Reformat files when loading them into the editor. This is only
necessary when you are loading files that were created with
another editor. Normally you don't need to set this option.
Reformat code Reformat code when entered in the editor. This will reformat
the line after you have set focus to a new line.
Smart tabs Will look at the previous line for non spaces to position the
cursor.
Syntax highlight Enables/disables syntax highlighting
Show margin Shows a margin at position 80.
Comment position The right position of the comment.
Tab size The number of spaces equivalent to one tab.
Key mapping Selects the behavior of the editor. Default behaves like
Delphi.
No reformat Specifies file extensions separated by a space where the
extension reformatting is disabled. (for text files or dat files)
Size of new edit Selects the size of the edit window when a file is opened.
window
OPTION DESCRIPTION
Background color Background color of the editor
Keyword color Color used to highlight keywords(statements)
Comment color Color used to highlight comment
ASM color Color used to highlight assembly
HW register color Color used to highlight special function registers
Editor font Font name of the editor
Bold Check to display keywords in bold
Italic Check to display comment in Italic
OPTION DESCRIPTION
Tool tips Will enable/disable tool tips.
Show Toolbar Will display/hide the toolbar of the IDE.
Save File As… for When you enable this option you will be prompted to give new
new files files a name before they will be saved with their default
name.
File location The path to the location of your BAS files. Normally Windows
will use My documents as a default.
The auto flash options will automatic program a chip without displaying the
programmer window.
The auto verify option will verify automatically after each programming.
Selecting 'Code + Data' will program both the flash and the EEPROM.
You can select various programmers. On the Parallel-TAB you can select the LPT-
address.
You can also Add or Remove an LPT-address. It is only possible to remove address
that you added yourself.
The port delay can best be set to 0. In some cases you might want to increase the
value.
Some programmers have I2C chips on them. For example the MCS Flash
programmer. Since different I2C chips exist for the PCF8574, you need to select the
checkbox when you use the PCF8574A.
The Altair monitor needs special instructions and uses binary files.
The hex upload feature is meant for monitor programs that work with hex files.
You can upload a file to the target uP from the terminal emulator with the Upload
file option.
The prefix and suffix can contain returns or any ASCII character.
Use {asc} , to imbed an ASCII character. asc=0-255.
For example @{13} for the prefix, will send @ followed by a return.
o monitor delay, must be specified in msec's, and is the delay time for each
line sent.
MCS would like to thank the following people who have contributed to BASCOM
development :
· Peter Averill from the Victoria University TAFE. Peter designed both the TAFE
AT89C2051 programmer and the software to support it.
· Antti from Silicon Studio Ltd. Antti designed the BlowIT ATA89C2051
programmer and software to support it.
· Jakub Jiricek, he designed the SPI-programmer and software to support it.
· Francois du Plessis, he wrote a Windows version of Jacub's SPI-programmer
software.
· Henry Arndt (DL2TM) , he provided me with the source for his popular Atmel
Programmer.
V
70 BASCOM-8051
5 Language fundamentals
5.1 Language fundamentals
Characters from the BASCOM character set are put together to form labels,
keywords, variables and operators.
These in turn combine to form statements that make up a program.
This chapter describes the character set and the format of BASCOM program lines.
In particular, it discusses:
· The specific characters in the character set and the special meanings of some
characters.
· The format of a line in a BASCOM program.
· Line labels.
· Program line length.
Character Set
The BASCOM BASIC character set consists of alphabetic characters, numeric
characters, and special characters.
The alphabetic characters in BASCOM are the uppercase letters (A-Z) and lowercase
letters (az) of the alphabet.
The BASCOM numeric characters are the digits 0-9.
The letters can be used as parts of hexadecimal numbers.
The following characters have special meanings in BASCOM statements and
expressions:
Character Description
ENTER Terminates input of a line
Blank ( or space)
' Single quotation mark (apostrophe)
* Asterisks (multiplication symbol)
+ Plus sign
, Comma
- Minus sign
. Period (decimal point)
/ Slash (division symbol) will be handled as \
: Colon
" Double quotation mark
; Semicolon
< Less than
= Equal sign (assignment symbol or relational operator)
> Greater than
\ Backslash (integer/word division symbol)
BASCOM LineLength
If you enter your programs using the built-in editor, you are not limited to any line
length, although it is advised to shorten your lines to 80 characters for clarity.
Data Types
Every variable in BASCOM has a data type that determines what can be stored in
the variable. The next section summarizes the elementary data types.
Integers are stored as signed sixteen-bit binary numbers ranging in value from
-32,768 to +32,767.
· Word (two bytes).
Words are stored as unsigned sixteen-bit binary numbers ranging in value from
0 to 65535.
· Long (four bytes).
Longs are stored as signed 32-bit binary numbers ranging in value from -
2147483648 to 2147483647.
· Single
Singles are stored as signed 32 bit binary numbers.
· String (up to 254 bytes).
Strings are stored as bytes and are terminated with a 0-byte.
A string dimensioned with a length of 10 bytes will occupy 11 bytes.
Variables
A variable is a name that refers to an object--a particular number.
A numeric variable can be assigned only a numeric value (either integer, word, byte
long, single or bit).
The following list shows some examples of variable assignments:
· A constant value:
A=5
C = 1.1
· The value of another numeric variable:
abc = def
k=g
· The value obtained by combining other variables, constants, and
operators:
Temp = a + 5
Temp = C + 5
Variable Names
A BASCOM variable name may contain up to 32 characters.
The characters allowed in a variable name are letters and numbers.
The first character in a variable name must be a letter.
A variable name cannot be a reserved word, but embedded reserved words are
allowed.
For example, the following statement is illegal because AND is a reserved word.
AND = 8
However, the following statement is legal:
ToAND = 8
Reserved words include all BASCOM commands, statements, function names,
internal registers and operator names.
(see BASCOM Reserved Words 283 , for a complete list of reserved words).
You can specify a hexadecimal or binary number with the prefix &H or &B.
a = &HA , a = &B1010 and a = 10 are all the same.
Before assigning a variable you must tell the compiler about it with the DIM
statement.
Dim b1 As Bit, I as Integer, k as Byte , s As String * 10
You can also use DEFINT 140 , DEFBIT 140 , DEFBYTE 140 and/or DEFWORD 140 .
For example DEFINT c tells the compiler that all variables that are not dimensioned
and that are beginning with the character c are of the Integer type.
This chapter discusses how to combine, modify, compare, or get information about
expressions by using the operators available in BASCOM.
Anytime you do a calculation you are using expressions and operators.
This chapter describes how expressions are formed and concludes by describing the
following kind of operators:
· Arithmetic operators, used to perform calculations.
· Relational operators, used to compare numeric values.
· Logical operators, used to test conditions or manipulate individual bits.
· Functional operators, used to supplement simple operators.
Arithmetic
Arithmetic operators are +, - , * and \.
· Integer
Integer division is denoted by the backslash (\).
Example: Z=X\Y
· Modulo Arithmetic
Modulo arithmetic is denoted by the modulus operator MOD.
Modulo arithmetic provides the remainder, rather than the quotient, of an
integer division.
Example: X = 10 \ 4 : remainder = 10 MOD 4
· Overflow and division by zero
Division by zero, produces an error.
At this moment there is no message, so you have to insure yourself that such
wont happen.
Relational Operators
Relational operators are used to compare two values as shown in the table below.
The result can be used to make a decision regarding program flow.
Logical Operators
Logical operators perform tests on relations, bit manipulations, or Boolean
operators.
There are four operators in BASCOM, they are :
Operator Meaning
NOT Logical complement
AND Conjunction
OR Disjunction
XOR Exclusive or
It is possible to use logical operators to test bytes for a particular bit pattern.
For example the AND operator can be used to mask all but one of the bits
of a status byte, while OR can be used to merge two bytes to create a particular
binary value.
Example
A = 63 And 19
PRINT A
A = 10 Or 9
PRINT A
Output
16
11
Floating point
Single numbers conform to the IEEE binary floating point standard.
An eight-bit exponent and 24 bit mantissa are supported.
Using four bytes, the format is shown below:
31 30________23 22______________________________0
s exponent mantissa
The exponent is biased by 128. Above 128 are positive exponents and below are
negative. The sign bit is 0 for positive numbers and 1 for negative. The mantissa is
stored in hidden bit normalized format so that 24 bits of precision can be obtained.
Arrays
An array is a set of sequentially indexed elements having the same type. Each
element of an array has a unique index number that identifies it. Changes made to
an element of an array do not affect the other elements.
The index must be a numeric constant, a byte, an integer or a word. This means
that an array can hold 65535 elements as a maximum. The minimum value is 1 and
not zero as in QB.
Arrays can be used on each place where a 'normal' variable is expected but there
are a few exceptions.
These exceptions are shown in the help topics.
Note that there are no BIT arrays in BASCOM-8051.
Example:
Dim a(10) as byte 'make an array named a, with 10 elements (1 to 10)
Dim c as Integer
For C = 1 To 10
a(c) = c 'assign array element
Print a(c) 'print it
Next
Strings
Strings can be up to 254 characters long in BASCOM.
To save memory you must specify how long each string must be with the DIM
statement.
Dim S As String * 10
This will reserve space for the string S with a length of 10 bytes. The actual length
is 11 bytes because a nul(0) is used to terminate the string.
In QB you can assign a string with a value and add the original string (or a part of
it) too :
S = "test"
S = "a" + s
VI
BASCOM Language Reference 77
-1-
-COMPILER DIRECTIVES-
#IF 80
#ELSE 81
#ENDIF 82
$ASM - $END ASM 88
$INCLUDE 93
$BAUD 89
$BGF 89
$CRYSTAL 91
$DEFAULT XRAM 92
$IRAMSTART 94
$LARGE 94
$LCD 95
$MAP 97
$NOBREAK 97
$NOINIT 98
$NONAN 98
$NONULL 99
$NORAMCLEAR 99
$NOSP 100
$OBJ 100
$RAMSIZE 101
$RAMSTART 103
$REGFILE 104
$ROMSTART 104
$SERIALINPUT 105
$SERIALINPUT2LCD 105
$SERIALOUTPUT 106
$SIM 107
-A-
ABS 109
ALIAS 108
ASC 110
AVG 110
-B-
BITWAIT 112
BCD 112
BREAK 113
-C-
CALL 113
CLOSE 198
CLS 115
CHR 114
CONFIG 116
CONST 116
COUNTER 132
CPEEK 134
CURSOR 135
-D-
DATA 136
DEBOUNCE 137
DECR 138
DECLARE 139
DEFINT 140
DEFBIT 140
DEFBYTE 140
DEFLCDCHAR 140
DEFWORD 140
DELAY 141
DIM 141
DISABLE 143
DISPLAY 143
DO 144
-E-
ELSE 144
ENABLE 145
END 146
END IF 146
ERASE 147
EXIT 148
-F-
FOR 148
FOURTHLINE 149
FUSING 150
-G-
GET 151
GETAD 152
GETAD2051 153
GETRC 158
GETRC5 160
GOSUB 162
GOTO 163
-H-
HEX 163
HEXVAL 164
HIGH 164
HIGHW 165
HOME 166
-I-
I2CRECEIVE 166
I2CSEND 167
I2CSTART 168
I2CSTOP 168
I2CRBYTE 168
I2CWBYTE 168
IDLE 169
IF 169
INCR 171
INKEY 171
INP 173
INPUT 173
INPUTBIN 175
INPUTHEX 176
INSTR 177
-L-
LCASE 178
LCD 178
LCDINIT 181
LCDHEX 182
LEFT 183
LEN 183
LOAD 184
LOCATE 185
LOOKUP 185
LOOKUPSTR 186
LOOP 144
LOW 187
LOWW 188
LOWERLINE 188
-M-
MAKEDEC 189
MAKEBCD 189
MAKEINT 190
MAX 190
MID 191
MIN 192
MOD 192
-N-
NEXT 196
-O-
ON Interrupt 196
ON Value 197
OPEN 198
OUT 200
-P-
P1,P3 201
PEEK 202
POKE 202
PSET 207
POWERDOWN 203
PRINT 203
PRINTBIN 204
PRINTHEX 205
PRIORITY 206
PUT 207
-R-
READ 208
READMAGCARD 209
REM 211
REPLACE 211
RESET 212
RESTORE 212
RETURN 213
RIGHT 214
RND 214
ROTATE 215
-S-
SELECT 216
SET 216
SHIFT 217
SHIFTCURSOR 217
SHIFTIN 218
SHIFTOUT 218
SHIFTLCD 219
SHOWPIC 220
SOUND 220
SPACE 222
SPC 223
SPIIN 224
SPIOUT 225
START 225
STOP 226
STOP TIMER 226
STR 228
STRING 228
SUB 229
SWAP 230
-T-
THEN 169
THIRDLINE 230
TIMEOUT 107
TO 148
-U-
UCASE 231
UPPERLINE 232
-V-
VAL 232
VARPTR 233
-W-
WAIT 233
WAITKEY 234
WAITMS 234
WHILE .. WEND 236
6.2 #IF
Action
Conditional compilation directive that tests for a condition.
Syntax
#IF test
[#ELSE]
#ENDIF
Remarks
test An expression to test for. The expression may contain defined
constants.
See Also
#ELSE 81 , #ENDIF 82
Example
Const DEMO = 1 ' 0 = normal , 1= demo
#If Demo
Print "Demo program"
#Else
Print "Full version"
#Endif
Since the constant DEMO is assigned with the value 1, the compiler will compile only
the line : Print "Demo program".
Code between #else and #endif is not compiled!
When you change the constant DEMO to 0, the other line will be compiled.
6.3 #ELSE
Action
Conditional compilation directive that tests for a NOT condition.
Syntax
#IF test
#ELSE
#ENDIF
Remarks
test An expression to test for. The expression may contain defined constants.
See Also
#IF 80 , #ENDIF 82
Example
CONST DEMO = 1 ' 0 = normal , 1= demo
#IF Demo
Print "Demo program"
#ELSE
Print "Full version"
#ENDIF
Since the constant DEMO is assigned with the value 1, the compiler will compile only
the line : Print "Demo program" . Code between #else and #endif is not compiled!
When you change the constant DEMO to 0, the other line will be compiled.
6.4 #ENDIF
Action
Conditional compilation directive that ends a test.
Syntax
#IF test
[#ELSE]
#ENDIF
Remarks
Test An expression to test for. The expression may contain defined constants.
See Also
#IF 80 , #ELSE 82
Example
CONST DEMO = 1 ' 0 = normal , 1= demo
#IF Demo
Print "Demo program"
#ELSE
Print "Full version"
#ENDIF
Since the constant DEMO is assigned with the value 1, the compiler will compile only
the line : Print "Demo program" . Code between #else and #endif is not compiled!
When you change the constant DEMO to 0, the other line will be compiled.
6.5 1WIRE
Action
These routines can be used to communicate with Dallas Semiconductors 1Wire-
devices.
Pin is the port pin to use with the device such as P1.1
Remarks
1WRESET Reset the 1WIRE bus. The error variable ERR will return 1 if an
error occurred.
1WWRITE var1 Sends the value of var1 to the bus.
Optional is the number of bytes that mist be sent. var1 is a
numeric variable or constant.
var2 = 1WREAD Reads a byte from the bus and places it into var2.
() Optional is the number of bytes that must be read. var2 is a
number variable.
Example
'--------------------------------------------------------------
' 1WIRE.BAS
' demonstrates 1wreset, 1wwrite and 1wread()
' pull-up of 4K7 required to VCC from P.1
' DS2401 serial button connected to P1.1
'--------------------------------------------------------------
Config 1wire = P1.1 'use this pin
Dim Ar(8) As Byte , A As Byte , I As Byte
6.6 1WIRECOUNT
Action
This statement returns the number of 1wire devices found on the bus.
Syntax
var2 = 1WIRECOUNT(array )
Remarks
var2 A word variable that is assigned with the number if found 1wire devices
on the bus.
Array A variable or array that should be at least 8 bytes long. It is used to
store the 1wire ID’s while counting.
The 1wireCount function uses the 1wSearchFirst() and 1wSearchNexy functions
internally.
See also
1WIRE 83 , 1WSEARCHFIRST 85 , 1WSEARCHNEXT 87
Example
'---------------------------------------------------------------------
------
' 1wirecount.bas
' (c)1995-2006 MCS Electronics
' demonstration of using multiple devices
'---------------------------------------------------------------------
-----
'chip we use
$regfile = "89s8252.dat"
'crystal attached
$crystal = 12000000
'baud rate
$baud = 4800
Print "start"
'get the number of connected 1wire device
W = 1wirecount(ar(1))
'print if there was an error and how many sensors are available
Print "ERR " ; Err ; " count " ; W
'now get the data from the first 1wire device on the bus
Ar(1) = 1wsearchfirst()
'print the ID
For I = 1 To 8
Printhex Ar(i);
Next
Print
'once you know the ID, you can address a specific device
End
6.7 1WSEARCHFIRST
Action
This statement reads the first ID from the 1wire bus into a variable array.
Syntax
var2 = 1WSEARCHFIRST( )
Remarks
var2 A variable or array that should be at least 8 bytes long and that will be
assigned with the 8 byte ID from the first 1wire device on the bus.
function calls to the 1wireSearchNext function to retrieve other ID's on the bus.
A string can not be assigned to get the values from the bus. This because a null may
be returned as a value and the null is also used as a string terminator.
We advice to use a byte array as shown in the example.
The ERR bit is set when there are no 1wire devices found.
See also
1WIRE 83 , 1WIRECOUNT 84 , 1WSEARCHNEXT 87
Example
'----------------------------------------------------------------------
' 1wirecount.bas
' (c) 1995-2006 MCS Electronics
' demonstration of using multiple devices
'----------------------------------------------------------------------
----
'chip we use
$ r e g f i l e = "89s8252.dat"
'crystal attached
$ c r y s t a l = 12000000
'baud rate
$baud = 4800
'now get the data from the first 1wire device on the bus
Ar(1) = 1wsearchfirst()
'print the ID
For I = 1 To 8
Printhex Ar(i);
Next
Print
Next
Print
Loop U n t i l E r r = 1
'when ERR is 1 it means there are no more devices
' IMPORTANT : 1wsearchfirst and next functions do require that you use
the SAME array
'In this example this is ar(1)
'once you know the ID, you can address a specific device
End
6.8 1WSEARCHNEXT
Action
This statement reads the next ID from the 1wire bus into a variable array.
Syntax
var2 = 1WSEARCHNEXT( )
Remarks
var2 A variable or array that should be at least 8 bytes long that will be
assigned with the 8 byte ID from the next 1wire device on the bus.
A string can not be assigned to get the values from the bus. This because a null may
be returned as a value and the null is also used as a string terminator.
I would advice to use a byte array as shown in the example.
The ERR variable is set when there are no more devices found.
See also
1WIRE 83 , 1WSEARCHFIRST 85 , 1WIRECOUNT 84
Example
'----------------------------------------------------------------------
-----
' 1wirecount.bas
' (c) 1995-2006 MCS Electronics
' demonstration of using multiple devices
'----------------------------------------------------------------------
----
'chip we use
$regfile = "89s8252.dat"
'crystal attached
$crystal = 12000000
'baud rate
$baud = 4800
Print "start"
'get the number of connected 1wire device
W = 1wirecount(ar(1))
'print if there was an error and how many sensors are available
Print "ERR " ; Err ; " count " ; W
'now get the data from the first 1wire device on the bus
Ar(1) = 1wsearchfirst()
'print the ID
For I = 1 To 8
Printhex Ar(i);
Next
Print
'once you know the ID, you can address a specific device
End
Syntax
$ASM
Remarks
Use $ASM together with $END ASM to insert a block of assembler code in your
BASIC code.
You can also insert ASM code by preceding the line with the ! sign.
See also
ASM programming 239
Example
Dim c as Byte
$ASM
Mov r0,#{C} ;address of c
Mov a,#1
Mov @r0,a ;store 1 into var c
$END ASM
Print c
End
6.10 $BAUD
Action
Instruct the compiler to override the baud rate setting from the options menu.
Syntax
$BAUD = var
Remarks
Var The baud rate that you want to use. Var must be a numeric
constant.
When you want to use a crystal/baud rate that can't be selected from the options,
you can use this compiler directive.
You must also use the $CRYSTAL 91 directive.
These statements always work together.
In the generated report you can view which baud rate is actually generated.
But the baud rate is only shown when RS-232 statements are used like PRINT,
INPUT etc.
See also
$CRYSTAL 91
Example
$baud = 2400
$crystal = 14000000 ' 14 MHz crystal
Print "Hello"
End
6.11 $BGF
Action
Binds a BASCOM Graphic File into the program for use with Graphic LCD displays.
Syntax
$BGF "file"
Remarks
"file" is the name of the BGF file that is included in the program,
BMP files can be converted with the Tools Graphic Converter 54 .
See also
SHOWPIC 220
Example
'---------------------------------------------------------------------
---------
' (c) 1995-2006 MCS Electronics
' GLCD.BAS
' Sample to show support for T6963C based graphic display
' Only 240*64 display is supported with 30 columns(yet)
' At the moment the display can only be used in PORT mode
' Connection :
' P1.0 - P1.7 to DB0-DB7 of LCD
' P3.2 to FS, font select of LCD can be hard wired too
' P3.5 to CE, chip enable of LCD
' P3.4 to CD, code/data select of LCD
' P3.6 to WR of LCD
' P3.7 to RD of LCD
'A future version will allow external data access too which also uses
RD and WR
'The display from www.conrad.com needs a negative voltage for the
contrast.
'I used two 9 V batteries
'---------------------------------------------------------------------
---------
'configure the LCD display
Config Graphlcd = 240 * 64 , Port = P1 , Ce = P3.5 , Cd = P3.4 , Cols
= 30
'
Reset P3.2 '8 bit
wide char is 30 columns
'Locate is supported and you can use 1-8 for the row and 1-30 for the
column
Locate 1 , 1
'To display the BGF file you use the SHOWPIC statement that needs an X
and Y parameter
'the third param is the label where the data is stored.
'The position must be divideble by 8 because this is the way the
display handles the data
Showpic 0 , 0 , Picture1
'And we use the PSET known from QB to set or reset a single pixel
'A value of 0 means clear the pixel and 1 means set the pixel
'create a block
For X = 0 To 10
For Y = 0 To 10
Pset X , Y , 1
Next
Next
6.12 $CRYSTAL
Action
Instruct the compiler to override the crystal frequency options setting.
Syntax
$CRYSTAL = var
Remarks
var Frequency of the crystal.
var : Constant.
When you want to use an unsupported crystal/baud rate you can use this compiler
directive.
When you do, you must also use the corresponding $BAUD 89 directive.
These statements always work together.
See also
$BAUD 89
Example
$baud = 2400
$crystal = 14000000 ' 14 MHz crystal
Print "Hello"
End
Syntax
$DEFAULT XRAM | IRAM
Remarks
When you are using many XRAM variables it make sense to set this option, so you
don't have to type XRAM each time.
To dimension a variable to be stored into IRAM, specify IRAM in that case.
See Also
DIM 141
Example
$default Xram
Dim X As Integer 'will go to XRAM
Dim Z As Iram Integer 'will be stored in IRAM
6.14 $EXTERNAL
Action
Compiler directive that instructs the compiler to include the specified assembler
routines.
Syntax
$EXTERNAL myrout [, other]
Remarks
The $EXTERNAL directive is used internally by the compiler in order to enable the
customizing of the assembler routines by the user.
You can use it to include your own assembler routines. At the moment using
$EXTERNAL will always include the routine no matter if it is used or not.
See also
$LIB 95 , LIB Manager 55
Example
$LIB "mylib.lib"
$EXTERNAL _dec76
6.15 $INCLUDE
Action
Includes an ASCII file in the program at the current position.
Syntax
$INCLUDE "file"
Remarks
file Name of the ASCII file which must contain valid BASCOM statements.
This option can be used if you make use of the same routines in
many programs. You can write modules and include them into your
program.
If there are changes to make you only have to change the module file,
not all your BASCOM programs.
You can only include ASCII files!
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: INCLUDE.BAS
' demo: $INCLUDE
'--------------------------------------------------------------
Print "INCLUDE.BAS"
$include "123.bas" 'include file that prints
Hello
Print "Back in INCLUDE.BAS"
End
6.16 $IRAMSTART
Action
Compiler directive to specify starting internal memory location.
Syntax
$IRAMSTART = constant
Remarks
Constant A constant with the starting value (0-255)
See also
$NOINIT 98 , $RAMSTART 103
Example
$NOINIT
$NOSP
$IRAMSTART = &H60 'first usable memory location
SP = 80
DIM I As Integer
6.17 $LARGE
Action
Instructs the compiler that LCALL statements must be used.
Syntax
$LARGE
Remarks
Internally when a subroutine is called the ACALL statement is used.
The ACALL instruction needs only 2 bytes (the LCALL needs 3 bytes)
The ACALL statement however can only address routines with a maximal offset of
2048 within the page. AT89C2051 chips will have no problems with that.
When code is generated for another uP, the subroutine being called can be further
away and you will receive an error. With the $LARGE statement you instruct the
compiler to use the LCALL statement which can address the full 64K address space.
Example
$LARGE 'I received an error 148 so I need this option
6.18 $LIB
Action
Compiler directive that instructs the compiler to look for assembler routines in the
specified LIB file.
Syntax
$LIB "myrout.LIB"
Remarks
The $LIB directive is used internally by the compiler in order to enable the
customizing of the assembler routines by the user.
You can use it to specify your own libraries. You can for example copy the mcs.lib
file to a new file named mylib.lib and delete the content of the mcs.lib file. This way
the compiler will use your routines. The mcs.lib file must exist in the \LIB
subdirectory and that is why you may not delete it.
Always make a backup of the mcs.lib file before you change it.
It is not encouraged to change the mcs.lib file itself other than making a dummy
because updates will contain more asm routines and you have to change everything
for each update.
See also
$EXTERNAL 92
Example
$LIB "mylib.lib"
$EXTERNAL _dec76
6.19 $LCD
Action
Instruct the compiler to generate code for 8-bit LCD displays attached to the data
bus.
Syntax
$LCD = [&H]address
Remarks
address The address where must be written to, to enable the LCD display.
The db0-db7 lines of the LCD must be connected to the datelines D0-
D7.
The RS line of the LCD must be connected to the address line A0.
See Also
$LCDRS 96
Example
$lcd = &HA000 'writing to this address will make the E line of
the LCD high.
Cls
Lcd "Hello world"
End
6.20 $LCDRS
Action
Instruct the compiler to generate code for 8-bit LCD displays attached to the data
bus.
Syntax
$LCDRS = [&H]address
Remarks
Address The address where must be written to, to enable the LCD display and
the RS of the LCD.
The db0-db7 lines of the LCD must be connected to the data lines D0-
D7.
The RS line of the LCD must be connected to the address line A0 by
default.
When it is connected to another address line you can specify $LCDRS
On systems with external RAM/ROM it makes more sense to attach the
LCD to the data bus. With an address decoder you can select the LCD
display.
See Also
$LCD 95
Example
$lcd = &H8000 'writing to this address will make the E line of
the LCD high.
$lcdrs = &H8002 'writing to this address will make the RS line of
the LCD high.
Cls
Lcd "Elektor"
End
6.21 $MAP
Action
Generates info in the report file with hexadecimal address of each source line.
Syntax
$MAP
Remarks
For debugging it can be useful to know at which address a source line begins.
See also
NONE
Example
$MAP
Print "Hello"
Print "Test"
Code map
-----------------------------------------------------------
Line Address(hex)
-----------------------------------------------------------
2 52
3 69
5 80
6.22 $NOBREAK
Action
Instruct the compiler that BREAK statements must not be compiled.
Syntax
$NOBREAK
Remarks
With the BREAK statement, you can generate a reserved opcode that is used by the
simulator to pause the simulation.
When you want to compile without these opcode's you don't have to remove the
BREAK statement: you can use the $NOBREAK statement to achieve the same.
See also
BREAK 113
Example
$nobreak
Break ' this isn't compiled into code so the simulator will
not pause
End
6.23 $NOINIT
Action
Instruct the compiler that no initialization must be performed.
Syntax
$NOINIT
Remarks
BASCOM initializes the processor depending on the used statements.
When you want to handle this by yourself you can specify this with the compiler
directive $NOINIT.
The only initialization that is always done is the setting of the stack pointer and the
initialization of the LCD display (if LCD statements are used).
When you have selected the Altair as a monitor in the Monitor options, the following
code will be generated:
Mov IE,#255
Mov scon,#82
This because the Altair monitor needs this code despite of the $NOINIT. When you
do not want that, you have to select HEX Monitor for example.
See also
$NOSP 100 , $NORAMCLEAR 99
Example
$NONIT
$NORAMCLEAR 99
'your program goes here
End
6.24 $NONAN
Action
Compiler directive for changing NAN (not a number) into 0.0
Syntax
$NONAN
Remarks
A single can return a NAN when it is not considered to be a number.
With the $NONAN directive 0.0 will be returned.
See also
NONE
Example
NONE
6.25 $NONULL
Action
Compiler directive for changing the behavior of the DATA statements.
Syntax
$NONULL = value
Remarks
value 0 for default behavior. And -1 for special behavior
When a string is stored with a DATA statement, a null is added to indicate the string
end. In some situations you might not want this. When you write a custom routine
to work with a long string for example. With $NONULL = -1 , the additional null byte
is not added. To switch back to normal mode use a value of 0.
See also
NONE
Example
$nonull = -1
Lbl:
Data "test" , "this"
Lbl2:
$nonull = 0 'normal mode
Data "test" , "this"
6.26 $NORAMCLEAR
Action
Instruct the compiler that the internal RAM should not be cleared at start up.
Syntax
$NORAMCLEAR
Remarks
BASCOM clears the internal memory after a reset. When you don’t want this
behavior you can use the $NORAMCLEAR compiler directive.
See also
NONE
Example
$NORAMCLEAR
‘your code goes here
End
6.27 $NOSP
Action
Instruct the compiler that the stack pointer must not be set.
Syntax
$NOSP
Remarks
BASCOM initializes the processor depending on the used statements.
When you want to handle this by yourself you can specify this with the compiler
directive $NOINIT.
The only initialization that is always done is the setting of the stack pointer and the
initialization of the LCD display (if LCD statements are used).
With the $NOSP directive the stack will not be initialized either.
See also
$NOINIT 98
Example
$NOSP
$NOINIT
End
6.28 $OBJ
Action
Includes Intel object code.
Syntax
$OBJ obj
Remarks
obj is the object code to include.
In some cases it can be useful to include object code. This object code can be
generated with other tools.
Example
$OBJ D291 'this is equivalent to SET P1.1
6.29 $RAMSIZE
Action
Specifies the size of the external RAM memory.
Syntax
$RAMSIZE = [&H] size
Remarks
Size Size of external RAM memory chip.
size : Constant.
See also
$RAMSTART 103
Example
$ROMSTART = &H4000
$RAMSTART = 0
$RAMSIZE = &H1000
DIM x AS XRAM Byte 'specify XRAM to store variable in XRAM
6.30 $RAMTRON
Action
Tell the compiler to use SPI memory as XRAM.
Syntax
$RAMTRON
Remarks
address The (hex)-address where the data is stored.
Or the lowest address which enables the RAM chip.
You can use this option when you want to run your code in systems
with external RAM memory.
Ramtron (www.ramtron.com) sell EEPROM's that are as fast as normal RAM chips.
They can be written billions of times. The $ramtron directive will use such as
ramtron device as xram device. This only works for the AT89S8252. You only add a
ramtron EEPROM to the hardware SPI lines and when you dim a variable as XRAM,
the EEPROM will be used to store and retrieve the data.
This is a convenient way to add more memory without adding an address decoder
and a RAM chip. Since the EEPROM is housed in a 8 pins chip it will make your
design simple.
Note however that it is best practice that writing to such a XRAM variable must not
be excessive. The data sheet of the Ramtron chips show that you can write it many
times and in effect it will take years until you reach the limit.
ASM
When XRAM is written with Movx @dptr,a , a call will be made to _WriteRamtron.
Nothing is destroyed or returned.
When XRAM is read with Movx a,@dptr , a call will be made to _ReadRamtron. Value
is returned in ACC as movx a,@dptr would do too.
Both routines are in the mcs.lib file. Both routines call _Wait_Spif to wait for the
SPI, SPIF bit.
Example
'-------------------------------------------------------
' (c) 1995-2006 MCS Electronics
' RAMTRON.BAS
' This example shos how to use the www.ramtron.com eeprom
' to be used a XRAM
'-------------------------------------------------------
'it works only for the 8252
$regfile = "89s8252.dat"
Wait 1
'I used P1.3 for the CS so the mcs.lib also uses this pin
'P1.4 could be used too but it needs a change in the mcs.lib
'This sample works actually!
'But since I also have code like *+4 it will not work always
'I need to rewrite that code. Let me know when some routines dont work
'with the $ramtron directive
6.31 $RAMSTART
Action
Specifies the location of the external RAM memory.
Syntax
$RAMSTART = [&H]address
Remarks
address The (hex)-address where the data is stored.
Or the lowest address which enables the RAM chip.
You can use this option when you want to run your code in systems
with external RAM memory.
Address must be a numeric constant.
See also
$RAMSIZE 101
Example
$ROMSTART = &H4000
$RAMSTART = 0
$RAMSIZE = &H1000
6.32 $REGFILE
Action
Instructs the compiler to use the specified register file.
Syntax
$REGFILE = "file"
Remarks
File The name of the register file to use.
The $REGFILE statement must be placed before any other executable statements or
compiler directives.
See also
NONE
Example
'comment is no problem before the $REGFILE statement
$REGFILE = "8052.DAT" 'use the 8052.DAT file
6.33 $ROMSTART
Action
Specifies the location of the ROM memory.
Syntax
$ROMSTART = [&H] address
Remarks
address The (hex)-address where the code must start.
Default is 0. This value will be used when $ROMSTART is not
specified.
You can use this option when you want to test the code in RAM.
The code must be uploaded and placed into the specified address and
can be called from a monitor program.
The monitor program must relocate the interrupts to the correct
address! When $ROMSTART = &H4000 is specified the monitor
program must perform a LJMP instruction. For address 3 this must be
&H4003. Otherwise interrupts can not be handled correctly. But that
is up to the monitor program.
See also
$RAMSTART 103
Example
$ROMSTART = &H4000 'ROM enabled at 4000 hex
6.34 $SERIALINPUT
Action
Specifies that serial input must be redirected.
Syntax
$SERIALINPUT = label
Remarks
Label The name of the assembler routine that must be called when an
character is needed from the INPUT routine. The character must be
returned in ACC.
With the redirection of the INPUT command, you can use your own routines.
This way you can use other devices as input devices.
Note that the INPUT statement is terminated when a RETURN code (13) is received.
See also
$SERIALOUTPUT 106
Example
$SERIALINPUT = Myinput
'here goes your program
END
!myinput:
;perform the needed actions here
mov a, sbuf ;serial input buffer to acc
ret
6.35 $SERIALINPUT2LCD
Action
This compiler directive will redirect all serial input to the LCD display instead of
echoing to the serial port.
Syntax
$SERIALINPUT2LCD
Remarks
You can also write your own custom input or output driver with the $SERIALINPUT
and $SERIALOUTPUT statements, but the $SERIALINPUT2LCD is handy when you
use a LCD display.
See also
$SERIALINPUT 105 , $SERIALOUTPUT 106
Example
$serialinput2lcd
Dim V As Byte
Cls
Input "Number " , V 'this will go to the LCD
display
6.36 $SERIALOUTPUT
Action
Specifies that serial output must be redirected.
Syntax
$SERIALOUTPUT = label
Remarks
label The name of the assembler routine that must be called when a
character is sent to the serial buffer (SBUF).
The character is placed into ACC.
With the redirection of the PRINT and other serial output related commands, you
can use your own routines.
This way you can use other devices as output devices.
See Also
$SERIALINPUT 105
Example
$SERIALOUTPUT = MyOutput
'here goes your program
END
!myoutput:
;perform the needed actions here
mov sbuf, a ;serial output buffer (default)
ret
6.37 $SIM
Action
Generates code without the actual waiting loops in order to speed up the simulator.
Syntax
$SIM
Remarks
When simulating the WAIT statement, you will experience that it takes a long time
to execute. You can also switch off the updating of variables/source which costs
time, but an alternative is the $SIM directive.
You must remove the $SIM statement when you want to place your program into a
chip/EPROM.
See also
BREAK 113
Example
$SIM 'don't make code for WAIT and WAITMS
WAIT 2 'the simulator is faster now
6.38 $TIMEOUT
Action
Compiler directive to specify that the TIMEOUT option is used with serial input.
Syntax
$TIMEOUT
Remarks
$TIMEOUT will modify the serial input routine so that it enables you to use the
TIMEOUT with the INPUT, INPUTBIN, INPUTHEX etc. statements.
See also
INPUT 173 , GET 207
Example
$TIMEOUT
DIM Name as string * 10
REM Now we can use theTIMEOUT option
INPUT "Name " , name TIMEOUT = 100000 'enable time out
INPUT "Name ", name 'wait until <13> pressed.
6.39 $WAIT
Action
Will insert a one second delay in the startup code.
Syntax
$WAIT
Remarks
When using the AT89C8252 ISP facility it is needed that the chip waits 1 second
after reset. Otherwise it can occur that the chip can not be programmed serial
anymore.
Do not confuse $WAIT with the WAIT statement.
$WAIT is only needed for the AT89C8252 !
See also
NONE
Example
$WAIT 'for at89c8252 only
6.40 ALIAS
Action
Indicates that the variable can be referenced with another name.
Syntax
newvar ALIAS oldvar
Remarks
Oldvar Name of the variable such as P1.1
Newvar New name of the variable such as direction
Aliasing port pins can give the pin names a more meaningful name.
You can also ALIAS a variable: M ALIAS var.0 for example.
See also
CONST 116
Example
Direction Alias P1.1 'now you can refer to P1.1
with the variable direction
Set Direction 'has the same effect as SET
P1.1
Dim A As Byte
M Alias A.0
N Alias A.1
Set M
Set N
If M = N Then
Print "Both bits are set"
End If
End
6.41 ABS
Action
Returns the absolute value of a numeric variable.
Syntax
var = ABS(var2)
Remarks
var Variable that is assigned the absolute value of var2. Var must be a
numeric variable.
Var2 The source variable to retrieve the absolute value from. Var2 must be
an integer or long.
See also
NONE
Example
Dim a as Integer, c as Integer
a = -1000
c = Abs(a)
Print c
End
Output
1000
6.42 ASC
Action
Convert a string into its ASCII value.
Syntax
var = ASC(string)
Remarks
var Target variable that is assigned.
String String variable or constant to retrieve the ASCII value from.
var : Byte, Integer, Word, Long.
string : String, Constant.
Note that only the first character of the string will be used.
When the string is empty, a zero will be returned.
See also
CHR 114
Example
Dim A As Byte , S As String * 10
S = "Abc"
A = Asc(s)
Print A
End
Output
65
6.43 AVG
Action
Returns the average value of a byte array.
Syntax
var = AVG( ar(1) )
Remarks
Var Numeric variable that will be assigned with the lowest value of the
array.
ar() The first array element of the array to return the lowest value of.
See also
MAX 190 , MIN 192
Example
Dim ar(10) As Byte
Dim bP as Byte
For bP = 1 to 10
ar(bP) = bP
Next
bP = Avg(ar(1))
Print bP
End
6.44 BAUD
Action
Instruct the compiler to set a new baud rate at run time.
Syntax
BAUD = var
Remarks
Var The baud rate that you want to use.
var : Constant.
When you want to use a crystal/baud rate that can't be selected from the options,
you can assign this special variable.
Do not confuse it with the $BAUD 89 directive!
See also
$CRYSTAL 91 , $BAUD 89
Example
$BAUD = 2400
$CRYSTAL = 14000000 ' 14 MHz crystal
PRINT "Hello"
BAUD = 9600
Print "Hello"
END
6.45 BCD
Action
Converts a variable into its BCD value.
Syntax
PRINT BCD( var )
LCD BCD( var )
Remarks
Var Variable to convert. This must be a numeric variable or constant.
When you want to use a I2C clock device which stores its values as BCD values you
can use this function to print the value correctly.
BCD() will displays values with a trailing zero.
See also
MAKEBCD 189 , MAKEDEC 189
Example
Dim A As Byte
A = 65
Lcd A
Lowerline
Lcd Bcd(a)
End
6.46 BITWAIT
Action
Wait until a bit is set or reset.
Syntax
BITWAIT x SET | RESET
Remarks
x Bit variable or internal register like P1.x , where x ranges form 0-7.
When using bit variables be sure that they are set/reset by software.
When you use internal registers that can be set/reset by hardware such as P1.0 this
doesn't apply.
See also
NONE
Example
Dim A As Bit
Bitwait A , Set 'wait until bit a is set
Bitwait P1.7 , Reset 'wait until bit 7 of Port 1
is 0.
End
ASM
BITWAIT P1.0 , SET will generate :
Jnb h'91,*+0
6.47 BREAK
Action
Generates a reserved opcode to pause the simulator.
Syntax
BREAK
Remarks
You can set a breakpoint in the simulator but you can also set a breakpoint from
code using the BREAK statement.
Be sure to remove the BREAK statements when you debugged your program or use
the $NOBREAK directive.
See also
$NOBREAK 97
Example
PRINT "Hello"
BREAK 'the simulator will pause now
End
6.48 CALL
Action
Call and execute a subroutine.
Syntax
CALL Test [(var1, var-n)]
Remarks
var1 Any BASCOM variable or constant.
var-n Any BASCOM variable or constant.
Test Name of the subroutine. In this case Test
When you don't supply the CALL statement, you must leave out the parenthesis.
So Call Routine(x,y,z) must be written as Routine x,y,z
See also
DECLARE 139 , SUB 229
Example
Dim A As Byte , Bb As Byte
Declare Sub Test(bb As Byte)
A = 65
Call Test(a) 'call test with parameter A
Test A 'alternative call
End
6.49 CHR
Action
Convert a byte, Integer/Word variable or a constant to a character.
Syntax
PRINT CHR(var)
s = CHR(var)
Remarks
Var Byte, Integer/Word variable or numeric constant.
S A string variable.
When you want to print a character to the screen or the LCD display,
you must convert it with the CHR() function.
See also
ASC 110
Example
Dim A As Byte
A = 65
Lcd A
Lowerline
Lcdhex A
Lcd Chr(a)
End
6.50 CLS
Action
Clear the LCD display and set the cursor home.
Syntax
CLS
Remarks
Clearing the LCD display does not clear the CG-RAM in which the custom characters
are stored.
See also
$LCD 95 , LCD 178
Example
Cls
Lcd "Hello"
Wait 5
Cls
End
6.51 CONST
Action
Declares a symbolic constant.
Syntax
CONST symbol = value
Remarks
symbol The name of the symbol.
Value The value to assign to the symbol.
See also
DIM 141
Example
'----------------------------------------------------
' (c) 1995-2006 MCS Electronics
' CONST.BAS
'----------------------------------------------------
Dim A As Const 5 'declare a as a constant
Dim B1 As Const &B1001
Dim S As Single
'Or use the new preferred syntax
Const Cbyte = &HF
Const Cint = -1000
Const Csingle = 1.1
Const Cstring = "test"
S = Csingle
Print S ; " " ; Cstring
Waitms A 'wait for 5 milliseconds
Print A
Print B1
End
6.52 CONFIG
The config statement configures all kind of hardware related statements.
Select one of the following topics to learn more about a specific config statement.
Syntax
CONFIG 1WIRE = pin
Remarks
pin The port pin to use such as P1.0
See also
1WRESET 83 , 1WREAD 83 , 1WWRITE 83
Example
Config 1WIRE = P1.0 'P1.0 is used for the 1-wire bus
1WRESET 'reset the bus
Remarks ADC
mode POWERDOWN, NORMAL, PDNE, STANDBY.
PDNE means POWERDOWN if not executing a conversion cycle.
clock This is a constant that specifies the clock division of the master
clock. It may be 1,2,4 or 8.
An ADC conversion will require 16 ADC clocks in addition to the
selected number of acquisition clocks.
aq This is a constant that specifies the time available for the input/track
hold amplifier to acquire the input signal.
It may be in range from 1-4. 1 Acquisition clock is enough for an
impedance up to 8K
tm2 The TIMER2 can be ENABLED or DISABLED. When enabled the
timer2 overflow serves as a trigger for the AD conversion.
value The external trigger may be ENABLED or DISABLED. When enabled
the external pin 23 (CONVST) can start the conversion while it is
low.
Remarks DAC
Mode The DAC can be in 8 bit mode or 12 bit mode. So the parameter may
be 8 or 12. Both DACS are set with this parameter.
r0 The DAC0 range can be set to VDD or VREF. With VDD the range is
from 0-VDD. For VREF it is 0-VREF.
r1 The DAC1 range can be set to VDD or VREF. With VDD the range is
from 0-VDD. For VREF it is 0-VREF
clr0 This parameter when TRUE will clear the DAC0. This will set the
output voltage to 0 V.
clr1 This parameter when TRUE will clear the DAC1. This will set the
output voltage to 0 V
Sync May be ENABLED or DISABLED. While enabled the DAC outputs as
soon as the DACxL SFR's are written. The user can simutaneously
update both DAC's by first updating the DACxL/H SFR's while SYNC
is disabled. Both DACs will then update when the SYNC is enabled.
pwr0 This parameter when ON will power ON the DAC0. When OFF the
DAC0 is powered OFF.
pwr1 This parameter when ON will power ON the DAC1. When OFF the
DAC1 is powered OFF
Syntax
CONFIG BAUD = baud rate
Remarks
Baud rate Baud rate to use : 4800 or 9600
Example
CONFIG BAUD = 9600 'use internal baud generator
Print "Hello"
End
Syntax
CONFIG BAUD1 = baudrate
Remarks
Baudrate Baud rate to use : 2048 - 37500
The 80517 and 80537 have 2 serial ports on board.
See also
CONFIG BAUD 119
Example
CONFIG BAUD1 = 9600 'use internal baud generator
Syntax
CONFIG DEBOUNCE = time
Remarks
time A numeric constant which specifies the delay time in mS.
See also
DEBOUNCE 137
Example
Config Debounce = 25 mS '25 mS is the default
Syntax
CONFIG I2CDELAY = value
Remarks
Value A numeric constant.
1 will generate the default clock.
0 will generate a higher clock and >=2 will generate a lower clock
frequency.
Delay5:
Nop
Ret
For 12 MHz, there is a 1 MHz system clock. So not counting the other statement, the
minimal delay is 4 * 2 = 8 cycles.
The I2Cdelay value will insert the number of specified NOP instructions.
By default the settings are right for all I2C devices and when working with a 12 MHz
crystal.
See also
CONFIG SCL 128 , CONFIG SDA 128
Example
CONFIG I2CDELAY = 0 'we need a higher clock
Syntax
Config GETRC = time
Remarks
Time The time in milli seconds to charge the capacitor
See also
GETRC 158
Syntax
Config GRAPHLCD = type , PORT = mode, CE = pin , CD = cd , COLS = 30
Remarks
Type This must be one of the following :
· 240 * 64
· 240 * 128
mode This is the name of the port that is used to put the data on the LCD
data pins db0-db7.
P1 for example.
Ce The name of the pin that is used to enable the chip on the LCD.
Cd The name of the pin that is used to control the CD pin of the display.
Cols The number of columns for use as text display. The current code is
written for 30 columns only.
The LCD used from www.conrad.de needs a negative voltage for the
contrast.
Two 9V batteries were used with a pot meter.
The FS (font select) must be set low to use 30 columns and 8x8 fonts.
It may be connected to ground. This pin is not used by the software
routines.
The current asm code only support 30 columns. You can change it however
to use 40 columns.
The T6963C displays have both a graphical area and a text area. They can
be used together. The routines use the XOR mode to display both text and
graphics layered over each other.
The statements that can be used with the graphical LCD are :
CLS 115 , will clear the graphic display and the text display
CLS GRAPH will clear only the graphic part of the display
CLS TEXT will only clear the text part of the display
CLS BOTH is the same as CLS and will clear both text and graphics.
LOCATE 185 row,column Will place the cursor at the specified row and
column
The row may vary from 1 to 8 and the column from 1 to 30.
CURSOR 135 ON/OFF BLINK/NOBLINK can be used the same way as for
text displays.
LCD 178 can also be the same way as for text displays.
LCDHEX 182 can also be used the same way as for text display
New are:
SHOWPIC 220 X, Y , Label where X and Y are the column and row and Label
is the label where the picture info is placed.
PSET 207 X, Y , color Will set or reset a pixel. X can range from 0-239 and Y
from 9-63. When color is 0 the pixel will turned off. When it is 1 the pixel
will be set on.
Example
'------------------------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
' GLCD.BAS
' Sample to show support for T6963C based graphic display
' Only 240*64 display is supported with 30 columns(yet)
' At the moment the display can only be used in PORT mode
' Connection :
' P1.0 - P1.7 to DB0-DB7 of LCD
' P3.2 to FS, font select of LCD can be hard wired too
' P3.5 to CE, chip enable of LCD
' P3.4 to CD, code/data select of LCD
' P3.6 to WR of LCD
' P3.7 to RD of LCD
'A future version will allow external data access too which also uses RD and WR
'The display from www.conrad.com needs a negative voltage for the contrast.
'I used two 9 V batteries
'------------------------------------------------------------------------------
'configure the LCD display
Config Graphlcd = 240 * 64 , Port = P1 , Ce = P3.5 , Cd = P3.4 , Cols = 30
'
Reset P3.2 '8 bit wide char is 30 columns
'Locate is supported and you can use 1-8 for the row and 1-30 for the column
Locate 1 , 1
'To display the BGF file you use the SHOWPIC statement that needs an X and Y
parameter
'the third param is the label where the data is stored.
'The position must be dividable by 8 because this is the way the display handles the
data
Showpic 0 , 0 , Picture1
'And we use the PSET known from QB to set or reset a single pixel
'A value of 0 means clear the pixel and 1 means set the pixel
'create a block
For X = 0 To 10
For Y = 0 To 10
Pset X , Y , 1
Next
Next
Syntax
CONFIG LCDPIN = PIN, DB4= P1.1,DB5=P1.2,DB6=P1.3,DB7=P1.4,E=P1.5,
RS=P1.6
Remarks
P1.1 etc. are just an example in the syntax. The pins of the LCD display that must
be connected in PIN mode are :
See also
CONFIG LCD 125
Example
CONFIG LCDPIN = PIN ,DB4= P1.1,DB5=P1.2,DB6=P1.3,DB7=P1.4,E=P1.5,
RS=P1.6
Syntax
CONFIG LCD = LCDtype
Remarks
LCDtype The type of LCD display used. This can be :
40 * 4, 40 * 2, 16 * 1, 16 * 1a, 16 * 2, 16 * 4, 16 * 4, 20 * 2 or 20
* 4 or 40 * 4a
Default 16 * 2 is assumed.
The 16 * 1a LCD display is a special one. It is intended for the display that has the
memory organized as 2 lines of 8 characters.
The 40 * 4a LCD display is also a special one. It has two ENABLE lines.
The CONFIG LCDPIN directive must be used to configure the second E line:
CONFIG LCDPIN = PIN , E1 = Pin, E2 = pin, etc.
To send data use the low level routine WRITE_LCD instead of LCD_CONTROL
Most LCD routines will work with the 40*4a display but some will fail. In that case
you need to use the low level ASM routines as shown above.
Example
REM Sample for normal displays
CONFIG LCD = 40 * 4
LCD "Hello" 'display on LCD
FOURTHLINE 'select line 4
LCD "4" 'display 4
END
Syntax
CONFIG LCDBUS = constant
Remarks
constant 4 for 4-bit operation, 8 for 8-bit mode (default)
See also
CONFIG LCD 125
Example
$LCD = &H8000 'address of enable signal
Config LCDBUS = 4 '4 bit mode
LCD "hello"
Syntax
Config Microwire = Pin , Cs = P1.1 , Din = P1.2 , Dout = P1.4 , Clock = P1.5 , Al
=7
Remarks
CS Chip select
DIN Data input
DOUT Data output
CLOCK Pin that generates the Clock
AL Address lines. See table below.
It depends if you work with bytes or words. In our example we will
use the 93C46 and work with bytes. AL will be 7 in this case.
See also
MWINIT 193 , MWWOPCODE 194 , MWWRITE 195 , MWREAD 193
Example
NONE
Syntax
Config PRINT = pin
Remarks
Pin The pin to use for the output control such as P3.0
Mode The mode of the control pin. SET or RESET.
When you want to control a RS-485 device you need an additional pin to control the
buffer direction. When the pin must be high during printing use SET. When it must
be low during print use RESET.
Example
Config Print = P3.0 'this pin controls the buffer
Config mode = SET 'during PRINT this pin goes high.
Print "Hello"
Syntax
CONFIG SCL = pin
Remarks
Pin The port pin to which the I2C-SCL line is connected.
When you use different pins in different projects, you can use this statement to
override the Options Compiler setting for the SCL pin. This way you will remember
which pin you used because it is in your code and you do not have to change the
settings from the options.
This statement can not be used to change the pin dynamically during runtime.
See also
CONFIG SDA 128 , CONFIG I2CDELAY 120
Example
CONFIG SCL = P3.5 'P3.5 is the SCL line
Syntax
Remarks
pin The port pin to which the I2C-SDA line is connected.
When you use different pins in different projects, you can use this statement to
override the Options Compiler setting for the SDA pin. This way you will remember
which pin you used because it is in your code and you do not have to change the
settings from the options.
See also
CONFIG SCL 128 , CONFIG I2CDELAY 120
Example
CONFIG SDA = P3.7 'P3.7 is the SDA line
Syntax
Config SERVOS = number , SERVO1 = P1.1 , SERVO2 = P1.2 , SERVO3 = P1.4 ,
SERVO4 = P1.5 , RELOAD = value
Remarks
number The number of servos you want to use.
When you specify 2, you must also add the SERVO1 and SERVO2
parameters.
servo1 The pin that is attached to servo 1.
servo2 The pin that is attached to servo 2.
servo3 The pin that is attached to servo 3.
servo4 The pin that is attached to servo 4.
RELOAD The reload value in uS. Default 100 uS
The CONFIG SERVOS compiler directive will include an interrupt that will execute
every 100 uS. The TIMER0 interrupt is enabled and the TIMER0 is started.
The number of bytes used by the use of SERVO's is 1 + number of servos.
The maximum number of servo's is 14. The example shows how to set it up for 4
servo's only.
When you specify RELOAD = 50 , 50 uS steps will be used!
When you have a lot of servo's the RELOAD must be higher than when you have
less servos. When you have a reload of 10 uS for example it will be impossible for
the 8051 to handle more than 1 servo without losing time.
For 2 servo's 20 or 25 should be used for best results.
Syntax
CONFIG SPI = SOFT, DIN = PIN, DOUT = PIN , CS = PIN, CLK = PIN ,DATA
ORDER = DO, NOCS =
CONFIG SPI = ON
CONFIG SPI = OFF
CONFIG SPI = HARD, INTERRUPT = ON|OFF, DATA ORDER = LSB|MSB,
MASTER=YES|NO,POLARITY=HIGH|LOW,PHASE=0|1,CLOCKRATE=4|16|64|128
Remarks
When you use the software SPI mode you must specify the following information:
DIN Data input. Pin is the pin number to use such as p1.0
DOUT Data output. Pin is the pin number to use such as p1.1
CS Chip select. Pin is the pin number to use such as p1.2
CLK Clock. Pin is the pin number to use such as p1.3
NOCS Option without parameter. Use it to disable the resetting and
setting of the CS pin.
DATA ORDER Use MSB or LSB. With MSB, MS bit will be sent first. LSB option
will send the LS bit first.
SPIOUTEDGE Falling or Rising. Falling is the default. The edge specifies if the
the data will be clocked with a low to high or a high to low edge.
When the NOCS option is used you must reset and set the CS pin yourself.
The option is intended when you want to do large transfers between the micro and
the SPI device. With the little internal memory you can do that in steps but of
course you don't want the CS pin to change after each use of the SPIIN or SPIOUT
routine.
When you want to use the hardware SPI that is available in the 89S8252, you must
specify the following information:
INTERRUPT ON or OFF to enable or disable that the SPI interrupt is set.
DATA ORDER LSB or MSB. Determines which bit is sent first.
MASTER Yes or No. Set it to Yes for usage with the BASCOM SPI routines.
See also
SPIIN 224 SPIOUT 225
Example
Config SPI = SOFT, DIN = P1.0 , DOUT = P1.1, CS = P1.2, CLK = P1.3
SPIINIT ‘ init pins
SPIOUT var , 1 'send 1 byte
Syntax
CONFIG TIMERx = COUNTER/TIMER , GATE=INTERNAL/EXTERNAL , MODE=0/3
Remarks
TIMERx TIMER0 or TIMER1.
COUNTER will configure TIMERx as a COUNTER and TIMER will
configure TIMERx as a TIMER.
A TIMER has built in clock input and a COUNTER has external clock
input.
GATE INTERNAL or EXTERNAL. Specify EXTERNAL to enable gate control
with the INT input.
MODE Time/counter mode 0-3. See Hardware for more details.
When the timer/counter is configured the timer/counter is stopped so you must start
it afterwards with the START TIMERx statement.
See the additional statements for other microprocessors that use the CONFIG
statement.
Example
CONFIG TIMER0=COUNTER, MODE=1, GATE=INTERNAL
Syntax
CONFIG WATCHDOG = time
Remarks
Time The interval constant in mS the watchdog timer will count to.
Possible settings:
16 , 32, 64 , 128 , 256 , 512 , 1024 and 2048.
When the WD is started, a reset will occur after the specified number of mS.
With 2048, a reset will occur after 2 seconds, so you need to reset the WD in your
programs periodically.
See also
START WATCHDOG 292 , STOP WATCHDOG 292 , RESET WATCHDOG 292
Example
'-----------------------------------------------------
' (c) 1995-2006 MCS Electronics
' WATCHD.BAS demonstrates the AT89S8252 watchdog timer
' select 89s8252.dat !!!
'-----------------------------------------------------
Config Watchdog = 2048 'reset after 2048 mSec
Start Watchdog 'start the watchdog timer
Dim I As Word
For I = 1 To 10000
Print I 'print value
' Reset Watchdog
'you will notice that the for next doesnt finish because of the reset
'when you unmark the RESET WATCHDOG statement it will finish because
the
'wd-timer is reset before it reaches 2048 msec
Next
End
6.72 COUNTER
Action
Set or retrieve the COUNTER0 or COUNTER1 variable.
For 8052 TIMER2 compatible chips, COUNTER2 can be used too.
Syntax
COUNTERX = var
var = COUNTERX
Remarks
Var A byte, Integer/Word variable or constant that is assigned to the
counter.
counterX COUNTER0 , COUNTER1 or COUNTER2.
Note that the COUNTERx variable operates on both the TIMERS and COUNTER
because the TIMERS and COUNTERS are the same thing except for the mode they
are working in. To load a reload value, use the LOAD 184 statement.
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: COUNTER.BAS
' demo: COUNTER
'--------------------------------------------------------------
' Connect the timer input P3.4 to a frequency generator
' *TIMER/COUNTER 1 is used for RS-232 baud rate generator
'--------------------------------------------------------------
Dim A As Byte , C As Integer
Config Timer0 = Counter , Gate = Internal , Mode = 1
'Timer0 = counter : timer0 operates as a counter
'Gate = Internal : no external gate control
'Mode = 1 : 16-bit counter
End
Generated code :
Clr TCON.4
Mov tl0,#232
Mov th0,#3
6.73 CPEEK
Action
Returns a byte stored in code memory.
Syntax
var = CPEEK( address )
Remarks
var Numeric variable that is assigned with the content of the program
memory at address
address Numeric variable or constant with the address location
There is no CPOKE statement because you cannot write into program memory.
See also
PEEK 202 , POKE 202 , INP 173 , OUT 200
Example
'-----------------------------------------------------
' (c) 1995-2006 MCS Electronics
' PEEK.BAS
' demonstrates PEEk, POKE, CPEEK, INP and OUT
'
'-----------------------------------------------------
Dim I As Integer , B1 As Byte
'dump internal memory
For I = 0 To 127 'for a 8052 225 could be used
' Break
B1 = Peek(i) 'get byte from internal
memory
Printhex B1 ; " ";
'Poke I , 1 'write a value into memory
Next
Print 'new line
'be careful when writing into internal memory !!
6.74 CURSOR
Action
Set the LCD cursor state.
Syntax
CURSOR ON / OFF BLINK / NOBLINK
Remarks
You can use both the ON or OFF and BLINK or NOBLINK parameters.
At power up the cursor state is ON and NOBLINK.
For Graphic LCD 121 displays the state is ON BLINK
See also
DISPLAY 143
Example
Dim a as byte
A = 255
LCD a
Cursor Off 'hide cursor
Wait 1 'wait 1 second
Cursor Blink 'blink cursor
End
6.75 DATA
Action
Specifies values to be read by subsequent READ statements.
Syntax
DATA var [, varn]
Remarks
Var Numeric or string constant.
To specify a character that cannot be written in the editor such as " you can use
$34. The number is the ASCII value of the string. A null will be added so it will be a
string of one character!
When you want to store the string data without the ending null you can use the
$NONULL directive as shown below:
DATA "abcd" 'stored with and ending 0
$NONULL = -1 'from now on store the data without the extra 0
DATA "abcd" , "edgh"
$NONULL = 0 'and go back to the normal default operation
Version 2.09 supports expressions. You must use either expressions or normal
constant data on the DATA lines. You may not mix them.
Difference with QB
Integer and Word constants must end with the % -sign.
Long constants must end with the &-sign.
Single constants must end with the !-sign.
See also
READ 208 , RESTORE 212
Example
Dim A As Byte , I As Byte , L As Long , S As Xram String * 15
Restore Dta1 'point to data
For A = 1 To 3
Read I : Print I 'read data and print it
Next
Restore Dta3
Read L : Print L ' long data
Restore Dta4
Read S : Print S ' string data
END
DTA1:
Data 5 , 10 , 100
DTA2:
Data -1% , 1000%
'Integer and Word constants must end with the %-sign.
' (Integer : <0 or >255)
DTA3:
Data 1235678&
'long constants must end with the &-sign
DTA4:
Data "Hello world" , $34
REM You can also mix different constant types on one line
Data "TEST" , 5 , 1000% , -1& , 1.1!
6.76 DEBOUNCE
Action
Debounces a port pin connected to a switch.
Syntax
DEBOUNCE Px.y , state , label [ , SUB]
Remarks
Px.y A port pin like P1.0 , to examine.
State 0 for jumping when Px.y is low , 1 for jumping when Px.y is high
Label The label to GOTO when the specified state is detected
SUB The label to GOSUB when the specified state is detected
When you specify the optional parameter SUB, a GOSUB to label is performed
instead of a GOTO.
The DEBOUNCE statements wait for a port pin to get high(1) or low(0).
When it does it will wait 25 mS and checks again (eliminating bounce of a switch)
When the condition is still true and there was no branch before, it branches to the
label.
When DEBOUNCE is executed again, the state of the switch must have gone back in
the original position before it can perform another branch.
Each DEBOUNCE statement which uses a different port uses 1 BIT of the internal
memory to hold it's state.
What also should be mentioned is that P2.2-P2.7 and P3 have internal pull up
resistors. This can affect the debounce statement. With these port pins, debounce is
Example
'-----------------------------------------------------
' DEBOUN.BAS
' Demonstrates DEBOUNCE
'-----------------------------------------------------
Config Debounce = 30 'when the config statement
is not used a default of 25mS will be used
Pr:
Print "P1.0 was/is low"
Return
6.77 DECR
Action
Decrements a variable by one.
Syntax
DECR var
Remarks
Var Variable to be decremented.
var : Byte, Integer, Word, Long, Single.
See also
INCR 171
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: DECR.BAS
' Demo: DECR
'--------------------------------------------------------------
Dim A As Byte
A = 5 'assign value to a
Decr A 'decrease (by one)
Print A 'print it
End
6.78 DECLARE
Action
Declares a subroutine.
Syntax
DECLARE SUB TEST[(var as type)]
Remarks
test Name of the procedure.
Var Name of the variable(s). Maximum 10 allowed.
Type Type of the variable(s). Bit, Byte,Word, Integer, Long or String.
You must declare each sub before writing or using the sub procedure.
See also
CALL 113 , SUB 229
Example
Dim A As Byte , B1 As Byte , C As Byte
Declare Sub Test(a As Byte)
A = 1 : B1 = 2 : C = 3
Print A ; B1 ; C
Call Test(b1)
Print A ; B1 ; C
End
6.79 DEF
Action
Declares all variables that are not dimensioned of the DefXXX type.
Syntax
DEFBIT b
DEFBYTE c
DEFINT I
DEFWORD x
Difference with QB
QB allows you to specify a range like DEFINT A - D. BASCOM doesn't support this.
Example
Defbit b : DefInt c 'default type for bit and integers
Set b1 'set bit to 1
c = 10 'let c = 10
6.80 DEFLCDCHAR
Action
Define a custom LCD character.
Syntax
DEFLCDCHAR char,r1,r2,r3,r4,r5,r6,r7,r8
Remarks
char Variable representing the character (0-7).
r1-r8 The row values for the character.
char : Byte, Integer, Word, Long, Constant.
r1-r8 : Constant.
See also
Edit LCD designer 54 , LCD 178
Example
DefLCDchar 0,1,2,3,4,5,6,7,8 'define special character
Cls 'select LCD DATA RAM
LCD Chr(0) 'show the character
End
6.81 DELAY
Action
Delay program execution for a short time.
Syntax
DELAY
Remarks
Use DELAY to wait for a short time.
The delay time is 100 microseconds based on a system frequency of 12 MHz.
See also
WAIT 233 , WAITMS 234
Example
P1 = 5 'write 5 to port 1
DELAY 'wait for hardware to be ready
6.82 DIM
Action
Dimension a variable.
Syntax
DIM var AS [XRAM/IRAM] type
Remarks
Var Any valid variable name such as b1, i or longname. var can also be an
array : ar(10) for example.
A string variable needs an additional parameter that specifies the length of the
string:
Dim s As XRAM String * 10
In this case, the string can have a length of 10 characters.
Difference with QB
In QB you don't need to dimension each variable before you use it. In BASCOM you
must dimension each variable before you use it.
Also the XRAM/IRAM options are not available in QB.
See Also
CONST 116 , ERASE 147
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: DIM.BAS
' demo: DIM
'--------------------------------------------------------------
Dim B1 As Bit 'bit can be 0 or 1
Dim A As Byte 'byte range from 0-255
Dim C As Integer 'integer range from -32767 -
+32768
Dim L As Long
Dim S As Single
'Assign bits
B1 = 1 'or
Set B1 'use set
'Assign bytes
A = 12
A = A + 1
'Assign integer
C = -12
C = C + 100
Print C
'Assign long
L = 12345678
Print L
'Assign single
S = 1234.567
Print S
End
6.83 DISABLE
Action
Disable specified interrupt.
Syntax
DISABLE interrupt
Remarks
Interrupt INT0, INT1, SERIAL, TIMER0, TIMER1 or TIMER2.
For other chips : INT2, INT3, INT4, INT5, INT6, INT7 , INT8, CAN
See also
ENABLE 145
Example
Enable Interrupts 'enable the setting of
interrupts
Enable Timer0 'enable TIMER0
Disable Serial 'disables the serial
interrupt.
Disable Interrupts 'disable all interrupts
6.84 DISPLAY
Action
Turn LCD display on or off.
Syntax
DISPLAY ON / OFF
Remarks
The display is turned on at power up.
See also
CURSOR 135 , LCD 178
Example
Dim a as byte
a = 255
LCD a
DISPLAY OFF
Wait 1
DISPLAY ON
End
6.85 DO
Action
Repeat a block of statements until condition is true.
Syntax
DO
statements
LOOP [ UNTIL expression ]
Remarks
You can exit a DO..LOOP with the EXIT DO 148 statement.
See also
EXIT 148 , WHILE 236 WEND 236 , FOR 148 , NEXT 196
Example
Dim A As Byte
Do 'start the loop
A = A + 1 'increment A
Print A 'print it
Loop Until A = 10 'Repeat loop until A = 10
Print A 'A is still 10 here
6.86 ELSE
Action
Executed if the IF-THEN expression is false.
Syntax
ELSE
Remarks
You don't have to use the ELSE statement in an IF THEN .. END IF structure.
You can use the ELSEIF statement to test for another condition.
IF a = 1 THEN
...
ELSEIF a = 2 THEN
..
ELSEIF b1 > a THEN
...
ELSE
...
END IF
See also
IF 169 , END IF 146 SELECT CASE 216
Example
Dim A As Byte
A = 10 'let a = 10
If A > 10 Then 'make a decision
Print "A >10" 'this will not be printed
Else 'alternative
Print "A not greater than 10" 'this will be printed
END IF
6.87 ENABLE
Action
Enable specified interrupt.
Syntax
ENABLE interrupt
Remarks
Interrupt INT0, INT1, SERIAL, TIMER0, TIMER1 or TIMER2
For other chips also : INT2, INT3, INT4, INT5, INT6, INT7, INT8 , CAN
See also
DISABLE 143
Example
ENABLE INTERRUPTS 'allow interrupts to be set
ENABLE TIMER1 'enables the TIMER1 interrupt
6.88 END
Action
Terminate program execution.
Syntax
END
Remarks
STOP can also be used to terminate a program.
See also
STOP 226
Example
PRINT " Hello" 'print this
END 'end program execution
6.89 END IF
Action
End an IF .. THEN structure.
Syntax
END IF
Remarks
You must always end an IF .. THEN structure with an END IF statement.
The editor converts ENDIF to End If when the reformat option is switched on.
See also
IF THEN 169 , ELSE 144
Example
6.90 ERASE
Action
Erases a variable so memory will be released.
Syntax
ERASE var
Remarks
var The name of the variable to erase.
When you need temporary variables you can erase them after you used them. This
way your program uses less memory.
You can only ERASE the last dimensioned variables. So when you DIM 2 variables
for local purposes, you must ERASE these variables. The order in which you ERASE
them doesn't matter.
For example :
Dim a1 as byte , a2 as byte , a3 as byte , a4 as byte
'use the vars
ERASE a3 : ERASE a4 'erase the last 2 vars because they were temp vars
Dim a5 as Byte 'Dim new var
Now you can't erase the vars a1 and a2 anymore !
Note that ERASED variables don't show up in the report file nor in the simulator.
Example
Dim A As Byte 'DIM variable
A = 255 'assign value
Print A 'PRINT variable
Erase A 'ERASE
6.91 EXIT
Action
Exit a FOR..NEXT, DO..LOOP , WHILE ..WEND or SUB..END SUB.
Syntax
EXIT [FOR] [DO] [WHILE] [SUB]
Remarks
With the EXIT ... statement you can exit a structure at any time.
See also
FOR 148 , DO 144 , WHILE 236
Example
Dim A As Byte , B1 As Byte 'DIM variable
A = 2 : B1 = 1
If A >= B1 Then 'some silly code
Do 'begin a DO..LOOP
A = A + 1 'inc a
If A = 100 Then 'test for a = 100
Exit Do 'exit the DO..LOOP
End If 'end the IF..THEN
Loop 'end the DO
End If 'end the IF..THEN
6.92 FOR
Action
Execute a block of statements a number of times.
Syntax
FOR var = start TO/DOWNTO end [STEP value]
Remarks
Var The variable counter to use
Start The starting value of the variable var
End The ending value of the variable var
Value The value var is increased/decreased with each time NEXT is
encountered.
See also
NEXT 196 , EXIT FOR 148
Example
Dim Y As Byte , A As Byte,x as byte
y = 10 'make y 10
For A = 1 To 10 'do this 10 times
For X = Y To 1 'this one also
Print X ; A 'print the values
Next 'next x (count down)
Next 'next a (count up)
Dim S As Single
For S = 1 To 2 Step 0.1
Print S
Next
End
6.93 FOURTHLINE
Action
Reset LCD cursor to the fourth line.
Syntax
FOURTHLINE
Remarks
Only valid for LCD displays with 4 lines.
See also
HOME 166 , UPPERLINE 232 , LOWERLINE 188 , THIRDLINE 230 , LOCATE 185
Example
Dim a as byte
a = 255
LCD a
Fourthline
LCD a
Upperline
END
6.94 FUSING
Action
Formats a floating point value.
Syntax
var = Fusing( source, mask)
Remarks
Var The string that is assigned with the result.
Source A variable of the type single that must be formatted.
Mask The formatting mask . ###.##
The # sign is used to indicate the number of digits before and
after the decimal point. Normal rounding is used.
When you don't need rouding the result, use the & sign instead of
the # sign after the point.
When you want leading zero's use the 0 character before the
point.
See also
STR 228
Example
Dim S As Single , Targ As String * 16
'The FUSING() function formats a single into a string in order to
'represent it better without all the digits after the point
'assign single
S = 99.4999
Targ = Fusing(s , ##.#)
Print Targ
'with the # mask, you can provide the number of digits before and
after 'the point
'with a 0 before the point, you can indicate how many digits you want
to 'have filled with zeros
Targ = Fusing(s , 000.#)
'the result should be 099.5
'When you dont want that the result is rounded, you can use the &
indicator
'note that if the number of digits you provide is not enough to store
the 'result result is extended automaticly
'Also note that the - sign will use one digit of the mask too
S = -99.12
Targ = Fusing(s , 00.&&)
'result is -99.12
End
6.95 GET
Action
Retrieves a byte from the software UART.
Syntax
GET #channel , var
Remarks
Channel Positive numeric constant that refers to the opened channel.
Var A variable that receives the value from the software UART.
Note that the channel must be opened with the OPEN statement.
Also, note that the CLOSE statement, must be the last in your program. Please see
comment on OPEN 198 statement
An optional TIMEOUT can be specified so that the routine will return when no
character is received.
See also
PUT 207 , $TIMEOUT 107
Example
Do
Get #2 , A 'get character from comport
Put #1 , A 'write it back
Print A 'use normal channel
Loop
6.96 GETAD
Action
Retrieves the analog value from channel 0-7.
Channel ranges from 0-11 on a 80517 or 80537.
Syntax
var = GETAD(channel, range)
Remarks
Var The variable that is assigned with the A/D value
Channel The channel to measure
0 = 0-5 Volt
192 = 0 - 3.75 Volt
128 = 0 - 2.5 Volt
64 = 0 - 1.25 Volt
12 = 3.75 - 5 Volt
200 = 2.5 - 3.75 Volt
132 = 1.25 - 2.5 Volt
The GETAD() function is only intended for the 80515, 80535,80517, 80535 and
80552.
For the 89Cc051 use GETAD2051().
It is a microprocessor depended support 288 feature.
See also
GETAD2051 153
Example
Dim b1 as Byte, Channel as byte,ref as byte
channel=0 'input at P6.0
ref=0 'range from 0 to 5 Volt
b1=getad(channel,ref) 'place A/D into b1
6.97 GETAD2051
Action
Retrieves the analog value from a 89C2051 or 89C4051.
Syntax
var = GETAD2051()
Remarks
var The variable that is assigned with the A/D value
The GETAD2051() function is only intended for the 89C2051 and 89C4051. It uses
the analog comparator of the chip.
See also
GETAD 152
Example
$regfile = "89c2051.dat"
Dim A As Byte
Do
A = Getad2051()
A = Lookup(a , Dta)
Print A
Loop
End
Dta:
Data 0 ' 0 0.000
Data 1 ' 1 0.047
Data 1 ' 2 0.093
6.98 GETRC
Action
Retrieves the value of a resistor or a capacitor.
Syntax
var = GETRC( pin )
Remarks
var The variable that receives the value.
pin The port pin the R/C is connect to.
GETRC needs a resistor and capacitor in order to work. The capacitor is discharged
and the charging time will vary depending on the user resistor/capacitor value.
Uses
This function uses TIMER0.
See also
NONE
Example
'--------------------------------------------------------------------
---
' GETRC.BAS
' Retrieve resistor value
' Connect 10KOhm variable resistor from +5V to P1.7 for this example
' Connect 10nF capacitor from P1.7 to ground
' The GETRC(pin) function measures the time needed to discharge the
capacitor
'--------------------------------------------------------------------
---
Config Timer0 = Timer , Gate = Internal , Mode = 1 'the GETRC()
functions needs timer 0
Config Getrc = 10 '10mS
wait for charging the capacitor. This is the default so for 10 the
CONFIG is not needed
$baud = 9600 'just my settings
$crystal = 11059200
Dim W As Word 'allocate space for
variable
Do 'forever
W = Getrc(p1.7) 'get RC value
Print W 'print it
Wait 1 'wait a moment
Loop
'return values for cap=10nF .The resistor values where measured with
a DVM
' 250 for 10K9
6.99 GETRC5
Action
Retrieves a RC5 infrared code and sub address.
Syntax
GETRC5(address , command)
Remarks
Address The RC5 sub address received.
Command The RC5 command received.
Use a Siemens infrared receiver SFH506-36 and connect it to port pin 3.2 to use this
command.
This statement works together with the INT0 interrupt. See the example below on
how to use it.
In version 2.09 the command returns the toggle bit in bit position 5 of the address.
You can clear it like : address = address AND &B0001_1111
The toggle bit will toggle after each key press of the remote control.
See Also
NONE
Example
'--------------------------------------------------------------------
--------
' RC5.BAS (c) 1995-2006 MCS Electronics
' connect SFH506-36 IR-receiver to PORT 3.2 (INT0)
' choose the correct port from the Compiler I2C TAB. Int0 should
have P3.2 pin
' On other chips it may be another pin!
'--------------------------------------------------------------------
--------
Dim New As Bit
Dim Command As Byte , Subaddress As Byte
Reset Tcon.0
'triggered by rising edge
On Int0 Receiverc5
Enable Int0
Enable Interrupts
Do
If New = 1 Then
'received new code
Disable Int0
Print Command ; " " ; Subaddress
New = 0 'reset
new bit
Enable Int0
End If
Loop
Receiverc5:
'interrupt routine
'the getrc5 routine uses 30 bytes ! of the stack for measuring
'the interval between the bits
Getrc5(Subaddress,command)
New = 1 'set
flag
Return
6.100 GOSUB
Action
Branch to and execute subroutine.
Syntax
GOSUB label
Remarks
label The name of the label where to branch to.
With GOSUB, your program jumps to the specified label, and continues execution at
that label.
When it encounters a RETURN statement, program execution will continue after the
GOSUB statement.
See also
GOTO 163 , CALL 113 , RETURN 213
Example
GOSUB Routine 'branch to routine
Print "Hello" 'after being at 'routine' print this
END 'terminate program
6.101 GOTO
Action
Jump to the specified label.
Syntax
GOTO label
Remarks
Labels can be up to 32 characters long.
When you use duplicate labels, the compiler will give you a warning.
See also
GOSUB 162
Example
Dim A As Byte
6.102 HEX
Action
Returns a string representation of a hexadecimal number.
Syntax
var = HEX( x )
Remarks
Var A string variable.
X A numeric variable such as Byte, Integer or Word.
See also
HEXVAL 164 , VAL 232 , STR 228
Example
Dim A As Byte , S As String * 10
A = 123
S = Hex(a)
Print S
End
6.103 HEXVAL
Action
Convert string representing a hexadecimal number into a numeric variable.
Syntax
var = HEXVAL( x )
Remarks
var The numeric variable that must be assigned.
X The hexadecimal string that must be converted.
var : Byte, Integer, Word, Long.
x : String.
The string that must be converted must have a length of 2 bytes ,4 bytes or 8
bytes, for bytes, integers/words and longs respectively.
Difference with QB
In QB you can use the VAL() function to convert hexadecimal strings.
But since that would require an extra test for the leading &H signs, that are required
in QB, a separate function was designed.
See also
HEX 163 , VAL 232 , STR 228
Example
Dim A As Integer , S As String * 15
S = "000A"
A = Hexval(s) : Print A '10
End
6.104 HIGH
Action
Retrieves the most significant byte of a variable.
Syntax
var = HIGH( s ) ‘ high function gets the upper byte of a word
HIGH(word) = byte ‘high statement set the upper byte of a word
Remarks
Var The variable that is assigned with the MSB of var S.
S The source variable to get the MSB from.
Word A word or integer variable that is assigned
Byte The value to set to the MSB of the Word/Integer variable
The HIGH() function returns the MSB of a variable while the HIGH() statement sets
the MSB of a word variable.
See also
LOW 187 , LOWW 188 , HIGHW 165
Example
Dim I As Integer , Z As Byte
I = &H1001
Z = High(I) ' is 16
6.105 HIGHW
Action
Retrieves the two most significant bytes of a long.
Syntax
var = HIGHW( s )
Remarks
Var The variable that is assigned with the two MSB of var S. It must
be an Integer or Word
S The source variable to get the MSB from. Must be a long
See also
LOW 187 , HIGH 164 , LOWW 188
Example
Dim I As Long , Z As Word
I = &H10011001
Z = HighW(I)
6.106 HOME
Action
Place the cursor at the specified line at location 1.
Syntax
HOME UPPER | LOWER | THIRD | FOURTH
Remarks
If only HOME is used than, the cursor will be set to the upper line.
You can also specify the first letter of the line like: HOME U
See also
CLS 115 , LOCATE 185 , LCD 178
Example
Lowerline
LCD " Hello"
Home Upper
LCD " Upper"
6.107 I2CRECEIVE
Action
Receives data from an I2C serial device.
Syntax
I2CRECEIVE slave, var
I2CRECEIVE slave, var ,b2W, b2R
Remarks
slave A byte, Word/Integer variable or constant with the slave address from
the I2C-device.
Var A byte or integer/word variable that will receive the information from
the I2C-device.
b2W The number of bytes to write.
Be cautious not to specify too many bytes!
b2R The number of bytes to receive.
Be cautious not to specify too many bytes!
In BASCOM LT you could specify DATA for var, but since arrays are supported now
you can specify and array instead of DATA.
This command works only with some additional hardware. See appendix D 251 .
See also
I2CSEND 167
Example
x=0 'reset variable
slave = &H40 'slave address of a PCF 8574 I/O IC
I2CRECEIVE slave, x 'get the value
PRINT x 'print it
6.108 I2CSEND
Action
Send data to an I2C-device.
Syntax
I2CSEND slave, var
I2CSEND slave, var , bytes
Remarks
slave The slave address off the I2C-device.
var A byte, integer/word or number that holds the value which will be sent
to the I2C-device.
bytes The number of bytes to send.
This command works only with additional hardware. See appendix D 251 .
See also
I2CRECEIVE 166
Example
x=5 'assign variable to 5
Dim ax(10) As Byte
slave = &H40 'slave address of a PCF 8574 I/O IC
For a = 1 to 10
ax(a) = a 'Fill dataspace
Next
bytes = 10
I2CSEND slave,ax(),bytes
END
6.109 I2C
Action
I2CSTART generates an I2C start condition.
I2CSTOP generates an I2C stop condition.
I2CRBYTE receives one byte from an I2C-device.
I2CWBYTE sends one byte to an I2C-device.
Syntax
I2CSTART
I2CSTOP
I2CRBYTE var, 8|9
I2CWBYTE val
Remarks
var A variable that receives the value from the I2C-device.
8/9 Specify 8 or ACK if there are more bytes to read. (ACK)
Specify 9 or NACK if it is the last byte to read. (NACK)
val A variable or constant to write to the I2C-device.
This command works only with additional hardware. See appendix D 251 .
These functions are provided as an addition to the I2CSEND 167 and I2CRECEIVE 166
functions.
See also
I2CRECEIVE 166 , I2CSEND 167
Example
'----- Writing and reading a byte to an EEPROM 2404 -----------------
Dim A As Byte
Const Adresw = 174 'write of 2404
Const Adresr = 175 'read adres of 2404
I2cstart 'generate start
I2cwbyte Adresw 'send slaveadres
I2cwbyte 1 'send adres of EEPROM
6.110 IDLE
Action
Put the processor into the idle mode.
Syntax
IDLE
Remarks
In the idle mode, the system clock is removed from the CPU but not from the
interrupt logic, the serial port or the timers/counters.
The idle mode is terminated either when an interrupt is received or upon system
reset through the RESET pin.
See also
POWERDOWN 203
Example
IDLE
6.111 IF
Action
Allows conditional execution or branching, based on the evaluation of a Boolean
expression.
Syntax
IF expression THEN
[ ELSE ]
END IF
Remarks
expression Any expression that evaluates to true or false.
See also
ELSE 144 , END IF 146
Example
Dim A As Integer
A = 10
If A = 10 Then 'test expression
Print " This part is executed." 'this will be printed
Else
Print " This will never be executed." 'this not
End If
If A = 10 Then Print "New in BASCOM"
If A = 10 Then Goto Label1 Else Print "A<>10"
Label1:
Rem The following example shows enhanced use of IF THEN
If A.15 = 1 Then 'test for bit
Print "BIT 15 IS SET"
End If
REM the following example shows the 1 line use of IF THEN [ELSE]
If A.15 = 0 Then Print "BIT 15 is cleared" Else Print "BIT 15 is set"
6.112 INCR
Action
Increments a variable by one.
Syntax
INCR var
Remarks
Var Any numeric variable.
See also
DECR 138
Example
Dim A As Integer
Do 'start loop
Incr A 'increment a by 1
Print A 'print a
Loop Until A > 10 'repeat until a is greater
than 10
6.113 INKEY
Action
Returns the ASCII value of the first character in the serial input buffer.
Syntax
var = INKEY()
var = INKEY(#channel)
Remarks
Var Byte, Integer, Word, Long or String variable.
Channel The channel number of device
The INKEY routine can be used when you have a RS-232 interface on your uP.
See the manual for a design of an RS-232 interface.
The RS-232 interface can be connected to a comport of your computer.
The INKEY() function only works with the hardware UART, not the software UART.
See also
WAITKEY 234
Example
Dim A As Byte
Do 'start loop
A = Inkey() 'look for character
If A > 0 Then 'is variable > 0?
Print A 'yes , there was a character in
the buffer
'so print it
End If
Loop 'loop forever
Example
$regfile = "80517.dat"
Open "COM2:" For Binary As #1 'open serial channel 1 on
80537
Dim St As Byte
St = Inkey(#1) 'get key from com2
If St > 0 Then
Printbin #1 , St 'send to com 2
End If
Close #1
6.114 INP
Action
Returns a byte read from a hardware port or external memory location.
Syntax
var = INP(address)
Remarks
var Numeric variable that receives the value.
address The address where to read the value from.
The INP statement only works on systems with an uP that can address external
memory.
See also
OUT 200 , PEEK 202 , POKE 202
Example
Dim a As Byte
a = INP(&H8000) 'read value that is placed on databus(d0-d7) at
'hex address 8000
PRINT a
END
6.115 INPUT
Action
Allows input from the keyboard during program execution.
Syntax
INPUT [" prompt" ] , var [ , varn ] [ NOECHO ] [ TIMEOUT = xx]
Remarks
Prompt An optional string constant printed before the prompt character.
Var,varn A variable to accept the input value or a string.
NOECHO Disables input echoed back to the Comport.
TIMEOUT Optional delay time. When you specify the delay time, the routine will
return when no input data is available after the specified time. No
timer is used but a long is used to count down.
The INPUT routine can be used when you have a RS-232 interface on your uP.
See the manual for a design of a RS-232 interface.
The RS-232 interface can be connected to a serial communication port of your
computer.
This way you can use a terminal emulator and the keyboard as an input device.
You can also use the built in terminal emulator. A backspace will remove the last
entered character.
Difference with QB
In QB you can specify &H with INPUT so QB will recognize that a hexadecimal string
is used.
BASCOM implements a new statement: INPUTHEX.
See also
INPUTHEX 176 , PRINT 203 , $TIMEOUT 107
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: INPUT.BAS
' demo: INPUT, INPUTHEX
'--------------------------------------------------------------
'To use another baudrate and crystalfrequency use the
'metastatements $BAUD = and $CRYSTAL =
$baud = 1200 'try
1200 baud for example
$crystal = 12000000 '12 MHz
'---------------------------------------------------------------
' When you need that the program times out on waiting for a
character
' you need to use the TIMEOUT option.
' When the charcter is not received within the specified time ERR
will be set to 1
' otherwise ERR will be 0.
' IMPORTANT : the TIMEOUT variable will use 4 bytes of internal
memory
'---------------------------------------------------------------
'unremark next line and remark all lines above for the TIMEOUT option
'this because when you use TIMEOUT once, you need to use it for all
INPUT statements
'Input "Name " , S Timeout = 0
'Print Err ; " " ; s
End
6.116 INPUTBIN
Action
Read binary values from the serial port.
Syntax
INPUTBIN var1 [,var2]
INPUTBIN #dev, var1 [,var2]
Remarks
var1 The variable that is assigned with the characters from the serial port.
var2 An optional second (or more) variable that is assigned with the
characters from the serial.
#dev Device number. For use with OPEN and CLOSE. Dev is the device number.
The number of bytes to read is depending from the variable you use.
When you use a byte variable, 1 character is read from the serial port.
An integer will wait for 2 characters and an array will wait wait until the whole array
is filled.
Note that the INPUTBIN statement doesn't wait for a <RETURN> but just for the
number of bytes.
See also
PRINTBIN 204 , INPUT 173 , INPUTHEX 176
Example
Dim a as Byte, C as Integer
INPUTBIN a, c 'wait for 3 characters
End
'This code only for 80517 and 80537 with dual serial port
Open "COM2:" For Binary As #1 'open serial channel 1
INPUTBIN #1, a
Close #1
6.117 INPUTHEX
Action
Allows input from the keyboard during program execution.
Syntax
INPUTHEX [" prompt" ] , var [ , varn ] [ NOECHO ] [TIMEOUT=xx]
Remarks
prompt An optional string constant printed before the prompt character.
Var,varn A numeric variable to accept the input value.
NOECHO Disables input echoed back to the Comport.
TIMEOUT Optional delay time. When you specify the delay time, the routine
will return when no input data is available after the specified time.
No timer is used but 4 bytes are taken from the internal memory to
provide a count down timer.
When you use the TIMEOUT option once, you must use it for all INPUT/INPUTHEX
statements. Providing zero as the timeout parameter will wait for the longest
possible time.
The INPUTHEX routine can be used when you have a RS-232 interface on your uP.
See the manual for a design of a RS-232 interface.
The RS-232 interface can be connected to a serial communication port of your
computer.
This way you can use a terminal emulator and the keyboard as input device.
You can also use the build in terminal emulator.
Difference with QB
In QB you can specify &H with INPUT so QB will recognize that a hexadecimal string
is used.
BASCOM implement a new statement : INPUTHEX.
See also
INPUT 173 , INPUTBIN 175 , PRINTBIN 204
Example
Dim x As Byte
INPUTHEX " Enter a number " , x 'ask for input
6.118 INSTR
Action
Returns the position of a sub string in a string.
Syntax
var = INSTR( start , string , substr )
var = INSTR( string , substr )
Remarks
Var Numeric variable that will be assigned with the position of the
sub string in the string. Returns 0 when the sub string is not
found.
Start An optional numeric parameter that can be assigned with the first
position where must be searched in the string. By default (when
not used) the whole string is searched starting from position 1.
String The string to search.
Substr The search string.
Difference with QB
No constants can be used for the string and sub string.
See also
None
Example
Dim S As String * 10 , Z As String * 5
Dim Bp As Byte
S = "This is a test"
Z = "is"
Bp = Instr(s , Z) : Print Bp 'should print 3
Bp = Instr(4 , S , Z) : Print Bp 'should print 6
End
6.119 LCASE
Action
Converts a string into lower or upper case.
Syntax
dest = LCASE( source )
Remarks
dest The string variable that will be assigned with the lower case of string
SOURCE.
source The source string. The original string will be unchanged.
See also
UCASE 231
Example
Dim S As String * 12 , Z As String * 12
Input "Hello " , S 'assign string
S = Lcase(s) 'convert to lowercase
Print S 'print string
6.120 LCD
Action
Send constant or variable to LCD display.
Syntax
LCD x
Remarks
See also
LCDHEX 182 , $LCD 95 CONFIG LCD 125
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: LCD.BAS
' demo: LCD, CLS, LOWERLINE, SHIFTLCD, SHIFTCURSOR, HOME
' CURSOR, DISPLAY
'--------------------------------------------------------------
$sim
Rem The $sim statement will remove long delays for the simulator
Rem It is important to remove this statement when compiling the final
file
'Config Lcdpin = Pin , Db4 = P3.1 , Db5 = P3.2 , Db6 = P3.3 , Db7 =
P3.4 , E = P3.5 , Rs = P3.6
Rem with the config lcdpin statement you can override the compiler
settings
Dim A As Byte
Config Lcd = 16 * 2 'configure lcd screen
'other options are 16 * 4 and 20 * 4, 20 * 2 , 16 * 1a
'When you dont include this option 16 * 2 is assumed
'16 * 1a is intended for 16 character displays with split addresses
over 2 lines
For A = 1 To 10
Shiftlcd Left 'shift the text to the left
Wait 1 'wait a moment
Next
6.121 LCDINIT
Action
Reinitialize the LCD display.
Syntax
LCDINIT
Remarks
When you use any of the LCD display routines the LCD display will be initialized
automatic at startup of your program.
The LCD routines demand that the WR of the LCD display is connected to GND.
When in your design the WR pin of the LCD is connected to a PIN of the micro
processor, it will be high during the initialization and so the display will not be
initialized properly.
The LCDINIT routine allows you to perform initialization after you have set the
pin that controls WR of the LCD to 0V.
See also
LCDHEX 182 , $LCD 95 CONFIG LCD 125
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: LCD.BAS
' demo: LCD, CLS, LOWERLINE, SHIFTLCD, SHIFTCURSOR, HOME
' CURSOR, DISPLAY
'--------------------------------------------------------------
$sim
Rem The $sim statement will remove long delays for the simulator
Rem It is important to remove this statement when compiling the final
file
'Config Lcdpin = Pin , Db4 = P3.1 , Db5 = P3.2 , Db6 = P3.3 , Db7 =
P3.4 , E = P3.5 , Rs = P3.6
Rem with the config lcdpin statement you can override the compiler
settings
Dim A As Byte
Config Lcd = 16 * 2 'configure lcd screen
'other options are 16 * 4 and 20 * 4, 20 * 2 , 16 * 1a
'When you dont include this option 16 * 2 is assumed
'16 * 1a is intended for 16 character displays with split addresses
over 2 lines
6.122 LCDHEX
Action
Send variable in hexadecimal format to the LCD display.
Syntax
LCDHEX var
Remarks
var Variable to display.
var1 : Byte, Integer, Word, Long, Single, Constant.
See also
LCD 178
Example
Dim a as byte
a = 255
LCD a
Lowerline
LCDHEX a
End
6.123 LEFT
Action
Return the specified number of leftmost characters in a string.
Syntax
var = LEFT(var1 , n )
Remarks
var The string that is assigned.
Var1 The sourcestring.
n The number of characters to get from the sourcestring.
n : Byte, Integer, Word, Long, Constant.
For string operations, all the strings must be of the same type : internal or external.
See Also
RIGHT 214 , MID 191
Example
Dim S As Xram String * 15 , Z As Xram String * 15
S = "ABCDEFG"
Z = Left(s , 5)
Print Z 'ABCDE
End
6.124 LEN
Action
Returns the length of a string.
Syntax
var = LEN( string )
Remarks
var A numeric variable that is assigned with the length of string.
string The string to calculate the length of.
Example
Dim S As String * 12
Dim A As Byte
S = "test"
A = Len(s)
Print A ' prints 4
6.125 LOAD
Action
Load specified TIMER with a value for auto reload mode.
Syntax
LOAD TIMER , value
Remarks
TIMER TIMER0, TIMER1 or TIMER2.
Value The variable or value to load.
When you use the ON TIMERx statement with the TIMER/COUNTER in mode 2,
you can specify on which interval the interrupt must occur.
The value can range from 1 to 255 for TIMER0 and TIMER1.
For TIMER2 the range is 1-65535.
The LOAD statement calculates the correct reload value out of the parameter.
The formula : TLx = THx = (256-value)
For TIMER2 : RCAP2L = RCAP2H = (65536 - value)
The load statement is not intended to assign/read a value to/from the timers/
counters. Use COUNTER 132 x instead.
Example
LOAD TIMER0, 100 'load TIMER0 with 100
Will generate :
Mov tl0,#h'9C
Mov th0,#h'9C
Will generate:
Mov RCAP2L,#24
Mov RCAP2H,#252
6.126 LOCATE
Action
Moves the LCD cursor to the specified position.
Syntax
LOCATE y , x
Remarks
X Constant or variable with the position. (1-64*)
Y Constant or variable with the line (1 - 4*)
See also
CONFIG LCD 125 , LCD 178 , HOME 166 , CLS 115
Example
LCD "Hello"
Locate 1,10
LCD "*"
6.127 LOOKUP
Action
Returns a value from a table.
Syntax
var =LOOKUP( value, label )
Remarks
var The returned value
value A value with the index of the table
label The label where the data starts
var : Byte, Integer, Word, Long, Single.
value : Byte, Integer, Word, Long, Constant.
See also
LOOKUPSTR 186
Example
Dim B1 As Byte , I As Integer
B1 = Lookup(1 , Dta)
Print B1 ' Prints 2 (zero based)
I = Lookup(0 , Dta2)
End
Dta:
Data 1 , 2 , 3 , 4 , 5
6.128 LOOKUPSTR
Action
Returns a string from a table.
Syntax
var =LOOKUPSTR( value, label [, language , length])
Remarks
var The string returned
value A value with the index of the table. The index is zero-based. That is, 0
will return the first element of the table.
label The label where the data starts
language An optional variable that holds a number to identify the language. The
first language starts with the number 0.
length The length of the data for each language.
value : Byte, Integer, Word, Long, Constant. Range(0-255)
See also
LOOKUP 185
Example
Dim S As String * 8 , Idx As Byte
Sdata:
Data "This" , "is" , "a test"
Example 2
Dim S As String * 8 , Idx As Byte , Language As Byte
Idx = 0 : Language = 1
S = Lookupstr(idx , Sdata , Language , 17)
Print S ' will print 'Dit '
End
Sdata:
Data "This" , "is" , "a test " 'each language data must have the
same length
Data "Dit " , "is" , "een test" 'the length is 17 because strings
include a 0 byte
6.129 LOW
Action
Retrieves the least significant byte of a variable.
Syntax
var = LOW( s )
Remarks
Var The variable that is assigned with the LSB of var S.
S The source variable to get the LSB from.
See also
HIGH 164 , LOWW 188 , HIGHW 165
Example
Dim I As Integer , Z As Byte
I = &H1001
Z = Low(I) ' is 1
6.130 LOWW
Action
Retrieves the two least significant bytes of a long.
Syntax
var = LOWW( s )
Remarks
var The variable that is assigned with the two LSB of var S.
s The source variable to get the LSB's from.
See also
HIGHW 165 , HIGH 164 , LOW 187
Example
Dim L As Integer , Z As Long
L = &H1001
Z = LowW(L)
6.131 LOWERLINE
Action
Reset the LCD cursor to the lower line.
Syntax
LOWERLINE
Remarks
None
See also
UPPERLINE 232 , THIRDLINE 230 , FOURTHLINE 149 , HOME 166
Example
LCD "Test"
LOWERLINE
LCD "Hello"
End
6.132 MAKEBCD
Action
Convert a variable into its BCD value.
Syntax
var1 = MAKEBCD(var2)
Remarks
var1 Variable that will be assigned with the converted value.
Var2 Variable that holds the decimal value.
When you want to use an I2C clock device, which stores its values as BCD values
you can use this function to convert variables from decimal to BCD.
For printing the bcd value of a variable, you can use the BCD() function.
See also
MAKEDEC 189 , BCD() 112
Example
Dim a As Byte
a = 65
LCD a
Lowerline
LCD BCD(a)
a = MakeBCD(a)
LCD " " ; a
End
6.133 MAKEDEC
Action
Convert a BCD byte or Integer/Word variable to its DECIMAL value.
Syntax
var1 = MAKEDEC(var2)
Remarks
var1 Variable that will be assigned with the converted value.
var2 Variable that holds the BCD value.
When you want to use an I2C clock device which stores its values as BCD values you
can use this function to convert variables from BCD to decimal.
See also
MAKEBCD 189 , BCD 112
Example
Dim a As Byte
a = 65
LCD a
Lowerline
LCD BCD(a)
a = MakeDEC(a)
LCD " " ; a
End
6.134 MAKEINT
Action
Compacts 2 bytes into a word or integer.
Syntax
varn = MAKEINT(LSB , MSB)
Remarks
Varn Variable that will be assigned with the converted value.
LSB Variable or constant with the Least Significant Byte.
MSB Variable or constant with the Most Significant Byte.
The equivalent code is :
varn = (256 * MSB) + LSB
See also
MAKEDEC 189 BCD() 112
Example
Dim a As Integer , I As Integer
a=2
I = MakeINT(a , 1) 'I = (1 * 256) + 2 = 258
End
6.135 MAX
Action
Returns the highest value of an array.
Syntax
var = MAX( ar(1) )
Remarks
Var Numeric variable that will be assigned with the highest value of the
array.
ar() The first array element of the array to return the highest value of.
See also
MIN 192 , AVG 110
Example
Dim ar(10) As Byte
Dim bP as Byte
For bP = 1 to 10
ar(bP) = bP
Next
bP = Max(ar(1))
Print bP 'should print 10
End
6.136 MID
Action
The MID function returns part of a string (a sub string).
The MID statement replaces part of a string variable with another string.
Syntax
var = MID(var1 ,st [, l] )
MID(var ,st [, l] ) = var1
Remarks
Var The string that is assigned.
Var1 The source string.
St The starting position.
L The number of characters to get/set.
Operations on strings require that all strings are of the same type(internal or
external)
See also
LEFT 183 , RIGHT 214
Example
6.137 MIN
Action
Returns the lowest value of an array.
Syntax
var = MIN( ar(1) )
Remarks
Var Numeric variable that will be assigned with the lowest value of the
array.
ar() The first array element of the array to return the lowest value of.
See also
MAX 190 , AVG 110
Example
Dim ar(10) As Byte
Dim bP as Byte
For bP = 1 to 10
ar(bP) = bP
Next
bP = Min(ar(1))
Print bP 'should print 1
End
6.138 MOD
Action
Returns the remainder of a division.
Syntax
ret = var1 MOD var2
Remarks
Ret The variable that receives the remainder.
var1 The variable to divide.
var2 The divisor.
Example
a = 10 MOD 3 'divide 10 through 3
PRINT a 'print remainder (1)
6.139 MWINIT
Action
Initializes the pins in order to use them with the micro wire statements.
Syntax
MWINIT
See also
CONFIG MICROWIRE 127 , MWREAD 193 , MWWRITE 195 , MWWOPCODE 194
6.140 MWREAD
Action
Read a value from the micro wire bus.
Syntax
MWREAD variable , opcode , address, bytes
Remarks
Variable The variable that is assigned with the value retrieved from the
micro wire bus.
Opcode The opcode to use.
Address The address of the device.
Bytes Number of bytes to send.
See also
MWWRITE 195 , MWWOPCODE 194 , MWINIT 193
Example
'-----------------------------------------------------------------
' MicroWire test file
'you could use the same pin for DIN and DOUT
'we use a 93C46 and send bytes not words so AL is 7
Config Microwire = Pin , Cs = P1.1 , Din = P1.2 , Dout = P1.4 , Clock = P1.5 , Al = 7
'init pins
Mwinit
X = 10
'write value of X to address 0
'opcode is 01
'we write 1 byte
'Mwwrite var,opcode,address,numberOfBytes
Mwwrite X , &B101 , 0 , 1
Waitms 10
X=0
'read back
' mwread var,opcode,address,numberofbytes
Mwread X , &B110 , 0 , 1
'disable write
'send startbit, opcode (00) and 00 + address
Mwwopcode &B1000000000 , 10
End
6.141 MWWOPCODE
Action
Write an opcode to a micro wire device.
Syntax
MWWOPCODE opcode , bits
Remarks
Opcode The opcode that needs to be send to the micro wire device.
See the micro wire docs for the right values.
Bits The number of bits to send.
Before you can work with micro wire you must send an opcode to enable writing an
EEPROM for example.
See also
MWINIT 193 , MWWRITE 195 , MWREAD 193
[****] 193
Example
'enable write to EEPROM
'Needed bits : startbit (1), opcode (00) and (11) + address
'Mwwopcode opcode, numberOfBits
Mwwopcode &B1001100000 , 10 'send the code
6.142 MWWRITE
Action
Writes a value to the micro wire bus.
Syntax
MWWRITE variable , opcode , address, bytes
Remarks
Variable The variable which's content must be send to the micro wires
device.
Opcode The opcode to use.
Address The address of the device.
Bytes Number of bytes to send.
See also
MWINIT 193 , MWREAD 193 , MWWOPCODE 194
Example
'write value of X to address 0
'opcode is 01 and we write one byte
Mwwrite X , &B101 , 0 , 1
6.143 NEXT
Action
Ends a FOR..NEXT structure.
Syntax
NEXT [var]
Remarks
Var The index variable that is used as a counter when you form the
structure with FOR var. Var is optional and not needed.
See also
FOR 148
Example
Dim X As Byte , Y As Byte , A As Byte
Y = 10 'make y 10
For A = 1 To 10 'do this 10 times
For X = Y To 1 'this one also
Print X ; A 'print the values
Next 'next x (count down)
Next A 'next a (count up) END
6.144 ON interrupt
Action
Execute subroutine when specified interrupt occurs.
Syntax
ON interrupt label [NOSAVE]
Remarks
interrupt INT0, INT1, SERIAL, TIMER0 ,TIMER1 or TIMER2.
Chip specific interrupts can be found under microprocessor
support.
Label The label to jump to if the interrupt occurs.
NOSAVE When you specify NOSAVE, no registers are saved and restored in
the interrupt routine. So when you use this option be sure to save
and restore used registers.
You must return from the interrupt routine with the RETURN statement.
You may have only one RETURN statement in your interrupt routine because the
compiler restores the registers and generates a RETI instruction when it encounters
You can't use TIMER1 when you are using SERIAL routines such as PRINT
because TIMER1 is used as a BAUDRATE generator.
When you use the INT0 or INT1 interrupt you can specify on which condition the
interrupt must be triggered.
You can use the Set/Reset statement in combination with the TCON-register for this
purpose.
See Also
ON VALUE 197
Example
ENABLE INTERRUPTS
ENABLE INT0 'enable the interrupt
ON INT0 Label2 nosave 'jump to label2 on INT0
DO 'endless loop
LOOP
END
Label2:
PRINT " A hardware interrupt occurred!" 'print message
RETURN
6.145 ON value
Action
Branch to one of several specified labels, depending on the value of a variable.
Syntax
ON var [GOTO] [GOSUB] label1 [, label2 ]
Remarks
Var The numeric variable to test.
This can also be a SFR such as P1.
label1, label2 The labels to jump to depending on the value of var.
Note that the value is zero based. So when var = 0, the first specified label is
jumped/branched.
See Also
ON interrupt 196
Example
Dim X As Byte
Lbl3:
Print "lbl3"
Return
Lbl1:
nop
Lbl2:
nop
6.146 OPEN
Action
Opens and closes a device.
Syntax
OPEN "device" for MODE As #channel
CLOSE #channel
Remarks
Device There are 2 hardware devices supported: COM1 and COM2.
With the software UART, you must specify the port pin and the baud
rate.
COM3.0:9600 will use PORT 3.0 at 9600 baud.
Optional is ,INVERTED this will use inverted logic so you don't need
MAX232 inverters.
MODE You can use BINARY, INPUT or OUTPUT for COM1 and COM2, but for the
software UART pins, you must specify INPUT or OUTPUT.
Channel The number of the channel to open. Must be a positive constant.
Since there are uP's such as the 80537 with 2 serial channels on board, the compiler
must know which serial port you want to use. That is why the OPEN statement is
implemented. With only 1 serial port on board, you don't need this statement.
The statements that support the device are PRINT 203 , PRINTHEX 205 , INPUT 173 and
INPUTHEX 176 .
Every opened device must be closed using the CLOSE #channel statement. Of
course you must use the same channel number.
The software UART, only supports the GET 151 and PUT 207 statements to retrieve and
send data and the PRINTBIN 204 and INPUTBIN 175 statement.
The SW UART uses timed loops and interrupts can slow down these loops. So turn
interrupts off before you use the SW UART.
COM1: and COM2: are hardware ports, and can be used with PRINT etc.
For the software UART it is important that the pin you use is bit addressable. In
most cases a PORT is bit addressable but some chips have ports that are not bit
addressable. When you use such a port you will get errors like : Error 208, bit
variable not found.
Since the OPEN statement doesn't use real file handles like DOS but only serves as a
compiler directive, it is important that you must use the CLOSE statement as the
last statement in your program.
The following example shows when it will NOT WORK :
Test:
Print #1, "test"
Return
Since the compiler frees the handle when it encounters the CLOSE statement, the
PRINT #1, "test" code is never executed. To solve this you should put the CLOSE #1
statement under the Return statement.
Test:
Print #1, "test"
Return
Close #1
See also
GET 151 , PUT 207
Example 1
Example 2
'works with every port pin
Dim A As Byte , S As String * 16 , I As Byte , Dum As Byte
'At this time only variables can be sent and received with the PUT and GET
statements.
'In the feature PRINT etc. will support these software comports.
Do
Get #2 , A 'get character from comport
Put #1 , A 'write it back
Print A 'use normal channel
Loop
6.147 OUT
Action
Sends a byte to a hardware port or external memory address.
Syntax
OUT address, value
Remarks
address The address where to send the byte to.
value The variable or value to send.
The OUT statement only works on systems with a uP that can address external
memory.
See also
INP 173 , PEEK 202 , POKE 202
Example
Dim a as byte
OUT &H8000,1 'send 1 to the databus(d0-d7) at hex address 8000
END
Will generate :
Mov A,#1
Mov dptr,#h'8000
Movx @dptr,a
6.148 PORT
Action
P1 and P3 are special function registers that are treated as variables.
Syntax
Px = var
var = Px
Remarks
X The number of the port. (1 or 3). P3.6 can't be used with an
AT89C2051!
Var The variable to retrieve or to set.
Note that other processors can have more ports such as P0, P2, P4 etc.
When you select the proper .DAT file you can also use these ports as variables.
In fact you can use any SFR as a byte variable in BASCOM.
Example
Dim A As Byte , B1 As Bit
6.149 PEEK
Action
Returns a byte stored in internal memory.
Syntax
var = PEEK( address )
Remarks
var Numeric variable that is assigned with the content of the memory
location address
address Numeric variable or constant with the address location.(0-255)
See also
POKE 202 , CPEEK 134 , INP 173 , OUT 200
Example
DIM a As Byte
a = Peek( 0 ) 'return the first byte of the internal memory (r0)
End
6.150 POKE
Action
Write a byte to an internal memory location.
Syntax
POKE address , value
Remarks
address Numeric variable with the address of the memory location to set. (0-
255)
value Value to assign. (0-255)
Be careful with the POKE statement because you can change variables with it, which
can cause your program to function incorrect.
See also
PEEK 202 , CPEEK 134 , INP 173 , OUT 200
Example
POKE 127, 1 'write 1 to address 127
End
6.151 POWERDOWN
Action
Put processor into power down mode.
Syntax
POWERDOWN
Remarks
The power down mode stops the system clock completely.
The only way to reactivate the micro controller is by system reset.
See also
IDLE 169
Example
POWERDOWN
6.152 PRINT
Action
Send output to the RS-232 port.
Syntax
PRINT var ; " constant"
Remarks
var The variable or constant to print.
You can use a semicolon (;) to print more than one variable at one line.
When you end a line with a semicolon, no linefeed will be added.
The PRINT routine can be used when you have a RS-232 interface on your uP.
See the manual for a design of an RS-232 interface.
See also
PRINTHEX 205 , INPUT 173 , OPEN 198 , CLOSE 198 , SPC 223
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: PRINT.BAS
' demo: PRINT, PRINTHEX
'--------------------------------------------------------------
Dim A As Byte , B1 As Byte , C As Integer
A = 1
Print "print variable a " ; A
Print 'new line
Print "Text to print." 'constant to print
B1 = 10
Printhex B1 'print in hexa notation
C = &HA000 'assign value to c%
Printhex C 'print in hex notation
Print C 'print in decimal notation
C = -32000
Print C
Printhex C
Rem Note That Integers Range From -32767 To 32768
End
6.153 PRINTBIN
Action
Print binary content of a variable to the serial port.
Syntax
PRINTBIN var [ ; varn]
PRINTBIN #dev, var ; [,varn]
Remarks
var The variable which value is sent to the serial port.
PRINTBIN is equivalent to PRINT CHR(var); but whole arrays can be printed this
way.
See also
INPUTBIN 175 , PRINT 203 , PRINTHEX 205 , INPUTHEX 176
Example
Dim a(10) as Byte, c as Byte
For c = 1 To 10
a(c) = a 'fill array
Next
PRINTBIN a(1) 'print content
6.154 PRINTHEX
Action
Sends a variable in hexadecimal format to the serial port.
Syntax
PRINTHEX var
Remarks
var The variable to print.
The PRINTHEX routine can be used when you have a RS-232 interface on your uP.
See the manual for a design of an RS-232 interface.
The RS-232 interface can be connected to a serial communication port of your
computer.
This way you can use a terminal emulator as an output device.
You can also use the build in terminal emulator.
See also
PRINT 203 , INPUTHEX 176 , SPC 223
Example
Dim x As Byte
INPUT x 'ask for var
PRINT x 'print it in decimal format
PRINTHEX "Hex " ; x 'print it in hex format
6.155 PRIORITY
Action
Sets the priority level of the interrupts.
Syntax
PRIORITY SET / RESET interrupt
Remarks
SET Bring the priority level of the interrupt to a higher level.
RESET Bring the priority level of the interrupt to a lower level.
Interrupt The interrupt to set or reset.
The interrupts are: INT0, INT1, SERIAL, TIMER0, TIMER1 and TIMER2.
Interrupt Priority
INT0 1 (highest)
TIMER0 2
INT1 3
TIMER1 4
SERIAL 5 (lowest)
Example
PRIORITY SET SERIAL 'serial int highest level
ENABLE SERIAL 'enable serial int
ENABLE TIMER0 'enable timer0 int
ENABLE INTERRUPTS 'activate interrupt handler
ON SERIAL label 'branch to label if serial int occur
DO 'loop for ever
LOOP
6.156 PSET
Action
Sets or resets a single pixel.
Syntax
PSET X , Y, value
Remarks
X The X location of the pixel. In range from 0-239.
Y The Y location of the pixel. In range from 0-63.
value The value for the pixel. 0 will clear the pixel. 1 Will set the pixel.
See also
CONFIG GRAPHLCD 121
Example
Dim X as Byte, Y as Byte
For X = 0 To 10
For Y = 0 To 10
Pset X , Y , 1 'make a nice block
Next
Next
End
6.157 PUT
Action
Sends a byte to the software UART.
Syntax
PUT #channel , var
Remarks
channel Positive numeric constant that refers to the opened channel.
var A variable or constant who's value is sent to the the software
UART.
See also
GET 151 , PRINT 203 , INPUT 173 , OPEN 198
Example
Open "com3.1:9600" For Output As #1 'p3.1 is normally used for
tx so testing is easy
Open "com3.0:9600" For Input As #2 'p3.0 is normally used for
RX so testing is easy
Do
Get #2 , A 'get character from comport
Put #1 , A 'write it back
Print A 'use normal channel
Loop
6.158 READ
Action
Reads those values and assigns them to variables.
Syntax
READ var
Remarks
var Variable that is assigned data value.
Difference with QB
It is important that the variable is of the same type as the stored data.
See also
DATA 136 , RESTORE 212
Example
Dim A As Byte, I As Byte, C As Integer, S As XRAM String * 10
RESTORE dta
FOR a = 1 TO 3
READ i : PRINT i
NEXT
RESTORE DTA2
READ C : PRINT C
READ C : PRINT C
Restore dta3 : Read s : Print s
END
dta:
Data 5,10,15
dta2:
Data 1000%, -2000%
dta3:
Data " hello"
6.159 READMAGCARD
Action
Reads data from a magnetic card reader.
Syntax
READMAGCARD var , bytes , code, timeout
Remarks
Var A byte array large enough to store the data from the magnetic
card reader.
bytes The number of bytes read from the card.
Shifts The coding used. Must be 5 or 7. In version 2.03 only 5 is
supported.
Timeout A LONG variable or constant that the routine will wait for a card.
Err will be set when no card is detected within Timeout.
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 hardware control
11 start byte
12 hardware control
13 separator
14 hardware control
15 stop byte
See also
None
Calls
_Read_Magcard_Code5
Example
'[DIM used variables]
Dim X(40) As Byte , I As Byte , Bts As Byte
Do
Print "Slide magcard through reader"
Readmagcard X(1) , Bts , 5, 10000 'call routine
' ^ may be 5 or 7. 7 bit coding not implemented yet
Print "Error " ; Err '1 if error occured
Print ; " " ; Bts ; " bytes read" 'show number of bytes read
Print Err
For I = 1 To Bts
Print X(i) ; " "; 'show number
Next
Print
Loop
End
6.160 REM
Action
Instruct the compiler that comment will follow.
Syntax
REM or '
Remarks
You can comment your program for clarity.
You can use REM or ' followed by your comment.
All statements after REM or ' are treated as comment so you cannot
use statements after a REM statement.
Note that the starting ' sign will ensure compatibility with QB
Each block must be closed with a ')
Example
REM TEST.BAS version 1.00
PRINT a ' " this is comment : PRINT " hello"
^--- this will not be executed!
6.161 REPLACE
Action
Replace all occurrences of a single character in a string.
Syntax
REPLACE string , old , new
Remarks
string The source string to change.
old A string constant or byte that specifies the character to replace.
new The new character. Also a string constant or a byte.
Example
Dim S as String * 12
s = "Hello"
REPLACE s , "e" , "a" ' now we got some dutch :-)
Print s ' should print Hallo
6.162 RESET
Action
Reset a bit of a PORT (P1.x, P3.x) or an internal bit/byte/integer/word/long variable.
Syntax
RESET bit
RESET var.x
Remarks
bit Can be a P1.x, P3.x or any bitvariable where x=0-7.
var Can be a byte, integer or word variable.
x Constant of variable to reset.(0-7) for bytes and (0-15) for Integer/
Word. 0-31 for a LONG.
See also
SET 216
Example
Dim b1 as bit, b2 as byte, I as Integer
RESET P1.3 'reset bit 3 of port 1
RESET b1 'bitvariable
RESET b2.0 'reset bit 0 of bytevariable b2
RESET I.15 'reset MS bit from I
6.163 RESTORE
Action
Allows READ to reread values in specified DATA statements.
Syntax
RESTORE label
Remarks
Label The label of a DATA statement.
See also
DATA 136 , READ 208
Example
DIM a AS BYTE, I AS BYTE
RESTORE dta
FOR a = 1 TO 3
READ a : PRINT a
NEXT
RESTORE DTA2
READ I : PRINT I
READ I : PRINT I
END
DTA1:
Data 5, 10, 100
DTA2:
Data -1%, 1000%
Integers must end with the %-sign. (Integer : <0 or >255)
6.164 RETURN
Action
Return from a subroutine.
Syntax
RETURN
Remarks
Subroutines must be ended with a related RETURN statement.
Interrupt subroutines must also be terminated with the Return statement.
See also
GOSUB 162
Example
Dim Result As Byte , Y As Byte
6.165 RIGHT
Action
Return a specified number of rightmost characters in a string.
Syntax
var = RIGHT(var1 ,st )
Remarks
var The string that is assigned.
Var1 The sourcestring.
st The starting position.
See also
LEFT 183 , MID 191
Example
Dim s As XRAM String * 15, z As XRAM String * 15
s = "ABCDEFG"
z = Right(s,2)
Print z 'FG
End
6.166 RND
Action
Returns a random number.
Syntax
var = RND(limit)
Remarks
Limit The maximum number that will be assigned to the random
number.
The RND() function uses 2 internal bytes to store the value of the random seed.
See also
NONE
Example
'---------------------------------------------------------
' (c) 1995-2006 MCS Electronics
' RND.BAS
'---------------------------------------------------------
Dim W As Word
Do
'get a random number and limit it to be maximum 100
W = Rnd(100)
Print W
Loop
End
6.167 ROTATE
Action
Shifts all bits one place to the left or right.
Syntax
ROTATE var , LEFT/RIGHT [ , shifts]
Remarks
Var Byte, Integer/Word or Long variable.
Shifts The number of shifts to perform.
Note that the behavior of ROTATE is just like the ASM RL or RR mnemonic. It works
for integer, words, single and longs also. All bits in the variable are preserved so for
a byte after 8 rotations, the value will be the same.
See also
SHIFTIN 218 , SHIFTOUT 218 , SHIFT 217
Calls
_ROTATE_LEFT or _ROTATE_RIGHT
Example
Dim a as Byte
a = 128
ROTATE a, LEFT , 2
Print a '1
6.168 SELECT
Action
Executes one of several statement blocks depending on the value of a variable.
Syntax
SELECT CASE var
CASE test1 : statements
[CASE test2 : statements ]
CASE ELSE : statements
END SELECT
Remarks
var Variable. to test
Test1 Value to test for.
Test2 Value to test for.
See also
IF THEN 169
Example
Dim b2 as byte
SELECT CASE b2 'set bit 1 of port 1
CASE 2 : PRINT "2"
CASE 4 : PRINT "4"
CASE IS >5 : PRINT ">5" 'a test requires the IS keyword
CASE 10 TO 20 'test the range from 10 to 20
CASE ELSE
END SELECT
END
6.169 SET
Action
Set a bit of a PORT(P1.x,P3.x) or a bit/byte/integer/word/long variable.
Syntax
SET bit
SET var.x
Remarks
Bit P1.x, P3.x or a Bit variable.
Var A byte, integer, word or long variable.
X Bit of variable (0-7) to set. (0-15 for Integer/Word) and 0-31 for a
LONG.
See also
RESET 212
Example
Dim b1 as Bit, b2 as byte, c as Word
SET P1.1 'set bit 1 of port 1
SET b1 'bitvariable
SET b2.1 'set bit 1 of var b2
SET C.15 'set highest bit of Word
6.170 SHIFTCURSOR
Action
Shift the cursor of the LCD display left or right by one position.
Syntax
SHIFTCURSOR LEFT | RIGHT
See also
SHIFTLCD 219 , LCD 178 , CLS 115 , LOCATE 185 , HOME 166
Example
LCD "Hello"
SHIFTCURSOR LEFT
End
6.171 SHIFT
Action
Shifts all bits one place to the left or right.
Syntax
SHIFT var , LEFT/RIGHT [ , shifts]
Remarks
Var Byte, Integer/Word or Long variable.
Shifts The number of shifts to perform.
The SHIFT statements shifts all bits to the left or right and so for a byte after 8
shifts, the byte will be zero.
See also
SHIFTIN 218 , SHIFTOUT 218 ROTATE 215
Example
Dim a as Word
a = 128
SHIFT a, LEFT , 1
Print a '256
6.172 SHIFTIN
Action
Shifts a bit stream in or out a variable.
Syntax
SHIFTIN pin , pclock , var , option [PRE]
SHIFTOUT pin , pclock , var , option
Remarks
pin The portpin which serves as as input/output.
pclock The portpin which generates the clock.
var The variable that is assigned.
option Option can be :
0 - MSB shifted in/out first when clock goes low
1 - MSB shifted in/out first when clock goes high
2 - LSB shifted in/out first when clock goes low
3 - LSB shifted in/out first when clock goes high
For the SHIFTIN statement you can add 4 to the parameter to use
the external clock signal for shifting.
PRE Add this additional parameter (no comma) to sample the input pin
before the clock signal is generated.
It depends on the type of the variable, how many shifts will occur.
When you use a byte, 8 shifts will occur and for an integer, 16 shifts will occur.
See also
NONE
Example
Dim a as byte
SHIFTIN P1.0 , P1.1 , a , 0
SHIFTOUT P1.2 , P1.1 , a , 0
Generated code:
Mov R0,#h'21
Mov r2,#h'01
__UNQLBL1:
Mov r3,#8
__UNQLBL2:
Jnb P1.1,*+0
Mov c,P1.0
Rlc a
Jb P1.1,*+0
Djnz r3,__UNQLBL2
Mov @r0,a
Dec r0
Djnz r2,__UNQLBL1
6.173 SHIFTLCD
Action
Shift the LCD display left or right by one position.
Syntax
SHIFTLCD LEFT / RIGHT
Remarks
NONE
See also
SHIFTCURSOR 217 , CLS 115 , LCD 178 , HOME 166 , LOCATE 185
Example
LCD "Very long text"
SHIFTLCD LEFT
Wait 1
SHIFTLCD RIGHT
End
6.174 SHOWPIC
Action
Shows a BGF file on the graphic display
Syntax
SHOWPIC x, y , label
Remarks
Showpic can display a converted BMP file. The BMP must be converted into a BGF
file with the Tools Grahic Converter 54 .
The X and Y parameters specify where the picture must be displayed. X and Y must
be 0 or a multiple of 8. The picture height and width must also be an multiple of 8.
The label tells the compiler where the graphic data is located. It points to a label
where you put the graphic data with the $BGF directive.
See also
$BGF 89 , CONFIG GRAPHLCD 121 , PSET 207
Example
CLS GRAPH 'clear graphic part of display
ShowPic 0,0, label 'show picture
End
Label:
$BGF "mypic.bgf" 'data will be inserted here
6.175 SOUND
Action
Sends pulses to a port pin.
Syntax
SOUND pin, duration, frequency [,NOINT]
Remarks
Pin Any I/O pin such as P1.0 etc.
duration The number of pulses to send. Byte, integer/word or constant.
(1- 32768).
Frequency The time the pin is pulled low and high.
NOINT An option to disable interrupts during the sound statement.
When you connect a speaker or a buzzer to a port pin (see hardware) , you can use
the SOUND statement to generate some tones.
The NOINT will clear the global interrupts so no interrupts can occur during the
sound statement. When the sound statement has completed the interrupt register is
restored.
The port pin is switched high and low for frequency uS. The pin will be in the low
state when the sound statement ends.
This loop is executed duration times.
See also
SOUNDEXT 221
Example
SOUND P1.1 , 10000, 10 'BEEP
End
6.176 SOUNDEXT
Action
Sends pulses to a port pin.
Syntax
SOUND pin, duration, frequency [,NOINT]
Remarks
Pin Any I/O pin such as P1.0 etc.
duration This is an integer, word or constant that specifies how long the sound
is generated. A bigger value will result in a longer duration of the
sound.
Frequency This is an integer, word, or constant that that will be used to
generate the frequency. A higher value will result in a higher
frequency. A very low value might result in a sound that can not be
heard.
NOINT An option to disable interrupts during the sound statement.
The SOUNDEXT should be used instead of the SOUND statement. It has a wider
range.
When you connect a speaker or a buzzer to a port pin (see hardware) , you can use
the SOUNDEXT statement to generate some tones.
The NOINT will clear the global interrupts so no interrupts can occur during the
sound statement. When the sound statement has completed the interrupt register is
restored.
When the statement is ready, it will leave the pin in the HIGH state.
The time the pin is low is exact the same time as the pin is high. So the created
pulse width is 50%.
Since loops are used, the frequency is relatively to the processor speed.
The width range of the frequency will ensure that you can create hearable tones
width a variety of oscillator values. When you want to create tones that are
independent of the processor speed, you need to use a timer.
See also
SOUND 220
Example
$regfile = "89s4051.dat"
$crystal = 8000000
Dim X As Word
X = 0
Do
X = X - 10
Soundext P3.4 , 500 , X
Waitms 1
Loop
6.177 SPACE
Action
Returns a string of spaces.
Syntax
var = SPACE(x )
Remarks
X The number of spaces.
Var The string that is assigned.
Using 0 for x, will result in a string of 255 bytes because there is no check for a zero
length assign.
See also
STRING 228 , SPC 223
Example
Dim s as XRAM String * 15, z as XRAM String * 15
s = Space(5)
Print " {" ;s ; " }" '{ }
Dim A as Byte
A=3
S = Space(a)
6.178 SPC
Action
Prints spaces to the serial port or LCD display.
Syntax
PRINT SPC(x )
Remarks
x The number of spaces to print. Range from 1 - 255.
See Also
SPACE 222
Example
Dim s as XRAM String * 15, z as XRAM String * 15
s = "Hello"
Print " {" ;s ; SPC(3) ; "}"
6.179 SPIIN
Action
Reads a value from the SPI-bus.
Syntax
SPIIN var, bytes
Remarks
Var The variable that is assigned with the value read from the SPI-bus.
Bytes The number of bytes to read.
See also
SPIOUT 225 , CONFIG SPI 130 , SPIINIT 224
Example
Dim a(10) as byte
CONFIG SPI = SOFT, DIN = P1.0, DOUT = P1.1, CS=P1.2, CLK = P1.3
SPIINIT
SPIIN a(1) , 4 'read 4 bytes
6.180 SPIINIT
Action
Initializes the pins of the SPI-bus.
Syntax
SPIINIT
Remarks
The pins used for the SPI bus must be set to the proper logical level before you can
use the SPI commands.
See also
SPIOUT 225 , CONFIG SPI 130 , SPIIN 224
Example
Dim a(10) as byte
CONFIG SPI = SOFT, DIN = P1.0, DOUT = P1.1, CS=P1.2, CLK = P1.3
SPIINIT
6.181 SPIOUT
Action
Sends a value of a variable to the SPI-bus.
Syntax
SPIOUT var , bytes
Remarks
var The variable woes content must be send to the SPI-bus.
bytes The number of bytes to send.
See also
SPIIN 224 , CONFIG SPI 130 , SPIINIT 224
Example
CONFIG SPI = SOFT, DIN = P1.0, DOUT = P1.1, CS=P1.2, CLK = P1.3
SPIINIT ‘ init SPI pins
Dim a(10) as Byte , X As Byte
SPIOUT a(1) , 5 'send 5 bytes
SPIOUT X , 1 'send 1 byte
6.182 START
Action
Start the specified timer/counter.
Syntax
START timer
Remarks
timer TIMER0, TIMER1, TIMER2, COUNTER0 or COUNTER1.
You must start a timer/counter in order for an interrupt to occur (when the external
gate is disabled).
See also
STOP TIMERx 226
Example
ON TIMER0 label2
LOAD TIMER0, 100
START TIMER0
DO 'start loop
LOOP 'loop forever
RETURN
6.183 STOP
Action
Stop program execution.
Syntax
STOP
Remarks
END can also be used to terminate a program.
See Also
STOP TIMER 226 , START 225
Example
PRINT var 'print something
STOP 'thats it
Syntax
STOP timer
Remarks
timer TIMER0, TIMER1, TIMER2, COUNTER0 or COUNTER1.
You can stop a timer when you don't want an interrupt to occur.
See also
START TIMERx 225 , STOP 226
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: TIMER0.BAS
' demo: ON TIMER0
' *TIMER1 is used for RS-232 baudrate generator
'--------------------------------------------------------------
Dim Count As Byte , Gt As Byte
On Timer0 Timer_0_int
Load Timer0 , 100 'when the timer reaches 100 an
interrupt will occur
Enable Interrupts 'enable the use of interrupts
Enable Timer0 'enable the timer
End If
Return
6.185 STR
Action
Returns a string representation of a number.
Syntax
var = STR( x )
Remarks
Var A string variable.
X A numeric variable.
See also
VAL 232 , HEX 163 , HEXVAL 164
Difference with QB
In QB STR() returns a string with a leading space. This behaviour is not in
BASCOM.
Example
Dim a as Byte, S as XRAM String * 10
a = 123
s = Str(a)
Print s
End
6.186 STRING
Action
Returns a string consisting of m repetitions of the character with ASCII
code n.
Syntax
var = STRING(m ,n )
Remarks
Var The string that is assigned.
N The ASCII-code that is assigned to the string.
M The number of characters to assign.
Since a string is terminated by a 0 byte, you can't use 0 for n.
Using 0 for m will result in a string of 255 bytes, because there is no check on a
length assign of 0. When you need this let me know.
See also
SPACE 222
Example
Dim s as XRAM String * 15
s = String(5,65)
Print s 'AAAAA
End
6.187 SUB
Action
Defines a Sub procedure.
Syntax
SUB Name[(var1)]
Remarks
name Name of the sub procedure, can be any non reserved word.
var1 The name of the parameter.
You must end each subroutine with the END SUB statement.
See also
CALL 113 , DECLARE 139
Example
NONE
6.188 SWAP
Action
Exchange two variables of the same type.
Syntax
SWAP var1, var2
Remarks
var1 A variable of type bit, byte, integer or word.
var2 A variable of the same type as var1.
After the swap, var1 will hold the value of var2 and var2 will hold the value of var1.
Example
Dim a as integer,b1 as integer
a = 1 : b1 = 2 'assign two integers
SWAP a, b1 'swap them
PRINT a ; b1
6.189 THIRDLINE
Action
Reset LCD cursor to the third line.
Syntax
THIRDLINE
Remarks
NONE
See also
UPPERLINE 232 , LOWERLINE 188 , FOURTHLINE 149
Example
Dim a as byte
a = 255
LCD a
Thirdline
LCD a
Upperline
End
6.190 UCASE
Action
Converts a string into upper case.
Syntax
dest = UCASE( source )
Remarks
dest The string variable that will be assigned with the upper case of string
SOURCE.
source The source string. The original string will be unchanged.
See also
LCASE 178
Example
Dim S As String * 12 , Z As String * 12
Input "Hello " , S 'assign string
S = Lcase(s) 'convert to lowercase
Print S 'print string
6.191 UPPERLINE
Action
Reset LCD cursor to the upper line.
Syntax
UPPERLINE
Remarks
NONE
See also
LOWERLINE 188 , THIRDLINE 230 , FOURTHLINE 149
Example
Dim a as byte
a = 255
LCD a
Lowerline
LCD a
Upperline
End
6.192 VAL
Action
Converts a string representation of a number into a number.
Syntax
var = Val( s )
Remarks
Var A numeric variable that is assigned with the value of s.
S Variable of the string type.
var : Byte, Integer, Word, Long, Single.
See also
STR 228 , HEXVAL 164
Example
Dim a as byte, s As XRAM string * 10
s = "123"
a = Val(s) 'convert string
Print a
End
6.193 VARPTR
Action
Retrieves the memory-address of a variable.
Syntax
var = VARPTR( var2 )
Remarks
Var The variable that is assigned with the address of var2.
var2 A variable to retrieve the address from.
See also
PEEK 202 POKE 202
Example
Dim I As Integer , B1 As Byte
B1 = Varptr(I)
Generated code:
Mov h'23,#h'21
6.194 WAIT
Action
Suspends program execution for a given time.
Syntax
WAIT seconds
Remarks
seconds The number of seconds to wait.
See also
DELAY 141 , WAITMS 234 , WAITMSE 235
Example
WAIT 3 'wait for three seconds
Print "*"
6.195 WAITKEY
Action
Wait until a character is received in the serial buffer.
Syntax
var = WAITKEY()
var = WAITKEY(#channel)
Remarks
Var Variable that is assigned with the ASCII value of the serial buffer.
channel The channel number of the device
var : Byte, Integer, Word, Long, String.
See also
INKEY 171
Example
Dim A As Byte
A = Waitkey 'wait for character
Print A
Example
Dim A As Byte
Open "COM2:" For Binary As #1 'open serial chan.1 COM2 of 80517/80537
Dim St As Byte
St = Inkey(#1) 'get key
St = Inkey() 'get key from COM1 (the default)
6.196 WAITMS
Action
Suspends program execution for a given time in mS.
Syntax
WAITMS mS
Remarks
mS The number of milliseconds to wait. (1-255)
See also
DELAY 141 , WAIT 233 , WAITMSE 235
Example
WAITMS 10 'wait for 10 mS
Print "*"
6.197 WAITMSE
Action
Suspends program execution for a given time in mS.
Syntax
WAITMS mS
Remarks
mS The number of milliseconds to wait. (1-65535)
See also
DELAY 141 , WAIT 233 , WAITMS 234
Example
WAITMSE 1000 'wait for 1000 mS
Print "*"
6.198 WATCHDOG
Action
Start and stop the watchdog timer.
Syntax
Remarks
The AT89S8252 has a built in watchdog timer.
A watchdog timer is a timer that will reset the uP when it reaches a certain value.
So during program execution this WD-timer must be reset before it exceeds its
maximum value. This is used to be sure a program is running correct.
When a program crashes or sits in an endless loop it will not reset the WD-timer so
an automatic reset will occur resulting in a restart.
You need to configure the reset time with CONFIG WATCHDOG.
See Also
CONFIG WATCHDOG 132
Example
DIM A AS INTEGER
CONFIG WATCHDOG = 2048 'after 2 seconds a reset will occur
START WATCHDOG 'start the WD
DO
PRINT a
a=a+1 'notice the reset
REM RESET WATCHDOG 'delete the REM to run properly
LOOP
END
Syntax
WHILE condition
statements
WEND
Remarks
If the condition is true then any intervening statements are executed until the
WEND statement is encountered.
BASCOM then returns to the WHILE statement and checks condition.
If it is still true, the process is repeated.
If it is not true, execution resumes with the statement following the WEND
statement.
See also
DO .. LOOP 144 , FOR .. NEXT 148
Example
Dim A As Byte
While A <= 10
Print A
Incr A
Wend
VII
Using assembly 239
7 Using assembly
7.1 Using assemly
In line assembly
Assembler statements are recognized by the compiler.
The only exception is SWAP because this is a valid BASIC statement.
You must precede this ASM-statement with the !-sign so the compiler knows that
you mean the ASM SWAP statement.
Note that for the ACC register, A is used in mnemonics.( Except for bit operations )
Example:
Mov a, #10 'ok
Mov acc,#10 'also ok but generates 1 more byte
Setb acc.0 'ok
Setb a.0 'NOT OK
You can also include an assembler file with the $INCLUDE FILE.ASM statement.
Boolean variable
manipulation
CLR C clear carry flag
CLR bit clear direct bit
SETB C set carry flag
SETB bit set direct bit
CPL C complement carry flag
CPL bit complement direct bit
ANL C, bit AND direct bit to carry flag
ORL C,bit OR direct bit to carry flag
MOV C,bit Move direct bit to carry flag
Arithmetic
operations
ADD A,Rn add register to accu
ADD A,direct add register byte to accu
ADD A,@Ri add indirect RAM to accu
ADD A,#data add immediate data to accu
ADDC A,Rn add register to accu with carry
ADDC A,direct add direct byte to accu with carry flag
ADDC A,@Ri add indirect RAM to accu with carry flag
ADDC A,#data add immediate data to accu with carry flag
SUBB A,Rn subtract register from A with borrow
SUBB A,direct subtract direct byte from A with borrow
SUBB A,@Ri subtract indirect RAM from A with borrow
SUBB A,#data subtract immediate data from A with borrow
INC A increment accumulator
Logical operations
ANL A,Rn AND register to accu
ANL A,direct AND direct byte to accu
ANL A,@Ri AND indirect RAM to accu
ANL A,#data AND immediate data to accu
ANL direct,A AND accu to direct byte
ANL direct,#data AND immediate data to direct byte
ORL A,Rn OR register to accu
ORL A,direct OR direct byte to accu
ORL A,@Ri OR indirect RAM to accu
ORL A,#data OR immediate data to accu
ORL direct,A ORL accu to direct byte
ORL direct,#data ORL immediate data to direct byte
XRL A,Rn exclusive OR register to accu
XRL A,direct exclusive OR direct byte to accu
XRL A,@Ri exclusive OR indirect RAM to accu
XRL A,#data exclusive OR immediate data to accu
XRL direct,A exclusive OR accu to direct byte
XRL direct,#data exclusive OR immediate data to direct byte
CLR A clear accu
CPL A complement accu
RL A rotate accu left
RLC A rotate A left through the carry flag
RR A rotate accu right
RRC A rotate accu right through the carry flag
Data transfer
MOV A,Rn move register to accu
MOV A,direct move direct byte to accu
MOV A,@Ri move indirect RAM to accu
MOV A,#data move immediate data to accu
MOV Rn,A move accu to register
MOV Rn,direct move direct byte to register
MOV Rn,#data move immediate data to register
MOV direct,A move accu to direct byte
MOV direct,Rn move register to direct byte
MOV direct,direct move direct byte to direct
MOV direct,@Ri move indirect RAM to direct byte
MOV direct,#data move immediate data to direct byte
MOV@Ri,A move accu to indirect RAM
MOV@Ri,direct move direct byte to indirect RAM
MOV@Ri,#data move immediate to indirect RAM
MOV DPTR,#data16 load datapointer with a 16-bit constant
MOVC A,@A+DPTR move code byte relative to DPTR to A
MOVC A,@A+PC move code byte relative to PC to A
MOVX A,@Ri move external RAM (8-bit) to A
MOVX A,@DPTR move external RAM (16 bit) to A
MOVX@Ri,A move A to external RAM (8-bit)
MOVX@DPTR,A move A to external RAM (16-bit)
PUSH direct push direct byte onto stack
POP direct pop direct byte from stack
XCH A,Rn exchange register with accu
XCH A,direct exchange direct byte with accu
XCH A,@Ri exchange indirect RAM with A
XCHD A,@Ri exchange low-order digit ind. RAM w. A
Example :
GOTO Test
Test:
When you are using ASM-labels you can also precede them with the !-Sign so the
label won't be converted.
Jb P1.0, Test ; no period
!test : ; indicate ASM label
Example:
$Asm
mov a,#1
test:
sjmp test
$End Asm
Or you can use the BASIC statement SET and RESET which do the same thing.
INTEGER/WORD variables are stored with the LSB at the lowest memory position.
LONG variables are stored with the LSB at the lowest memory position too.
Example :
$RAMSTART = 0
Dim s As String * 10 'reserve 10 bytes + 1 for string terminator
s = "abcde" 'assign string constant to string
Helper routines
There are two ASM helper routines that can make it a bit easier:
PLACEVALUE var , SFR
PLACEADRES var, SFR
Dim x as Byte
Placevalue x ,R0 will generate:
Mov a, h'3A ; in this example only of course
Mov r0,#h'3A
Mov a,@r0
Rl a
Add a,#h'1F
Mov R0,a
Mov a,@r0
These are all examples, the generated code will differ with the type of variables
used.
You can only assign 1 SFR with the PLACEVALUE statement.
This is where PLACEADRES comes around the corner.
Placeadres , places a variables address into a register.
Placeadres ar(x),A
Placeadres z , R0
When external variables are used, you don't need to specify a register because DPTR
is always assigned.
Or with arrays :
PLACEADRES ar(x)
Mov dptr,#2
Mov r0,#h'37
Mov a,@r0
Mov r2,a
Inc r0
Mov a,@r0
Mov r3,a
Mov r1,#1
Acall _AddIndex
Of course these are also examples, the generated code depends on the types and if
they are internal or external variables.
Hexdecimal notation
You can also use hexadecimal notation.
Example : Mov a,#h'AA
Or use the BASIC notation :
Mov a,#&HAA
Binary notation
You can also use binary notation.
Example : Mov a,#&B10001000
This also applies to the other instructions where can be jumped to a label like SJMP,
LJMP DJNZ etc.
Example :
Dim s as single
s = 1.1
Print s 'now the buffer is needed
___TMP_S1 = "Use this space"
Print ___TMP_S1
Comment
The ; sign can be used or the BASIC comment sign '
Mov a,#1 ; comment
Mov a,#2 'comment
The registers and their addresses are defined in the REG51.DAT file which
is placed in the BASCOM application directory.
You can use an other file for other uPs.
You can select the appropriate register file with the Options Compiler settings 60 .
Bit addressable registers can be used with the SET 216 /RESET 212 statements and as
bit-variables.
Byte addressable registers can be used as byte variables.
P1 = 40 will place a value of 40 into port 40.
So you can't use the statement DIM B as Byte because B is an internal register.
You can however manipulate the register with the B = value statement.
A register file has a few sections. The following example shows only a few items
under each section.
The [BIT] section contains all SFR's which are bit addressable. A bit addressable
SFR ends with 0 or 8.
After the SFR name you can write the hexadecimal address.
An optional initial value for the simulator can also be specified. Separate the values
by a comma.
Acc = E0 , 00
longer than 6 characters. As you can see in the example below the last interrupt
T2 has an entry address of 73 (hex). So the org is set to 73+3 = 76 (hex).
You only need to specify the additional interrupts. The interrupts for INT0,INT1,
TIMER0, TIMER1 and SERIAL are already handled by the compiler.
· CLOCKDIV : The division factor of the oscillator. By default this is 12 and when
you don't specify it, 12 will be used. Some micro processors have a division
factor of 6 or 4.
EXAMPLE
[BIT]
ACC = E0
B = F0
[BYTE]
ADCH = C6
ADCON = C5
CTCON = EB
[MISC]
up = 80552
I_TIMER2 = 2B
I_CT0 = 33
I_CT1 = 3B
I_CT2 = 43
I_CT3 = 4B
I_ADC = 53
I_CM0 = 5B
I_CM1 = 63
I_CM2 = 6B
I_T2 = 73
org = 76
IRAM = 256
CLOCKDIV = 12
7.3 Initialization
BASCOM initializes the processor depending on the used statements.
When you want to handle this by yourself you can specify this by the meta
command $NOINIT 98 .
The only initialization that is always done is the setting of the stack pointer and the
initialization of the LCD display (if LCD related statements are used).
You can use the $NOSP 100 statement when you don't want the stack pointer to be
set.
All data used for variables like the internal RAM or external RAM, is in an unknown
condition at startup. This means that you can not assume that a variables is 0.
For example:
Dim a as byte
Print a
End
When you run the code, 'a' can contain any value. When you want to be sure the
variable is 0, assign it with 0. During a reset, the memory content might be the
VIII
Additional Hardware 251
8 Additional Hardware
8.1 Additional Hardware
You can attach additional hardware to the ports of the microprocessor.
The following statements will become available :
I2CSEND and I2CRECEIVE and other I2C related statements.
LCD, LCDHEX, DISPLAY and other related LCD statements.
1 WIRE bus explanation. 258
More about connecting a LCD display 257 .
More about the I2C bus 258
When RS-232 statements such as INKEY, PRINT and INPUT are used, TIMER1 is
connected to the system clock.
So TIMER1 cant be used for other purposes such as ON TIMER1 anymore.
When no RS-232 related statements are used you can use TIMER1.
Clock
The clock frequency is the system frequency divided by 12.
With a 12 Mhz crystal this means that every microsecond the register is
incremented.
You can stop a timer/counter with the statement STOP TIMER0 226 /COUNTER0.
You can start a timer/counter with the statement START TIMER0 225 /TIMER1.
The timer/counter can also be controlled with the alternative pin P3.2.
This pin is labeled for its alternative INT0-input but it can be used to control the
timer.
When GATE is reset the timer/counter is enabled.
When GATE is set the timer/counter is enabled if INT0 is active(low). (provided that
the timer is started)
When the timer/counter is used in mode 2 (auto reload) the reload value can be
specified with the LOAD TIMERx, value statement.
Because it is an 8-bit register a maximum time of 255 uS can be achieved.
So for a period of 10 uS you must supply a value of (256-10) is 246. To make things
easier you can assign the value directly : LOAD TIMERx , 250 will internally be
transformed into 256-250=6.
This saves you the trouble of calculating the correct value.
The COUNTER0 and COUNTER1 variables hold the values of timer/counter 0 and 1.
You can also set the timer/counter contents with the COUNTER0 = value statement.
Please note that with the LOAD statement, you can only load a byte value into the
timer/counter.
Because the statement is meant for timer/counter mode 2.
Also note that you can assign a value to the timer/counter with the COUNTER0/
COUNTER1 variables. You can not use the TIMER0/TIMER1 in it's place but it does
the same thing : assigning/retrieving the timer/counter.
When you make use of the PRINT, INPUT and other RS-232 related statements
P3.0 and P3.1 are used for the RS-232 interface.
When you make use of the INT0/INT1 interrupts, you must connect an interrupt
source to the corresponding pins. A switch for example.
The INTx interrupt can occur on the falling edge of a signal or when the signal is
low.
Use the following statements to specify the trigger:
When TCON.x is RESET the interrupts keep on occurring while the input is low.r
When TCON.x is SET the interrupt only occurs on the falling edge.
To test if a hardware interrupt is generated you can test the TCON.1 and TCON.3
flags.
These flags are set by hardware when an external interrupt edge is detected.
They are reset by the RETURN statement of the interrupt service routine or
subroutine.
TCON.1 must be tested for INT0 and TCON.3 must be tested for INT1.
Some uPs have an additional timer named TIMER2 289 . It depends on the used chip
which features TIMER2 has.
The port 1 output buffers can sink 20 mA and can drive LED displays directly.
When 1s are written to Port 1 pins, they can be used as inputs.
When pins P1.2 to P1.7 are used as inputs and are externally pulled low,
they will source current because of the internal pullups.
Port 3 pins P3.0 to P3.5, P3.7 are seven bi-directional I/O pins with internal pull-
ups.
P3.6 is hard wired as an input to the output of the on-chip comparator and is not
accessible as a general purpose I/O pin.
Writing to a Port
P1 = 255 will write the value 255 to the port 1, setting all the pins to 1
so all pins can be used as inputs.
You can change the LCD pin layout from the Options LCD menu.
You can select the display used with the CONFIG LCD 125 statement.
Note that lcd_control and write_lcd are assembler subroutines which can be called
from BASCOM.
See manufacture details from your LCD display for the correct assignment.
You can also select the SDA and SCL pin with the CONFIG SDA 128 and
CONFIG SCL 128 statement.
With 2 wires, then DQ and ground is used on the device. Power is supplied on the
DQ line, which is +5V, and used to charge a capacitor in the DS device. This power
is used by the device for its internal needs during communication, which makes DQ
go low for periods of time. This bus is called the 1wirebus.
With 3 wires, when +5V is supplied to the VDD line of the device, and DQ +
ground as above. This bus is called the 2wirebus.
So, the ground line is "not counted" by DS. But hereafter we use DS naming
conventions.
When the host (your micro controller (uC)) wants something to happen with the
1w-bus, it issues a reset-command. That is a very simple electric function that
happens then; the DQ goes active low for a time (480uS on original DS 1w-bus).
This put the DS-devices in reset mode; then (they) send a presence pulse, and then
(they) listen to the host.
The presence pulse is simply an active low, this time issued by the device(s).
Now, the host cannot know what is on the bus, it is only aware of that at least 1 DS
device is attached on the bus.
All communication on the 1w-bus is initialized by the host, and issued by time-slots
of active-low on a normally high line (DQ), issued by the device, which is sending at
the moment. The devices(s) internal capacitor supplies its power needs during the
low-time.
When you made a 1w-reset, all devices of the bus are listening. If you chose to
address only one of them, the rest of them will not listen again before you have
made a new 1w-reset on the bus.
I do not describe BASCOM commands in this text - they are pretty much self-
explaining. But the uC has to write the commands to the bus - and thereafter read
the answer. What you have to write as a command depends on devices you are
using - and what you want to do with it. Every DS chip has a datasheet, which you
can find at http://www.dalsemi.com/datasheets/pdfindex.html. There you can find
out all about the actual devices command structure.
There are some things to have in mind when deciding which of the bus-
types to use.
The commands, from BASCOM, are the same in both cases. So this is not a problem.
The +5V power-supply on the VDD when using a 2wire-bus has to be from separate
power supply, according to DS. But it still works with taking the power from the
same source as for the processor, directly on the stabilising transistor. I have not
got it to work taking power directly from the processor pin.
Some devices consume some more power during special operations. The DS1820
consumes a lot of power during the operation "Convert Temperature". Because the
sensors knows how they are powered (it is also possible to get this information from
the devices) some operations, as "Convert T" takes different amount of time for the
sensor to execute. The command "Convert T" as example, takes ~200mS on 2wire,
but ~700mS on 1wire. This has to be considered during programming.
If you use 1wire, there are things to think about. It is about not consuming more
power than you feed. And how to feed power? That depends on the devices (their
consumption) and what you are doing with them (their consumption in a specific
operation).
With +5V through a 4K7 resistor, to the DQ-line, 70 sensors are tested. But, take
care, cause issuing "Convert T" simultaneously, would cause that to give false
readings. About ~15 sensors is the maximum amount of usable devices, which
simultaneously performs some action. This approach DS refers to as "pull-up
resistor".
With this in mind, bus up to 70 devices has been successfully powered this way.
The resistor mentioned, 4K7, could be of smaller value. DS says minimum 1K5, I
have tested down to 500 ohm - below that the bus is not usable any more. (AVR).
Lowering the resistor feeds more power - and makes the bus more noise -resistant.
But, the resistor minimum value is naturally also depending on the uC-pin electric
capabilities. Stay at 4K7 - which is standard recommendation.
DS recommends yet another approach, called "strong pull-up" which (short) works
via a MOS-FET transistor, feeding the DQ lines with enough power, still on 1wire,
during power-consuming tasks. This is not tested, but should naturally work. Cause
this functionality is really a limited one; BASCOM has no special support for that.
But anyway, we tell you about it, just in case you wonder. Strong pull-up has to use
one uC pin extra - to drive the MOS-FET.
DS standard examples show 100 meters cable lengths, so they say, that's no
problem. They also show examples with 300m cabling, and I think I have seen
something with 600-meter bus (but I cant find it again).
Transfer speed
On the original 1w-bus, DS says the transfer speed is about 14Kbits /second. And, if
that was not enough, some devices has an overdrive option. That multiplies the
speed by 10. This is issued by making the communication-time-slots smaller (from
60 uS to 6uS ) which naturally will make the devices more sensitive, and CRC-error
will probably occur more often. But, if that is not an issue, ~140Kbit is a reachable
speed to the devices. So, whatever you thought before, it is FAST.
The BASCOM scanning of the bus is finds about 50 devices / second , and reading a
specific sensors value to a uC should be about 13 devices / second.
Topology
Of the 1w-net - that is an issue we will not cover so much. Star-net, bus-net? It
seems like you can mix that. It is a bus-net, but not so sensitive about that.
DS supplies with different types of devices, which all are made for interfacing an uC
- directly. No extra hardware. There are sensors, so you can get knowledge about
the real world, and there are also potentiometers and relays, so you can do
something about it. On the very same bus.
And the Ibutton approach from DS (ever heard of it?) is based on 1wire technology.
Maybe something to pick up.
BASCOM let you use an uC with 1wire-devices so easy, that (since now) also has to
count as a benefit - maybe one of the largest. ;-)
Göte Haluza
System engineer
IX
264 BASCOM-8051
9 Supported Programmers
9.1 MCS Flash programmer
There are different models of the MCS Flash programmer, but all of them are
compatible with the driver software.
When you run the programmer, the buffer will be filled automatically with your
program data. The programmer works with binary files. The following menu options
are available.
Exit
Exit the programmer.
Buffer clear
Clear the buffer. That is, fill it with zero bytes.
Buffer Verify
Compares the content of the buffer with the content of the chip.
Chip Erase
Erases the chip. Lock bits are also erased.
The programmer can program the AT89S52 which has an extra 2048 bytes built in
EEPROM for storing data and the AT89S53.
The nice thing about SPI-programmable chips is that the chip can be programmed in
circuit. You only must design your application so that the SPI-port pins will not be
pulled low.
File exit
Will exit the programmer.
Write code
Will program the chip with the current programs binary image.
Write data
Will ask for a file and will write the data to the EEPROM.
Verify code
Will verify the programs binary image with the chip content.
Verify data
Will verify a file with the chips EEPROM content.
Read code
Will ask for a filename and will write the chip content to the file.
Read data
Will ask for a filename and will write the EEPROM content to the file.
Chip reset
Will reset the chip.
Chip erase
Will erase the chip.
My PC's LPT port was set to NORMAL mode in the BIOS. Symptoms include
normal reset pulse but very slow progress bar with eventual failure to verify.
parallel port) mode in BIOS. I can only assume that the s/w must be using
one line in bi-directional mode. Of course, this "fix" may only apply to my PC.
The programmer uses the same interface as the MCS Flashprogrammer, but doesn't
support all the features due it's design. So for a description read the MCS
Flashprogrammer 264 help.
File Exit
This will exit the programmer.
Buffer download
With this option you send the programs' hex file to the programmer/simulator.
After it is sent, you can program the chip or simulate the program.
Buffer retrieve
Use this option to load the chip content into the buffer.
Buffer verify
This option will verify the buffer with the chip content.
Buffer autoprogram
This option will erase the chip, download the buffer, program the chip and finally
verifies the chip.
Chip erase
Erases the chip.
Chip program
Will program the chip with the downloaded buffer.
Chip simulate
Will simulate the programmed program. This saves swapping the chip in and out of
the target application.
You must select the target chip from the device list.
Some chips will enable the memory radio buttons. For example the AT89S8252.
You can select the memory-area with the radio buttons in these cases.
Blank check
Will perform a blank check on the chip. That is, every memory location will be
checked if it is equal to 255 (hex FF), indicating an un-programmed byte.
Erase
Will erase the chip. All memory locations will be set to 255.
Program
Will program the chip with the current program.
If EEPROM-memory is selected, you will be asked for a filename.
Verify
Will verify the current program with the target chip.
Read
Will read the target chip and saves the result to a file.
Set lockbit
Will set the selected lock bits.
You must select the lock bits first. The lock bits to set depend on the selected target
chip.
Auto erase
When this checkbox is selected, the target chip will be erased before it will be
programmed.
Auto verify
When this checkbox is selected, the result will be verified after each programming.
Buffer clear
Will clear the buffer.
Chip Erase
Will erase the target chip.
Chip verify
Will verify the buffer with the chipcontent.
Chip autoprogram
Will erase, program and verify the chip.
Note that the targetchip will be detected automatic. When the targetchip can't be
detected, the menu options will not work.
9.7 SE-812
The SE-812 from Sample Electronics is a programmer for the aduc812.
The programmer is well suited for in circuit programming.
Since it is a serial programmer that operates via the COM port, the programming is
done with the terminal emulator. When you select the SE812 from the programmer
options there will be an additional menu in the terminal emulator.
- Erase chip. This option will erase both the code flash and the EEPROM.
- Erase code flash. This option will erase only the code flash memory.
- Program chip. This will program the chip with the current program.
- Auto program. This will erase the chip and program the chip.
The programmer works only with version 2.00 of the boot loader.
What you need is a DB25 centronics male connector, a flat cable and a connector
that can be connected to the target MCU board.
Tip : when testing programmers etc. on the LPT it is best to buy an I/O card for
your PC that has a LPT port. This way you dont destroy your LPT port that is on the
motherboard in the event you make a mistake!
The following picture shows the connections to make. Both a setup for the DT104
and stand alone PCB are shown.
I have been having spurious success with the simple cable programmer from
Sample Electronics for the AVR series.
After resorting to hooking up the CRO I have figured it out (I think). When
trying to identify the chip, no response on the MISO pin indicates that the
Programming Enable command has not been correctly received by the target.
The SCK line Mark/Space times were okay but it looked a bit sad with a slow
rise time but a rapid fall time. So I initially tried to improve the rise
time with a pullup. No change ie still could not identify chip. I was about
to add some buffers when I came across an Atmel app note for their serial
programmer
"During this first phase of the programming cycle, keeping the SCK line
free from pulses is critical, as pulses will cause the target AVR to loose
syncronisation with the programmer. When syncronisation is lost, the only
means of regaining syncronisation is to release the RESET line for more
than 100ms."
I have added a 100pF cap from SCK to GND and works first time every time
now. The SCK rise time is still sad but there must have been enough noise
to corrupt the initial command despite using a 600mm shielded cable.
Regards,
Mark Hayne
When you program the cygnal chip BASCOM will erase and program the chip.
9.10 Futurelec
The Futurelec programmer from www.futurlec.com is an ISP programmer for the
89S8252.
All tests are performed with the AT89S8252 board from Futurelec Electronics.
Select device
Use this option to select the targetdevice. You can choose between the 89S8252 and
the 89S53.
Erase
Erase the target chip.
Read code
Will read the codememory from the chip. You will be asked for a filename first.
Program chip
Set lockbits
Will set the lockbits of the targetchip. All lockbits will be set.
Read EEPROM
Will save the EEPROM data into a file. This only applies to the AT89S8252.
Write EEPROM
Will program the EEPROM with a file. This only applies to the AT89S8252.
Of course all commands can be typed manually too, but you must set the terminal
emulator communication settings to 2400N82 in that case.
Peter also has schematics available on the web so you can build your own PCB.
The programmer supports all the usual features except the 'read signature' feature.
Thats is why you have to select the used chip yourself from the mnu.
The programmer uses the same interface as the MCS Flashprogrammer, so for a
description read the MCS Flashprogrammer 264 help.
I got some feedback from a user that had problems with his programmer.
he added 5K1 pullup resistors to +5V. This is shown in the picture below. The dots
(11) must each have a resistor of 5K1 to +5V.
For those who don't have this kit and the programmer the following schematic
shows how to make your own programmer:
The dongle has a chip with no identification but since the schematic is all over the
web, I have included it. Kanda also sells a very cheap separate programmer dongle.
So I suggest you buy this one!
MCS also sells a compatible dongle.
The following screen will pop up when you have selected this programmer:
You must select the chip you use. By selecting the FlashROM TAB or the EEPROM
TAB you can write that info to the chip. When the chip does not have EEPROM
memory, the EEPROM TAB will not be visible.
When the chip such as the 89S8253, 89S2051 or 89S4051 has USER data, an
additional TAB will be shown.
This is intended to read/write the user data.
When you select auto Flash, pressing F4 from the IDE will program the chip
automatic and the window will not be displayed.
When Code + Data is selected from the programmer options 64 both the Code and
the EEPROM data are programmed.
Transferring your program to RAM goes very fast. Faster than loading it into the
traditional FLASHROM. So during debugging it is well suited for debugging large
applications.
When you select the SCE-51, the following window will appear when you press F4.
You must select the target memory before you click the Program button.
The baud rate is fixed to 19200 baud. Support for 115200 baud will be added later.
When you launch the programmer, the current program will be loaded into the
memory.
You can also use the LOAD button to load a program into the buffer.
Reset This button will reset the programmer and will determine the used chip.
Load Load a binary or Intel HEX file into the buffer
Save Save the current buffer to file
Read Read the chip flash content
Blank Test if a chip is blank
Erase Erase (blank) a chip
Write Write(program) the buffer into the chip
Verify Verify if the buffer is the same as the chip content
Write the selected lock bits
Lock Bits
X
BASCOM Misc 279
10 BASCOM Misc
10.1 Error messages
The following table list all errors that can occur.
Nr Error message
1 BASIC source file not found
2 Code does not fit into FLASHROM
3 Unknown statement
4 Extension expected
5 Wrong variable or variable not dimensioned
6 Two parameters expected
7 No more space for BIT
8 No more space for BYTE
9 No more space for INTEGER/WORD
10 Wrong type (BIT,BYTE or INTEGER/WORD) expected
11 AS expected by DIM
12 , expected
13 Unknown interrupt
14 IF THEN expected
15 FOR, DO or WHILE expected
16 Wrong number of parameters
17 Illegal compare (=,>,<,<>,<=,>=) expected
18 THEN expected
19 TIMER0 or TIMER1 expected
20 DO expected
21 UNTIL expected
22 Illegal mathematical operation
23 FOR expected
24 WHILE expected
25 Variable not dimensioned
26 Source file not found
27 Label not found
100-134 These are internal assembler warnings. Contact MCS
Electronics .
135 Too many RAM used
136 Variable already dimensioned
137 Constant must be in range of 1-8
138 Baudrate not supported with selected frequency
Maximum nesting :
FOR .. NEXT 50
IF .. THEN 50
DO .. LOOP 50
WHILE .. WEND 50
SELECT .. CASE 25
!
;
$INCLUDE
$NOINIT
$NOSP
$NOBREAK
$BAUD
$BGF
$DEFAULT
$CRYSTAL
$LARGE
$LCD
$ROMSTART
$RAMSIZE
$RAMSTART
$SERIALINPUT
$SERIALOUTPUT
$SIM
1WRESET
1WREAD
1WWRITE
ACK
ALIAS
ABS()
AND
AS
ASC()
BAUD
BCD()
BIT
BITWAIT
BLINK
BOOLEAN
BREAK
BYTE
CALL
CASE
CLS
CHR()
CONFIG
CONST
COUNTER
COUNTER0
COUNTER1
CPEEK()
CURSOR
DATA
DEC
DECLARE
DEFBIT
DEFBYTE
DEFLCDCHAR
DEFINT
DEFWORD
DELAY
DIM
DISABLE
DISPLAY
DO
DOWNTO
ELSE
ELSEIF
ENABLE
END
ERR
EXIT
EXTERNAL
FOR
FOURTH
FOURTHLINE
GATE
GETAD
GOSUB
GOTO
HEXVAL()
HIGH()
HIGHW()
HOME
I2CRECEIVE
I2CSEND
I2CSTART
I2CSTOP
I2CRBYTE
I2CWBYTE
IDLE
IF
INC
INKEY
INP()
INPUT
INPUTHEX
INT0
INT1
INTEGER
INTERNAL
IS
LCD
LCDHEX
LEFT
LEFT()
LOAD
LOCATE
LONG
LOOKUP
LOOP
LOW()
LOWW()
LOWER
LOWERLINE
MAKEBCD()
MAKEDEC()
MAKEINT()
MID()
MOD
MODE
NACK
NEXT
NOBLINK
NOSAVE
NOT
OFF
ON
OR
OUT
P0-P6
PEEK()
POKE
POWERDOWN
PSET
PRINT
PRINTHEX
PRIORITY
READ
READEEPROM
REM
RESET
RESTORE
RETURN
RIGHT
RIGHT()
RND()
ROTATE
SELECT
SERIAL
SET
SHIFT
SHIFTLCD
SHIFTCURSOR
SHIFTIN
SHIFTOUT
SHOWPIC
SOUND
SPACE()
START
STEP
STR()
STRING()
STOP
STOP TIMER
SUB
SWAP
THEN
THIRD
THIRDLINE
TIMEOUT
TIMER0
TIMER1
TO
UNTIL
UPPER
UPPERLINE
VAL()
WAIT
WAITKEY
WAITMS
WATCHDOG
WRITEEEPROM
WEND
WHILE
WORD
XOR
XRAM
TCON
P1
SCON
IE
P3
IP
PSW
ACC
B
SP
DPL
DPH
PCON
TMOD
TL0
TL1
TH0
TH1
SBUF
Note that you can change the internal registers with the Register File 60 settings
from the Options menu.
XI
288 BASCOM-8051
11 Microprocessor support
11.1 Microprocessor support
Some microprocessors have additional features compared to the AT89C2051/8051.
8032/8052/AT89S8252
TIMER2 289
AT89S8252
WATCHDOG 235
DATA EEPROM 292
Alternative port-pin functions 256
80515,80535,80517,80535
GETAD 152
WATCHDOG 293
BAUDRATE GENERATOR 119
INTERRUPTS and PRIORITY 293
80517,80537
GETAD 152
WATCHDOG 293
BAUDRATE GENERATOR 119
BAUDRATE GENERATOR1 119
INTERRUPTS and PRIORITY 294
89C51+
WATCHDOG 297
PRIORITY 206
ADUC812
CONFIG ADUC812 117
Using the DAC 294 that also contains an example
The additional interrupts are :
ADCI , I2CSPI and PSMI
To enable them :
ENABLE 145 ADCI, ENABLE I2CSPI, ENABLE PSMI
To disable them:
DISABLE 143 ADCI, DISABLE I2CSPI, DISABLE PSMI
To set the priority to the highest level in addition to the normal priority interrupt
sources:
PRIORITY 206 SET|RESET ADCI
PRIORITY 206 SET|RESET I2CSPI
80552
GETAD(channel, prm) where channel is the channel and the prm is a paramter that
may be 0 for software trigger only or 32(dec) for trigger by rising edge on STADC
too.
11.2 TIMER2
Some microprocessors have an additional timer on board : TIMER2.
This section describes the 8032 compatible TIMER2 and is not compatible with the
TIMER2 found in the 80C535 and others.
TIMER2 is a 16-bit timer/counter which can operate as either an event timer or an
event counter. TIMER2 has three main operating modes : capture, auto-reload(up or
down counting) , and baud rate generator.
When using the TIMER2 interrupt, you must reset the interrupt bit that caused the
interrupt yourself in the ISR handler.
Capture mode
In the capture mode there are two options :
· 16-bit timer/counter which upon overflowing sets bit TF2, the TIMER2 overflow
bit. This bit can be used to generate an interrupt.
Counter mode :
CONFIG TIMER2 = COUNTER, GATE = INTERNAL, MODE = 1
Timer mode:
CONFIG TIMER2=TIMER, GATE= INTERNAL,MODE =1
· As above but with the added future that a 1 to 0 transition on at external input
T2EX causes the current values in the TIMER2 registers TL2 and TH2 to be
captured into the capture registers RCAP2L and RCAP2H.
Counter mode:
CONFIG TIMER2 = COUNTER, GATE = EXTERNAL, MODE = 1
Timer mode:
CONFIG TIMER2=TIMER,GATE=EXTERNAL,MODE=1
In addition the transition at T2EX causes bit EXF2 in T2CON to be set and EXF2 like
TF2 can generate an interrupt.
The TIMER2 interrupt routine can interrogate TF2 and EXF2 to determine which
event caused the interrupt.
(there is no reload value in this mode. Even when a capture event occurs from T2EX
the counter keeps on counting T2EX pin transitions or osc/12 pulses)
Counter mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL,MODE=0
Timer mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL,MODE=0
Counter mode:
CONFIG TIMER2=COUNTER,GATE=EXTERNAL,MODE=0
Timer mode:
CONFIG TIMER2=TIMER,GATE=EXTERNAL,MODE=0
TIMER2 can also count up or down. This mode allows pin T2EX to control the
direction of count. When a logic 1 is applied at pin T2EX TIMER2 will count up.
TIMER2 will overflow at &HFFFF and sets the TF2 flag, which can then generate an
interrupt, if the interrupt is enabled. This timer overflow also causes the 16-bit
value in RCAP2L en RCAP2H to be reloaded in to the timer registers TL2 and TH2.
Counter mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL/EXTERNAL,MODE=0,DIRECTION=UP
Timer mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL/EXTERNAL,MODE=0,DIRECTION=UP
A logic 0 applied at pin T2EX causes TIMER2 to count down. The timer will under
flow when TL2 and TH2 become equal to the value stored in RCAP2L and RCAP2H.
TIMER2 under flows sets the TF2 flag and causes &HFFFF to be reloaded into the
timer registers TL2 and TH2.
Counter mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL/EXTERNAL,MODE=0,
DIRECTION=DOWN
Timer mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL/EXTERNAL,MODE=0,
DIRECTION=DOWN
The external flag TF2 toggles when TIMER2 under flows or overflows.
The EXF2 flag does not generate an interrupt in counter UP/DOWN mode.
Receive only
This mode can be used to generate the baudrate for the receiver only.
TIMER1 can be used for the transmission with an other baudrate.
CONFIG TIMER2=TIMER,GATE=INTERNAL,MODE=3
Transmit only
This mode can be used to generate the baud rate for transmitter only.
TIMER1 can be used for the reception with an other baudrate.
CONFIG TIMER2=TIMER,GATE=INTERNAL,MODE=4
Clock output
Some 8052 deviants have the ability to generate a 50% duty cycle clock on P1.0.
CONFIG TIMER2=TIMER,MODE=5
Timer2_ISR:
If T2CON.7 = 1 Then
Print "Timer overflowed"
Reset T2con.7
Else
If T2CON.6 = 1 Then
Print "External transition"
Reset t2con.6
End if
End If
Return
Example
Dim S As String * 15 , S2 As String * 10
S = "Hello" : S2 = "test"
Dim L As Long
L = 12345678
Writeeeprom S
Writeeeprom S2 'write strings
Writeeeprom L 'write long
See also
CONFIG WATCHDOG 132
Example
'-----------------------------------------------------
' (c) 1998 MCS Electronics
' WATCHD.BAS demonstrates the AT89S8252 watchdog timer
' select 89s8252.dat !!!
'-----------------------------------------------------
Config Watchdog = 2048 'reset after 2048 mSec
Start Watchdog 'start the watchdog timer
Dim I As Word
For I = 1 To 10000
Print I 'print value
' Reset Watchdog
'you will notice that the for next doesnt finish because of the reset
'when you unmark the RESET WATCHDOG statement it will finish because the
'wd-timer is reset before it reaches 2048 msec
Next
End
Enable interrupts:
ENABLE AD 'AD converter
ENABLE INT2|INT3|INT4|INT5|INT6 'external interrupt 2-6
ENABLE TIMER2EX 'timer2 external reload
Disable interrupts:
DISABLE AD 'AD converter
DISABLE INT2|INT3|INT4|INT5|INT6 'external interrupt 2-6
DISABLE TIMER2EX 'timer2 external reload
Selecting of priority:
PRIORITY SET|RESET source , level
level can be 0,1,2 or 3.(0=lowest,3=highest)
TIMER1/INT4
SERIAL/INT5
TIMER2/INT6
Enable interrupts:
ENABLE AD 'AD converter
ENABLE INT2|INT3|INT4|INT5|INT6 'external interrupt 2-6
ENABLE TIMER2EX 'timer2 external reload
ENABLE CTF 'compare timer interrupt
ENABLE SERIAL1 'serial1 interrupt
Disable interrupts:
DISABLE AD 'AD converter
DISABLE INT2|INT3|INT4|INT5|INT6 'external interrupt 2-6
DISABLE TIMER2EX 'timer2 external reload
DISABLE CTF 'compare timer interrupt
DISABLE SERIAL1 'serial1 interrupt
Selecting of priority:
PRIORITY SET|RESET source , level
level can be 0,1,2 or 3.(0=lowest,3=highest)
source can be :
INT0/ADC/SERIAL1
TIMER0/INT2
INT0/INT3
TIMER1/CTF/INT4
SERIAL/INT5
TIMER2/INT6
Note that only one of the TRIPLE-pairs must be selected.
PRIORITY SET INT4,3 'will set INT4 to the highest priority.
When two ints occur with the same priority the first source in the list will be handled
first. So when both TIMER1 and INT4 have the same priority, TIMER1 will be
serviced first.
Look at a datasheet for more details.
You can use the CONFIG ADUC812 117 statement to set the DAC behaviour.
The sync bit is reset and to sync the DAC with the supplied values use :
DAC.SYNC
Note that the SYNC method operates on both DACS and so there is no 0 or 1
specified!
All the previous methods shown can work with 0 for DAC0 or 1 for DAC1.
'---------------------------------------------------------------------
' ADCU812.bas (c) 2000 MCS Electronics
' Note that the support for this chip is untested
' Any feedback appreciated!
'---------------------------------------------------------------------
'Use this dat file
$regfile = "812.dat"
'configure ADC
Config Aduc812 = Adcon , Mode = Normal , Clock = 1 , Aquisition = 1 , Timer2 =
Disabled , Extrig = Disabled
'configure DACS
Config Aduc812 = Dac , Mode = 12 , Range1 = Vref , Range0 = Vref , Clear0 =
False , Sync = Enabled , Power0 = On , Power1 = Off
'dim variables
'and after setting the value(s) the dacs must be updated with the sync method
Dac.sync
Sub Write_ebyte
Page = Eeadr \ 4 'page
mov edarl,{page} ; page address
mov econ,#1 ; read 4 current bytes
mov econ,#5 ; erase page
Waitms 20 'wait 20 msecs
Page = Page * 4
Page = Eeadr - Page
If Page = 0 Then
Sub Read_ebyte
Page = Eeadr \ 4 'page
mov edarl,{page} ; page address
mov econ,#1 ; read 4 current bytes
Page = Page * 4
Page = Eeadr - Page
If Page = 0 Then
mov {EEbyte},edata1 ; data register to read
Elseif Page = 1 Then
mov {eebyte},edata2 ; data register to read
Elseif Page = 2 Then
mov {eebyte},edata3 ; data register to read
Else 'must be 3
mov {eebyte},edata4 ; data register to read
End If
mov econ,#2 ; write registers
End Sub
End
11.9 89C51
The 89C51 has an additional PCA interrupt.
The priority mechanism is also different compared to a normal 8051.
You can set a level in the range from 0-3.
PRIORITY SET|RESET source , level
level can be 0,1,2 or 3.(0=lowest,3=highest)
XII
300 BASCOM-8051
12 International Resellers
12.1 International Resellers
The list with resellers is updated frequently. Please look at the resellers list at the
MCS website :
http://www.mcselec.com/index.php?option=com_contact&catid=82&Itemid=59
XIII
302 BASCOM-8051
13.1.1 Grifo
EXAMPLES
BASCOM - BASIC
· Examples - \BASCOM-8051
· Examples - \BASCOM-AVR
x_AD4
This program monitors one analogue channel out of four, managed by IC12
(PCF8591), visualization of the channel is in hexadecimal format, through T1 the
channel to convert is selected: Whenever a key is pressed, an acoustic signal is
emitted.
Display DY1 shows the channel to convert, while displays DY3 and DY4 show the
converted value in HEX.
Before compiling set in menu Option/Compiler/Misc: Byte End 5F; Register File
89c1051.DAT or 8052.DAT.
For use with 8xC51/52 modify the source where the pins used are described
replacing pins for 89c1051 with pins for 8xc51.
x_DA
This program monitors one D/A converter channel on IC2 (PCF8591), key T1
increments the value, while key T2 decrements the value which is shown in
hexadecimal format the 7 segments displays.
Whenever a key is pressed, an acoustic signal is emitted.
Before compiling set in menu Option/Compiler/Misc: Byte End 5F; Register File
89c1051.DAT or 8052.DAT.
For use with 8xC51/52 modify the source where the pins used are described
replacing pins for 89c1051 with pins for 8xc51.
x_REE
This program allows to read a serial EEPROM on IC4 (max 24c08), with addresses
ranging from &H400 to &H7ff, addresses from &H0 to &H0FF are taken by IC7 (RTC
PCF8583) while addresses from &H100 to &H3FF are free space.
At start the program shows the address where to write, through keys T1 and T2 the
value in incremented or decremented.
Through key T3 the address is accepted and the value read at such address is
shown.
Whenever a key is pressed, an acoustic signal is emitted.
Before compiling set in menu Option/Compiler/Misc: Byte End 5F; Register File
89c1051.DAT or 8052.DAT.
For use with 8xC51/52 modify the source where the pins used are described
replacing pins for 89c1051 with pins for 8xc51.
x_WEE
This program allows to write to a serial EEPROM on IC4 (max 24c08), with
addresses ranging from &H400 to &H7ff, addresses from &H0 to &H0FF are taken by
IC7 (RTC PCF8583) while addresses from &H100 to &H3FF are free space.
At start the program shows the address where to write, through keys T1 and T2 the
value in incremented or decremented.
Through key T3 the address is accepted, then the value to write is selected through
T1 and T2, as last press key T3 to write.
Whenever a key is pressed, an acoustic signal is emitted.
After the operation is terminated the selected address and the written data are
shown one after the other.
Before compiling set in menu Option/Compiler/Misc: Byte End 5F; Register File
89c1051.DAT or 8052.DAT.
For use with 8xC51/52 modify the source where the pins used are described
replacing pins for 89c1051 with pins for 8xc51.
x_LCD
This program allows to manage an alphanumeric LCD featuring a number rows and
columns definable by User.
The display must be connected to CN5 following the connections shown in the
diagram of K51-AVR page 4 of 4.
Before compiling select in menu Option/Compiler/Misc/ :
Byte End 5F, Register File REG51.DAT
In menu Option/ LCD select:
Db4 = P1.5 , Db5 = P1.6 , Db6 = P1.7 , Db7 = P1.2 , E
= P1.4 , Rs = P1.3
x_PPI
This program shows, in hexadecimal format, the status of the eight lines connected
to IC1 (PCF8547A9).
Before compiling set in menu Option/Compiler/Misc: Byte End 5F; Register File
89c1051.DAT or 8052.DAT.
For use with 8xC51/52 modify the source where the pins used are described
replacing pins for 89c1051 with pins for 8xc51.
x_PPO
This program activates sequentially one at a time all the 8 lines connected to IC1
(PCF8574A).
Before compiling set in menu Option/Compiler/Misc: Byte End 5F; Register File
89c1051.DAT or 8052.DAT.
For use with 8xC51/52 modify the source where the pins used are described
replacing pins for 89c1051 with pins for 8xc51.
x_PPO2
This program turns on in sequence the 16 TTL lines available on connector CN3.
Before compiling select in menu Option/Compiler/Misc/ :
Byte End 5F; Register File 8052.DAT
x_RTC
This program allows you to show the RTC or Real Time Clock on IC7 (PCF8583) to
the four 7 segments displays: To set the RTC values keys T2 and T3 are used, in
detail key T2 increments the hours and T3 increments the minutes.
Whenever one of the two keys is pressed the seconds are reset.
Key T1 switches between visualization of seconds and hours.
Whenever a key is pressed, an acoustic signal is emitted.
Date and eventual alarm are not managed: Before compiling set in menu Option/
Compiler/Misc: Byte End 5F; Register File 89c1051.DAT or 8052.DAT.
For use with 8xC51/52 modify the source where the pins used are described
replacing pins for 89c1051 with pins for 8xc51.
x_TER
This program reads the temperature measured by IC3 (DS1621) and shows it in
centigrade degreases with values ranging from -55 to +125.
Before compiling set in menu Option/Compiler/Misc: Byte End 5F; Register File
89c1051.DAT or 8052.DAT.
For use with 8xC51/52 modify the source where the pins used are described
replacing pins for 89c1051 with pins for 8xc51.
KND_08
This program allows to manage the board resources of KND 08 card through a
menu, using 2 TTL lines driven by a family 51 micro controller.
This program is managed through a RS 232 serial line, so it is essential to connect a
free COM port of the PC to connector CN2 of K51-AVR.
To configure the BASCOM 8051 terminal in menu Options/Communication select the
COM port and set Baud Rate to 19200, parity to none, data bits to 8, stop bits to 1.
The board used to drive KND 08 is K51-AVR, connections are:
K51-AVR ................ KND 08
L1 (pin4 CN6) ----> SC (pin2 CN1 KND08)
L2 (pin5 CN6) ----> SD (pin1 CN1 KND08)
KND_44
This program allows to manage the board resources of KND 44 card through a
menu, using 2 TTL lines driven by a family 51 micro controller.
This program is managed through a RS 232 serial line, so it is essential to connect a
free COM port of the PC to connector CN2 of K51-AVR.
To configure the BASCOM 8051 terminal in menu Options/Communication select the
COM port and set Baud Rate to 19200, parity to none, databits to 8, stopbits to 1.
The board used to drive KND 44 is K51-AVR, connections are.
K51-AVR .................. KND 44
L1 (pin4 CN6) ----> SC (pin2 CN1 KND44)
L2 (pin5 CN6) ----> SD (pin1 CN1 KND44)
Supply both the boards.
Before compiling in menu Option/Compiler/Misc set Byte End(Hex) = 60.
KAD_08
This program manages a sliding alphanumeric message on eight 14-segments
displays, installed on KAD 08 board, through 2 TTL signals driveb by a micro
controller of family 51.
The master board is K51-AVR which must be connected to KAD 08 as follows:
K51-AVR ........... KAD 08
L1 (pin4 CN6) ----> SC (pin2 CN1 KAD08)
L2 (pin5 CN6) ----> SD (pin1 CN1 KAD08)
Supply both the boards.
Before compiling in menu Option/Compiler/Misc set Byte End(Hex) = 70.
KAD_08_2
This program allows to manage the resources on the KAD 08 board through a menu
and 2 TTL lines driven by a micro controller of the 51 family.
This program is controlled through the RS 232 serial line so it is essential to connect
a free COM port on the PC to the connector CN2 of K51-AVR.
Configure the BASCOM 8051 terminal using menu Option/Communication, select the
COM port and set baud rate to 19200, parity to none, data bits to 8 and stop bits to
1.
The master board is K51-AVR which must be connected to KAD 08 as follows:
K51-AVR ........... KAD 08
L1 (pin4 CN6) ----> SC (pin2 CN1 KAD08)
L2 (pin5 CN6) ----> SD (pin1 CN1 KAD08)
Supply both the boards.
Before compiling in menu Option/Compiler/Misc set Byte End(Hex) = 50.
EXAMPLEs
BASCOM-LT
for K51-AVR.
K51-AVR
DEMO_AD11, DEMO_AD4, DEMO_DA, DEMO_REE, DEMO_WEE, DEMO_LCD,
DEMO_PPI, DEMO_PPI1, DEMO_PPO, DEMO_PPO1, DEMO_PPO2,
DEMO_RTC, DEMO_TER,
EXAMPLEs
BASCOM-8051
for K51-AVR..
K51-AVR
51_AD11, 51_AD4, 51_DA, 51_REE, 51_WEE, 51_PPI, 51_PPO, 51_RTC,
51_TER
GPC® F2
F2_AD11, F2_AD4, F2_DA, F2_REE, F2_WEE, F2_PPI, F2_PPO, F2_RTC,
F2_TER
GPC® F2
F2_KND_08, F2_KND_44, F2_KAD_08, F2_KND_08_2
EXAMPLEs
BASCOM-AVR
for K51-AVR.
K51-AVR
DEMO_AD11, DEMO_AD4, DEMO_DA, DEMO_REE, DEMO_WEE, DEMO_PPI,
DEMO_PPO, DEMO_RTC, DEMO_TER
GRIFO®
Via dell'Artigiano, 8/6
40016 San Giorgio di Piano
Bologna ITALY
13.1.2 Rhombus
Rhombus developed the SCE-51. A powerful small 8051 micro processor board with
on board RAM and FLASHROM and bootloader.
In addition the board serves as an in circuit emulator.
Transferring your program to RAM goes very fast. Faster than loading it into the
traditional FLASHROM. So during debugging it is well suited for debugging large
applications.
There are many possibilities with this board and you have to look at www.
rhombusinc.com for all the details.
1WRESET 83
Index 1WSEARCHFIRST
1WSEARCHNEXT
85
87
1WWRITE 83
-#- -8-
#ELSE 81 8032_Alternative port-pin functions 256
#ENDIF 82 8032_TIMER2 289
#IF 80 80515_WATCHDOG 293
89C51 297
-$-
-A-
$BAUD 89
$BGF 89 ABS 109
$CRYSTAL 91 Additional Hardware 251
$DEFAULT XRAM 92 ALIAS 108
$END ASM 88 ASC 110
$EXTERNAL 92 AT898252 WATCHDOG 292
$INCLUDE 93 AVG 110
$IRAMSTART 94
$LARGE 94 -B-
$LCD 95, 97
$LCDRS 96 BASCOM 38
$LIB 95 BASCOM statements 77
$NOBREAK 97 BAUD 111
$NOINIT 98 BCD 112
$NONAN 98 BITWAIT 112
$NONULL 99, 136 Blow IT Flashprogrammer 267
$NORAMCLEAR 99 BREAK 113
$NOSP 100 BROWSE001e 144
$OBJ 100
$RAMSIZE 101 -C-
$RAMSTART 103
$RAMTRON 101 CALL 113
$REGFILE 104 CASE 216
$ROMSTART 104 CHR 114
$SERIALINPUT 105 CLOSE 198
$SERIALINPUT2LCD 105 CLS 115
$SERIALOUTPUT 106 Compiler Limits 282
$SIM 107 CONFIG 116
$TIMEOUT 107 CONFIG 1WIRE 117
$WAIT 108 CONFIG ADUC812 117
CONFIG BAUD 119
-1- CONFIG BAUD1 119
CONFIG DEBOUNCE 120
1WIRE 258 CONFIG GETRC 121
1WIRECOUNT 84 CONFIG GRAPHLCD 121
1WREAD 83 CONFIG I2CDELAY 120
-J- -O-
JPK Systems X-programmer 272 ON interrupt 196
ON value 197
-K- OPEN 198
Options Communication 60
Keyword Reference 17 Options Compiler Communication 58
Options Compiler I2C 58
-L- Options Compiler LCD 59
Options Compiler Misc 60
Language fundamentals 70 Options Compiler Output 57
LCASE 178 Options Environment 62
LCD 178 Options hardware simulator 64
LCD designer 54 Options Monitor 65
LCDHEX 182 Options Printer 66
LCDINIT 181 Options Programmer 64
Window tile 67
Windows minimize all 67