Home
bascom-8051
Contents
1. 53 LEICA Meanie CTT e DRM 54 2007 MCS Electronics Contents 5 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 Part V 1 Part VI o BR ON h h N Tools Graphic Converter ss isniinnnnnennnnennnnnnnneenenennneenenneente 54 Tools LIB Manager 55 Tools Triscent CONVE EE ts den ii 56 TOOLS Expr 57 Options Compiler Output anas asas 57 Options Compiler Communication seen 58 Options Compiler 2 58 Options Compiler ECD 59 Options Compiler Rasen 60 Options Communication asas nn Rasa na n 60 Options Environment EID dicere 62 Options hardware simulator init 64 Options Programmer 2 04
2. 196 145 ON WAM ioe aaE 197 146 OPEN des Se Sak e Li EM 198 a Tano E ERIT DTE 200 148 PORT EEE EE T T 201 149 PEEK k eu RE PEE 202 WSO POKE EEA A A A A E T AAEE 202 151 POWERDOWN meer 203 152 dinem A ne 203 153 A A T H 204 154 PRIN THE X 55555200 205 155 PRIOR Y Re RP nee 206 156 PSET E E AE A AA EA E a 207 OA PUT LM CC aC 207 158 READ EET EE E T E T 208 159 READMA CCAR ipm 209 d uii apaec 211 161 idus ie c 211 162 RESET iie e cien Ite ene Ir euer nn ete anses 212 163 b hnic iie 212 164 tur nee tette reset nee me anse manne se tue done see 213 165 clue een ee 214 166 RND eniin en A OT 214 1617 LU 215 168 5 leue uu e ca voce 216 169 SET 216 170 SHIFT CURSOR
3. 40 File Save AS o 40 File Print Previ W onire LEE EE 40 uade RS 41 PHC EXE E 41 C 42 zac M 42 Edit COPY E 42 cage 42 tete E mue nie 43 Edit Find M nn 43 Edit 43 Edit coche races eee cease aea Aaa a uere e nn Nues re 44 scr 44 Edit indent Block 1 0 su sus 45 Edit Unindent Block 3 45 perd Cup 46 Program Compile sissisodan eeina 47 Program Syritax etre e rapra Sa de rere cea 47 Program Show Result s n Da doses 48 Program 51 49 Program Send to chip ec nn tan ne nette tien 52 Tools Terminal Emulator
4. 85 1WSEARCHNEXT M 87 SASM END ASM c 88 SBAUD 5 89 EA 89 Ple R4 p Me 91 2007 MCS Electronics BASCOM 8051 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 DEFAULT XRAM 5 92 Heli 92 SINGLUDE DD 93 SIRAMSTART M CEU 94 SIAR GE ot e 94 UB cm 95 Lc E S 95 NIME 96 LA PNR RE ME 97 22022 en dr 97 hielt 98 os 98 FAI IUBE 99 CR 99 SNOSP eer RC EET 100 RE EE RER een 100 SRAMSIZE A EEEE N E EE 101 Meere 101 5 Me DE 103 E nn en se 104
5. Remote control Remote control statements send or receive IR commands for remote control GETRC5 164 RS 232 RS 232 are serial routines that use the UART or emulate a UART WAITKEY 2h PRINT 208 PRINTBIN oh PRINTHEX 201 PUT 2071 OPEN 198 SPC eh INKEY 1711 INPUT 175 INPUTBIN 51 6 GET list CLOSET SPI SPI routines communicate according to the SPI protocol with either hardware SPI or software emulated SPI SPIIN 225 SPIOUT 2251 SPIINIT 2201 String String routines are used to manipulate strings 2007 MCS Electronics INDEX 19 5 MID sh LCASE 1177 LEFT LEN fish RIGHT 214 STRING zzi REPLACE af SPACE zzh UCASE sh Text LCD Text LCD routines work with the normal text based LCD displays CLS 11151 CURSOR 53i FOURTHLINE 145 HOME i65 LCD 1781 LCDINIT 8h LCDHEX 182 LOCATE 85 SHIFTLCD 29 SHIFTCURSOR lei DISPLAY 145 LOWERLINE 185 UPPERLINE 232 THIRDLINE 230 Various This section contains all statements that were hard to put into another group CALL 1 33 CONST 6 COUNTER 131 DECR 138 DECLARE 13 DEFINT 140 DEFBIT 1401 1401 DEFLCDCHAR 14 DEFWORD 1401 GETAD 152 GETAD2051 153 158 GOSUB 162 13 INCR 1711 LOAD eh LOOKUP 85 LOOKUPSTR 11861 LOW 1871 LOWW 11881 O
6. la den 233 E 233 234 E E 234 WAITMSE 235 liec 235 iz oec 236 Using assembly 239 Using assemly 5 2 239 Internal registefs uere ure i dereud eM IST 246 Uter utt pc 248 Additional Hardware 251 Additional Hardware sis nnne nnn nsn insunt h inne nnns sanie nnne 251 Alternative port pin functions 256 Hardware LCD display nri ieu 257 Hardware 2C 258 juice M 258 Supported Programmers 264 MCS Flash programmer 264 MCS SPI programmer ce cece tiec a sao dure anne arc 266 Blow Flashprogrammer 267 PG2051 flash programmer ane ie 267 PG302 p
7. M 121 CONFIG GRAPHLGD Lew 121 CONFIG EC DPI e 125 CONFIG LOD ne 125 CONFIG LGD BUS o D 126 CONFIG MICRO VIRE 2 ts 127 CONFIG PRINT engage sets mate nn ce 127 5 A 128 CONFIG SDA M 128 leen zicRizli4orluee cmm 129 CONEIGISPI ep EE 130 CONFIG TIMERO TIMER 131 CONFIG WATCHDOG sseni 132 COUNTER 2 132 enun MI 134 CURSOR pP 135 eT 136 DEBOUNGCGE viisi 137 pen E E T 138 zie ODE 139 140 2 CP es aiment anne 140 DELAY pM 141 DIM idt eit a a vnda da RN tue 141 DISABLE SOR M MI DEI MUI 143 PERIERE 143 DO nd 144 ELSE 144 III 145 AE 146 eL 146 ERASE EL 147 EXIT
8. 148 FOR M 148 FOUR TEI NE Et 149 EUSING 150 CE En a a 151 GETAD EE EE 152 2007 MCS Electronics BASCOM 8051 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 2081 153 E 158 ic u d ene 160 GOS WB orc E 162 copo 163 Q2 ETUR 163 24 164 cin Ma ALIE 164 PGW ET EE 165 EE 166 2 166 praelo 167 roe ERES 168 joa 169 URS ra Na UR La SCR ARE LR NE E COSA RR 169 INCR rss 171 INKE Ke 171 CN dense 173 UN PUT Me 173 eI 175 INPUT IBA eL 176 INSTR d 177 oJ Vc cipes E ERE 178 oo EUN 178 ei ue ELE 181 Hei zb E PT d 182 LEFT
9. 6 80515 222 240 0 toca e aerea dn oo a pea aiina 293 6 INTERRUPTS and PRIORITY 80515 293 7 INTERRUPTS and PRIORITY 80537 294 8 ADUG 812 ssc a a edt 294 BOC SN 297 Part XII International Resellers 300 1 International Resellers 300 Part Third party hardware 302 1 Third party Hardware 302 cu M r see 302 RROMBUS ETE 309 Index 311 2007 MCS Electronics INDEX 13 1 INDEX 8051 LECTRONICS Ox mms Batic Convent ICCLOPPCNT 1995 2007 MCS Electronics Help Version 2 0 14 0 See Installing BASCOM 8051 21 for the installation procedure IMCS Electronics may update this documentation without notice Products specification and usage may change accordingly MCS Electronics will not be liable for any miss information or errors found in this document software provided with this product package is provided AS IS without any warranty expressed or implied MCS Electronics will not be liable for any dama
10. 64 Options Monitor nn ee 65 Options Printer rne nn 66 Window Ecce 66 WOOW UI eec 67 Window arrange ICONS enne nennen nnne nint nain nennen anie nnn annie nnns 67 Window minimize all niece certe reete 67 Fle Ip ADO UU rte 67 Help Index 5 06 2 67 Flelp on ge 67 ade 68 Help Foru em 68 Help S pport 5 eene ee 68 Help 68 Language fundamentals 70 Language fundamentals 70 BASCOM Language Reference 77 BASCOM 77 t nn pere aae e nee antenne nette eme nel 80 HELGE EP 81 dati nas 82 83 jdizeelree 84 jd zc viedd ye M
11. cada an su suce Inna nee sad 183 DEN qn evo cuu e dust d IE 183 Roy iom REUS 184 LOG AT Bio secs PR 185 PR 185 ep T 186 No gre PR D LM 187 LOWW e S 188 E A E A te fee 188 dried 189 LhLi4d dc sine 189 MANKEINT uitio ci aac can unser niae tie a sante ara nan ic cava oa adam uk dur aa sk 190 LE 190 MID 191 5 en sr ans ges esse tes 192 MOD Rs nee eL de hix ub elsi 192 2007 MCS Electronics Contents 9 139 MWINIT eter 193 140 MWREAD D a EA EEA EAE A 193 141 MWWOPGCODBDBE 5 2 0 041 194 2 TU 195 pq 196 144 ON Bm
12. 2007 MCS Electronics Updates 35 MCS Auto Update Wiz 1 0 0 13 Downloading MCS ELECTRONICS MCS Auto Update BASIC COMPILERS 125415224274 Downloading help zip 2 0 13 0 IMPORTANT Run setupio8051 exe after the Wizard has finished Setupio8051 exe is located in the BASCOM 8051 Application dir Vista and Xp 64 supported a Help During the download you will see the history file When all packages are downloaded they will be installed unzipped Press the Next button to install the downloaded files MCS Auto Update Wiz 1 0 0 13 Install New Files 8 ELECTRONICS MCS Auto Update rocd DEVEL Archive Progress _ ERBEBEBEB File Progress BASCOM EEE During the installation you will see the progress When installation is ready you need to press the Finish button The Wiz can also backup all files it will replace 2007 MCS Electronics BASCOM IDE 37 4 BASCOM IDE 41 RUNNING BASCOM 8051 When you run BASCOM 8051 the following window will appear IT 8051 IDE DER File Edit Program Tools Options Window Help vr C DATA apps D7 BASCOM SAMPLES 89540451 BAS 8954051 5 c 1995 2006 MCS Electronics demonstration file for the ATMEL 8954051 Select the STK200 programmer for ISP programming Sregfile 8934051 dat crystal 8000000 Do P3 PB 1 Vait 1 Loop
13. 2007 MCS Electronics 64 BASCOM 8051 BASCOM 8051 Options X Hardware simulator Programmer Monitor Printer Editor Font IDE V Tooltips Pi C Program Files Borland Show Toolbar Save file as for new files Tool tips ill enable disable tool tips Show Toolbar ill display hide the toolbar of the IDE hen you enable this option you will be prompted to give new iles a name before they will be saved with their default name File location he path to the location of your BAS files Normally Windows ill use My documents as a default 4 41 Options hardware simulator This option let you select the address of the LPT connected to the optional hardware simulator 4 42 Options Programmer This option let you select the target programmer The supported programmers are MCS Flashprogrammer 264 Blow IT programmer 267 PG2051 25 MCS SPI programmer 2661 PG302 268 JPK Systems X programmer 2721 Peter Averill s TAFE programmer 273 SE512 or SE514 26 SE 812 270 CYGNAL 272 FutureLec 272 SE511 SE516 276 2007 MCS Electronics BASCOM IDE 65 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 BASCOM 8051 Options Compiler Communication Enviro
14. he name of the parameter You must end each subroutine with the END SUB statement You must Declare Sub procedures before the SUB statement The parameter names and types must be the same in both the declaration and the Sub procedure Parameters are global to the application That is the used parameters must be dimensioned with the DIM statement Therefore the variables can be used by the program and sub procedures The following examples will illustrate this Dim a as byte b1 as byte c as byte dim used variables Declare Sub Test a as byte declare subroutine a 1 bl 2 c 3 assign variables Printa bl c print them 2007 MCS Electronics 230 BASCOM 8051 Call Test b1 call subroutine Print a b1 c print variables again End Sub Test a as byte begin procedure subroutine printa b1 c print variables End Sub See also 15 DECLARE 7 Example NONE 6 188 SWAP Action Exchange two variables of the same type Syntax SWAP vari var2 Remarks A variable of type bit byte integer or word A variable of the same type as vari After the swap 1 will hold the value of var2 and var2 will hold the value of vari Example Dim a as integer b1 as integer a 1 bi1 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 2007 MCS Electronics BASCOM L
15. 2007 MCS Electronics Microprocessor support 297 mov edatal eebyte Elseif Page 1 Then mov edata2 eebyte Elseif Page 2 Then mov edata3 ebyte Else mov edata4 eebyte End If mov econ 2 End Sub Sub Read ebyte Page Eeadr 4 mov edarl page mov econ 1 Page Page 4 Page Eeadr Page If Page 0 Then mov EEbyte edatai Elseif Page 1 Then mov eebyte edata2 Elseif Page 2 Then mov eebyte edata3 Else mov eebyte edata4 End If mov econ 2 End Sub End 11 9 89C51 The 89C51 has an additional PCA interrupt data register to write data register to write data register to write must be data register to write write registers page page address read 4 current bytes data register to read data register to read data register to read must be data register to read write registers 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 The source can be INTO TIMERO INT1 TIMER1 SERIAL TIMER2 PCA 2007 MCS Electronics 298 BASCOM 8051 PRIORITY SET INTO 3 will set INTO to the highest priority Look at a datasheet for more details The WATCHDOG can be started with the statement START WATCHDOG RESET WATCHDOG must be used in your program to re
16. 182 BASCOM 8051 Config Pin Db4 P3 1 Db5 P3 2 Db6 3 3 Db7 P3 4 P3 5 Rs P3 6 Rem with the config lcdpin statement you can override the compiler settings Dim As Byte Config Led 16 2 configure lcd screen other options are 16 4 and 20 4 20 2 16 la When you dont include this option 16 2 is assumed 16 la is intended for 16 character displays with split addresses over 2 lines SLCD address will turn LCD into 8 bit databus mode use this with uP with external RAM and or ROM 1 because it doesnt need the port pins these 2 lines can be used when WR is connected to P1 0 for example 1 0 0 INITLCD Cls clear the LCD display Led Hello world display this at the top line Wait 1 Lowerline select the lower line Wait 1 Led Shift this display this at the lower line 6 122 LCDHEX Action Send variable in hexadecimal format to the LCD display Syntax LCDHEX var Remarks ariable to display vari Byte Integer Word Long Single Constant The same rules apply as for 2051 See also 2007 MCS Electronics BASCOM Language Reference 183 LCD 178 Example Dim a as byte a 255 LCD Lowerline LCDHEX a End 6 123 LEFT Action Return the specified number of leftmost characters in a string Syntax var LEFT vari n Remark
17. 2007 MCS Electronics BASCOM Language Reference Data amp H45 Data amp H44 Data amp H44 Data amp H44 Data amp H43 Data amp H43 Data amp H42 Data amp H42 Data amp H42 Data amp H41 Data amp H41 Data amp H40 Data amp H40 Data amp H40 Data amp H39 Data amp H39 Data amp H39 Data amp H38 Data amp H38 Data amp H38 Data amp H37 Data amp H37 Data amp H37 Data amp H36 Data amp H36 Data amp H36 Data amp H35 Data amp H35 Data amp H35 Data amp H34 Data amp H34 Data amp H34 Data amp H33 Data amp H33 Data amp H33 Data amp H32 Data amp H32 Data amp H32 Data amp H31 Data amp H31 Data amp H31 Data amp H31 Data amp H30 Data amp H30 90 4 511 91 4 469 92 4 427 93 4 386 94 4 345 95 4 304 96 4 264 97 4 224 98 4 185 99 4 146 100 4 107 101 4 069 102 4 031 103 3 994 104 3 956 105 3 920 106 3 883 107 3 847 108 3 811 109 3 776 110 3 740 111 3 705 112 3 671 113 3 637 114 3 603 115 3 569 116 3 536 117 3 503 118 3 470 119 3 438 120 3 406 121 3 374 122 3 343 123 3 312 124 3 281 125 3 250 126 3 220 127 3 190 128 3 160 129 3 131 130 3 102 131 3 073 132 3 044 133 3 016 157 2007 MCS Electronics 158 BASCOM 8051 Data amp H30 134 2 988 amp 29 135 2 960 amp 29 136 2 932 amp 29 137 2 905 amp 29 138 2 878 Data amp H28 139 2 851 Data amp H28
18. 8051 See also MAKEBCD 1185 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 ariable that will be assigned with the converted value LSB ariable or constant with the Least Significant Byte MSB ariable or constant with the Most Significant Byte The equivalent code is varn 256 MSB LSB See also 1 BCD 112 Dim As Integer As Integer a 2 I MakeINT a 1 1 1 256 2 258 End 6 135 MAX Action Returns the highest value of an array Syntax var MAX ar 1 2007 MCS Electronics BASCOM Language Reference 191 Remarks Var Numeric variable that will be assigned with the highest value of the array he first array element of the array to return the highest value of At the moment MAX works only with BYTE arrays Support for other data types will be added too See also MINDA 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 1 MID var st vari
19. After access to the counter the timer counter is stopped So when it was running start it with the statement START COUNTERx 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 TimerO Counter Gate Internal Mode 1 Timer0 counter timer0 operates as a counter Internal no external gate control 1 16 bit counter CounterO 0 clear counter Start CounterO0 enable the counter to count Do set up a loop A Inkey check for input 2007 MCS Electronics 134 BASCOM 8051 Counter0 get counter value Print C print it Start CounterO0 re start it because it was stopped by accessing the COUNTER Loop Until A 27 until escape is pressed End For the next example the ASM code is shown COUNTERO 1000 Generated code TCON 4 Mov tl0 232 Mov 3 6 73 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 204 POKE 22 INP 173 OUT 2o Example c
20. The last saved closed program will be loaded automatic When reformatting is enabled the loaded program will be reformatted too This is only meaningful for programs written with another editor 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 The filename is shown in the caption of the window The status bar is separated in four panels e line character position indicator modified indicator to indicate that text has changed insert overwrite indicator message panel Some actions such as programming will make a progress indicator visible 2007 MCS Electronics 38 BASCOM 8051 4 2 BASCOM IDE Running BASCOM 8051 371 File File File Open ss File 7 File Save bl File Save As 401 File Print a File Print Preview 2 File Edit Edit Undo 42 K Edit Redo 2 Ql Edit Copy 4 Edit amp Edit Paste Edit Find 4 7 Edit Find Next Mil Edit Replace 44 Editor Keys 461 Program Compile IM Syntax check 4 iM Show Result 48 Simulate Send to chip ES Tools Terminal Emulator 53 LCD designer 547 Graphic Converter s LIB Manager 557 Options 2007 MCS Electronics BASCOM IDE 39
21. fill the data For X 1 To 10 200 X Next print the data For X 1 To 10 Print Z x Next End 6 31 RAMSTART Action Specifies the location of the external RAM memory Syntax SRAMSTART amp H address Remarks he hex address where the data is stored Or the lowest address which enables the RAM chip ou can use this option when you want to run your code in systems ith external RAM memory Address must be a numeric constant See also RAMSIZE hot Example ROMSTART amp H4000 RAMSTART 0 RAMSIZE amp H1000 2007 MCS Electronics 104 BASCOM 8051 6 32 REGFILE Action Instructs the compiler to use the specified register file Syntax REGFILE file Remarks he 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 8052 DAT use the 8052 DAT file 6 33 ROMSTART Action Specifies the location of the ROM memory Syntax SROMSTART amp H address Remarks he hex address where the code must start Default is 0 This value will be used when ROMSTART is not Specified ou can use this option when you want to test the code in RAM he code must be uploaded and placed into the specified address and an be called from a monitor program he monitor program must re
22. rks he string that is assigned he starting position he number of characters to get set Lez on strings require that all strings are of the same type internal or external See also LEFT 15 RIGHT 214 Example 2007 MCS Electronics 192 BASCOM 8051 Dim S As Xram String 15 Z As Xram String 15 S ABCDEFG 2 5 2 3 Print 7 Z 12345 Mid s 2 2 7 Print 5 6 137 Action Returns the lowest value of an array Syntax var MIN ar 1 Remarks m de variable that will be assigned with the lowest value of the array A12D KEG he first array element of the array to return the lowest value of At the moment MIN works only with BYTE arrays Support for other data types will be added too See also 190 10 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 MOD var2 2007 MCS Electronics BASCOM Language Reference 193 Remarks Ret he variable that receives the remainder he variable to divide 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
23. 2007 MCS Electronics BASCOM Language Reference 203 Be careful with the POKE statement because you can change variables with it which can cause your program to function incorrect See also PEEK 204 CPEEK 13 INP 173 OUT 20 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 he 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 2007 MCS Electronics 204 BASCOM 8051 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 2051 INPUT 1731 11 CLOSE 108 SPC 223 Example c 1995 2006 MCS Electronics 1 file PRINT BAS demo PRINT PRINTHEX Dim A As Byte As By
24. 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 10 as byte CONFIG SPI SOFT DIN P1 0 DOUT P1 1 CS P1 2 CLK P1 3 SPIINIT 2007 MCS Electronics BASCOM Language Reference 225 SPIIN 1 4 read 4 bytes 6 181 SPIOUT Action Sends a value of a variable to the SPI bus Syntax SPIOUT var bytes Remarks he variable woes content must be send to the SPI bus he number of bytes to send See also SPIIN 2221 CONFIG SPI 1307 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 IMERO TIMER1 TIMER2 COUNTERO or 1 You must start a timer counter in order for an interrupt to occur when the external gate is disabled TIMERO and COUNTERO are the same device See also STOP TIMERx 2261 2007 MCS Electronics 226 BASCOM 8051 Example ON TIMERO label2 LOAD TIMERO 100 START TIMERO DO start loop LOOP loop forever label2 perform an action here RETURN 6 183 STOP Action
25. 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 endif is not compiled When you change the constant DEMO to the other line will be compiled ELSE Action Conditional compilation directive that tests for a NOT condition Syntax IF test ELSE ENDIF Remarks An expression to test for The expression may contain defined constants Conditional compilation is used to include parts of your program This is a convenient way to build different files depending on some constant values Note that unlike the IF statement the IF directive does not expect a THEN You may nest conditions to 25 levels The use of ELSE is optional The code between ELSE and will be compiled when the expression is not true 2007 MCS Electronics 82 BASCOM 8051 6 4 See Also IFle ENDIF amp Example CONST DEMO 1 0 normal 12 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 the other line will be compiled ENDIF Action Conditional compilation directive that ends a test Syntax test ELSE ENDIF Remarks An
26. Go to the main MCS website at http www mcselec com e In the left pane under Main Menu you will find a link named Registration ACC MC pum BASCOM AVR Home E Latest News E Shopping zone 4 154 Useful modding Categories spectrum s analyzer watch 2 MCS Shop b AN 153 MP3 Player b AN 152 Led 3D ball matrix b AN 151 Nordic nRF24L01 with BASCOM AVR b AN 150 PID motor Hardware 103 H Software 15 H P Industrial 27 controller M Books 2 El Main Menu M Service 3 9 Home List All Products amp 5 News Product Search products Search Application Notes Publications Links Support Center Downloads Forum Resellers Contact Us 77 Registration Updates El Online Help Registration asiiy Ukraine 2007 Read more AN 153 MP3 Dilaver 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 2007 MCS Electronics 28 5 8051 Product registration Login Product registration Login User Name Password Forgot your login data Q e Create account Need Help For troubleshooting read here e Click the link and select Create new account Create new account Required Information User Name agooduserName cACAC
27. t MSB of C t MOV c 10 assign value You can also change SFRs from BASIC P1 12 this is obvious 5 this is ok too B 3 B is a SFR too 2007 MCS Electronics 244 BASCOM 8051 MUL AB acc acc b Print acc EXTERNAL variables are stored similar Strings are stored with a terminating zero Example RAMSTART 0 Dim s As String 10 reserve 10 bytes 1 for string terminator S abcde assign string constant to string first memory location ram location 0 a ram location 1 b ram location 2 2 c ram location 3 d e ram location 4 ram location 5 0 External variables must be accessed somewhat different Dim T as XRAM Byte mov dptr Z T address of T to datapointer mov a 65 place A into acc movx dptr a move to external memory Print T print it from basic Dim T1 as XRAM Integer mov Z T1 Set datapointer mov a 65 place A into acc LSB movx dptr a move to external memory inc dptr move datapointer mov a 1 1 to MSB movx dptr a move to external memory Print T1 print it from basic Helper routines There are two ASM helper routines that can make it a bit easier PLACEVALUE var SFR PLACEADRES var SFR PLACEVALUE assigns the variable var to the specified register SFR Placevalue 1 A will generate Mov a 1 Dim x as Byte Placevalue x RO will generate Mov a h 3A in this example only of course Where
28. 217 171 5 cr 217 jeep een nn qi ne sn mare secte 218 173 SANE TCD nn nt de 219 174 I ECTS 220 179 SOUND h a EP 220 176 5 state einen ere N 221 177 Jem 222 TZR SPC per HE 223 179 224 180 gm 224 2007 MCS Electronics 10 BASCOM 8051 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 Part VII 1 2 3 Part VIII a Ff OND Part IX ON OA BR WN SPIOUT T 225 qe 225 Eire pee 226 STOP TIm r etie eee Ed ILI LM LIE 226 lE ERE 228 STRING 228 S R 229 Kl pce PPS 230 UB ep 230 H 231 232 232 VARPTR
29. 242 BASCOM 8051 SWAP A Swap nibbles within the accu Da MOV A Rn MOV A direct MOV A Ri MOV A data MOV Rn A MOV Rn direct MOV Rn data MOV direct A MOV direct Rn MOV direct direct MOV direct Ri MOV direct data MOV Ri A MOV Ri direct MOV Ri data MOV DPTR data16 MOVC A A DPTR MOVC A A PC MOVX A Ri MOVX A DPTR MOVX Ri A MOVX DPTR A PUSH direct POP direct XCH A Rn A direct A Ri XCHD A Ri move direct byte to accu move indirect RAM to accu move immediate data to accu move direct byte to register move immediate data to register move accu to direct byte move register to direct byte move direct byte to direct move indirect RAM to direct byte move immediate data to direct byte move accu to indirect RAM move direct byte to indirect RAM move immediate to indirect RAM load datapointer with a 16 bit constant move code byte relative to DPTR to A move code byte relative to PC to A move external RAM 8 bit to A move external RAM 16 bit to A move A to external RAM 8 bit move A to external RAM 16 bit push direct byte onto stack pop direct byte from stack exchange register with accu exchange direct byte with accu exchange indirect RAM with A ta transfer exchange low order digit ind RAM w A How to access labels from ASM Each label in BASCOM is changed into a period followed by the label name Example GOTO Test Test 2007 MCS Electronics Usi
30. H RST HS 21 P3 0 P1 7 e H P3 1 P1 6 4 17 2 P1 5 27 xi P1 4 HE DIS 4P3 2 P1 3 HE H P3 3 P1 2 H P3 4 P1 1 H 1H P3 5 P1 0 H GND P3 7 2051 45V 1 45V RESET P1 7 to turn LED on 330 SET P1 7 to turn LED off 1 H 29 A E 4 P3 0 P1 7 Ks 2 5 HS xa 5 P3 1 P1 6 4 17 LED x2 5 He 24 1 P1 4 HE 4 6 3 ns 4TuF 16V t Pz 2 P1 3 Suitch 7052 PISIS 1c 2 E iz 21 5 P3 4 1 1 3 12 2 2 P3 5 P1 0 19 GND P3 7 a SPEAKER ATESC20S 1 SOUND P1 0 1000 50 to make some noice BITWAIT P3 4 RESET To wait for button pressed MCS ELECTRONICS Title HARDHARE Size Document Number REY A 1 4 Date September 28 1997 Sheet of 1 The schematic above shows how to connect LED as an output a speaker as an output and a switch as an input device 8 2 Alternative port pin functions The AT89S8252 ports have alternative functions The following table shows the alternative functions 2007 MCS Electronics Additional Hardware 257 1 timer 1 external input WR external data memory write strobe RD external data memory read strobe means active low 8 3 Hardware LCD display The LCD display can be connected as follows Lover port ps p RS pa This leaves P1 1 and P1 0 and P3 for other purposes You c
31. INL Logout It is important that you enter 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 2007 MCS Electronics 30 5 8051 BASCOM 8051 Compiler version 2 0 14 0 IDE version 2 0 14 0 Serial number Windows OS Microsoft Windows XP Windows SP Service Pack 2 Explorer 7 0 5730 11 Company MCS Owner Mark Alberts Windows dir C WIHHT System dir C WIHHT system32 Support support mcselec com Copy 1995 2007 NCS Electronics When the product is selected the serial number is entered and you press Register product you will see the following message The page at http register mcselec com says A Your number is now registered e This does mean that you registered successfully e MCS Electronics will validate all registrations once in a few days When the product is validated you will receive an email After you receive the email you can login to the register again e Now you need to select Download LIC files The following screen will be shown 2007 MCS Electronics Updates 31 List of registered products Q Main page Logout 8 Humber of registered products 3 Product Serial number SN status Date of registration
32. SOUNDEXT zeh SPACE zz SPC 2231 SPIIN 224 SPIOUT 225 START 25 STOP 225 STOP TIMER 2061 STR 2281 STRING 228 SUB 2231 SWAP 2301 T THEN 15 THIRDLINE TO 145i U UCASE 23h UPPERLINE 232 V VAL esi VARPTR 2s 2007 MCS Electronics INDEX 17 1 2 W WAIT 2321 WAITKEY sh WAITMS s WAITMSE s WHILE ss Keyword Reference 1WIRE 1Wire routines allow you to communicate with Dallas 1wire chips 1WRESET 1WREAD 1 31 1WSEARCHFIRST 85 1WSEARCHNEXT 871 1WIRECOUNT Conditions Conditions execute a part of the program depending on the condition 6 ELSEN END IF 14 EXIT 148 SELECT A8 NEXT h TOl 148 THEN 169 WHILE WEND 2361 Configuration Configuration command initialize the hardware to the desired state CONFIG 5 Conversion A conversion routine is a function that converts a number or string 110 BCD 112 CHR FUSING 1501 13 HEXVALI164 HIGH i6 HIGHW 15 MAKEDEC 189 MAKEBCD hs 190 228 VAL 232 Delay Delay routines delay the program for the specified time DELAY ah WAIT 235 WAITMS 234 Directives Directives are special instructions for the compiler They can override a setting from the IDE 1 ELSE e 1 amp ENDIF sez ASM INCLUDE
33. Using for x will result in a string of 255 bytes because there is no check for a zero 2007 MCS Electronics BASCOM Language Reference 223 length assign See also STRING s SPC 220 Example Dim s as XRAM String 15 z as XRAM String 15 S Space 5 Print S i 4 Dim A as Byte A 3 S Space a Genereated code for last 2 lines j mene Eee library routine sStr String Mov r1 a Inc r1 Djnz r2 sStr String Clra Mov r1 a Mov R1 h 22 location of string Mov R2 h 21 number of spaces Mov a 32 Acall _sStr_String 6 178 SPC Action Prints spaces to the serial port or LCD display Syntax PRINT SPC x Remarks he number of spaces to print Range from 1 255 Use SPACE function to assign spaces to a string SPC can only be used in combination with PRINT and LCD See Also SPACE 22 Example Dim s as XRAM String 15 z as XRAM String 15 2007 MCS Electronics 224 BASCOM 8051 5 Hello Print 36 SPC 3 6 179 SPIIN Action Reads a value from the SPI bus Syntax SPIIN var bytes Remarks he variable that is assigned with the value read from the SPI bus he number of bytes to read See also SPIOUT zz CONFIG 101 SPIINIT 24 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
34. Windows OS Microsoft Windows XP Windows SP Service Pack 2 Explorer 7 0 5730 11 Company MCS Owner Mark Alberts Windows dir C WIHHT System dir C WIHHT system32 support supportGmcselec com 53 Copy 1995 2006 MCS Electronics Your serial number is shown in the about box You will need this when you have questions about the product The library version is also shown You can compare it with the one from our web site in case you need an update Click on the Ok button to return to the editor Help Index Will show the help index of BASCOM Help on help Will bring up help about the Windows help system 2007 MCS Electronics 68 BASCOM 8051 4 52 Help Shop Action This option will launch your default web browser and will open the MCS Electronics Shop We have a number of BASCOM 8051 KIT s and affordable 89Cx051 programmers from Sample Electronics 4 53 Help Forum Action This option will launch your default web browser and will open the MCS Forum The forum can be used to talk to other BASCOM users You can get idea s there discuss your problems and questions and you can help other members 4 54 Help Support Action This option will launch your default web browser and will open the MCS Support system The support system can be used to search the knowledge base 4 55 Help Credits Will launch this help file and show this topic MCS would like to thank the fo
35. BASCOM AYR Valid 2005 11 15 06 58 36 BASCOM 8051 Valid 2006 05 12 20 01 27 BASCOM AVR Validation pending 2007 09 04 19 04 26 Actual available product versions Actual version of B amp SCOM AVR 111 88 Actual version of B amp SCOM 8051 20130 Download full BASCOM AVR Download full BASCOM 8051 Order updates on CD you will be redirected to shop order to keep traffic to a minimum it is preferred that you download the LIC But instead of the LIC file you can also download the full install file This is zipped with the password that you find in the LIC file the LIC file just text file with the LIC extension The full file requires the license DLL that your received when you purchased BASCOM We longer have the file so please don t ask for it was given to you because you purchased it R s yours alone don t Jose it 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 wi
36. Regards Mark Hayne 9 9 CYGNAL JTAG Programmer The CYGNAL JTAG programmer comes with the CYGNAL development kit and is also available from www sample co kr tests were performed with the programmer evaluation board from Sample Electronics The Cygnal JTAG programmer is controlled by a COM port You need to select a free COM port of your PC that is connected to the programmer 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 8958252 tests are performed with the 8958252 board from Futurelec Electronics 9 11 JPK Systems X programmer The JPK Systems X programmer is a serial comport based SPI programmer It is fully optical isolated and so an ideal device for industrial equipment It supports AVR chips too but these aren t supported in BASCOM of course so there is only support for the 8958252 and the 89553 Since it is serial based the support is placed in the terminal emulator After selecting the JPK programmer there will be additional menu options available in the terminal emulator All these options can be found under the JPK menu The transfer between the PC and the programmer is implemented with the X modem CRC protocol Select device Use this option to select the targetdevice You can choose between the 8958252 and the 89553 Erase Erase the target chip Read code Will read th
37. Relational 3 Logical 4 Functional Arithmetic Arithmetic operators and e Integer Integer division is denoted by the backslash Y Example Z X Y e 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 e 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 T gt fer reater than or equal to 2007 MCS Electronics 74 BASCOM 8051 Logical Operators Logical operators perform tests on relations bit manipulations or Boolean operators There are four operators in BASCOM they Meaning Logical complement onjunction Disjunction 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 0r 9 PRINT A Output 16 11 Floating point Sing
38. SIM 107 TIMEOUT 107 WAIT 108 1WIRE 258 1WIRECOUNT 84 1WREAD 83 1WRESET 83 1WSEARCHFIRST 85 1WSEARCHNEXT 87 1WWRITE 83 8 8032 Alternative port pin functions 256 8032 TIMER2 289 80515 WATCHDOG 293 89C51 297 ABS 109 Additional Hardware 251 ALIAS 108 ASC 110 AT898252 WATCHDOG 292 AVG 110 BASCOM 38 BASCOM statements 77 BAUD 111 BCD 112 BITWAIT 112 Blow IT Flashprogrammer 267 BREAK 113 BROWSEO001e 144 C CALL 113 CASE 216 CHR 114 CLOSE 198 CLS 115 Compiler Limits 282 CONFIG 116 CONFIG 1WIRE 117 CONFIG ADUC812 117 CONFIG BAUD 119 CONFIG BAUD1 119 CONFIG DEBOUNCE 120 CONFIG GETRC 121 CONFIG GRAPHLCD 121 CONFIG I2CDELAY 120 2007 MCS Electronics 312 BASCOM 8051 CONFIGLCD 125 CONFIG LCDBUS 126 CONFIG LCDPIN 125 CONFIG MICROWIRE 127 CONFIG PRINT 127 CONFIG SCL 128 CONFIG SDA 128 CONFIG SERVOS 129 CONFIG SPI 130 CONFIG TIMERO TIMER1 131 CONFIG WATCHDOG 132 CONST 116 COUNTER 132 CPEEK 134 Credits 68 CURSOR 135 CYGNAL JTAG Programmer 272 s D DATA 136 DATA EEPROM 292 DEBOUNCE 137 DECLARE 139 DECR 138 DEF 140 DEFBIT 140 DEFBYTE 140 DEFINT 140 DEFLCDCHAR 140 DELAY 141 DIM 141 DISABLE 143 DISPLAY 143 alls Edit Copy 42 Edit Cut 42 Edit Find 43 Edit Find Next 43 Edit Goto 44 Edit Indent Block 45 Edit Paste 43 Edit Redo 42 Edit Replace 44 Edit Undo 42 Edit Unindent Block 45 Editor Key
39. 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 A picture of the board is included here Since the help file must be kept small the quality of the picture is poor 2007 MCS Electronics 310 5 8051 F4 2800331 FEIE IE JEJE IE inn gt a 3 AE EEL AmE 9923 Buy ATFI6V8BQL 15SC 5 4 N iE iO Lil lt 0 39393 99 9 JE AE IE IE IC IE 9 999 A bootloader is integrated into BASCOM Select the Rhombus SCE 51 programmer to enable it 2007 MCS Electronics Index 311 Index ELSE 81 ENDIF 82 80 BAUD 89 BGF 89 CRYSTAL 91 DEFAULT XRAM 92 END ASM 88 EXTERNAL 92 INCLUDE 93 IRAMSTART 94 LARGE 94 LCD 95 97 LCDRS 96 LIB 95 NOBREAK 97 NOINIT 98 NONAN 98 NONULL 99 136 NORAMCLEAR 99 NOSP 100 OBJ 100 RAMSIZE 101 RAMSTART 103 RAMTRON 101 REGFILE 104 ROMSTART 104 SERIALINPUT 105 SERIALINPUT2LCD 105 SERIALOUTPUT 106
40. replacing pins for 89c1051 with pins for 8xc51 BASCOM Examples for boards O8 KND_44 KAD 08 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 4 CN6 gt SC pin2 CN1 KNDO8 L2 5 CN6 gt SD pint CN1 KNDO8 2007 MCS Electronics 306 BASCOM 8051 Supply both the boards Before compiling in menu Option Compiler Misc set Byte End Hex 60 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
41. 140 2 824 Data amp H28 141 2 798 Data amp 28 142 2 772 Data amp H27 143 2 746 Data amp H27 144 2 721 Data amp H27 145 2 695 Data amp H27 146 2 670 Data amp H26 147 2 645 Data amp H26 148 2 621 Data amp H26 149 2 596 Data amp H26 150 2 572 Data amp H25 151 2 548 Data amp H25 152 2 524 Data amp H25 153 2 501 Data amp H25 154 2 477 Data amp H24 155 2 454 Data amp H24 156 2 431 Data amp H24 157 2 409 6 98 GETRC Action Retrieves the value of a resistor or a capacitor Syntax var GETRC pin he variable that receives the value he 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 2007 MCS Electronics BASCOM Language Reference 159 Uses This function uses TIMERO See also NONE Example 5 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 TimerO 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 Sbaud 9600 just my settings crystal 11059200 D
42. 8051 9 13 STK200 300 ISP Programmer The STK200 and STK300 are AR starter kits from Atmel They come with a parallel printer port programmer dongle for in system programming of the chips This dongle can be used to program the 89S8252 or 89S53 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 2007 MCS Electronics Supported Programmers 275 F1STK200 STK300 ISP programmer SE File Buffer Chip SB Sel me Chess Manufactor Atmel Flash ROM Chip 8354051 EEPROM 0 FlashROM User 1000 02 00 56 32 00 00 00 00 00 00 00 32 00 00 00 NES 00 00 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 00 00 00 7B C8 11 4 03 11 44 DO 78 95 F5 22 78 FF D8 FD 01 BO EO F5 BO rr rr rr rr rr STK200 STK300 ISP 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 add
43. 93 BAUD amp 891 6 5 1 91 DEFAULT XRAM e IRAMSTART 9 LARGE 9 LCD 1951 MAP 971 NOBREAK 971 981 NONULL 991 NORAMCLEAR 9 NOSP SRAMSIZE ot RAMSTART 0 REGFILE ROMSTART o SERIALINPUT v SSERIALINPUT2LCD iei SERIALOUTPUT ob SIM o Graphical LCD Graphical LCD commands extend the normal text LCD commands PSET 27 SHOWPIC 220 I2C 2007 MCS Electronics 18 BASCOM 8051 I2C commands allow you to communicate with I2C chips with the TWI hardware or with emulated I2C hardware I2CRECEIVE 1661 I2CSEND 167 2 5 168 I2CSTOP 15 I2CRBYTE 168 I2CWBYTE list cdi c Interrups Interrupt related routines ON Interrupt 195 ENABLE 1451 DISABLE 143 PRIORITY 2061 IO I O commands are related to the I O pins of the processor ALIAS 1081 BITWAIT 112 DEBOUNCE 137 161 RESET 212 Math Math functions ABS 08 101 MAX o MINI MOD ea Micro Micro statements are highly related to the micro processor BREAK 1131 1 2011 IDLE 19 1461 POWERDOWN 2031 START zi STOP 226 STOP TIMER 226 Memory Memory functions set or read RAM EEPROM or flash memory CPEEK ERASE 47 1731 OUT 200 2021 2021 READ 208 RESTORE 212 i36 VARPTR 235
44. As Byte As Byte DIM variable 2 1 gt 1 some silly code Do begin a DO LOOP 1 inc 100 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 he variable counter to use he starting value of the variable var he ending value of the variable var Value he value var is increased decreased with each time NEXT is encountered 2007 MCS Electronics BASCOM Language Reference 149 var Byte Integer Word Long Single start Byte Integer Word Long Single Constant end Byte Integer Word Long Single Constant step Byte Integer Word Long Single Constant For incremental loops you must use TO For decremental loops you must use DOWNTO You may use TO for a decremental loop but in that case you must use a negative STEP For a 10 To 1 STEP 1 You must end a FOR structure with the NEXT statement The use of STEP is optional By default a value of 1 is used See also NEXT 61 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 5 1 T
45. CAN By default all interrupts are disabled To enable the enabling and disabling of interrupts use ENABLE INTERRUPTS Other microprocessors can have more interrupts than the 8051 8052 Look at specific microprocessor support 294 for more details See also DISABLE 145 2007 MCS Electronics 146 BASCOM 8051 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 When an END or STOP statement is encountered a never ending loop is generated See also STOP zzi Example PRINT Hello print this END end program execution 6 89 ENDIF Action End an IF THEN structure Syntax END IF Remarks You must always end an IF THEN structure with an END IF statement You can nest IF THEN statements The use of ELSE is optional The editor converts ENDIF to End If when the reformat option is switched on See also IF THEN 169 ELSE 144 Example 2007 MCS Electronics BASCOM Language Reference 147 Dim Nmb As Byte Again label Input Number Nmb ask for number If Nmb 10 Then compare Print Number is 10 yes Else no If Nmb 10 Then is it greater Print Number 10 yes Else no Print Number 10 print this End If end structure End If end structure End end progra
46. CN6 gt SC pin2 CN1 KND44 12 pin5 CN6 gt SD pint CN1 KND44 Supply both the boards Before compiling in menu Option Compiler Misc set Byte End Hex 60 KAD 08 This program manages 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 4 CN6 SC pin2 1 KADO8 12 5 CN6 gt SD pint CN1 KADO8 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 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 4 CN6 SC pin2 CN1 KADO8 L2 5 CN6 gt SD pint CN1 KADO8 Supply both the boards Before compiling in menu Option Compiler Misc set Byte End Hex 50 2007 MCS Electronics Third party hardware 3
47. DELAY 4h 4 DISABLE iA DISPLAY 14 E ELSEN ENABLE 1 END IFMA ERASE F FOR 48 FOURTHLINE 48 FUSING 154 2007 MCS Electronics 16 5 8051 G GET st GETAD 151 2051 153 151 GETRC5 1601 GOSUB ie 168 H HEX 163 HEXVAL eh HIGH 164 HIGHW 165 HOME 166 1 I2CRECEIVE 1166 I2CSEND 167 I2CSTART ies 2 5 IACRBYTE 164 I2CWBYTE IDLE 191 IF es 171 INKEY 1711 INPI INPUT 1751 INPUTBIN 1751 1761 INSTR 177 L LCASE 11781 LCD 178 LCDINIT het LCDHEX i83 LEFT hes LEN hss LOAD 2 LOCATE 1851 LOOKUP 16 LOOKUPSTR 16 LOOP ah LOW i65 LOWW lis LOWERLINE 1861 M MAKEDEC MAKEBCD 15 MAKEINT MAX 1 MID ish MIN foh MOD 192 N NEXT 195 ON 195 ON 197 OPEN 18 OUT 2001 P P1 P3 20 PEEK 202 204 207 POWERDOWN 208 PRINT 2051 PRINTBIN 204 PRINTHEX 208 PRIORITY 206 PUT 207 R READ 2081 READMAGCARD zi REM 2 REPLACE zh RESET I RESTORE eb RETURN RIGHT 214 RND fi ROTATE Lei S SELECT 216 2161 SHIFT 217 SHIFTCURSOR 217 SHIFTIN 218 SHIFTOUT 218 SHIFTLCD 219 SHOWPIC zz SOUND 226
48. Electronics 166 5 8051 Z HighW I 6 106 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 See also CLS LOCATE 8 LCD 1178 Example Lowerline LCD Hello Home Upper LCD Upper 6 107 IZCRECEIVE 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 he I2C device Var A byte or integer word variable that will receive the information from he I2C device b2W he number of bytes to write Be cautious not to specify too many bytes b2R he number of bytes to receive Be cautious not to specify too many bytes 2007 MCS Electronics BASCOM Language Reference 167 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 Example x 0 reset variable slave amp H40 slave address of a PCF 8574 I O IC I2CRECEIVE slave x the value PRINT x print it Dim buf 10 as String buf 1 1 buf 2 2 I2CRECEIVE slave buf 2 1 sen
49. H of new editor DESCRIPTION Auto indent ith auto indent the cursor will be set to the same left margin as the current line when you press return Don t change case his 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 when entered in the editor This will reformat he line after you have set focus to a new line Smart tabs ill look at the previous line for non spaces to position the ursor 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 2007 MCS Electronics BASCOM IDE BASCOM 8051 Options X Compiler Communication 1 B Hardware simulator Programmer Monitor Printer Editor Font ip Backaround color White E ditorFont Font Keyword color Y N Bold Comment color Green v Italic ASM color 1 Purple HW Register color Maroon X Cancel Background color Background color of the editor 63
50. I O pins I advise to look at these chips 4 33 Tools Export to RTF Action Exports the current file to an RTF file 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 4 34 Options Compiler Output With this option you can specify which files must be created BASCOM 8051 Options Output Communication I2C LCD Misc Binary file Repot file Debug File Error file M HEX file M NOI file Old Intel HEX file Binary file his will generate a ROM image of the program Of course you can 2007 MCS Electronics 58 5 8051 store it in a flashrom Debug file his option will generate a DBG file It is used by the simulator hen you don t use the simulator you don t need to generate it Hex file his is an Intel hex file that is used by most programmers and monitor programs his option will generate an old style Intel hex file and is used by the Elektor monitor If you choose this option you must unselect the Hex File option Error file his file is generated when an error occurs It holds the error descriptions hen there is no error the file will not be created 4 35 Options Compiler Communication With this options you can select the used crystal and the baud rate that mus
51. Optional is the number of bytes that mist be sent 1 is numeric variable or constant var2 1WREAD Reads 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 lwreset lwwrite and lwread pull up of 4K7 required to VCC from 1 DS2401 serial button connected to 1 1 Config lwire P1 1 use this pin Dim Ar 8 As Byte A As Byte I As Byte lwreset reset the device Print Err print error 1 if error lwwrite amp H33 read ROM command For I 1 To 8 Ar i lwread place into array Next For I 1 To 8 Printhex Ar i print output Next Print linefeed You can also use multiple pins 2007 MCS Electronics 84 5 8051 alias the first Tsensor Alias 1 2 the optional argument specifies the pin to use lwreset Tsensor reset lwwrite amp H33 Tsensor write value to Tsensor lwwrite Ar 1 2 Tsensor write 2 bytes to Tsensor lwread tsensor return byte from Tsensor Ar 1 1wread 2 P1 2 read 2 bytes from Tsensor End 6 6 1WIRECOUNT Action This statement returns the number of 1wire devices found on the bus Syntax var2 AWIRECOUNT array Remarks 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
52. SROMSTART e 104 SSERIALIN PUD e M 105 Ei znIPYMnpglypuRerim 105 SSERIAL OUTPUT mmc 106 SE SO Br BP ea Pea E AI Pe 107 STIMEOUT RR MS 107 QW AUT ee PE EP 108 ALIAS teat neo E cec 108 ABS M MIU I ae tee 109 Dem pu a A 110 pic PS 110 BAUD 5 caen 111 BOD ES 112 LN puE Y 112 BREAK casas i ds ca T 113 CALL Er E 113 CHR 114 GLS sise nine 115 CONS E DR 116 RP RS 116 CONFIG M RE cscs er 117 CONFIG ADUGCO 12 x utes nn ter ner ne 117 2007 MCS Electronics Contents 7 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 CONFIG 119 CONFIG BAUD PR 119 CONFIG DEBOUNGCE m iei en ne ete 120 CONFIG ZC DELAY rot d 120 leenlzicucigpim e
53. See also CONFIG MICROWIRE 27 MWREAD 123i j MWWRITE 195 MWWOPCODE 195 6 140 MWREAD Action Read a value from the micro wire bus Syntax MWREAD variable opcode address bytes Remarks Variable he variable that is assigned with the value retrieved from the micro wire bus he address of the device Bytes Number of bytes to send See also MWWRITE 1951 MWWOPCODE 194 MWINIT hio MicroWire test file 2007 MCS Electronics 194 BASCOM 8051 please read microwire specs for understanding microwire 1 CS chip select DIN data in DOUT data Out CLOCK Clock AL address lines i 93C46 93 56 93 57 93 66 Data bits 8 16 8 16 8 16 8 16 AL 7 6 9 8 8 7 9 8 could use the same pin for DIN 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 dimension variable used Dim X As Byte enable write to eeprom send startbit opcode 00 and 11 address Mwwopcode opcode numberOfBits Mwwopcode amp B1001100000 10 the mwwopcode can send a command opcode to a device X 10 write value of X to address 0 opcode is 01 we write 1 byte Mwwrite var opcode address numberOfBytes Mwwrite X 101 0 1 Waitms 10 X20 read back mwread var opcode address numberofbytes Mwread X 8B110 0 1 disable write send startbit opcod
54. Select this option to enable the compiler to give a warning message when the code size exceeds the specified size decimal 4 39 Options Communication With this option you can modify the communication settings for the BASCOM terminal emulator The following window will appear 2007 MCS Electronics BASCOM IDE 61 BASCOM 8051 Options X Compiler n Environment Hardware simulator Programmer Monitor Printer COM port com Handshake None Baudrate 13200 Emulation TTY Y Parity None X Font Font Databits 8 x Backcolor E Stopbits 1 m Run emulator modal LL Runs the terminal emulator 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 2007 MCS Electronics 62 BASCOM 8051 4 40 Options Environment With this option you can modify the environment options BASCOM 8051 Options X Compiler Communication ardware simulator Programmer Monitor Printer Lomp m I Editor Font IDE Autoindent Comment position 050 Don t change case Reformat BAS files TAB size mm v Reformat code Keymapping Default Smart TAB Syntax highlight No reformat extension DAT v Show margin Normal Maximized
55. Stop program execution Syntax STOP Remarks END can also be used to terminate a program When an END or STOP statement is encountered a never ending loop is generated See Also STOP TIMER 25 START 228 Example PRINT var print something STOP thats it 6 184 STOP Timer Action Stop the specified timer counter Syntax STOP timer Remarks IMERO TIMER1 TIMER2 COUNTERO or 1 You can stop a timer when you don t want an interrupt to occur 2007 MCS Electronics BASCOM Language Reference 227 TIMERO and COUNTERO the same See also START TIMERx 251 STOP 226 Example c 1995 2006 MCS Electronics file TIMERO BAS demo ON TIMERO TIMER1 is used for RS 232 baudrate generator Dim Count As Byte Gt As Byte Config TimerO Timer Gate Internal Mode 2 Timer0 counter timer0 operates as a counter Gate Internal no external gate control Mode 2 8 bit auto reload default On TimerO Timer O0 int Load TimerO 100 when the timer reaches 100 an interrupt will occur Enable Interrupts enable the use of interrupts Enable Timer0 enable the timer Rem Setting Of Priority Priority Set Timer0O highest priority Start start the timer Count 0 reset counter Do Input Number Gt Print You entered Gt Loop Until Gt 1 loop until users enters 1 Stop TimerO End Rem The Inter
56. 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 he portpin which serves as as input output pclock he portpin which generates the clock Var he 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 he 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 2007 MCS Electronics BASCOM Language Reference 219 For the SHIFTIN example the following code is generated Setb P1 1 Mov RO h 21 Mov r2 h 01 UNQLBL1 Mov r3 8 __ UNQLBL2 Clr P1 1 Nop Nop Mov c P1 0 Rica Setb P1 1 Nop Nop Djnz r3 __ UNQLBL2 Mov r0 a Dec Djnz r2 __ UNQLBL1 Of course it depends on the parameter which code will be generated To shift with
57. an external clock signal SHIFTIN P1 0 P1 1 a 4 add 4 for external clock Generated code Mov RO h 21 Mov r2 h 01 ___UNQLBL1 Mov r3 8 ___UNQLBL2 Jnb 1 1 0 Mov 1 0 Rica Jb P1 1 0 Djnz r3 __ UNQLBL2 Mov r0 a Dec rO Djnz r2 __ UNQLBL1 6 173 SHIFTLCD Action Shift the LCD display left or right by one position Syntax SHIFTLCD LEFT RIGHT Remarks NONE 2007 MCS Electronics 220 BASCOM 8051 See also SHIFTCURSOR 217 CLS LCD 178 HOME hss LOCATE ie 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 Converters 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 29 CONFIG GRAPHLCD 125 207 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 duration frequency NO
58. be 099 5 When you dont want that the result is rounded you can use the amp indicator Targ Fusing s 000 amp amp result should be 099 49 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 5 99 12 Targ Fusing s 00 66 result is 99 12 End 6 95 GET Action Retrieves a byte from the software UART Syntax GET channel var Remarks Channel fPositive numeric constant that refers to the opened channel 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 OPEN 118 statement An optional TIMEOUT can be specified so that the routine will return when no character is received See also PUT 27 TIMEOUT 107 J Example 2007 MCS Electronics 152 BASCOM 8051 Dim S As String 12 I As Byte A As Byte Dum As Byte 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 S test this assign string Dum Len s get length of string For I 1 To Dum for all characters from left to right A Mid s 1 get cha
59. clicking the Set All button you can set all points With the Options Compiler LCD 9 settings you can choose if the 3 most significant bits must be set high Some LCD displays require this When you are finished you can press the Ok button a statement will be inserted in your active program editor window at the current cursor position The statement looks like this Deflcdchar 45 1 2 3 4 5 6 7 8 You must replace the sign with a number ranging from to7 When you want to display the custom character you can use the chr function LCD chr 0 will display custom character 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 4 30 Tools Graphic Converter The Graphic converter is intended to convert BMP files into BASCOM Graphic Files BGF that can be used with Graphic LCD displays The following dialog box will be shown 2007 MCS Electronics BASCOM IDE 55 Graphic converter 1 To load a picture click the Load button The picture may be 64 pixels high and 240 pixels width When the picture is larger it will be adjusted 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 bla
60. clicking the hardware simulator button El a special window will become visible This window has a LCD simulator which can simulate custom characters LED simulation for port 0 3 and a 7 digit LED display simulation The LCD type can be selected from the menu Note that the display isn t as fast as it could be but to assign display all the dots costs a lot of processor time The advantage however is that custom characters can be displayed too The LED s can be switched on or off by clicking on it The LED type can be set with the CG checkboxes To select common ground you must set the marker This will have the effect that all common cathodes are connected to ground and so the LED will be on when the port value will be high The 7 digit display can be connected to individual port pins To change the setting you must press the right mouse button to bring up the digit properties window E dit digit properties X a P1 0 f 11 c P1 2 4 3 e P14 E dai 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 Real hardware simulation Press the real hardware simulation button to enable the hardware simulation You need additional hardware to use this feature You can use the MCS flash programmer to simulate one port An application note
61. data Restore Dta4 Read 5 Print 5 string data END DTA1 Data 5 10 100 DTA2 Data 1 1000 Integer and Word constants must end with the sign Integer 0 or gt 255 DTA3 Data 12356786 long constants must end with the amp sign DTA4 Data Hello world 34 REM You can also mix different constant types on one line Data TEST 5 1000 1 amp 1 1 6 76 DEBOUNCE Action Debounces a port pin connected to a switch Syntax DEBOUNCE Px y state label SUB Remarks Py b port pin like P1 0 to examine State for jumping when Px y is low 1 for jumping when Px y is high UB he label to GOTO when the specified state is detected he 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 de
62. 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 CONFIG WATCHDOG value he time in mS it takes the WD will overflow causing a reset Possible values are 16 32 64 128 256 512 1024 or 2048 See Also CONFIG WATCHDOGI132 Example DIM A AS INTEGER CONFIG WATCHDOG 2048 after 2 seconds a reset will occur START WATCHDOG start the WD DO PRINT a 1 notice the reset REM RESET WATCHDOG delete the REM to run properly LOOP END 6 199 WHILE WEND Action Executes a series of statements in a loop as long as a given condition is true 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 2007 5 Electronics BASCOM Language Reference 237 statement See also DO LOOP 144 FOR NEXT 148 Example Dim A As Byte While A lt 10 Print A Incr A Wend 2007 MCS Electronics Using
63. expression to test for The expression may contain defined constants Conditional compilation is used to include parts of your program This is a convenient way to build different files depending on some constant values Note that unlike the IF statement the IF directive does not expect a THEN You may nest conditions to 25 levels The use of ELSE is optional Note that ENDIF must be written as ENDIF not as END IF See Also 807 821 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 the other line will be compiled 2007 MCS Electronics BASCOM Language Reference 83 65 Action These routines can be used to communicate with Dallas Semiconductors 1Wire devices Syntax 1 for use with the CONFIG 1WIRE statement 1WRESET 1WWRITE vari bytes var2 1WREAD bytes Syntax 2 for use with multiple devices pins 1WRESET pin 1WWRITE vari bytes pin var2 1WREAD bytes pin var2 1WREAD pin 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 vari Sends the value of vari to the bus
64. 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 amp H400 to amp H7ff addresses from amp HO to amp HOFF are taken by IC7 RTC PCF8583 while addresses from amp H100 to amp 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 2007 MCS Electronics 304 BASCOM 8051 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 amp H400 to amp H7ff addresses from amp HO to amp HOFF are taken by IC7 RTC PCF8583 while addresses from amp H100 to amp H3FF are free space At start the program shows the address where to write through keys
65. it is becoming handy is with arrays Placevalue a x RO will generate Mov r0 h 3A Mov a ro 2007 MCS Electronics Using assembly 245 RI a Add a h 1F Mov RO a Mov a ro 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 RO When external variables are used you don t need to specify a register because DPTR is always assigned Dim X as xram Integer PLACEADRES x dptr or PLACEADRES x Will generate Mov dptr 2 Or with arrays PLACEADRES ar x Mov dptr 2 Mov 0 37 Mov a ro 2 Inc rO Mov a ro 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 Z amp HAA Binary notation You can also use binary notation Example Mov a amp B10001000 Jumping with offset You can specify an offset instead of a labelname when jumping Jb P1 0 12 jump forward Jb P1 0 12 jump back Jnb P1 0 0 loop until P1 0 becomes high 2007 MCS Electronics This also applies to the other ins
66. numeric data On track 2 and 3 the data is stored with 5 bit coding The ReadMagCard routine works with ISO7811 2 5 and 7 bit decoding The returned numbers for 5 bit coding are Returned number 5 characterT 2007 MCS Electronics 210 BASCOM 8051 HC 1 See also None Calls Read Magcard Code5 Example DIM used variables Dim X 40 As Byte I As Byte Bts As Byte TALIAS the pins used mcs Alias P1 1 mclock Alias P1 2 _mdata Alias 1 0 Do Print Slide magcard through reader Readmagcard X 1 Bts 5 10000 call routine j 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 2007 MCS Electronics BASCOM Language Reference 211 Loop End 6 160 REM Action Instruct the compiler that comment will follow Syntax REM Remarks You can comment your program for clarity You can use REM or followed by your comment All statements after REM or treated as comment so you cannot use statements after a REM statement It is also possible to use block comments start block comment print This will not be compiled end block comment Note that the starting sign will ensure compatibility with QB Each block must be closed with Example REM TEST BAS ve
67. register Mov b 0 selects E1 Mov b 1 selects E2 LCD with a constant will work and also with strings To call the low level routines Mov a 2 code into acc Mov B 0 or use Mov b 1 Acall LCD_CONTROL call routine 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 6 63 CONFIG LCDBUS Action Configures the LCD databus Syntax CONFIG LCDBUS constant Remarks constant for 4 bit operation 8 for 8 bit mode default Use this statement together with the LCD address statement When you use the LCD display in the bus mode the default is to connect all the data lines With the 4 bit mode you only have to connect data lines 47 44 See also CONFIG LCD 1251 2007 MCS Electronics BASCOM Language Reference 127 Example LCD amp H8000 address of enable signal Config LCDBUS 4 4 bit mode LCD hello 6 64 CONFIG MICROWIRE Action Configures the micro wire pins Syntax Config Microwire Pin Cs P1 1 Din P1 2 Dout P1 4 Clock P1 5 Al 7 Remarks Address lines See table below It depends if you work with bytes or words In our example we wil
68. the memory You can also use the LOAD button to load a program into the buffer Erase _ Erase blank a chip rite program the buffer into the chip erify if the buffer is the same as the chip content rite the selected lock bits Lock Bits 2007 MCS Electronics BASCOM 279 10 BASCOM Misc 10 1 Error messages The following table list all errors that can occur Nr Error message Error message O SUS 00 134 These are internal assembler warnings Contact MCS Electronics 1 E oo many RAM used ariable already dimensioned onstant must be in range of 1 8 138 Baudrate not supported with selected frequency 1 10 1 12 13 14 15 16 17 18 19 0 2 3 4 5 6 7 N boy QM QM o TEM o 2 Bo pa PF THEN expected TEN Ta TN TEN 9 2007 5 Electronics 280 5 8051 us rames ep SSCS 40 EouwreRoorcouTERrexpeded 42 Maximum of 128 aliases statements alowed punis OOOO Valve does notftinto bye nas No more space for extemal ave LG more space for external INTEGER WORD 47 Nomore space for STRING iso ist all outside 2048 page range Use LARGE to compile this program Unsupported LCD display Unsupported mode ariable not found or dimensioned 153 rong type BYTE INTEGER WORD LONG or STRING expected 160 Valve does her exp
69. 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 The terminal menu has a few options 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 2007 MCS Electronics 54 5 8051 4 29 Tools LCD designer With this option you can design special characters for LCD displays The following window will appear LCD designer X Clear all Set all x Cancel The LCD matrix has 7x5 points The bottom row is reserved for the cursor but can be used You can select a point by clicking the left mouse button If a cell was selected it will be de selected By clicking the Clear All button you can clear all points By
70. the TIMER2 registers to be reloaded with the 16 bit value in RCAP2L and RCAP2H The values in RCAP2L and RCAP2H are preset by software means Counter mode CONFIG TIMER2 COUNTER GATE INTERNAL MODE 0 Timer mode CONFIG TIMER2 COUNTER GATE INTERNAL MODE 0 If EXEN2 1 then a 16 bit reload can be triggered either by an overflow or by a 1 to 0 transition at input T2EX This transition also sets the EXF2 bit The TIMER2 interrupt if enabled can be generated when either TF2 or EXF2 are 1 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 2 TIMER2 will count up TIMER2 will overflow at amp HFFFF and sets the TF2 flag which can then generate 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 amp HFFFF to be reloaded into the timer registers TL2 and TH2 Counter mode CONFI
71. to drive the MOS FET Cable lengths this section is only for some limited understanding For short runs up to 30 meters cable selection for use on the 1W bus is less critical Even flat modular phone cable works with limited numbers of 1 Wire devices However the longer the 1W bus the more pronounced cable effects become and therefore the greater importance placed on cable selection For longer distances DS recommends twisted pair cable CAT5 DS standard examples show 100 meters cable lengths so they say that s no 2007 MCS Electronics Additional Hardware 261 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 Noise and CRC The longer cable and the noisier environment the more false readings will be made The devices are equipped with a CRC generator the LSByte of the sending is always a checksum Look in program examples to learn how to re calculate this checksum in your uC AND if you notice that there are false readings do something about your cables Shield lower resistor 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
72. turn LCD into 8 bit databus mode use this with uP with external RAM and or ROM because it doesnt need the port pins Cls clear the LCD display Led Hello world display this at the top line Wait 1 Lowerline select the lower lin Wait 1 Leod Shift this display this at the lower line Wait 1 For A 1 To 10 2007 MCS Electronics 180 5 8051 Shiftlcd Right shift the text to the right Wait 1 wait a moment Next For A 1 To 10 Shiftlcd Left shift the text to the left Wait 1 wait a moment Next Locate 2 1 set cursor position Lcd display this Wait 1 wait a moment Shiftcursor Right shift the cursor Lcd Q display this Wait 1 wait a moment Home Upper select line 1 and return home Led Replaced replace the text Wait 1 wait a moment Cursor Off Noblink hide cursor Wait 1 wait a moment Cursor On Blink show cursor Wait 1 wait a moment Display Off turn display off Wait 1 wait a moment Display On turn display on NEW support for 4 line LCD Thirdline Led Line 3 Fourthline Led Line 4 Home Third goto home on line three Home Fourth Home F first letteer also works Locate 4 1 Lcd Line 4 Wait 1 Now lets build special character the first number is the characternumber 0 7 The other numbers are the rowvalues Use the LCD tool to insert this line Deflcdchar 0 31 17 17 17 17 17 31 0 re
73. 0 3 See Hardware for more details So CONFIG TIMERO COUNTER GATE INTERNAL MODE 2 will configure TIMERO as a COUNTER with no external gate control in mode 2 auto reload 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 TIMERO COUNTER MODE 1 GATE INTERNAL 2007 MCS Electronics 132 5 8051 COUNTERO 0 reset counter 0 START COUNTERO enable the counter to run DELAY wait a while PRINT COUNTERO print it END 6 71 CONFIG WATCHDOG Action Configures the watchdog timer from the AT89C8252 Syntax CONFIG WATCHDOG time Remarks he interval constant in mS the watchdog timer will count to Possible settings 16 32 64 128 256 512 1024 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 24 STOP WATCHDOG 2 RESET WATCHDOG 22 Example 1995 2006 MCS Electronics WATCHD BAS demonstrates the 478958252 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 wil
74. 07 EXAMPLEs BASCOM LT for K51 AVR K51 AVR DEMO AD11 DEMO AD4 DEMO DA DEMO DEMO WEE DEMO LCD DEMO PPI DEMO PPI1 DEMO PPO DEMO PPO1 DEMO 2 DEMO RTC DEMO TER BASCOM LT Examples for boards KND O8 44 KAD 08 KND 08 KND 44 KAD 08 EXAMPLEs BASCOM 8051 for K51 AVR K51 AVR 51 11 51 4 51 DA 51 51 WEE 51 PPI 51 51 51 TER GPC F2 F2 11 F2 ADA F2 DA F2 F2 WEE F2 PPI F2 PPO F2 RTC F2 TER BASCOM 8051 Examples for boards O8 44 KAD 08 2007 MCS Electronics 308 5 8051 KND 08 KND 44 KAD 08 KAD 08 2 GPC F2 F2 KND 08 F2 KND 44 F2 KAD 08 F2 KND 08 2 EXAMPLEs BASCOM AVR for KB1 AVR K51 AVR DEMO 11 DEMO AD4 DEMO DA DEMO REE DEMO WEE DEMO PPI DEMO PPO DEMO RTC DEMO TER BASCOM AVR Examples for boards O8 44 KAD 08 KND 08 KND 44 KAD 08 Page up dated at June 7st 2000 GRIFO Via dell Artigiano 8 6 40016 San Giorgio di Piano Bologna ITALY Tel 39 051 892 052 4 lines FAX 39 051 893 661 E mail for commercial communications sales grifo it for technical communications tech grifo it for general communications grifo grifo it 2007 MCS Electronics Third party hardware 309 13 1 2 Rhombus Rhombus developed the SCE 51 A powerful small 8051 micro processor board with
75. 1 006 25 1 044 26 1 080 27 1 117 28 1 153 29 1 189 30 1 224 31 1 260 32 1 295 33 1 329 34 1 363 35 1 397 36 1 431 37 1 464 38 1 497 39 1 530 40 1 562 41 1 594 42 1 626 43 1 657 44 1 688 45 1 719 46 1 750 155 2007 MCS Electronics 156 BASCOM 8051 Data amp H18 Data amp H18 Data amp H19 Data amp H19 Data amp H19 Data amp H19 Data amp H20 Data amp H20 Data amp H20 Data amp H21 Data amp H21 Data amp H21 Data amp H21 Data amp H22 Data amp H22 Data amp H22 Data amp H22 Data amp H23 Data amp H23 Data amp H23 Data amp H23 Data amp H24 Data amp H24 Data amp H24 Data amp H24 Data amp H25 Data amp H25 Data amp H25 Data amp H25 Data amp H26 Data amp H26 Data amp H26 Data amp H50 Data amp H49 Data amp H49 Data amp H48 Data amp H48 Data amp H47 Data amp H47 Data amp H47 Data amp H46 Data amp H46 Data amp H45 47 1 780 48 1 810 49 1 840 50 1 869 51 1 898 52 1 927 53 1 956 54 1 984 55 2 012 56 2 040 57 2 068 58 2 095 59 2 122 60 2 149 61 2 176 62 2 202 63 2 228 64 2 254 65 2 279 66 2 305 67 2 330 68 2 355 69 2 379 70 2 404 71 2 428 72 2 452 73 2 476 74 2 499 75 2 523 76 2 546 77 2 569 78 2 591 79 5 000 80 4 953 81 4 907 82 4 862 83 4 816 84 4 771 85 4 727 86 4 683 87 4 639 88 4 596 89 4 553
76. 1995 2006 MCS Electronics 5 demonstrates PEEk CPEEK and OUT Dim I As Integer 1 As Byte dump internal memory For I 0 To 127 for a 8052 225 could be used Break Bl Peek get byte from internal 2007 MCS Electronics BASCOM Language Reference 135 memory Printhex Poke I 1 write a value into memory Next Print new line be careful when writing into internal memory now dump a part ofthe code memory program For 0 To 255 Cpeek i get byte from internal memory Printhex Next note that you can not write into codememory Out amp H8000 1 write 1 into XRAM at address 8000 Bl INP amp H8000 return value from XRAM Print Bl End 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 z displays the state is ON BLINK See also DISPLAY 1431 Example Dim a as byte 255 LCD a Cursor Off hide cursor Wait 1 wait 1 second Cursor Blink Dlink cursor End 2007 MCS Electronics 136 BASCOM 8051 6 75 DATA Action Specifies values to be read by subsequent READ statements Syntax DATA var varn Remarks Var Numeric or string constant
77. 2007 MCS Electronics 122 5 8051 P1 0 to P1 7 to DBO DB7 of the 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 write P3 7 to RD of LCD read 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 1115 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 55 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 ON OFF BLINK NOBLINK can be used the same way as for text displays LCD 175 can also be the same way as for text displays LCDHEX 8 can also be used the same way as for text disp
78. 4 and stand alone PCB are shown JS 07104 SimmStick Connect when use without DT boards 2 1006F Optional cap see Helpfile I received the following useful information Hi Mark 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 This may be useful to your users 2007 MCS Electronics 272 BASCOM 8051
79. 5 CONFIG BAUD Action Configure the uP to select the intern baud rate generator This baud rate generator is only available in the 80515 80517 80535 80537 and compatible chips 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 6 56 CONFIG BAUD1 Action Configure the uP to select the internal baud rate generator for serial channel 1 This baud rate generator is only available in the 80517 and 80537 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 Example CONFIG BAUD1 9600 use internal baud generator OPEN Com2 for Binary as 1 Print 1 Hello Close 1 End 2007 MCS Electronics 120 BASCOM 8051 6 57 CONFIG DEBOUNCE Action Configures the delay time for the DEBOUNCE statement Syntax CONFIG DEBOUNCE time Remarks A numeric constant which specifies the delay time in mS When the debounce time is not configured 25 mS will be used as a default Note that the delay time is based on a 12 MHz clock frequency See also DEBOUNCE 13 Example Config Debounce 25 mS 25 mS is the default 6 58 CONFIG I2CDELAY Action Configures the delay for the I2C clock Syntax CONFIG I2CDELAY value Remarks A numeric constant 1 will generate the def
80. 51 PRIORITY 20 PUT 20 READ 2051 READMAGCARD 209 REM 21 REPLACE 211 79 2007 Electronics 80 5 8051 6 2 RESET 2121 RESTORE 5 3 RETURN 213 RIGHT 215 RND 2 4 ROTATE 215 SELECT 21 SET 216 SHIFT 217 SHIFTCURSOR 217 SHIFTIN 18 SHIFTOUT 18 SHIFTLCD 218 SHOWPIC 2207 SOUND 220 SPACE 222 gt 23 SPIIN 221 SPIOUT 2251 START 225 STOP zx STOP TIMER 2201 STR 25 STRING 24 SUB 22 SWAP 2361 T THEN 169 THIRDLINE 231 TIMEOUT 10 TO 1481 U UCASE lzsh UPPERLINE 235 V VAL 255 VARPTR 233 W WAIT 2357 WAITKEY 237 WAITMS 237 WHILE WEND 23 Action Conditional compilation directive that tests for a condition Syntax test ELSE 2007 MCS Electronics BASCOM Language Reference 81 ZENDIF Remarks test An expression to test for The expression may contain defined onstants Conditional compilation is used to include parts of your program This is a convenient way to build different files depending on some constant values Note that unlike the IF statement the directive does not expect a THEN You may nest conditions to 25 levels The use of ELSE is optional See Also ELSE 81 ENDIF s Const DEMO 1 0 normal 1 demo Demo Print Demo program
81. 7 MCS Electronics Third party hardware 303 Examples BASCOM 8051 Examples BASCOM AVR SHORT PROGRAM DESCRIPTION X AD11 This program monitors one anagogic channel out of eleven managed by IC12 TLC2543 visualization of the channel is in hexadecimal format through T1 and T2 the channel to convert is selected T1 increments while T2 decrements The display shows first the channel being converted then the 12 bits wide hexadecimal value of the channel converted 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 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
82. 8051 MCS ELECTRONICS UC SYSTEMS BASIC COMPILERS SCVELOPRIENT MCS Electronics 1995 2007 BASCOM 8051 user manual Introduction by MCS Electronics Dear reader Thank you for your interest in BASCOM BASCOM was invented in 1995 It was intended for personal usage only 1 decided to make it public as 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 We hope that BASCOM will contribute in making your work with microprocessors Easy and enjoyable The MCS Electronics Team BASCOM 8051 2007 MCS Electronics All rights reserved No parts of this work 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
83. 812 117 Using the DAC 294 that also contains an example The additional interrupts are ADCI I2CSPI and PSMI To enable them ENABLE 1451 ADCI ENABLE I2CSPI ENABLE PSMI To disable them DISABLE 1431 ADCI DISABLE I2CSPI DISABLE PSMI To set the priority to the highest level in addition to the normal priority interrupt Sources PRIORITY 206 PRIORITY 20 80552 SET RESET ADCI SET RESET I2CSPI 2007 MCS Electronics Microprocessor support 289 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 To use the PWM of the 80552 Dim Pwp As Byte Pwa as Byte Pwb as Byte Pwp 200 set output frequency 0 255 Pwa 50 set channel 0 a pulse width 0 255 Pwb 0 set channel 1 b pulse width 0 255 Do Gosub Pwm Loop Pwm asm MOV PWMP Pwp MOV PWMO Pwa MOV PWM1 Pwb end asm Return 11 2 2 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 inter
84. A Mid s I 1 get character Put 1 A write it to comport Next Do Get 2 A get character from comport Put 1 A write it back Print A use normal channel Loop Close 1 finally close device Close 2 End 6 158 READ Action Reads those values and assigns them to variables Syntax READ var Remarks var ariable 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 2007 MCS Electronics BASCOM Language Reference 209 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 100095 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 ard reader he number of bytes read from the card Shifts he 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 There can be 3 tracks on a magnetic card Track 1 strores the data in 7 bit including the parity bit This is handy to store alpha
85. A value with the index of the table The index is zero based That is 0 ill return the first element of the table he label where the data starts ar language optional variable that holds a number to identify the language The irst language starts with the number 0 he length of the data for each language value Byte Integer Word Long Constant Range 0 255 See also LOOKUP 85 Example Dim S As String 8 Idx As Byte 2007 MCS Electronics BASCOM Language Reference 187 Idx 0 5 Lookupstr idx Sdata Print 5 will print THIS End 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 yili print DIt End Sdata Data This is a test T 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 he variable that is assigned with the LSB of var S he source variable to get the LSB from See also HIGH 68 LOWW i HIGHW 165 Example Dim I As Integer Z As Byte I amp H1001 Z Low I is1 2007 MCS Electronics 188 5 8051 6 130 LOWW Action Retrieves the two least significant bytes of a long Syntax var LO
86. ACACACACACACACACACACAC Password Enter Password Again Email Enter Email again Full name Full Name Sending Email notify on updates vi Submit Registration 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 e 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 e If the registration is successful you will get a message that the registration succeeded Now you can login You will see the following screen 2007 MCS Electronics Updates Product registration Login 29 Product registration Login Your current status Registration approved SLA Service access Yes Support Center Add help tip f SLA Service You need to chose Product registration following screen will be shown Modify email address Modify password Download Lic files Logout p D c zProduct registration Q Main page Available products Product serial number example CD 0000 12345 e Select a product from the list e Enter the serial number BASCOM AVR
87. AD 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 9o sign Integer 0 or gt 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 eh Example Dim Result As Byte Y As Byte Gosub Pr jump to subroutine Print Result print result End program ends pas start subroutine with label Result 5 Y do something stupid Result Result 100 add something to it Return return 2007 MCS Electronics 214 BASCOM 8051 6 165 RIGHT Action Return a specified number of rightmost characters in a string Syntax var RIGHT var1 st he string that is assigned st he starting position All strings must be of the same data type internal or external See also LEFT ef MID eh Example Dim s As XRAM String 15 z As XRAM String 15 s ABCDEFG z Right s 2 Print z 6 166 RND Action Returns a random number Syntax var RND limit Remarks Limit he 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 A It is important to understand that the RND function is a math function Every time you r
88. AKEBCD MAKEDEC MAKEINT MID MOD MODE NACK NEXT NOBLINK NOSAVE NOT OFF ON OR OUT PO 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 2007 MCS Electronics 286 5 8051 TIMERO TIMER1 TO UNTIL UPPER UPPERLINE VAL WAIT WAITKEY WAITMS WATCHDOG WRITEEEPROM WEND WHILE WORD XOR XRAM The internal registers are also reserved words variables TMOD TLO TL1 THO TH1 SBUF Note that you can change the internal registers with the Register File c settings from the Options menu 2007 MCS Electronics 288 5 8051 11 11 1 Microprocessor support Microprocessor support Some microprocessors have additional features compared to the AT89C2051 8051 8032 8052 AT89S8252 TIMER2 285 AT89S8252 WATCHDOG 235 DATA EEPROM 22 Alternative port pin functions 2561 80515 80535 80517 80535 GETAD 157i WATCHDOG 295 BAUDRATE GENERATOR 11 INTERRUPTS and PRIORITY 2951 80517 80537 GETAD 154 WATCHDOG 2951 BAUDRATE GENERATOR 119 BAUDRATE GENERATOR1 n INTERRUPTS and PRIORITY 24 89C51 WATCHDOG 297 PRIORITY 205 ADUC812 CONFIG ADUC
89. APH CLS BOTH Remarks Clearing the LCD display does not clear the CG RAM in which the custom characters are stored See also LCD 951 LCD 1761 15 Lcd Hello Wait 5 Cls End 2007 MCS Electronics 116 BASCOM 8051 6 51 CONST Action Declares a symbolic constant Syntax CONST symbol value Remarks he name of the symbol he value to assign to the symbol Assigned constants consume no program memory The compiler will replace all occurrences of the symbol with the assigned value Value may also be an expression that uses other defined constants The functions that may be used for the expressions are ASC ABS ATN COS EXP FIX INT LOG RND SGN SIN SQR TAN Operators are AND OR XOR NOT gt lt gt lt lt gt G See also DIM at Example 1995 2006 MCS Electronics CONST BAS Dim A As Const 5 declare a as a constant Dim B1 As Const amp B1001 Dim S As Single Or use the new preferred syntax Const Cbyte amp HF Const Cint 1000 Const Csingle 1 1 Const Cstring test S Csingle Print 5 Cstring Waitms A wait for 5 milliseconds Print A Print Bl 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 CONFIG TIMERO TIMER1 13h 2007 MCS Electronics BASCOM Language Refere
90. APH will clear only the graphic part To init the display manual you can use Ledinit But this should not be needed as it is initilised at start up Locate is supported and you can use 1 8 for the row and 1 30 for the column Locate 1 1 2007 MCS Electronics BASCOM Language Reference 91 cursor control is the same as for normal LCD Cursor On Blink And to show some text you can use LCD Lcd Hello world Note that the cursor position is not adjusted You can set it with locate Now comes the fun part for using a graphic LCD can display a BMP file You may use MSPAINT or any other tool that can create a BMP file With the Graphic converter from the Tools Menu you can convert the file into a BGF file BASCOM GRAPHICS FILE The conversion will convert all non white pixels to BLACK 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 Picturel 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 You could remove it too For X 0 To 10 For Y 0 To 10 Step 2 Pset X Y 0 Next Next A sim
91. ASCOM 8051 LIBRARY V 2 12 8954051 89540451 12 08 2006 21 42 22 Print 1 Baudrate 0 Frequency 8000000 2 212 Fa amp HO amp HO 4 bit Sort vars amp H21 oN amp H73 115 dec are Address Sort Const Name C Type See the Options Compiler Output 571 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 Information provided in the report he start and end time needed for compilation he timer used for the generation of the baud rate he baud rate selected for the uP and the used crystal This info is used for RS232 related statements such as PRINT and INPUT Note that when you use the crystal and baud Statements the exact baud rate is shown 2007 MCS Electronics BASCOM IDE 49 ROM start he starting location of ROM memory RAM start he starting location of RAM memory LCD mode 4 bit or 8 bit LCD mode Stack start he starting location of the stack The space below the stack is used for internal variables The stack grows when calls are made by the machine language routines Used ROM Displays the length of the binary file Variable he name type and the location in memory of the used ariables 4 26 Program Simulate This option displays the Simulator window in which
92. BASCOM IDE 45 to the line number of your choice 4 20 Edit Indent Block Action Indents a block of selected text You need to select at least one line in order to use this option When you have a structure like Do 1 b b 1 Loop It is hard to see the structure You can best indent your code Do 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 4 21 Edit Unindent Block Action UnIndents a block of selected text You need to select at least one line in order to use this option When you have a structure like Do 1 b b 1 Loop It is hard to see the structure You can best indent your code Do 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 1 b b 1 Loop 2007 MCS Electronics 46 BASCOM 8051 The sample above show that too much indention does not make the program readable 4 22 Editor Keys The following table lists all editor shortcuts 2007 MCS Electronics BASCOM IDE 47 CTRL F Find text CTRL W Show result of compilation CTRL L LCD designer CR To select text Hold the SHIFT key down and use t
93. COM Language Reference 161 IR Empf nger Demodulator Baustein IR Receiver Demodulator Device Surface not 762 A2 54 See Also NONE Example SFH 506 3 E 2 RC5 BAS connect SFH506 36 IR receiver to choose the correct port from the have P3 2 pin On other chips it may be another 1995 2006 MCS PORT 3 2 INTO Compiler I2C TAB Electronics IntO0 should pin Dim New As Bit Dim Command As Byte Subaddress As Reset Tcon 0 triggered by rising edge On 0 Receiverc5 Enable IntO Enable Interrupts Do If New 1 Then received new code Disable IntO Print Command New 0 new bit Enable IntO End If Byte Subaddress reset 2007 MCS Electronics 162 BASCOM 8051 Loop Receivercsd 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 he 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 ei CALL 113 RETURN 213 Example GOSUB Routine branch to routine Print Hello
94. CONST 116 ERASE 147 Example c 1995 2006 MCS Electronics file DIM BAS demo DIM Dim As Bit bit be 0 or 1 Dim A As Byte byte range from 0 255 Dim C As Integer integer range from 32767 132768 Dim L As Long Dim S As Single Assign bits B1 1 Or Set Bl use set Assign bytes 12 1 Assign integer 12 100 Print C Assign long L 12345678 Print L Assign single 2007 MCS Electronics BASCOM Language Reference 143 S 1234 567 Print S End 6 83 DISABLE Action Disable specified interrupt Syntax DISABLE interrupt Remarks Interrupt INTO INT1 SERIAL TIMERO TIMER1 or TIMER2 For other chips INT2 INT3 4 INT5 INT6 INT7 INT8 CAN By default all interrupts are disabled To disable all interrupts specify INTERRUPTS To enable the enabling and disabling of individual interrupts use ENABLE INTERRUPTS Depending on the chip used there can be more interrupts Look at microprocessor support 28 for more details See also ENABLE 145 Example Enable Interrupts enable the setting of interrupts Enable 0 enable TIMERO 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 2007
95. Compiler Output 571 Compiler Communication 581 Compiler I2C s8 Compiler LCD 591 Compiler Misc 607 Communication 601 Environment s Hardware Simulator 647 Programmer 647 Monitor Printer 661 Window Cascadel 1 Tile s Arrange Icons s Minimize 671 About 67 Index 167 Forum es Support es Credits ee 4 3 File New Action This option creates a new window in which you can write your program The focus is set to the new window Depending on the environment settings the window is normal sized or maximized 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 4 4 File Open Action With this option you can load an existing program from disk BASCOM saves files in ASCII format Therefore if you want to load a file which is made with another editor be sure that it is saved as an ASCII file You can specify that BASCOM must reformat the file when it opens the file See Options Environment amp options 2007 MCS Electronics 40 BASCOM 8051 4 5 4 6 4 7 4 8 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 o
96. E 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 2007 MCS Electronics BASCOM Language Reference 95 6 18 LIB Action Compiler directive that instructs the compiler to look for assembler routines in the specified LIB file Syntax SLIB 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
97. ENABLE INTERRUPTS activate interrupt handler ON SERIAL label branch to label if serial int occur DO loop for ever LOOP 2007 MCS Electronics BASCOM Language Reference 207 Label start label PRINT Serial int occurred print message RETURN return from interrupt 6 156 PSET Action Sets or resets a single pixel Syntax PSET X Y value Remarks he X location of the pixel In range from 0 239 he Y location of the pixel In range from 0 63 he value for the pixel O will clear the pixel 1 Will set the pixel The PSET is handy to create a simple data logger or oscilloscope See also CONFIG GRAPHLCD 125 Example Dim X as Byte Y as Byte For X 0 To 10 For Y 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 fPositive numeric constant that refers to the opened channel var A variable or constant who s value is sent to the the software UART 2007 MCS Electronics 208 BASCOM 8051 See also GET sh PRINT 208 INPUT 175 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 S test this assign string Dum Len s get length of string For I 1 To Dum for all characters from left to right
98. G TIMER2 COUNTER GATE INTERNAL EXTERNAL MODE 0 DIRECTION DOWN Timer mode 2007 MCS Electronics Microprocessor support 291 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 Baud rate generator This mode can be used to generate a baud rate for the serial port TIMER1 can be used for an other task this way CONFIG TIMER2 TIMER GATE INTERNAL MODE 2 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 Note that TIMER1 must be setup from assembler this way 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 Note that TIMER1 must be setup from assembler this way Clock output Some 8052 deviants have the ability to generate a 50 duty cycle clock on P1 0 CONFIG TIMER2 TIMER MODE 5 The output frequency fOSC 4 65536 CAPTURE Use CAPTURE value to set the capture register How to determine what caused the interrupt You can test the bit T2CON 7 to see if an overflow caused the interrupt You can test bit T2CON 6 whether either a reload or capture is caused by a negative trans
99. INIT 98 991 NORAMCLEAR 9 NOSP 1001 2 1001 RAMSIZE hot RAMSTART 103 REGFILE 02 ROMSTART SERIALINPUT 105 SERIALINPUT2LCD 1105 SERIALOUTPUT 1061 SIM ho BITWAIT BCD 1121 BREAK 113 2007 MCS Electronics 78 5 8051 CLS 115 CONFIG 11 CONST COUNTER 135 CPEEK CURSOR 3 D DEFBYTE 145 DEFLCDCHAR 145 DEFWORD 4 DELAY hat DIM ha DISABLE 145 DISPLAY 143 DO ELSE 4h ENABLE 145 END F FOR FOURTHLINE 1451 FUSING 151 GET 15h GETAD 54 GETAD2051 155 H I I2CRECEIVE 166 I2CSEND 671 I2CSTART 164 I2CSTOP 165 I2CRBYTE 68 2007 MCS Electronics BASCOM Language Reference I2CWBYTE 1641 IDLE 165 IF fies INCR 7h INKEY 17h INP INPUT 173i INPUTBIN 175 INPUTHEX 176 INSTR 177 LCASE 8 LCD LCDINIT hat LCDHEX 182 LEFT Ha LEN fief LOAD fish LOCATE 185 LOOKUP 185 LOOKUPSTR hs 4 LOW LOWW 188 LOWERLINE 185 MAKEDEC 8 MAKEBCD 18 MAKEINT 195 MAX 194 MID hot MIN 1941 MOD ho NEXT 195 ON Interrupt 195 ON Value ts OPEN 195 OUT zo POWERDOWN 2051 PRINT 205 PRINTBIN 207 PRINTHEX 20
100. INT 2007 MCS Electronics BASCOM Language Reference 221 Remarks bn ny I O pin such as 1 0 etc duration he number of pulses to send Byte integer word or constant 1 32768 he 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 duration frequency NOINT Remarks Any I O pin such as 1 0 etc his 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 Frequency his is an integer word or constant that that will be used to generate the frequency A higher value will result in a higher requency 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 instea
101. IPS 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 The Baud rate is generated by dividing the system clock When a crystal of 11 0592 Mhz is used the Baud rate can be generated very accurately Other crystals can be used too but the generated baud rate will never be exactly 2400 or 4800 baud and higher baud rates are almost impossible The exact baud rate is shown in the report file 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 Timers and Counters The 8051 has two 16 bit timers named TIMERO and TIMER1 Below the internal representation of timerO is shown TIMERO and TIMER1 are almost identical so you can read TIMER1 for TIMERO 2007 MCS Electronics 252 BASCOM 8051 H rt gt Va CO Each counter register has two SFRs associated with it For TIMERO the SFRs are TLO and THO TLO is the lowest byte of TIMERO and THO is the highest byte of TIMERO These two registers make the timers 16 bit wide The timer can operate as a timer or as a counter A timer uses the system clock divided by 12 as the source of its input pulses So it increments periodical A co
102. L 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 MCS Auto Update Wiz 1 0 0 10 Check for Newer Auto Update MCS ELECTRONICS MCS Auto Update ereenn BASIC COMPILERS DEVEL Downloading New Wizzard SORT 2007 MCS Electronics Updates 33 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 Select Directory Directory Name c Program Files MCS Electronics BAS COMS051 Directories Files c B0515C DAT gt Program Files 3051 7 DAT 151 F000 dat gt MCS Electronics 2051F020 dat B SCOM8051 4 SAMPLES Drives c cdisk After you click Ok the directory to update is stored in the LIC file It will not be asked again MCS Auto Update Wiz 1 0 0 13 Welcome ELECTRONICS MCS Auto Up
103. LCD to the data bus With an address decoder you can select the LCD display See Also 951 Sled amp H8000 the LCD high Sledrs amp H8002 the Cls LCD high Led Elektor End writing to this address will writing to this address will make the make the E line of RS line of 2007 MCS Electronics BASCOM Language Reference 97 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 Will generate the following section in the report file 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 13 2007 MCS Electronics 98 BASCOM 8051 Example Snobreak Break this isn t compiled into code so the simulator will not pause End 6 23 NOINIT Action Instruct the compiler that no initializatio
104. LIB Manager 55 Tool Triscent Converter 56 Tools Exportto RTF 57 Tools Graphic Converter 54 U UCASE 231 UPPERLINE 232 Using assemly 239 Using the DAC 294 VAL 232 VARPTR 233 W WAIT 233 WAITKEY 234 WAITMS 234 WATCHDOG 235 WEND 236 WHILE 236 WHILE WEND 236 Window arrange icons 67 Window cascade 66 2007 MCS Electronics Index Window 67 Windows minimize all 67 315 2007 MCS Electronics MCS Electronics 1995 2007 www mcselec com Making BASIC Easy
105. MCS Electronics 144 5 8051 See also CURSOR hs LCD 178 Example Dim a as byte 255 LCD 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 statement See also EXIT 1481 i WHILE 236 WEND 236 FOR 145 NEXT 1951 Dim As Byte Do start the loop 1 increment Print pranb LE Loop Until A 10 Repeat loop until 10 Print A A is still 10 here 6 86 ELSE Action Executed if the IF THEN expression is false Syntax ELSE Remarks 2007 MCS Electronics BASCOM Language Reference 145 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 bi gt a THEN ELSE END IF See also IF 1169 END IFI4 SELECT CASE le amp Example Dim A As Byte A 10 let a 10 If gt 10 Then make a decision Print A gt 10 this will not be printed Else alternative Print A not greater than 10 this will be printed END IF 6 97 ENABLE Action Enable specified interrupt Syntax ENABLE interrupt Remarks Interrupt INTO INT1 SERIAL TIMERO TIMER1 or TIMER2 For other chips also INT2 INT3 INT4 INT5 INT6 INT7 INT8
106. N Value 191 READMAGCARD 208 REM ei RETURN 2131 RND 21h ROTATElei SHIFT 247 SHIFTIN e SHIFTOUT 218 SOUND 221 SUB zzi SWAP 2301 2007 MCS Electronics 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 You must have Administrator rights in order to be able to run setup The opening screen looks like 1 Setup BASCOM 8051 Welcome to the BASCOM 8051 Setup Wizard This will install 2 12 13 0 on your computer It is recommended that you close all other applications before continuing Click Next to continue or Cancel to exit Setup You need to click the Next button to continue 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 2007 MCS Electronics 22 BASCOM 8051 1 Setup BASCOM 8051 License Agreement Please read the following im
107. OUT Action Compiler directive to specify that the TIMEOUT option is used with serial input Syntax 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 1731 GET 2071 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 2007 MCS Electronics 108 BASCOM 8051 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 of the variable such as 1 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 0 for example See also CONST 2007 MCS Electronics BASCOM Language Reference 109 Example Direction Ali
108. SET End If REM the following example shows the 1 line use of IF THEN ELSE If 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 Any numeric variable There are often situations where you want a number to be increased by 1 The INCR statement is faster then var var 1 See also DECR 138 Example Dim A As Integer Do start Loop Incr A increment a by 1 Print A print Loop Until A gt 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 2007 MCS Electronics 172 BASCOM 8051 Syntax var INKEY var INKEY channel Remarks Var Byte Integer Word Long or String variable he channel number of device If there is no character waiting a zero will be returned 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 les Example Dim A As Byte Do VStart loop A Inkey Look for character If A 0 Then is variable 0 Print A yes there was a character in the buffer print LE End If Loop loop forever Example r
109. See also CRYSTALI eri 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 2007 MCS Electronics 90 5 8051 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 5 See also SHOWPIC 226 Example 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 V PL0 P1 7 DB DBT of LCD UPS to FS font select of LCD can be hard wired too V SENS to CE chip enable of LCD 5 sod to CD code data select of LCD MK PS to WR of LCD P37 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 Ce P3 5 Cd P3 4 Cols 30 dimension some variables used by the DEMO Dim X As Byte Y As Byte Reset P3 2 8 bat wide char is 30 columns The following statements are supported Cis wilr clear graphic and text cls TEXT will clear only the text cls GR
110. 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
111. The GETAD2051 function is only intended for the 89C2051 and 89C4051 It uses the analog comparator of the chip Connect the hardware as following 2007 MCS Electronics 154 5 8051 Unknown Voltage In pm O ZRXD 1 1 2 P1 3 4 5 6 7 See also GETAD 1521 Example regfile 89c2051 dat Dim A As Byte Do Getad2051 Lookup a Dta Print A Loop End this table converts the value into a packed BCD value this value can be used to diaplay the value on 2 7 segment displays Dta Data 0 0 0 000 Data 1 1 0 047 Data 1 2 0 093 2007 5 Electronics BASCOM Language Reference Data 2 Data 2 Data 3 Data 3 Data 3 Data 4 Data 4 Data 5 Data 5 Data 6 Data 6 Data 6 Data 7 Data 7 Data 8 Data 8 Data 8 Data 9 Data 9 Data amp H10 Data amp H10 Data amp H10 Data amp H11 Data amp H11 Data amp H11 Data amp H12 Data amp H12 Data amp H12 Data amp H13 Data amp H13 Data amp H13 Data amp H14 Data amp H14 Data amp H14 Data amp H15 Data amp H15 Data amp H15 Data amp H16 Data amp H16 Data amp H16 Data amp H17 Data amp H17 Data amp H17 Data amp H18 3 0 138 4 0 184 5 0 229 6 0 273 7 0 317 8 0 361 9 0 404 10 0 447 11 0 489 12 0 531 13 0 573 14 0 614 15 0 655 16 0 696 17 0 736 18 0 776 19 0 815 20 0 854 21 0 893 22 0 931 23 0 969 24
112. 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 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 DATA INTEGER 15 constval x Where constval is a declare constant CONST and x is a CONST too The INTEGER funtion must be used to indicate that the resulting constant is of the integer type Use WORD INTEGER LONG or SINGLE to specify the resulting constant Difference with QB Integer and Word constants must end with the sign Long constants must end with the amp sign Single constants must end with the sign See also READ 208 RESTORE 2121 Example Dim A As Byte I As Byte L As Long S As Xram String 15 Restore Dtal point to data For A 1 To 3 Read Print I read data and print it Next Restore Dta2 point to data Read I Print I integer data Read I Print I 2007 MCS Electronics BASCOM Language Reference 137 Restore Dta3 Read L Print L long
113. WW s Remarks he variable that is assigned with the two LSB of var S he source variable to get the LSB s from See also HIGHW 1651 HIGH 16 1871 Example Dim L As Integer Z As Long L amp 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 45 HOME 66 LCD Test LOWERLINE LCD Hello End 2007 MCS Electronics BASCOM Language Reference 189 6 132 MAKEBCD Action Convert a variable into its BCD value Syntax vari MAKEBCD var2 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 189 BCD 1121 65 LCD 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 MAKEDEC var2 Remarks ariable that will be assigned with the converted value ariable 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 2007 MCS Electronics 190 5
114. after being at routine print this END terminate program Routine this is a subroutine X x 2 perform some math PRINT X print result RETURN return 2007 MCS Electronics BASCOM Language Reference 163 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 e Example Dim A As Byte Start a label must end with a colon 41 increment lt 10 is it less than 10 Goto Start do it again End If close IF Print Ready that Xs xt 6 102 HEX Action Returns a string representation of a hexadecimal number Syntax var HEX x Remarks Var A string variable A numeric variable such as Byte Integer or Word See also HEXVAL her VAL 232 STR 224 2007 MCS Electronics 164 BASCOM 8051 Example Dim A As Byte S As String 10 123 S Hex a Print 5 End 6 103 HEXVAL Action Convert string representing a hexadecimal number into a numeric variable Syntax var HEXVAL x Remarks he numeric variable that must be assigned he 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 Differ
115. amed a with 10 elements 1 to 10 Dim c as Integer For C 1 To 10 5510 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 You can concatenate string with the sign Dim S As String 10 Z As String 10 S test Z S abc var 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 This will result in the string atest In BASCOM 8051 this is NOT possible because this would require a copy of the string In BASCOM the string S is assigned with a and on that moment the original string S is destroyed So you must make a copy of the string yourself in the event you need this functionality 2007 MCS Electronics BASCOM Language Reference 6 BASCOM Language Reference 6 1 BASCOM Statements 1 1WRESET 1WREAD 1WWRITE 83 1WSEARCHFIRST 851 1WSEARCHNEXT 871 1WIRECOUNT 8 COMPILER DIRECTIVES IF 01 ELSE 8 ENDIF 82 ASM END 5 881 INCLUDE 9 BAUD 89 BGF a CRYSTAL 9 DEFAULT XRAM 921 IRAMSTART 9 LARGE 94 951 A NOBREAK 7 NO
116. amp H or amp B a amp HA amp B1010 and 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 14 140 DEFBYTE 14 and or DEFWORD i4 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 Expressions and Operators 2007 MCS Electronics Language fundamentals 73 This chapter discusses how to combine modify compare 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 e Arithmetic operators used to perform calculations e Relational operators used to compare numeric values Logical operators used to test conditions or manipulate individual bits e Functional operators used to supplement simple operators Expressions and Operators An expression can be a numeric constant a variable or a single value obtained by combining constants variables and other expressions with operators Operators perform mathematical or logical operations on values The operators provides by BASCOM can be divided into four categories as follows 1 Arithmetic 2
117. an change the LCD pin layout from the Options LCD menu You can select the display used with the CONFIG LCD 125 statement The LCD display operates in 4 bit mode See the 1 1 statement for operation in 8 bit mode BASCOM supports a lot of statements to control the LCD display For those who want to have more control the example below shows how to do so 5 load register A with value Call Lcd control it is a control value to control the display Acc 65 load with new value letter A Call Write write it to the LCD display Note that control and write lcd are assembler subroutines which can be called from BASCOM See manufacture details from your LCD display for the correct assignment 2007 MCS Electronics 258 BASCOM 8051 8 4 8 5 Hardware 2 The design below shows how to implement I2C bus Note that you can select which port pins you want to use for the I2C interface with the compiler settings 587 D V 1 1 1 1 1 1 1 1 61 UT GND ATS9c20S51 330 You can also select the SDA and SCL pin with the CONFIG SDA 12 and CONFIG SCL 128 statement 1WIRE INFO The following information is written by G te Haluza thanks Dallas Semiconductor DS 1wire This is a brief description of DS 1wirebus when used in combination with BASCOM For more detailed explanations about t
118. anguage Reference 231 NONE See also UPPERLINE 225 LOWERLINE 188 7 FOURTHLINE 15 Example Dim a as byte 255 LCD Thirdline LCD a Upperline End 6 190 UCASE Action Converts a string into upper case Syntax dest UCASE source Remarks dest he string variable that will be assigned with the upper case of string SOURCE he source string The original string will be unchanged See also LCASE 178i Example Dim S As String 12 2 As String 12 Input Hello 5 assign string 5 Lcase s convert to lowercase Print 5 print String S Ucase s convert to upper case Print 5 PEINE string 2007 MCS Electronics 232 BASCOM 8051 6 191 UPPERLINE Action Reset LCD cursor to the upper line Syntax UPPERLINE Remarks NONE See also LOWERLINE 1881 THIRDLINE 237 FOURTHLINE 145 Example Dim a as byte a 255 LCD Lowerline LCD 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 ariable of the string type var Byte Integer Word Long Single See also STR zzii HEXVAL 64 Example Dim a as byte s As XRAM string 10 5 123 a Val s convert string 2007 MCS Electronics BASCOM Language Reference Print a End 6 193 VARPTR A
119. ariable types The following BASCOM statements are examples of non executable statements REM or starts a comment e DIM A comment is a nonexecutable statement used to clarify a programs operation and purpose A comment is introduced by the REM statement or a single quote character The following lines are equivalent PRINT Quantity remaining REM Print report label PRINT Quantity remaining Print report label More than one BASCOM statement can be placed on a line but colons must separate statements as illustrated below FOR I 1 TO 5 PRINT Gday mate NEXT I 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 Elementary Data Types Bit 1 8 byte Byte 1 byte Bytes are stores as unsigned 8 bit binary numbers ranging in value from to 255 e Integer two bytes 2007 MCS Electronics 72 BASCOM 8051 Integers are stored as signed sixteen bit binary numbers ranging in value from 32 768 to 32 767 e Word two bytes Words are stored as unsigned sixteen bit binary numbers ranging in value from 0 to 65535 e Long four bytes Longs are stored as signed 32 bit binary numb
120. ary files The following menu options are available Exit Exit the programmer Buffer clear Clear the buffer That is fill it with zero bytes Buffer Read from disk Load a file into the buffer By default the current program BIN file is selected Select a file with the file selection dialog box and press the Ok button Buffer Write to disk Write the content of the buffer to a file Note that the file size is 1024 2048 or 4096 bytes depending on the chip type 2007 MCS Electronics Supported Programmers 265 Buffer read from chip Read the content of the FLASGROM into the buffer If the lock bits are set all bytes will return FF Buffer Write to chip Program the chip with the content of the buffer The chip is erased before the buffer is written to the chip Buffer Verify Compares the content of the buffer with the content of the chip Buffer program chip Erases the chip writes the buffer to the chip and finally verifies the buffer with the chip Chip get type Retrieves the chip type AT89C1051 AT89C2051 or AT89C4051 Chip Erase Erases the chip Lock bits are also erased Chip Set lockbit 1 When LB1 is set the chip can not be programmed anymore Chip Set lockbit 2 When LB2 is set the chip can not be programmed nor can it be verified read Use LB1 and LB2 together for securing your program Options LPT1 LPT3 Select the printer port the programmer is connected to Optio
121. as 1 1 now you can refer to 1 1 with the variable direction Set Direction has the same effect as SET 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 44 ABS Action Returns the absolute value of a numeric variable Syntax var ABS var2 Remarks var ariable that is assigned the absolute value of var2 Var must be a numeric variable 2 he source variable to retrieve the absolute value from Var2 must be an integer or long The absolute value of a number is always positive See also NONE Example Dim a as Integer c as Integer a 1000 c Abs a Print End Output 1000 2007 MCS Electronics 110 BASCOM 8051 6 42 ASC Action Convert a string into its ASCII value Syntax var ASC string Remarks arget 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 d 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 variable that will be assigned with the lowest value of the array he first array elem
122. 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 0 ok Setb a 0 OK You can also include an assembler file with the INCLUDE FILE ASM statement The assembler is based on the standard Intel mnemonics The following codes are used to describe the mnemonics orking register RO R7 Direct 128 internal RAM locations any IO port control or status register For example P1 P3 ACC Ri internal RAM location addressed by register RO or R1 8 bit constant included in instruction 16 bit constant included in instruction 128 software flags any IO pin control or status bit For example ACC O P1 0 P1 1 Boolean variable manipulation lear direct bit SETB C set carry flag CPL C omplement carry flag Program and machine control 2007 MCS Electronics 240 BASCOM 8051 Arithmetic operations 2007 MCS Electronics Using assembly 241 Logical operations 2007 MCS Electronics
123. ault clock will generate a higher clock and gt 2 will generate a lower clock By default the following delay routine is called with an ACALL 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 2007 MCS Electronics BASCOM Language Reference 121 See also CONFIG SCL r2h CONFIG SDA Example CONFIG I2CDELAY 0 we need a higher clock 6 59 CONFIG GETRC Action Configures the GETRC charge time Syntax Config GETRC time Remarks he time in milli seconds to charge the capacitor See also GETRC 158 6 60 CONFIG GRAPHLCD Action Configures the Graphical LCD display Syntax Config GRAPHLCD type PORT mode CE pin CD cd COLS 30 Remarks his must be one of the following e 240 64 e 240 128 his is the name of the port that is used to put the data on the LCD data pins dbO db7 P1 for example Ce he name of the pin that is used to enable the chip on the LCD d C he name of the pin that is used to control the CD pin of the display Cols he number of columns for use as text display The current code is ritten for 30 columns only In the sample the following connections were used
124. ax Px var var Px Remarks X he number of the port 1 or 3 P3 6 can t be used with an AT89C2051 he variable to retrieve or to set Note that other processors can have more ports such as PO 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 ACC 0 will reset the accumulator for example See hardware 251 for a more detailed description of the ports Example Dim As Byte As Bit 2007 MCS Electronics 202 BASCOM 8051 P1 get value from port 1 2 manipulate it 1 set port 1 with new value P1 amp B10010101 use binary notation amp HAF use hex notation Bl P1 1 read pin 1 1 P1 1 0 set it to 0 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 2021 CPEEK 13h INP1173 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 pne ns variable with the address of the memory location to set 0 255 alue to assign 0 255
125. baud Optional is INVERTED this will use inverted logic so you don t need MAX232 inverters ou can use BINARY INPUT or OUTPUT for COM1 2 but for the Software UART pins you must specify INPUT or OUTPUT he number of the channel to open Must be a positive constant 2007 MCS Electronics BASCOM Language Reference 199 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 31 PRINTHEX 5 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 5h and PUT 207 statements to retrieve and send data and the PRINTBIN 24 and INPUTBIN 173 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 2 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 does
126. bounce statement With these port pins debounce is 2007 MCS Electronics 138 BASCOM 8051 best to be used as Debounce P1 1 0 Pr sub as it will not require an external pull up resistor See also CONFIG DEBOUNCE 120 Example DEBOUN BAS Demonstrates DEBOUNCE Config Debounce 30 when the config statement is not used a default of 25mS will be used Debounce P1 1 1 Pr try this for branching when high 1 Debounce P1 0 0 Pr Sub Debounce P1 0 0 Pr Sub label to branch to Branch when P1 0 goes low 0 Examine 1 0 When 1 0 goes low jump to subroutine Pr 0 must go high again before it jumps again to the label Pr when P1 0 is low Debounce P1 0 1 no branch Debounce P1 0 1 Pr will result in a return without gosub End Pr Print P1 0 was is low Return 6 77 DECR Action Decrements a variable by one Syntax DECR var Remarks ariable to be decremented var Byte Integer Word Long Single There are often situations where you want a number to be decreased by 1 2007 MCS Electronics BASCOM Language Reference 139 The DECR statement is faster then var var 1 See also INCR 17h Example 1995 2006 MCS Electronics file DECR BAS Demo DECR Dim A As Byte 5 assign value to Decr A decrease by one Pri
127. c and text cls TEXT will clear only the text cls GRAPH will clear only the graphic part init the display manual you can use Lcdinit But this should not be needed as it is initilised at start up Locate is supported and you can use 1 8 for the row and 1 30 for the column Locate 1 1 cursor control is the same as for normal LCD Cursor On Blink 2007 MCS Electronics 124 BASCOM 8051 to show some text you can use LCD Led Hello world Note that the cursor position is not adjusted You can set it with locate Now comes the fun part for using a graphic LCD We can display a BMP file You may use MSPAINT or any other tool that can create a BMP file With the Graphic converter from the Tools Menu you can convert the file into a BGF file BASCOM GRAPHICS FILE The conversion will convert all non white pixels to BLACK 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 O 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 To 10 Pset X Y 1 Next Next You could remove it too For X 0 To 10 For Y 0 To 10 Step 2 Pset X Y 0O Next Next A sim
128. can be downloaded that describes the needed hardware The hardware simulator can simulate port 1 and 3 This way you can test your program in circuit without programming the device Now only the status reading and setting of the ports is supported This means that interrupts are not yet supported in hardware simulation 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 El button to enable disable the update 2007 MCS Electronics 52 5 8051 Display memory window To display the memory of the internal RAM you can click the button By clicking again you can hide the window 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 The sections can be made larger or smaller by using the splitters When you press the right mouse button a popup menu will be visible Depending on the place the mouse cursor was at the time you pressed the right mouse button different options will be showed Extra options that will be come available are Clear breakpoints Hide register window e Hide watch window To end a session close the windows or just set the focus to an editor window 4 27 Program Send to chip Afte
129. ce 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 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 How you work with 1w bus Thereafter you can read a device and write to it If you know you only have 1 sensor attached or if you want to address all sensors you can start with a Skip Rom command This means take no notice about the Ids of the sensors skip that part of the communication When you made a iw 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 cas
130. ck The resulting file will have the BGF extension Press the Ok button to return to the editor The picture can be shown with the ShowPic z2 statement 4 31 Tools LIB Manager With this option you can add and remove ASM routines to the libraries The following windows will be displayed LIB Manager Libraries Reutines abc lib DEC 5 at emulator lib MINBYTE bipom lib MINBYTExX Itc1081 lib MAXBYTE Itc1238 lib AVGBYTE Add AVGBYTEX MAXBYTEX INSTR Delete INSTRX GETAD552 ROTATE_RIGHT ROTATE_LEFT BIN_STR BIN STRX DAC 537 ADC 2051 c Ji e BYTE COMP EQ BYTE SUB BYTE GT 2007 MCS Electronics 56 5 8051 Select library first by clicking on it The Routines list will be refreshed with the contents of the selected library 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 A library is an ASCII file that contains ASM routines Each routine must be preceded by the name of the routine between brackets Each routine must be ended with the END line A sample routine is shown here _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 resu
131. ction Overrides the SDA pin assignment from the Option Settings s Syntax 2007 MCS Electronics BASCOM Language Reference 129 CONFIG SDA pin Remarks pin he 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 23 CONFIG I2CDELAY 1201 Example CONFIG SDA P3 7 P3 7 is the SDA line 6 68 CONFIG SERVOS Action Configures the number of servos and their pins Syntax Config SERVOS number SERVO1 P1 1 SERVO2 1 2 SERVO3 P1 4 SERVO4 1 5 RELOAD value Remarks he number of servos you want to use hen you specify 2 you must also add the SERVO1 and SERVO2 parameters he pin that is attached to servo 1 The CONFIG SERVOS compiler directive will include an interrupt that will execute every 100 uS The TIMERO interrupt is enabled and the TIMERO is started The number of bytes used by the use of SERVO s is 1 number of servos When you use 2 servo s it will take 3 bytes of internal memory TIMERO can not be used by your program anymore To change the pulse duration you assign the special reserved variables the number of 100 uS steps SERVO1 8 800 uS pulse SERVO2 12 1200 uS d
132. ction Retrieves the memory address of a variable Syntax var VARPTR var2 Remarks 233 he variable that is assigned with the address of var2 A variable to retrieve the address from See also PEEK 4 POKE 20 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 he number of seconds to wait The delay time is based on the used X tal frequency When you use interrupts the delay can be extended See also DELAY 4h WAITMS 234 WAITMSE 235 2007 MCS Electronics 234 BASCOM 8051 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 ariable that is assigned with the ASCII value of the serial buffer he 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 key from 1 the default 6 196 WAITMS Action Suspends program execution for a given time in mS Syntax WAITMS mS Remarks he number of milliseconds
133. d of the SOUND statement It has a wider range 2007 MCS Electronics 222 BASCOM 8051 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 The SoundExt routine will create the sound as following e The port pin is set LOW The specified frequency is inverted The inverted value is decreased The port pin is set HIGH The inverted value is restored and decreased again The actions are executed for DURATION times 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 225 Example regfile 89s4051 dat crystal 8000000 Dim X As Word X 0 Do X 10 Soundext P3 4 500 X Waitms 1 Loop 6 177 SPACE Action Returns a string of spaces Syntax var SPACE x Remarks he number of spaces Var he string that is assigned
134. d the result Dim Ar 8 As Byte we also need counter variable and a word variable Dim As Byte W As Word some ids of wire chips tested 01 51 B5 8D 01 00 00 56 01 84 8D 01 00 00 E5 Print start get the number of connected 1wire device W lwirecount ar 1 print if there was error and how many sensors are available Print ERR Err count now get the data from the first wire device on the bus Ar 1 1wsearchfirst print the ID For 1 To 8 Printhex Ar i Next Print assume that there are more than 1 1wire devices Do get the next device Ar 1 1wsearchnext For 1 To 8 Printhex Ar i 2007 MCS Electronics BASCOM Language Reference 87 Next Print Loop Until Err 1 when ERR is 1 it means there are no more devices IMPORTANT wsearchfirst and next functions do require that you use the SAME array 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 1WSEARCHNEXTC 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 The 1wireSearchFirst function must be called once to initiate the ID retrieval process After the 1wireSearchFirst function is used you shoul
135. d to a serial communication port of your computer 2007 MCS Electronics 174 BASCOM 8051 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 amp H with INPUT so QB will recognize that a hexadecimal string is used BASCOM implements a new statement INPUTHEX See also INPUTHEX 175 PRINT 23 TIMEOUT 107 Example 1 c 1995 2006 MCS Electronics file INPUT BAS INPUT INPUTHEX To use another baudrate and crystalfrequency use the metastatements SBAUD SCRYSTAL baud 1200 er 1200 baud for example crystal 12000000 12 MHz When you need that the program times out on waiting for a character 1 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 Dim V As Byte As Byte Dim C As Integer D As Byte Dim S As String 15 only for uP with XRAM support Input Use this to ask a question V Input Bl leave out for no question Input Enter integer C Print C 2007 MCS Electronics BASCOM Language Reference 175 Inputhex Enter hex number 4 bytes EE Pri
136. d two bytes and receive one byte Print buf 1 print the received byte 6 108 I2CSEND Action Send data to an I2C device Syntax I2CSEND slave var I2CSEND slave var bytes Remarks he slave address off the I2C device var A byte integer word or number that holds the value which will be sent the I2C device he number of bytes to send This command works only with additional hardware See appendix D 251 See also I2CRECEIVE 65 Example x 5 assign variable to 5 Dim ax 10 As Byte slave amp H40 slave address of a PCF 8574 I O IC 2007 MCS Electronics 168 5 8051 bytes 1 send 1 byte I2CSEND slave x send the value or For a 1 to 10 ax a dataspace Next bytes 10 I2CSEND slave ax bytes END 6 109 2 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 CM A variable that receives the value from the I2C device 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 JA variable or constant to write to the I2C device variable or constant to write to the I2C device or constant to write to the I2C device This command works only with additional hardware See appendi
137. d use successive 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 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 1 83 7 1WSEARCHFIRST 851 1WIRECOUNT 84 Example lwirecount bas 1 c 1995 2006 MCS Electronics demonstration of using multiple devices chip we use regfile 89s8252 dat crystal attached crystal 12000000 baud rate baud 4800 2007 MCS Electronics 88 BASCOM 8051 for 500 mili secs Waitms 500 the pins we use connect a 4K7 resistor from the data pin to VCC Config lwire P1 0 need an array of 8 bytes to hold the result Dim Ar 8 As Byte we also need a counter variable and a word variable Dim I As Byte W As Word some ids of lwire chips I tested 01 51 B5 8D 01 00 00 56 t 01 84 8D 01 00 00 E5 Print start get the number of connected 1 device W lwirecount ar 1 print if there was an error and how many sensors are available Print ERR T gt Err count gt W now get the data from the first 1 device on the bus Ar 1 lwsearchfirst print the ID For I 1 To 8 Printhex Ar i Next Print assume t
138. date SYSTENS esl Welcome to the MCS Auto Update Wiz Rollback Next gt Click the Next button to start the update It depends on the downloaded LIC files how many products are found You will get a similar window 2007 MCS Electronics 4 BASCOM 8051 MCS Auto Update Wiz 1 0 0 13 Product Selection MCS ELECTRONICS MCS Auto Update BASIC COMPILERS DEVEL Select an Installed Product you want to update d BASCOM 8051 2 0 13 0 Update PwD When you press the Next button the Wiz will check the Internet for updates Remove New gt Cancel 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 MCS Auto Update Wiz 1 0 0 13 Available Updates ELECTRONICS MCS Auto Update rocd COWIRLERT DEVEL Components found to update Select All Unselect All Press the Next button to download the selected components Select at least 1 component Help lt Back 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
139. e 00 and 00 address Mwwopcode amp B1000000000 10 End 6 141 MWWOPCODE Action Write an opcode to a micro wire device Syntax MWWOPCODE opcode bits 2007 MCS Electronics BASCOM Language Reference 195 Remarks Opcode he opcode that needs to be send to the micro wire device See the micro wire docs for the right values he 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 1931 MWWRITE 195 i MWREAD 5 193 enable write to EEPROM Needed bits startbit 1 opcode 00 and 11 address Mwwopcode opcode numberOfBits Mwwopcode amp B1001100000 10 send the code 6 142 MWWRITE Action Writes a value to the micro wire bus Syntax MWWRITE variable opcode address bytes Remarks he variable which s content must be send to the micro wires device he address of the device Bytes Number of bytes to send See also MWINIT 1931 MWREAD 1937 MWWOPCODE ok write value of X to address 0 opcode is 01 and we write one byte Mwwrite X 8B101 0 1 2007 MCS Electronics 196 BASCOM 8051 6 143 NEXT Action Ends a FOR NEXT structure Syntax NEXT var Remarks Var he index variable that is used as a counter when you form the Structure with FOR var Var is optional and not needed You mu
140. e 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 2007 MCS Electronics 60 5 8051 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 bits high when the DEFLCDCHAR 1401 statement is generated 4 38 Options Compiler Misc With the miscellaneous options you can change the following BASCOM 8051 Options X E Communication Environment Hardware simulator Programmer Monitor Printer Output Communication 22 LCD Misc Register file 8958252 7 Byte End hex ce gt Size warning 81 a 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 Specifies the last location of internal memory that can be used by he 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 higher value FO for example size warning
141. e alle7 Help About 67 671 Help on 671 68 Shop 68 Support 68 BASCOM Statements 77 gt Language Fundamentals Internal Registers 2461 Initialization 245 2007 MCS Electronics INDEX 15 Microprocessor support 2861 Reserved Words 284 Errors 278 5 Additional hardware 251 Compiler limits 282 ASM programming 239 International Resellers ao Available third party hardware 3001 Language Reference 1 1WRESET 1WREAD 1WWRITE s 1WSEARCHFIRST s 1 71 1WIRECOUNT COMPILER DIRECTIVES 1 ELSE s ENDIF s2 ASM ASM 8 INCLUDE s BAUD 991 BGF amp 1 6 5 1 911 DEFAULT XRAM 2 IRAMSTART 941 LARGE 1 LCD 951 971 NOBREAK 71 NOINIT 981 98 NONULL 994 NORAMCLEAR 99 NOSP o OBIJ o RAMSIZE 101 RAMSTART 101 REGFILE 101 ROMSTART ioi SERIALINPUT 1051 SSERIALINPUT2LCD o SERIALOUTPUT 1051 SIM 107 ABS ALIAS 1081 5 101 n B BITWAIT BREAK d CALL 133 CLOSE 198 CLS 1151 CHR 114 CONFIG 118 CONSTI COUNTER 32 CPEEK lis CURSOR 1351 D DATA 36 DEBOUNCE 137 DECR 1381 DECLARE 38 DEFINT 140 DEFBIT 4 DEFBYTE 1401 DEFLCDCHAR 14 DEFWORD h
142. e codememory from the chip You will be asked for a filename first Program chip 2007 MCS Electronics Supported Programmers 273 Will program the targetchip with the current program Set lockbits Will set the lockbits of the targetchip 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 that case 9 12 Peter Averill s TAFE programmer The TAFE flashprogrammer is a parallel printer port based programmer and can be build with the DT004 and DT206 SimmSticks from Dontronics The programmer can program only AT89C1051 to AT89C4051 chips 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 ze help I got some feedback from a user that had problems with his programmer he added 5K1 pullup resistors to 5V This is shown the picture below dots 11 must each have a resistor of 5K1 to 5V 2007 MCS Electronics 274 BASCOM
143. e 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 8958252 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 2007 MCS Electronics BASCOM Language Reference 131 4 16 64 or 128 This is a division that determines the clock rate The oscillator clock is divided by the number you specify You can turn on enable SPI by using this option It sets the enable bit You an turn off the SPI by using this option It resets the enable bit See also SPIIN 22 SPIOUT 2251 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 6 70 CONFIG TIMERO TIMER1 Action Configure TIMERO or TIMER1 Syntax CONFIG TIMERx COUNTER TIMER GATE INTERNAL EXTERNAL MODE 0 3 IMERO or TIMER1 OUNTER will configure TIMERx as a COUNTER and TIMER will onfigure TIMERx as a TIMER A TIMER has built in clock input and a COUNTER has external clock GATE INTERNAL or EXTERNAL Specify EXTERNAL to enable gate control ith the INT input MODE ime counter mode
144. e 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 S Ucase s convert to upper case Print S print Strang 6 120 LCD Action Send constant or variable to LCD display Syntax LCD x Remarks 2007 MCS Electronics BASCOM Language Reference 179 ariable or constant to display More variables can be displayed separated by the sign LCD a b1 constant The LCD statement behaves just like the PRINT statement See also LCDHEX 182 LCD 951 CONFIG LCD 125 Example 1995 2006 MCS Electronics file LCD BAS LCD CLS LOWERLIN CURSOR DISPLAY SHIFTLCD SHIFTCURSOR HOME 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 Pin Db4 P3 1 Db5 P3 2 Db6 P3 3 Db7 PZA P3 5 Rs P3 6 Rem with the config lcdpin statement you can override the compiler settings Dim As Byte Config Led 16 2 configure lcd screen other options 16 4 and 20 4 20 2 p 16 la When you dont include this option 16 2 is assumed 16 la is intended for 16 character displays with split addresses over 2 lines SLCD address will
145. e to select a different folder click Browse MCS Electronics BASCOM 8051 Browse lt Cancel Click the Next button again to continue 2007 MCS Electronics 24 5 8051 The files will now be installed A screenshot is shown below Setup BASCOM 8051 Installing Please wait while Setup installs B amp SCOM 8051 on your computer Extracting files C Program Files MCS Electronics BASCOM8051 BASCOM chm When the files are installed the installer will install some addiitonal files Setup BASCOM 8051 151x Additional Files Installing additional files Installing additional 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 2007 MCS Electronics Installing BASCOM 8051 25 When setup is completely finished it will show the last screen Setup BASCOM 8051 Completing the BASCOM 8051 Setup Wizard To complete the installation of BASCOM 8051 Setup must restart your computer Would you like to restart now No will restart the computer later You MUST reboot your PC since it will install a driver needed for the programming 2007 MCS Electronics Updates 27 3 Updates The update process is simple
146. ected ep Les string expected 64 Variable not mensona Lee ree parameters expected hp hoos es frorsexpeced iro urena valve for WATCHDOG i urenaperamererforzac i172 ytenteger or Long expected integer or tong esea 175 Valve does not ft into bit 1 must be ofthe 139 140 141 142 143 144 145 146 147 148 150 151 160 161 162 163 164 166 167 168 170 171 172 173 174 175 176 2007 MCS Electronics BASCOM Misc 281 177 78 179 180 81 182 183 84 85 86 Illegal operation Ha alue doesn t fit Illegal operation in PlaceValue puri onstant or Internal byte or integer expected for index hannel not opened Device already open Device was not open 2 a a TD D lt i a alue does not fit into byte IF THEN not allowed on same line as CASE 188 END IF expected 189 ONST expected H 190 hannel expected x 91 ALIAS already used 92 ord or Integer expected Ha 93 ONST already defined 94 expected 95 O expected ejeje 96 ump ou
147. ed Administrator rights to install BASCOM You also need to run it at least once as an Administrator to install the 10 port driver After BASCOM has runned once you can log in as a user without Admin rights too If you run into a problem send an email to support mcselec com with the problem and if possible the source code Back Cancel Click the Next button again to continue with the setup 2007 MCS Electronics Installing BASCOM 8051 23 You can now select where you want to Install BASCOM 8051 The default is shown below 21 Setup BASCOM 8051 2 5 x Select Destination Location Where should BASCOM 8051 be installed Setup will install B amp SCOM 8051 into the following folder To continue click Next If vou would like to select a different folder click Browse C Program Files MCS Electronics B4SCOM8051 Browse At least 11 8 MB of free disk space is required ECC Click the Next button again to continue You can now select enter the Program Group name The default is shown below iG Setup BASCOM 8051 ioj xj Select Start Folder Where should Setup place the program s shortcuts Setup will create the program s shortcuts in the following Start Menu folder To continue click Next If vou would lik
148. egfile 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 gt 0 Then Printbin 1 St send to com 2 End If Close 1 2007 MCS Electronics BASCOM Language Reference 173 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 he 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 6 PEEK oi POKE 204 Example Dim a As Byte a INP amp H8000 read value that is placed on databus dO d7 at hex address 8000 PRINT a END 6 115 INPUT Action Allows input from the keyboard during program execution Syntax INPUT prompt 1 var varn NOECHO 1 TIMEOUT xx Remarks An optional string constant printed before the prompt character A variable to accept the input value or a string NOECHO Disables input echoed back to the Comport Optional delay time When you specify the delay time the routine will return when no input data is available after the specified time No imer 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 connecte
149. en to Port 3 pins they are pulled high by the internal pullups and can be used as inputs Port 3 pins that are externally being pulled low will source current because of the pullups Port 3 also serves the functions of various special features of the AT89C2051 as listed below P3 3 NTI interrupt 1 input timer 1 gate control 0 timer 0 input or counter input 1 timer 1 input or counter input 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 P1 0 will write the value to port 1 setting al pins to zero Reading from a Port byte P1 will read the value from port 1 and will assign the value to variable byte Setting individual pins of a Port You can also set individual pins of the ports in BASCOM SET P1 0 will set pin P1 0 high P1 0 1 will also set pin P1 0 high RESET P1 0 will set pin P1 0 low P1 0 0 will also set pin P1 0 low At power up both ports are high and can be used an inputs Individual bits can be set to use a port both as input output For example P1 amp B00001111 will set a value of 15 to port 1 P1 0 to P1 3 can be used as inputs because they are set high How to interface the port pins 2007 MCS Electronics 256 5 8051 v 1 LCD ET DDDD RY BBBB R s 1 7654 5 Ws ic
150. ence 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 amp H signs that are required in QB a separate function was designed See also VAL STR 2201 Example Dim A As Integer 5 As String 15 S 000A A Hexval s Print A 10 6 104 Action Retrieves the most significant byte of a variable 2007 MCS Electronics BASCOM Language Reference 165 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 he variable that is assigned with the MSB of var S he source variable to get the MSB from A word or integer variable that is assigned he 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 e LOWW eh HIGHW 165 Example Dim I As Integer Z As Byte I amp 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 he variable that is assigned with the two MSB of var S It must be an Integer or Word he source variable to get the MSB from Must be a long See also LOW en HIGH eh LOWW 1861 Example Dim I As Long Z As Word I 8H10011001 2007 MCS
151. ent of the array to return the lowest value of 2007 MCS Electronics BASCOM Language Reference 111 At the moment AVG works only with BYTE arrays Support for other data types will be added too See also MAXI 1921 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 he 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 s directive See also 911 BAUD sd Example BAUD 2400 CRYSTAL 14000000 14 MHz crystal PRINT Hello BAUD 9600 Print Hello END 2007 MCS Electronics 112 BASCOM 8051 6 45 BCD Action Converts a variable into its BCD value Syntax PRINT BCD var LCD BCD var Remarks Var ariable 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 The BCD function is intended for the PRINT LCD statements Use the MAKEBCD function to convert variables See also MAKEBCD 1 amp 5 MAKEDEC 88 E
152. er Use asc to imbed an ASCII character ascz 0 255 For example 9413 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 4 44 Options Printer These options let you select the printer margins BASCOM 8051 Options Communication Environment Hardware simulator Programmer Monitor Left Margin 10 Color Top Margin 0 Wrap Lines Right Margin M Print Header Bottom Margin pA Line Numbers M Syntax he left printer margin in mm he right printer margin in mm he bottom printer margin in mm Wrap Lines heck when you want long lines to be wrapped This is onvenient when you have long lines of source code that ould otherwise would not fit on the paper heck to print a header with file name and page number heck to print line numbers heck to use syntax highlighting options and colors 4 45 Window cascade Will cascade all editor windows so they will all be visible 2007 MCS Electronics BASCOM IDE 67 4 46 4 47 4 48 4 49 4 50 4 51 Window Tile Window Tile will tile all editor windows Window arrange icons Will arrange all iconized windows Window minimize all Will minimize all editor windows Help About This option shows an about box as displayed below BASCOM 8051 Compiler version 2 0 12 0 Compiler build IDE version 2 0 13 0 Serial number
153. er 264 MCS SPI programmer 266 Microprocessor support 288 MID 191 MIN 192 192 MWINIT 193 MWREAD 193 MWWOPCODE 194 MWWRITE 195 ONinterrupt 196 ON value 197 OPEN 198 Options Communication 60 Options Compiler Communication 58 Options Compiler I2C 58 Options Compiler LCD 59 Options Compiler Misc 60 Options Compiler Output 57 Options Environment 62 Options hardware simulator 64 Options Monitor 65 Options Printer 66 Options Programmer 64 2007 MCS Electronics 314 BASCOM 8051 Options View Report 48 OUT 200 202 Peter Averill s TAFE programmer 273 PG2051 flash programmer 267 PG302 programmer 268 POKE 202 PORT 201 POWERDOWN 203 PRINT 203 PRINTBIN 204 PRINTHEX 205 PRIORITY 206 PSET 207 PUT 198 207 4 2 208 READMAGCARD 209 REM 211 REPLACE 211 Reserved Words 283 RESET 212 RESTORE 212 RETURN 213 Rhombus 309 Rhombus SCE 51 275 RIGHT 214 RND 214 ROTATE 215 RUNNING BASCOM 8051 37 Sample Electronics ISP programmer 270 SE 512 or SE514 programmer 269 SE511 SE516 programmer 276 SE 812 270 SELECT 216 Sendto chip 52 SET 216 SHIFT 217 SHIFTCURSOR 217 SHIFTIN 218 SHIFTLCD 219 SHOWPIC 220 SOUND 220 SPACE 222 SPC 223 SPIIN 224 SPIINIT 224 SPIOUT 225 START 225 STK200 300 ISP Programmer 274 STOP 226 STOP TIMER 226 STR 228 STRING 228 SUB 229 SWAP 230 Syntax check 47 S PL Table of contents 14 THIRDLINE 230 Tool
154. er 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 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 2007 MCS Electronics Using assembly same as before the reset but again there is no guarantee 249 2007 MCS Electronics 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 2581 More about connecting a LCD display 257 More about the I2C 25 Hardware related commands The uP must be connected to a crystal The frequency of the crystal can range from 0 to 24 Mhz for most chips The frequency is divided by 12 internally So with a 12 Mhz crystal the processor is clocked with 1 Mhz Because almost each instruction takes 1 clock cycle to execute the processor can handle 1 M
155. ers ranging in value from 2147483648 to 2147483647 e 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 O byte A string dimensioned with a length of 10 bytes will occupy 11 bytes Variables can be stored internal default or external 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 e Aconstant value 5 1 1 The value of another numeric variable abc def k g e The value obtained by combining other variables constants and operators 5 Temp 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 2831 for a complete list of reserved words You can specify a hexadecimal or binary number with the prefix
156. es 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 2007 MCS Electronics 260 BASCOM 8051 sensor to execute The command Convert as example takes 200mS on 2wire but 700mS on 1wire This has to be considered during programming And that power also has to be supplied somehow If you use 2wire you don t have to read further in this part You can simultaneously Convert T on all the devices you attach on the bus And save time This command is the most power consuming command possible to execute on several devices I am aware of 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 Short not so accurate descriptio
157. eset the micro it will produce the same sequence Only when you vary the variables with for example a timer temperature reading or a clock you can make a more random value See also 2007 MCS Electronics BASCOM Language Reference 215 c 1995 2006 5 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 he 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 2181 SHIFTOUT 21 SHIFT 215 Calls ROTATE LEFT ROTATE RIGHT Example Dim a as Byte a 128 ROTATE a LEFT 2 Print a 1 2007 5 Electronics 216 BASCOM 8051 6 168 SELECT Action Executes one of several statement blocks depending on the value of a variable Syntax SELECT CASE var CASE testi statements CASE test2 statements CASE ELSE statements END SELECT Remarks ariable to test alue to test for alue to test for See also IF THEN 164 Example Dim b2 as byte SELECT CASE b2 set bit 1 of
158. file for other uPs You can select the appropriate register file with the Options Compiler settings 601 Take care when you are directly manipulating registers The ACC and B register are frequently used by BASCOM Also the SP register is better to be left alone Altering SP will certainly crash your application 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 Please note that internal registers are reserved words This means that they can t be dimensioned as BASCOM variables 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 Making your own register file is very simple copy the 8052 DAT file to a new DAT file for example myproc DAT DOS c bascom copy 8052 dat myproc dat e edit the registerfile with BASCOM 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 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 00 The BYTE section contains all the other SFR s The MISC section has a few items e
159. 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 sz 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 amp H address Remarks he address where must be written to to enable the LCD display dbO db7 lines of the LCD must be connected to the datelines DO D7 he RS line of the LCD must be connected to the address line AO 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 2007 MCS Electronics 96 BASCOM 8051 See Also LCDRS se Example Sled amp HAO000 the LCD high Cls Led End Hello world 6 20 LCDRS Action Instruct the compiler to generate code for 8 bit LCD displays attached to the data bus Syntax LCDRS amp H adaress Remarks writing to this address will make the E line of he address where must be written to to enable the LCD display and he RS of the LCD he dbO db7 lines of the LCD must be connected to the data lines DO D7 he RS line of the LCD must be connected to the address line AO by hen it is connected to another address line you can specify LCDRS On systems with external RAM ROM it makes more sense to attach the
160. ges costs or loss of profits arising from the usage of this product package No part of this document may be reproduced or transmitted in any form or by any means electronic or mechanical including photocopying and recording for any purpose without written permission of MCS Electronics MCS Electronics All rights reserved 2007 MCS Electronics 14 5 8051 1 1 Table of contents Installing BASCOM 8051 21 BASCOM IDE sei Running BASCOM 8051 371 Updates 27 File File New s File 3 2 File Close 4 File File Save 1401 File 4 2 File Print Preview 4c pg File Exit 41 Edit Edit 22 0 Edit Redola Edit Copy 1 11 Edit Cut Edit Paste Edit 43 J Edit Find Edit 1 2 Editor 461 Edit Goto 44 Edit Indent 1451 Edit Unindent 451 Program Compile B Syntax check Show Result AS Simulate S Send to chips Tools Terminal Emulator s31 LCD designer s amp Graphic 541 LIB Manager 587 Export to 71 Options Compiler Output sA Compiler 581 Compiler 2 s Compiler LCD 595 Compiler Misc 601 Communication e Environment s Hardware Simulator e amp Programmers Monitor es Printer se Window 1 Tile 671 Arrange Icons 671 Minimiz
161. h dual serial port Open COM2 For Binary As 1 open serial channel 1 INPUTBIN 1 Close 1 6 117 Action Allows input from the keyboard during program execution Syntax INPUTHEX prompt 1 var varn TIMEOUT xx Remarks prompt n optional string constant printed before the prompt character A numeric variable to accept the input value NOECHO Disables input echoed back to the Comport Optional delay time When you specify the delay time the routine ill 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 If var is a byte then the input must be 2 characters long If var is an integer word then the input must be 4 characters long If var is a long then the input must be 8 characters long 2007 MCS Electronics BASCOM Language Reference 177 Diffe
162. h line by pressing the INS key You can delete a variable watch line by pressing the CTRL DEL keys You can change the value of a variable by setting the focus to the cell with the variables value and then by entering the new value The variable names are saved and loaded after each simulation session The terminal section The blue window emulates the serial port So serial output the PRINT statement for example is displayed in this window When serial input is required you must set the focus to the serial window before you enter text The INPUT statement for example requires serial input The source code window The source code windows shows the source file being simulated You can start a simulation by pressing F5 or by clicking the run button When your program runs you can pause it by clicking the pause button ll You can stop the simulation by clicking the stop button B You can also step through the code line by line by pressing F8 or by clicking the step button By pressing SHIFT F8 s you can step over code like GOSUB and CALL 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 al
163. hat there are more than 1 lwire devices Do get the next device Ar 1 lwsearchnext For I 1 To 8 Printhex Ar i Next Print Loop Until Err 1 when ERR is 1 it means there are no more devices IMPORTANT lwsearchfirst 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 9 ASM SEND ASM Action Start of inline assembly code block 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 2007 MCS Electronics BASCOM Language Reference 89 See also ASM programming 2391 Example Dim c as Byte ASM Mov r0 Z 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 SBAUD var Remarks Var he baud rate that you want to use Var must be a numeric onstant 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 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
164. he 1w bus please go to http www dalsemi com techbriefs tb1 html Using BASCOM makes the world a lot easier This paper will approach the subject from a BASCOM user point of view iwire net is a serial communication protocol used by DS devices The bus could be implemented in two basic ways 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 is supplied to the VDD line of the device 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 2007 MCS Electronics Additional Hardware 259 How it works 1wire The normal state of the bus is DQ high Through DQ the device gets its power and performs the tasks it is designed for 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 devi
165. he cursor keys to select text or keep the left mouse key pressed and tag the cursor over the text to select To select a word double click on it 4 23 Program Compile Action With this option you can compile your current program Your program will be saved automatically before it will be compiled So if you didn t give it a name you will be asked for it The following files will be created depending on the Option Compiler Settings File Description Binary file which can be burned into EPROM Kxx DBG Debug file which is needed by the simulator boo HEX hexadecimal file boo ERR Error file only when errors are found boo RPT Report file XXx SIM enerated by the simulator to store the variable names of the watch xxx PRJ indow 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 4 24 Program Syntax check Action With this option you can check the syntax of your program No files are generated with this option 2007 MCS Electronics 48 5 8051 Shortcut CTRL F7 4 25 Program Show Result Action Use this option to view the result of the compilation BASCOM 8051 Report Der Report Error B
166. her 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 91 LIB Manager s5 Example LIB mylib lib EXTERNAL dec76 6 15 INCLUDE Action Includes an ASCII file in the program at the current position Syntax SINCLUDE file Remarks Name of the ASCII file which must contain valid BASCOM statements his 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 ou can only include ASCII files c 1995 2006 MCS Electronics file INCLUDE BAS demo SINCLUDE Print INCLUDE BAS include 123 bas include file that prints Hello Print Back in INCLUDE BAS End 2007 MCS Electronics 94 BASCOM 8051 6 16 IRAMSTART Action Compiler directive to specify starting internal memory location Syntax SIRAMSTART constant Remarks Constant A constant with the starting value 0 255 See also NOINIT 985 RAMSTART 10 Example NOINIT NOSP IRAMSTART amp H60 first usable memory location SP 80 DIM I As Integer 6 17 LARG
167. hink their devices are expensive And until now it was really difficult to communicate with the devices Particularly when using the benefit of several devices on one bus Still some people say that the 1w bus is slow but I don t think so 2007 MCS Electronics 262 BASCOM 8051 G te Haluza System engineer 2007 MCS Electronics 264 5 8051 9 9 1 Supported Programmers MCS Flash programmer There are different models of the MCS Flash programmer but all of them are compatible with the driver software The MCS Flash programmer is a parallel printer port based programmer It can only program the ATMEL 89C1051 AT89C2051 and 89 4051 Select the correct printer port address before you run the programmer Be sure to switch on the power supply before running BASCOM BASCOM 8051 MCS Flashprogrammer OI x Exit Buffer Chip File test bin T Manufactor ___ ype 89 051 ele LV Jo OC DU 0 00 00 00 00 00 00 00 00 T m 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 75 81220291 21 A 01 7B 2 90 33 0291 00 DBF3 F6 18 0080 DAED 85 0 21 85 0 21 85 A0 21 When you run the programmer the buffer will be filled automatically with your program data The programmer works with bin
168. iable 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 Note that RAMTRON does not need a parameter 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 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 i 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 tell the compiler about ramtron THIS SAMPLE WILL NOT SIMULATE beause of the RAMTON directive Suggestion is to add the directive when you simulated your program ramtron dim some variables Dim X As Byte X1 As Byte Now dim XRAM This will be stored in the Ramtron devic Dim Z 10 As Xram Byte 2007 MCS Electronics BASCOM Language Reference 103 Wait 1 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 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
169. ill use 1 byte 1 used integer word will use 2 bytes 1 used long will use 4 bytes 1 used single will use 4 bytes 1 string with a length of 10 bytes will use 11 bytes Maximum nesting FOR NEXT 25 WHILE WEND SELECT CASE 2007 MCS Electronics BASCOM 283 10 3 Reserved Words The following table shows the reserved BASCOM statements Red keywords can only be used on systems which can address external RAM memory 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 COUNTERO COUNTER1 CPEEK CURSOR DATA DEC DECLARE DEFBIT DEFBYTE 2007 MCS Electronics 284 BASCOM 8051 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 2 I2CWBYTE IDLE IF INC INKEY INP INPUT INPUTHEX INTO INTEGER INTERNAL IS LCD LCDHEX LEFT LEFT LOAD LOCATE LONG LOOKUP LOOP LOW LOWW LOWER 2007 MCS Electronics BASCOM 285 LOWERLINE M
170. im W As Word allocate space for variable Do forever W Getrc p1l 7 get RC value Print W print xt Wait 1 wait a moment Loop return values for cap 10nF The resistor values where measured with a DVM 250 for 10 9 2007 MCS Electronics 160 BASCOM 8051 198 for 9 02 182 for 8 04 166 for 7 154 for 6K02 138 for 5 04 122 for 4 04 106 for 3K06 L 86 for 2 16 54 for 1 00 22 198 18 for 150 10 104 6 for 1 ohm minimum As you can see there is a reasonable linearity So you can do some math to get the resistor value But the function is intended to serve as a rough indication for resistor values You can also change the capacitor to get larger values With 10nF the return value fits into a byte 6 99 GETRC5 Action Retrieves a RC5 infrared code and sub address Syntax GETRC5 address command Remarks he RC5 sub address received he 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 INTO 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 amp BOOO1 1111 The toggle bit will toggle after each key press of the remote control 2007 MCS Electronics BAS
171. 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 2007 MCS Electronics Third party hardware 305 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 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
172. ip set lockbits Will set the selected lock bits The following use feedback was received I have at last found my problem with the SPI flash programmer designed by Jakub Jiricek 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 Correct programmer operation was achieved by changing to EPP enhanced 2007 MCS Electronics Supported Programmers 267 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 A Not recommended for new programmers 93 Blow Flashprogrammer The Blow IT flashprogrammer is a parallel printer port based programmer and can only erase and program a chip The programmer works only with the AT89C1051 to AT89C4051 chips 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 lzeh help Not recommended for new programmers 9 4 PG2051 flash programmer The PG2051 is a serial comport based programmer and can program AT89C1051 and ATC2051 chips only A nice feature is that the programmer can serve as an simulator too The programmer works with Intel HEX files only The following menu options are available File Exit This will exit the programmer Buffer read fr
173. ith 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 bl Data test this 1512 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 2007 MCS Electronics 100 BASCOM 8051 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 981 NOSP NOINIT End 6 28 OBJ Action Includes Intel object code Syntax 2007 MCS Electronics BASCOM Language Reference 101 OBJ obj Remarks obj is the object code to include In some cases it can be
174. ition on T2EX 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 2007 MCS Electronics 292 BASCOM 8051 11 3 DATA EEPROM The 8958252 has a built in 2Kbytes flash EEPROM You can use this to store data Two statements are provided WRITEEEPROM and READEEPROM WRITEEEPROM var address var Any BASCOM variable name Address The address of the EEPROM where to write the data to Ranges from to 2047 When you omit the address the address will be assigned automatically You can view the assigned address in the report file READEEPROM var address var Any BASCOM variable name Address The address of the EEPROM where to read the data from Ranges from to 2047 You can omit the address when you have written a value before with the WRITEEEPROM var statement Because in that case the compiler knows about the address because it is assigned by the compiler Example Dim S As String 15 S2 As String 10 S Hello S2 test Dim L As Long 12345678 Writeeeprom S Writeeeprom S2 write strings Writeeeprom L write long 5 5 52 0 clear variables Readeeprom L Print L Readeeprom S Print S Readeeprom S2 Print S2 End 11 4 AT898252 WATCHDOG The AT89S8252 has a built in watchdog timer A watchdog timer is a timer that will reset the uP when i
175. itional 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 4 both the Code the EEPROM data are programmed The STK200 300 is recommended for new programmers 9 14 Rhombus SCE 51 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 When you select the SCE 51 the following window will appear when you press F4 2007 MCS Electronics 276 5 8051 SCE amp Flash Loader 1 0 File s Borland D elphib amp BASCOMNDOR HEX Checksum 000000 Memory Erase FLASH Program Verify The filename is automatic filled The original SCE 51 software from Rhombus has much more options and BASCOM only supports programming to RAM and FLASH You must select the target memory before you click the Program button By clicking the Erase button you can erase the memory During programming a status bar will be shown The baud rate is fixed to 19200 baud Support f
176. l use the 93C46 and work with bytes AL will be 7 in this case See also MWINIT 1931 MWWOPCODE 195 MWWRITE 1953 MWREAD 193 6 65 Action Configures the PRINT statement Syntax Config PRINT pin 2007 MCS Electronics 128 BASCOM 8051 Config PRINTMODE mode Remarks Pin he pin to use for the output control such as P3 0 he 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 6 66 CONFIG SCL Action Overrides the SCL pin assignment from the Option Settings s8 Syntax CONFIG SCL pin Remarks Pin he 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 18i CONFIG I2CDELAY 126 Example CONFIG SCL P3 5 P3 5 is the SCL line 6 67 CONFIG SDA A
177. l 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 COUNTERO or 1 variable For 8052 TIMER2 compatible chips COUNTER2 can be used too 2007 MCS Electronics BASCOM Language Reference 133 Syntax COUNTERX var var COUNTERX Remarks A byte Integer Word variable or constant that is assigned to the ounter OUNTERO COUNTER1 or COUNTER2 Use counterX 0 to reset the counter The counter can count from 0 to 255 in mode 2 8 bit auto reload And to 65535 in mode 1 16 bit In mode 0 the counter can count to 8192 The MSB and 5 bits of the LSB are used in that case When you assign a constant to a TIMER COUNTER in mode O the bits will be placed in the right place COUNTERO 8B1 1111 1111 1111 1111 13 bits Will be translated for mode O into 1111 1111 0001 1111 The counterx variables are intended to set retrieve the TIMER COUNTER registers from BASCOM COUNTERO TLO and THO So the COUNTERx reserved variable is a 16 bit variable To set TLx or THx you can use TLO 5 for example 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
178. lay New are SHOWPIC 20X Y Label where X and Y are the column and row and Label is the label where the picture info is placed PSET 27 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 es file bgf inserts a BGF file at the current location is removed from the Help but it still supported this version BGF should be used however 2007 MCS Electronics BASCOM Language Reference 123 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 DBO 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 used two 9 V batteries configure the LCD display Config Graphlcd 240 64 Port P1 Ce P3 5 Cd P3 4 Cols 30 dimension some variables used by the DEMO Dim X As Byte Y As Byte Reset P3 2 8 bit wide char is 30 columns The following statements are supported Cls will clear graphi
179. le 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 3130 2322 0 S exponent mantissa The exponent is biased by 128 Above 128 are positive exponents and below are negative The sign bit is O 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 mathematical operations are supported by the single You can also convert a single to an integer or word or vise versa Dim I as Integer S as Single S 100 1 assign the single 1 5 will convert the single to an integer Take a look at the single bas example for more information 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 2007 MCS Electronics Language fundamentals 75 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 n
180. ll 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 See Installing BASCOM 2 on how to do a full install 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 2007 MCS Electronics 32 5 8051 Available LIC files for download BASCOM AVR 11188 Download Download BASCOM AVR 1 11 8 5 Download BASCOM AVR 1 11 8 4 Download BASCOM AVR 1 11 8 3 Download BASCOM AVR 1 11 8 2 Download BASCOM AVR 1 11 8 1 Download BASCOM AVR 1 11 8 0 Download BASCOM AVR 1 11 8 6 Download BASCOM AVR 1 11 8 7 Download Download BASCOM 8051 2 0 12 0 Download Download Updatevviz Download 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 DL
181. llowing people who have contributed to BASCOM development e 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 e 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 2007 MCS Electronics 70 5 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 the character set and the special meanings of some characters format of a line in a BASCOM program e Line labels e 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
182. locate the interrupts to the correct address When ROMSTART amp H4000 is specified the monitor program must perform a LJMP instruction For address 3 this must be amp H4003 Otherwise interrupts can not be handled correctly But that is up to the monitor program 2007 MCS Electronics BASCOM Language Reference 105 See also RAMSTART l Example ROMSTART amp H4000 enabled at 4000 hex 6 34 SERIALINPUT Action Specifies that serial input must be redirected Syntax SERIALINPUT label Remarks he name of the assembler routine that must be called when an haracter is needed from the INPUT routine The character must be 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 Imyinput perform the needed actions here mov a sbuf serial input buffer to acc ret 6 35 S SERIALINPUT2LCD Action This compiler directive will redirect all serial input to the LCD display instead of echoing to the serial port Syntax SERIALINPUT2LCD Remarks 2007 MCS Electronics 106 BASCOM 8051 You can also write your own custom input or output driver with the SERIALINPUT and SERIALOUTPUT statements but the SERIALINPUT2LCD i
183. lows The special characters can be printed with the Chr function See also Edit LCD designer s41 LCD 178 Example DefLCDchar 0 1 2 3 4 5 6 7 8 define special character 5 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 24 Example 1 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 2007 MCS Electronics 142 BASCOM 8051 Type pit Boolean Byte Word Integer Long Single or String XRAM Specify XRAM to store variable in external memory IRAM Specify IRAM to store variable in internal memory default 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 Note that BITS can only be stored in internal memory 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
184. lt into a Orl a r6 OR with r6 to see if it is zero Ret END The library can be included with the LIB 9 directive A routine be imported with the EXTERNAL directive lib mylib lib external dec76 4 32 Tools Triscent Converter The Triscent Converter will convert a H file generated by the Triscend program into a triscend DAT file that can be used by BASCOM The triscend DAT file has an additional section named XBYTE XBYTE CMAPO ff00 CMAPO ALT 01 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 CMAPO TAR the value is written to location amp HFFOO where the register is located Reading this XRAM SFR will do the reverse 2007 MCS Electronics BASCOM IDE 57 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
185. luation of a Boolean expression 2007 MCS Electronics 170 BASCOM 8051 Syntax IF expression THEN ELSEIF expression THEN ELSE END IF Remarks expression Any expression that evaluates to true or false New is the ability to use the one line version of IF IF expression THEN statement ELSE statement The use of ELSE is optional Also new is the ability to test on bits IF var bit 1 THEN In V 2 00 support for variable bit index is added Dim Idx as Byte For IDX 0 To 7 If P3 IDX 1 Then Print 1 Else Print 0 End if Next A new feature in V2 is the ability to use multiple tests If a gt 10 AND A lt 10 OR A 15 Then NOP End if It does not work with strings but only numeric conditions When you want to test on bytes you can also use the string representation Dim X As Byte If X A then normally you need to write If X 65 Then so these two lines do the same thing See also 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 b xecuted thas hot 2007 MCS Electronics BASCOM Language Reference 171 End If If A 10 Then Print New in BASCOM If A 10 Then Goto Labell Else Print lt gt 10 Labell Rem The following example shows enhanced use of IF THEN If A 15 1 Then test for bit Print BIT 15 IS
186. m 6 90 ERASE Action Erases a variable so memory will be released Syntax ERASE var Remarks var name of the variable to erase The variable must be dimensioned before you can erase it 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 1 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 2007 MCS Electronics 148 5 8051 Dim As Integer DIM again but now as INT Print A PRINT again REM Note that A uses the same space a the previous ERASED var so REM it still holds the value of the previous assigned variable 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
187. must open the device for OUTPUT When you want to use the pin for receiving you must open the device for INPUT 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 Open com3 1 9600 For Output As 1 p3 1 is normally used for tx so testing is easy Open com3 0 9600 INVERTED For Input As 2 p3 0 is normally used for RX so testing is easy S test this assign string Dum Len s get length of string For I 1 To Dum for all characters from left to right A Mid s I 1 character Put 1 A write it to comport Next Do Get 2 A get character from comport Put 1 A write it back Print use normal channel Loop Close 1 finally close device Close 2 End 6 147 OUT Action Sends a byte to a hardware port or external memory address Syntax OUT address value 2007 MCS Electronics BASCOM Language Reference 201 Remarks he address where to send the byte to value he variable or value to send A The OUT statement only works on systems with a uP that can address external memory See also INPI PEEK 202 POKE 202 Example Dim a as byte OUT amp H8000 1 send 1 to the databus dO 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 Synt
188. n Port delay Because computers become faster every day and the hardware is run by software a delay can be specified for very fast computers A value of 5 is used on a 486DX266 You must increase the value on faster computers if problems occur The default is O and for best results O should be used 2007 MCS Electronics 266 BASCOM 8051 9 2 MCS SPI programmer The MCS SPI programmer is a parallel printer port based SPI programmer It is a modified design of Jakub Jiricek s SPI programmer two LED s were added The programmer can program the 89552 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 The following menu options are available 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 Ch
189. n 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 Example NONIT NORAMCLEAR s your program goes here End 6 24 NONAN Action Compiler directive for changing NAN not a number into 0 0 Syntax NONAN 2007 MCS Electronics BASCOM Language Reference 99 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 vau 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 w
190. n of power needs not reflecting on cable lengths Only the processor pin as power supplier will work 5 sensors AVR 1w functions use an internal pull up 8051 not yet tested Don t even think of simultaneous commands on multiple sensors With 5V through 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
191. n 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 OPEN COM2 FOR BINARY AS 1 open the port PRINT 1 Hello print to serial 1 Gosub Test PRINT Hello print to serial O CLOSE 1 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 OPEN COM2 FOR BINARY AS 1 open the port PRINT 1 Hello print to serial 1 Gosub Test PRINT Hello print to serial 0 Test Print 1 test Return Close 1 See also GET 15h PUT 207 Example 1 2007 MCS Electronics 200 5 8051 only works with 80517 or 80537 CONFIG BAUD1 9600 serial 1 baudrate OPEN COM2 FOR BINARY AS 1 open the port PRINT 1 Hello print to serial 1 PRINT Hello print to serial 0 CLOSE 1 close the channel Example 2 works with every port pin Dim As Byte S As String 16 I As Byte Dum As Byte a software comport is named after the pin you use for example P3 0 will be COM3 0 so there is no P for software comports you must provide the baudrate So for 9600 baud the devicename is COM3 0 9600 When you want to use the pin for sending you
192. nce 117 CONFIG 2 28 for 8052 compatible chips CONFIG LCD 125 CONFIG LCDBUS 25 CONFIG LCDPIN 12 CONFIG BAUDI118 CONFIG 1WIRE 11 CONFIG SDA 28 CONFIG SCL 112 CONFIG DEBOUNCE 125 CONFIG WATCHDOG 132 CONFIG SPI hs CONFIG I2CDELAY 120 CONFIG MICROWIRE 127 CONFIG SERVOS i2 CONFIG ADUCS812 CONFIG 2 CONFIG PRINT 127 CONFIG GRAPHLCD 2h 6 53 CONFIG 1WIRE Action Configure the pin to use for 1WIRE statements Syntax CONFIG 1WIRE pin Remarks pin he port pin to use such as P1 0 See also 1 5 31 1WREAD 837 1WWRITE 831 Config 1WIRE 1 0 P1 0 is used for the 1 wire bus 1WRESET reset the bus 6 54 CONFIG ADUC812 Action Configures the ADUC812 microprocessor Syntax for ADC Config ADUC812 ADCON MODE mode CLOCK clock AQUISITION TIMER2 EXTRIG value Syntax for DAC 2007 MCS Electronics BASCOM 8051 Config ADUC812 DAC MODE mode RANGEO 0 RANGE1 ri CLEARO clr0 CLEAR1 SYNC sync POWERO 0 POWER1 pwri Remarks ADC POWERDOWN NORMAL PDNE STANDBY PDNE means POWERDOWN if not executing a conversion cycle clock his is a constant that specifies the clock division of the master lock 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 his i
193. nctions 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 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 The 1wireSearchFirst function must be called once to initiate the ID retrieval process After the 1wireSearchFirst function is used you should use successive 2007 MCS Electronics 86 BASCOM 8051 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 1 83 1WIRECOUNT 84 1WSEARCHNEXT 87 1wirecount bas l c 1995 2006 MCS Electronics demonstration of using multiple devices chip we use regfile 89s8252 dat crystal attached crystal 12000000 baud rate baud 4800 wait for 500 mili secs Waitms 500 he pins we use connect a 4K7 resistor from the data pin to VCC Config 1wire P1 0 we need an array of 8 bytes to hol
194. ng assembly 243 generated ASM code LJMP 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 Itest indicate ASM label Or you can include the period in the labelname Another good alternative is to use the ASM END ASM directives Example Asm mov 1 test sjmp test End Asm How variables are stored BIT variables are stored in bytes These bytes are stored from 20hex 2Fhex thus allowing 16 8 128 bit variables You can access a bit variable as follows Dim var As Bit dim variable SETB Set bit CLR Clear bit Print var print value End Or you can use the BASIC statement SET and RESET which do the same thing BYTE variables are stored after the BIT variables Starting at address 20 hex used bytes for bit vars 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 You can access variables by surrounding the variable with To refer to the MSB of an Integer Word use var 1 To refer to the MSB of a Long use var 3 The following example shows how to access the variables from ASM Dim t as Byte c as Integer CLR a clear register a MOV t a clear variable t INC t t t 1 MOV c t MOV 0 t LSB of C 2 t you don t have to enter the 0 MOV lain 1
195. nment Hardware simulator i Monitor Pr 4 Programmer STK200 300 ISP programmer i AutoVerify Nor Code Data Parallel Serial Other LPT address 378 PCF85744 Add Remove Port delay 2 Send HEX Cancel 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 4 43 Options Monitor With the monitor options you can select the monitor you use There are only a few monitor programs supported e Altair 535 537 e Altair 552 e Monitor hex upload 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 For hex file based monitors there are 3 additional options 2007 MCS Electronics 66 5 8051 o monitor prefix is sent before the hex file o monitor suffix is sent after the hex file upload is completed The prefix and suffix can contain returns or any ASCII charact
196. nt A PEINE LE End 6 78 DECLARE Action Declares a subroutine Syntax DECLARE SUB TEST var as type Remarks test of the procedure Var Name of the variable s Maximum 10 allowed ype 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 3 SUB 229 Example Dim A As Byte B1 As Byte C As Byte Declare Sub Test a As Byte A 1 B122 C 23 Print Bl C 2007 MCS Electronics 140 BASCOM 8051 Call Test b1 Print A Bl C End Sub Test As Byte Print A Bl C End Sub 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 2 10 6 80 DEFLCDCHAR Action Define a custom LCD character Syntax DEFLCDCHAR char ri r2 r3 r4 r5 r6 r7 r8 Remarks char ariable representing the character 0 7 ri r8 he row values for the character char Byte Integer Word Long Constant ri r8 Constant You can use the LCD designer to build the characters 2007 MCS Electronics BASCOM Language Reference 141 It is important that after the DEFLCDCHAR statement s a CLS fol
197. nt C Inputhex Enter hex byte 2 bytes D Print D Input More variables D Print C s D Input C Noecho supress echo Input Enter your name 5 Hello T S Print Input 5 Noecho without echo Print 5 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 Bre T of End 6 116 INPUTBIN Action Read binary values from the serial port Syntax INPUTBIN vari var2 INPUTBIN dev vari var2 Remarks he variable that is assigned with the characters from the serial port 2 An optional second or more variable that is assigned with the haracters from the serial dev number For use with OPEN 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 2007 MCS Electronics 176 BASCOM 8051 Note that the INPUTBIN statement doesn t wait for a lt RETURN gt but just for the number of bytes See also PRINTBIN 2o INPUT 73 INPUTHEX 1761 Example Dim a as Byte C as Integer INPUTBIN a c wait for 3 characters End This code only for 80517 and 80537 wit
198. o 2 Step 0 1 Print 5 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 651 UPPERLINE 2321 LOWERLINE 1881 THIRDLINE 235 LOCATE 185 2007 5 Electronics 150 BASCOM 8051 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 he string that is assigned with the result A variable of the type single that must be formatted he formatting mask he sign is used to indicate the number of digits before and after the decimal point Normal rounding is used hen you don t need rouding the result use the amp sign instead of he sign after the point See also STR 22 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 2007 MCS Electronics BASCOM Language Reference 151 the result should be 99 5 with a 0 before the point you can indicate how many digits you want to have filled with zeros Targ Fusing s 000 1 the result should
199. ode one 8 bit timer is available See a datasheet for more details The timer counter can be configured with the CONFIG statement CONFIG TIMERO COUNTER TIMER GATE INTERNAL EXTERNAL MODE 0 3 The first argument is the timer counter you want to configure TIMERO in this case GATE specifies if external timer control with the INTO pin is enabled MODE specifies the timer counter mode 0 3 So CONFIG TIMERO COUNTER GATE INTERNAL MODE 2 will configure TIMERO as a COUNTER with no external gate control in mode 2 auto reload When the timer counter is configured the timer counter is stopped so you must start it afterwards with the START TIMERO statement The ON TIMERx statement can be used to respond to a timer counter interrupt when the timer overflows 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 COUNTERO and COUNTER variables hold the values of timer counter 0 and 1 You can also set the timer counter contents with the COUNTERO value statement Please note that with the LOAD statement you can only load a byte value in
200. of hexadecimal numbers The following characters have special meanings in BASCOM statements and expressions Pantone fing quotation mark apostrophe Peron decimal sign assignment symbol or relational operator The BASCOM program line BASCOM program lines have the following syntax ine identifier statement statement comment 2007 MCS Electronics Language fundamentals 71 Using Line Identifiers BASCOM support one type of line identifier alphanumeric line labels An alphanumeric line label may be any combination of from 1 to 32 letters and digits starting with a letter and ending with a colon BASCOM keywords not permitted The following are valid alphanumeric line labels Alpha ScreenSUB Test3A Case is not significant The following line labels are equivalent alpha Alpha ALPHA Line labels may begin in any column as long as they are the first characters other than blanks on the line Blanks are not allowed between an alphabetic label and the colon following it A line can have only one label BASCOM Statements A BASCOM statement is either executable nonexecutable An executable statement advances the flow of a programs logic by telling the program what tot do next Non executable statement perform tasks such as allocating storage for variables declaring and defining v
201. 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 Printed september 2007 in whereever you are located Special thanks to Publisher MCS Electronics All the people who contributed to this document all the forum members that contributed in a positive way all beta testers and all Managing Editor customers M C Alberts Technical Editors M C Alberts Cover Designer B F de Graaff BASCOM 8051 Table of Contents Part 1 1 2 Part Il Part Ill Part IV o OA BR D ON N a BW d OA RAON BF d OA BR WON 0 INDEX 13 Logd 14 Keyword ean ee we uil ele eae 17 Installing BASCOM 8051 21 Updates 27 BASCOM IDE 37 RUNNING BASCOM 805 1 ridic ne en 37 BASGOM IDE 38 39 dixe m 39 File Close e M 40
202. om disk This allows you to load a binary file from disk The current projects binary file is always loaded automatic Buffer write to disk This option can be used to save the buffer to disk 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 get type To identify the chip you can select this option 2007 MCS Electronics 268 BASCOM 8051 The radio button 89C1051 or 89C2051 will be set Chip set lockbit 1 Set lockbit 1 so the chip can not be programmed anymore Chip set lockbit 2 Set lockbit 2 so the chip can not be programmed or verified read anymore 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 9 5 PG302 programmer The PG302 is a serial comport based programmer The programmer can program a wide variety of chips with additional adapters The BASCOM interface is designed to look similar with the original PG302 driver software You must select
203. or 115200 baud will be added later 9 15 SE511 SE516 programmer The SE511 SE516 can be used for the 5 511 and SE516 programmers from Sample Electronics These programmers are serial programmers They require a COM port 2007 MCS Electronics Supported Programmers 277 5 511 5 5165 Sample Electronics Programmer Simulator Load Save PE Read Blank Erase EE Write Verify JH Reset Lock Bits LB1 J LB2 LB3 LockBits 00 01 02 03 04 os 06 oz jos on 0 Set lock bit FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF Ji NES 3 0000 FF j 0010 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0020 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0030 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0040 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF j 0050 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF j 0050 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF j 0070 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0080 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0090 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0040 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0080 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF j der rr rr rr rr rr rr rr rr rr rr rr Fr FF FF i lt E5165 ample Electronics Programmer When you launch the programmer the current program will be loaded into
204. ority PRIORITY SET RESET source level level can be 0 1 2 or 3 0 lowest 3 highest source can be INTO ADC SERIAL1 TIMERO INT2 INTO 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 11 8 ADUC 812 The 812 has 2 DACS named DACO DAC1 You can use the CONFIG ADUC8121 117 statement to set the DAC behaviour 2007 MCS Electronics Microprocessor support 295 The DAC can be powered on or off DACO POWEROFF will power off the DACO DAC1 POWERON will power on the DAC1 To force the output of the DAC to 0 volt use DACO CLEAR To let it output the voltage use DACO NORMAL The DAC values can be written with the following statements DACO value 1024 or a variable DAC1 value word 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 0 or 1 specified All the previous methods shown can work with 0 for DACO or 1 for DAC1 See the aduc812 bas example ADCUS812 bas c 2000 MCS Electronics Note that the support for this chip is untested Any feedback apprecia
205. pen a file by selecting it from the File menu File Close Action Close current editor window When changes are made and they are not saved yet you will be asked to save your program File Save Action With this option you can quick save your current program to disk If the program was created with the File 397 option you will be asked for a filename first Use the File Save 401 option to save the file with another name Note that the file is saved as an ASCII file File Save As Action With this option you can save your current program to disk You can enter a filename before your program is saved Note that the file is saved as an ASCII file File Print Preview Action This will display the print preview window 2007 MCS Electronics BASCOM IDE 41 8954051 B S c 1995 2006 MCS Electronics demonstration file for the ATMEL 8954051 Select the STK200 programmer for ISP programming regfile 89s4051 dat crystal 8000000 D o Fert 1 Wait 1 Loop By clicking the Setup button you can change some printer properties For margin settings you must use the Options Printer settings e amp For a hardcopy click the Print button See also Print 4 4 9 File Print Action With this option you can print the current program Note that the current program is the editor window which has the focus See also Print preview 40 gt 4 10 File Exit Action With
206. place with number 0 7 Deflcdchar 1 16 16 16 16 16 16 16 31 replace with number 0 7 2007 5 Electronics BASCOM Language Reference 181 15 select data RAM Rem it is important that a CLS is following the deflcdchar statements because it will set the controller back in datamode Lcd Chr 0 Chr 1 print the special character Now use an internal routin Acc 1 value into ACC Call Write lcd put it on LCD End 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 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 LCDINIT routine allows you to perform initialization after you have set the pin that controls WR of the LCD to OV See also LCDHEX 182 1 951 CONFIG LCD 125 Example 1995 2006 MCS Electronics file LCD BAS demo LCD CLS LOWERLINE SHIFTLCD SHIFTCURSOR HOME CURSOR DISPLAY sim Rem The Ssim statement will remove long delays for the simulator Rem It is important to remove this statement when compiling the final file 2007 MCS Electronics
207. ple scope or data logger could be made with PSET hope to get an AN from an inspired user End label for the picture Picturel SBGF includes the data from the specified file bgf Samples mcs bgf 6 12 CRYSTAL Action Instruct the compiler to override the crystal frequency options setting Syntax CRYSTAL var 2007 MCS Electronics 92 5 8051 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 directive These statements always work together See also BAUD 897 Example baud 2400 crystal 14000000 14 MHz crystal Print Hello End 6 13 DEFAULT XRAM Action Compiler directive to handle each dimensioned variable as XRAM variable 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 Example default Xram Dim X As Integer 111 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 2007 MCS Electronics BASCOM Language Reference 93 Syntax SEXTERNAL myrout ot
208. ple scope or data logger could be made with PSET We hope to get an AN from an inspired user End label for the picture Picture1 BGF includes the data from the specified file bgf samples mcs bgf 2007 MCS Electronics BASCOM Language Reference 125 6 61 CONFIG LCDPIN Action Override the LCD options to store the settings in your program Syntax CONFIG LCDPIN PIN DB4 P1 1 DB5 P1 2 DB6 P1 3 DB7 P1 4 E P1 5 RS P1 6 Remarks 1 1 etc are just an example in the syntax The pins of the LCD display that must be connected in PIN mode are The WR line of the display must be connected to GND See also CONFIG LCD 1251 Example CONFIG LCDPIN PIN DB4 P1 1 DB5 P1 2 DB6 P1 3 DB7 P1 4 E P1 5 RS P1 6 6 62 CONFIG LCD Action Configure the LCD display Syntax CONFIG LCD LCDtype Remarks he 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 1 LCD display is a special one It is intended for the display that has the memory organized as 2 lines of 8 characters 2007 MCS Electronics 126 BASCOM 8051 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 E1 Pin E2 pin etc To select between 1 and E2 you need to set the
209. port 1 CASE 2 PRINT 2 CASE 4 PRINT 4 CASE IS gt 5 PRINT gt 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 P1 x P3 x or a Bit variable A byte integer word or long variable 2007 MCS Electronics BASCOM Language Reference 217 PE 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 bi 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 1151 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 Integer Word Long variable he 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 2007 MCS Electronics 218 BASCOM 8051 See also SHIFTIN 2181 SHIFTOUT 218 2151 Example Dim
210. portant information before continuing Please read the following License Agreement You must accept the terms of this agreement before continuing with the installation BASCOM 8051 MCS Electronics NO NONSENSE LICENSE STATEMENT AND LIMITED WARRANTY IMPORTANT READ CAREFULLY This license statement and limited warranty constitutes a legal agreement License amp greement between you either as an individual or a single entity and MCS Electronics for the software product Software identified above including any software media and accompanying on line or do not accept the agreement After clicking the I accept the agreeement option you need to click the Next button again to continue The readme txt file is shown Basicly it tells you to contact support mcselec com in case of a problem 1 Setup 8051 Information Please read the following important information before continuing When you are ready to continue with Setup click Next Thank you for using BASCOM 8051 This file contains some additional info on B amp SCOM 8051 When you don t see the Interrupt buttons in the simulator you need to install a newer version of the comctl32 dll fou can download the file 40comupd exe from microsoft On windows NT you ne
211. ps too Buffer clear Will clear the buffer Buffer load from file With this option you can load a file into the buffer By default the current program is loaded into the buffer Buffer save to file With this option you can save the buffer to a binary file Chip Write buffer into chip With this option you program the chip Chip Read chipcode into buffer This option will read the target device its memory into the buffer Chip Blank check Performs a blank check on the target device A chip is considered blank if every memory location contains 255 FF hex 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 2007 MCS Electronics 270 BASCOM 8051 9 7 9 8 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 Prog
212. r 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 61 menu MCS Flashprogrammer 264 Blow IT Flashprogrammer 5265 PG2051 267 MCS SPI programmer 2641 PG302 264 JPK Systems X programmer 272 Peter Averill s TAFE programmer 2731 SE512 or SE514 269 SE 812 270 STK200 STK300 ISP programmer 274 Sample Electronics simple cable ISP programmer 2701 RHOMBUS SCE 51 2751 CYGNAL JTAG programmer 272 2007 MCS Electronics BASCOM IDE 4 28 Tools Terminal Emulator With this option you can start the built in terminal emulator The following window will appear d BASCOM 8051 Terminal emulator CIE x File 53 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
213. racter Put 1 A write it to comport Next Do Get 2 A get character from comport Put 1 A write it back Print A use normal channel Loop Printbin 1 a Printbin is also supported Inputbin 2 a Inputbin is also supported Close 1 finally close device Close 2 End To use the TIMEOUT option include without the remarks STIMEOUT Get 2 A TIMEOUT 10000 character from comport 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 he variable that is assigned with the A D value Channel he channel to measure 2007 5 Electronics BASCOM Language Reference 153 he internal range selection 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 2051 It is a microprocessor depended support 2 feature See also GETAD205 11158 Example Dim bi 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 he variable that is assigned with the A D value
214. ram 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 Sample Electronics ISP programmer The simple cable programmer was submitted by Sample Electronics They produce professional programmers too This simple programmer you can make yourself within a 10 minutes And only a few resistors are needed The operation is the same a for the STK200 300 programmer 2741 What you need is a DB25 centronics male connector a flat cable and a connector that can be connected to the target MCU board The connections to make are as following DB25 pin arget MCU pin AT89S8252 DT104 11 BUSY __ MISO 7 18 25 GND GROUND The MCU pin numbers are shown for an 8252 Note that 18 25 means pins 18 19 20 21 22 23 24 and 25 You can use a small resistor of 100 ohm in series with the DO D2 and D3 line in order not to short circuit your LPT port in the event the MCU pins are high But it was tested without these resistors and my PC still works 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 2007 MCS Electronics Supported Programmers 271 The following picture shows the connections to make Both a setup for the DT10
215. relest for more details Example LOAD TIMERO 100 load TIMERO with 100 Will generate Mov tl0 h 9C Mov th0 h 9C LOAD TIMER2 1000 2007 MCS Electronics BASCOM Language Reference 185 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 onstant or variable with the position 1 64 onstant or variable with the line 1 4 depending on the used display For Graphical displays X can be in the range from 1 30 and y in the range from 1 8 See also CONFIG LCD 1251 LCD 178 HOME 66 CLS 11151 Example LCD Hello Locate 1 10 LCD 6 127 LOOKUP Action Returns a value from a table Syntax var LOOKUP value label Remarks var he returned value A value with the index of the table labe he label where the data starts var Byte Integer Word Long Single value Byte Integer Word Long Constant 2007 MCS Electronics 186 5 8051 See also LOOKUPSTR 185 Example Dim Bl As Byte I As Integer Lookup 1 Dta Print B1 Prints 2 zero based Lookup 0 Dta2 End Dta Data 1 2 3 4 5 Dta2 integer data Data 1000 2000 6 128 LOOKUPSTR Action Returns a string from a table Syntax var LOOKUPSTR value label language length Remarks he string returned value
216. rence with QB In QB you can specify amp 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 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 Numeric variable that will be assigned with the position of the sub string in the string Returns 0 when the sub string is not 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 At the moment INSTR works only with internal strings Support for external strings will be added too 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 test 2007 MCS Electronics 178 BASCOM 8051 Z is Bp Instr s Z Print Bp should print 3 Instr 4 5 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 he string variable that will be assigned with the lower case of string SOURCE h
217. rigger INTO by low level SET TCON 2 trigger by falling edge RESET TCON 2 trigger INT1 by low level See Hardware 251 for more details See Also ON VALUE 597 Example ENABLE INTERRUPTS ENABLE INTO enable the interrupt ON INTO Label2 nosave jump to label2 on INTO 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 1 Remarks Var he numeric variable to test his 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 2007 MCS Electronics 198 BASCOM 8051 ON interrupt 195 Example Dim X As Byte 2 assign a variable interrupt On X Gosub Lbl11 1512 Lb13 jump to label 1613 0 X Goto 11 Lb12 Lb13 End Lb13 Print 1013 Return Lb11 nop Lb12 nop is ASM statement that does nothing 6 146 OPEN Action Opens and closes a device Syntax OPEN device for MODE As channel CLOSE channel here are 2 hardware devices supported COM1 and COM2 ith the software UART you must specify the port pin and the baud rate OM3 0 9600 will use PORT 3 0 at 9600
218. rint The same rules apply to PRINTHEX as 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 205 j INPUTHEX 178 SPC 2221 2007 5 Electronics 206 BASCOM 8051 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 INTO INT1 SERIAL TIMERO TIMER1 and TIMER2 Interrupt INTO always has the highest priority When more interrupts occur at the same time the following order is used to handle the interrupts Note that other microprocessors can have additional other interrupt setting Read microprocessor support 288 to check the additions Interrupt INTO 1 highest 5 lowest Example PRIORITY SET SERIAL serial int highest level ENABLE SERIAL enable serial int ENABLE TIMERO enable timerO int
219. rogrammer un nr Re esie cele ortus en nette 268 SE512 or SE514 programmier inuenies ct eei lr ensi 269 Kio T 270 Sample Electronics ISP programmer sine 270 CYGNAL JTAG Programmer 272 M nn ne et nn 272 2007 5 Electronics Contents 11 11 JPK Systems X programmer 272 12 Peter Averill s TAFE programmer eene nennen 273 13 STK200 300 ISP Programmer sneennneennnnnnennnnnnneennees 274 14 Rhombus SGE 5 T a te ere te rene een E tn nie 275 15 SE511 SE516 program Meh css sisi scheceataessncvenseteecececes 276 Part X BASCOM Misc 279 1 Eitor messages ss ec 279 2 Compiler Limits 282 3 Reserved Words 283 Part XI Microprocessor support 288 1 Microprocessor Support nuoc re sel ecueeesesenceeedssuneestedecncesers 288 PARTI 5 nt 289 S DATA EER ROM Rem 292 4 AT898252 WAT CHDOG ie 292 5
220. rsion 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 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 2007 MCS Electronics 212 BASCOM 8051 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 an be a P1 x P3 x or any bitvariable where 0 7 an be a byte integer or word variable x onstant of variable to reset 0 7 for bytes and 0 15 for Integer ord 0 31 for a LONG See also SET a 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 he label of a DATA statement See also DATA 135 READ 2051 2007 5 Electronics BASCOM Language Reference 213 Example DIM a AS BYTE I AS BYTE RESTORE dta FOR a 1 TO 3 RE
221. rupt Handler For TimerO Interrupt Timer 0 int Inc Count If Count 250 Then Print TimerO Interrupt occured 0 Count 2007 MCS Electronics 228 BASCOM 8051 End If Return 6 185 STR Action Returns a string representation of a number Syntax var STR x Remarks Var A string variable A numeric variable The string must be big enough to store the string See also 232 HEX HEXVAL 16h Difference with 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 2007 MCS Electronics BASCOM Language Reference 229 Remarks he string that is assigned IN o he ASCII code that is assigned to the string he 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 2i Example Dim s as XRAM String 15 s String 5 65 Print s 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
222. rupt bit that caused the interrupt yourself in the ISR handler Capture mode In the capture mode there are two options e 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 INTERNAL MODE 1 As above but with the added future that a 1 to 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 2007 MCS Electronics 290 BASCOM 8051 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 Auto reload mode In the 16 bit auto reload mode TIMER2 can be configured as a timer or counter which can be programmed to count up or down The counting direction is determined by bit DCEN TIMER2 will default to counting up to amp HFFFF and sets the TF2 overflow flag bit upon overflow This causes
223. rupts 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 The source can be INTO ADC TIMERO INT2 INTO INT3 2007 MCS Electronics 294 BASCOM 8051 TIMER1 INT4 SERIAL INT5 TIMER2 INT6 Note that only one of the 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 11 7 INTERRUPTS and PRIORITY 80537 The 80517 and 80537 have more interrupts and priority is handled different compared to the 8051 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 seriall 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 seriall interrupt Selecting of pri
224. s he string that is assigned he 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 hot Dim S As Xram String 15 7 As Xram String 15 5 ABCDEFG 2 Left s 5 Print 7 ABCDE End 6 124 LEN Action Returns the length of a string Syntax var LEN string 2007 MCS Electronics 184 BASCOM 8051 Remarks var A numeric variable that is assigned with the length of string he 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 IMERO TIMER1 or TIMER2 Value he 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 TIMERO 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 zx instead See Additional hardwa
225. s 46 ELSE 144 ENABLE 145 END 146 ENDIF 146 ERASE 147 Error messages 279 EXIT 148 Rs File Close 40 File Compile 47 File End 41 File Exit 41 File New 39 File Open 39 File Print 41 File Print Preview 40 File Save 40 File Save 40 File Simulate 49 File Transmit 53 FOR 148 FOURTHLINE 149 FUSING 150 Futurelec 272 M e GET 151 198 GETAD 152 GETAD2051 153 GETRC 158 GETRC5 160 GOSUB 162 GOTO 163 Grifo 302 Hardware 2 258 Hardware LCD display 257 Help About 67 Help Credits 68 Help Forum 68 Help index 67 Help on 67 Help Shop 68 2007 MCS Electronics Index 313 Help Support 68 HEX 163 HEXVAL 164 HIGH 164 HIGHW 165 HOME 166 l2C 168 I2CRBYTE 168 I2CRECEIVE 166 I2CSEND 167 I2CSTART 168 I2CSTOP 168 I2CWBYTE 168 IDLE 169 IF 169 INCR 171 INDEX 13 Initialization 248 INKEY 171 173 INPUT 173 INPUTBIN 175 INPUTHEX 176 Installing BASCOM 8051 21 INSTR 177 Internal registers 246 International Resellers 300 INTERRUPTS and PRIORITY 80515 293 INTERRUPTS and PRIORITY 80537 294 JPK Systems X programmer 272 Keyword Reference 17 Language fundamentals 70 LCASE 178 LCD 178 LCD designer 54 LCDHEX 182 LCDINIT 181 LEFT 183 LEN 183 LIB 55 LOAD 184 LOCATE 185 LOOKUP 185 LOOKUPSTR 186 LOOP 144 LOW 187 LOWERLINE 188 LOWW 188 189 MAKEDEC 189 MAKEINT 190 MAX 190 MCS Flash programm
226. s 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 he TIMER2 can be ENABLED or DISABLED When enabled the imer2 overflow serves as a trigger for the AD conversion value he external trigger may be ENABLED or DISABLED When enabled he external pin 23 CONVST can start the conversion while it is low Remarks DAC he 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 he DACO range can be set to VDD or VREF With VDD the range is rom O VDD For VREF it is O VREF DAC1 range can be set to VDD or VREF With VDD the range is rom 0 VDD For VREF it is 0 VREF his parameter when TRUE will clear the DACO This will set the output voltage to 0 V his parameter when TRUE will clear the DAC1 This will set the output voltage to 0 V 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 his parameter when ON will power ON the DACO When OFF the DACO is powered OFF his parameter when ON will power ON the DAC1 When OFF the DAC1 is powered OFF 2007 MCS Electronics BASCOM Language Reference 119 6 5
227. s handy when you use a LCD display See also SERIALINPUT 105 SERIALOUTPUT 106 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 he name of the assembler routine that must be called when a haracter is sent to the serial buffer SBUF he 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 Imyoutput perform the needed actions here mov sbuf a serial output buffer default ret 2007 MCS Electronics BASCOM Language Reference 107 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 112 Example SIM don t make code for WAIT and WAITMS WAIT 2 the simulator is faster now 6 38 TIME
228. s 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 INTO and TCON 3 must be tested for Some uPs an additional timer named TIMER2 281 It depends on the used chip which features TIMER2 has Ports and Power Up Port 1 is an 8 bit bi directional I O port Port pins P1 2 to P1 7 provide internal pull ups P1 0 and P1 1 requires external pull ups P1 0 and P1 1 also serve as the positive input AINO and the negative input AIN1 respectively of the on chip precision analog comparator 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 2007 MCS Electronics Additional Hardware 255 The port3 output buffers can sink 20 mA When 1 s are writt
229. se sensitive Forward Whole words only C Backward Regular expressions Scope Origin Global From cursor C Selected text Entire scope 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 4 17 Edit Find Next Action With this option you can search for the next occurrence of the specified text When you didn t specify a search text you will be asked for the text to find with the windows find dialog See Also 2007 MCS Electronics 44 BASCOM 8051 Edit Find 434 Shortcut F3 4 18 Edit Replace Action With this option you can replace text in your program The following replace dialog will appear Replace Text Text to find 11 Replace with 22 Options Direction Case sensitive Forward Whole words only Backward Regular expressions Prompt on replace Scope Origin fe Global From cursor Selected text Entire scope Replace All Cancel Enter the text to search for and the text to replace with and press return Shortcut CTRL R 4 19 Edit Goto Action With this option you can type the line number of the line you want to go to The following screen will be shown Go to line Number Enter new line number The current line number will be shown You can edit this and press RETURN to jump 2007 MCS Electronics
230. set the WD timer When it reaches 16384 the chip will be reset The input to the WD timer is the XTAL frequency 2007 MCS Electronics 300 5 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 amp catid 82 amp Itemid 59 2007 MCS Electronics 302 5 8051 13 Third party hardware 13 1 Third party Hardware There is a lot of third party hardware available Below you find links to some of the available hardware Grifo boards for BASCOM AVR BASCOM 8051 and BASCOM LT 302 Rhombus SCE 51 small 8051 board and in circuit emulator 305 13 1 4 Grifo EXAMPLES BASCOM BASIC IER TEL 4 E La The content of this page is provided by Grifo As following you can find a wide range of demo programs The programs have been realized to be used on a well known hardware as the K51 AVR or the DEB 01 etc in order to avoid any doubts about the interpretation of the results The demo programs are well documented in order to allow a fast approach for anybody In addition to that being the same demoes written in different languages it is possible to get an efficient comparison both for Quality and Speed terms INDEX BASIC Examples BASCOM LT 200
231. so run to a specified line by clicking the run to button The status bar The status bar is also divided into a few sections These sections from left to right display the following information e The value of a variable the source code window You can select a variable by moving the mouse cursor over the variable name e The status of the simulator stopped running or paused e The number of clock cycles and the execution time of the executed code You can reset the value by clicking on this section e The stack depth of the program The stack depth is the deepest level the stack has reached during execution If it exceeds the available internal memory 128 or 256 bytes the program will not run correctly in the chip 2007 MCS Electronics BASCOM IDE 51 The interrupt buttons 2107043147151 ro 2 sem The INTO INT1 TO T1 and SER buttons can be clicked to generate an interrupt Because this is a software emulator no hardware interrupts can be generated You have to do this yourself by clicking these buttons TIMER 0 and TIMER 1 are simulated by software Therefore they will generate an interrupt automatically if the software enables this The external gate however isn t simulated so for this occasion you must click the corresponding button Depending on the chip used other interrupt buttons can be visible They have the same purpose as the default interrupt buttons Hardware simulator button By
232. st end each FOR statement with a NEXT statement See also FOR 148 Example Dim X As Byte Y As Byte A As Byte Y 10 y 10 For A 1 To 10 this 10 times For X Y To 1 this one also Print X 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 INTO INT1 SERIAL TIMERO TIMER1 or TIMER2 hip specific interrupts can be found under microprocessor he label to jump to if the interrupt occurs hen you specify NOSAVE no registers are saved and restored in he 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 2007 MCS Electronics BASCOM Language Reference 197 a RETURN statement in the ISR 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 INTO 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 SET TCON O trigger INTO by falling edge RESET TCON O t
233. t be used with serial communications BASCOM 8051 Options Output Communication 12C LCD Misc Baudrate 2400 Frequency 11 059 We advise to use the BAUD 991 and CRYSTAL 2 compiler directives in your program This way the settings are stored in your source code 4 36 Options Compiler 2 With this option you can select the port pins that serve as the SDA and SCL line for the I2C statements 2007 MCS Electronics BASCOM IDE 59 BASCOM 8051 Options X E Communication Environment Hardware simulator Programmer Monitor Output Communication 12C p35 SDA port P37 RC5 pot p You can also use the CONFIG SDA ziand CONFIG SCL 124 statements 4 37 Options Compiler LCD With this option you can select the port pins for the LCD display This only applies to the LCD statements when used in 4 bit mode and if the LCD display is connected to the port pins You can also choose the port pins with the CONFIG LCDPIN 125 statement BASCOM 8051 Options X er Communication Environment Hardware simulator Programmer Monitor Printer Output Communication 12C LCD Misc DB P1 0 Enable P14 DBE 11 RS 15 DB5 12 DB4 p13 upper 3 bits high in LCD desianer 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 th
234. t of address range 97 RNDDATA variable not dimensioned a 98 expected ay 99 expected 06 Library file not found NIN 07 Library file already registered 08 09 expected 210 LEFT or RIGHT expected 211 212 213 214 215 N expected N External routine not found alid number must be in range from 1 16 Numeric constant expected No SUB found Already in SUB rong mode NOINT expected must be between Address gt 127 use indirect addressing NIN NIO 2007 MCS Electronics 282 BASCOM 8051 999 DEMO allows 2048 bytes of code only 10 2 Compiler Limits There are some limitations to the compiler You can perform only one calculation in a formula Good False a a bi a a bi c Maximum number of BIT variables Maximum number of STRING variables Up to available external memory Maximum number of ALIAS statements A28 Depending on the used statements and the used variables of the other types A maximum of 32 bytes is used internally This depends on the used statements The stack uses some space too So it depends on the used statements how much variables you can use In the worst case 32 16 8 56 bytes are used You can find out by viewing the report file 48 how much bytes are used by your program When you have a micro such as the 8958252 with 256 bytes of internal memory you can have more variables 8 used bit vars will use 1 byte 1 used byte w
235. t 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 START WATCHDOG will start the watchdog timer STOP WATCHDOG will stop the watchdog timer RESET WATCHDOG will reset the watchdog timer 2007 MCS Electronics Microprocessor support 293 See also CONFIG WATCHDOGI132 Example c 1998 MCS Electronics WATCHD BAS demonstrates the 8958252 watchdog timer select 8958252 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 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 11 5 WATCHDOG 80515 The 80515 and 80535 both have a WD timer This is a 16 bit timer that can t be stopped It will reset the system after 65535 uS at 12MHz START WATCHDOG start the WD timer RESET WATCHDOG will reset the WD timer 11 6 INTERRUPTS and PRIORITY 80515 The 80515 80535 80517 and 80537 have more interrupt sources and priority is handled different compared to the 8051 Enable inter
236. te As Integer 1 Print print variable A Print new line Print Text to print constant to print B1 10 Printhex B1 print hexa notation amp 000 assign value to c Printhex C print in hex notation Print C print in decimal notation 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 he variable which value is sent to the serial port 2007 5 Electronics BASCOM Language Reference 205 vam optional variables to send separated by a Device number for use with OPEN and CLOSE PRINTBIN is equivalent to PRINT CHR var but whole arrays can be printed this way When you use a Long for example 4 bytes are printed See also INPUTBIN 175 i PRINT 20 PRINTHEX 205 76 Dim a 10 as Byte as Byte For c 1 To 10 a c a fill array Next PRINTBIN a 1 print content This code only for 80517 80537 with dual serial port Open 2 For Binary As 1 open serial channel 1 PRINTBIN 1 a 1 a 2 a 3 note that the channel is separated by a and the vars by Close 1 6 154 PRINTHEX Action Sends a variable in hexadecimal format to the serial port Syntax PRINTHEX var Remarks var he variable to p
237. ted 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 Rangel Vref RangeO Vref ClearO False Sync Enabled PowerO Power1 Off Declare Sub Write ebyte Declare Sub Read ebyte dim variables 2007 MCS Electronics 296 BASCOM 8051 Dim Wdac As Word Dim Adc As Word Dim Eeadr As Word Eebyte As Byte Page As Word get value from adc channel 0 note that simulator will halt until you make the adccon2 bit 4 zero Adc Getad 0 enable dacO by powering it on Dac0 poweron OV to output of DacO clear put voltage into dacs Dac0 value 12 Daci value 500 dacO was OV but must work normal now Dac0 normal and after setting the value s the dacs must be updated with the sync method Dac sync the EEPROM is accessed via pages each page is 4 bytes to write 1 byte you need to write the whole 4 byte page assign eeadr with the address and eebyte with the value to write Eeadr 100 Eebyte 5 Call Write ebyte Eeadr 100 Call Read ebyte Print Eebyte End 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
238. the subroutine In this case Test With the CALL statement you can call a procedure or subroutine As much as 10 parameters can be passed but you can also call a subroutine without parameters For example Call Test2 The call statement enables you to implement your own statements You don t have to use the CALL statement Test2 will also call subroutine test2 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 2 See also DECLARE 135 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 alternative call End Sub Test bb As Byte use the same variable as the declared one Led Bb put it on the LCD Lowerline Led Bcd End Sub 6 49 CHR Action Convert a byte Integer Word variable or a constant to a character Syntax PRINT CHR var s CHR var 2007 MCS Electronics BASCOM Language Reference 115 Remarks Var Byte Integer Word variable or numeric constant 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 Dim 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 Syntax for graphic LCD CLS TEXT CLS GR
239. 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 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 2007 MCS Electronics Supported Programmers 269 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 9 6 5 512 or SE514 programmer The SE512 and SE514 are parallel printer port based programmers The nice thing about these programmers is that they can simulate the application too This has the advantage that no device swapping is needed until your application works like you want The SE512 can program the AT89C1051 to AT89C4051 The SE514 can program larger chi
240. this option you can leave BASCOM If you have made changes to your program you can save them upon leaving BASCOM 2007 MCS Electronics 42 BASCOM 8051 4 11 Edit Undo Action With this option you can undo the last change you made to your program By selecting this option again you can undo the previous change to your program See also Edit Redo 42 Shortcut CTRL Z 4 12 Edit Redo Action With this option you can redo the last undo action See also Edit 27 Shortcut SHIFT CTRL Z 4 13 Edit Copy Action With this option you can copy selected text into the clipboard You can select text by dragging the mouse cursor over the text or by Double clicking on a word Another possibility is to hold the shift key down and pressing the cursor keys Selected text is shown inverted Shortcut CTRL C and CTRL INS 4 14 Edit Cut Action With this option you can cut selected text into the clipboard The selected text is copied into the clipboard and deleted from your program Shortcut CTRL T 2007 MCS Electronics BASCOM IDE 43 4 15 Edit Paste Action With this option you can paste text from the clipboard into the current cursor position Shortcut CTRL V and SHIFT INS 4 16 Edit Find Action With this option you can search for text in your program The following dialog window will appear Find Text Find Text to find Options Direction Ca
241. to store the 1wire ID s while counting The 1wireCount function uses the 1wSearchFirst and 1wSearchNexy functions internally See also 1 83 1WSEARCHFIRST 51 1WSEARCHNEXT si lwirecount bas 1995 2006 MCS Electronics demonstration of using multiple devices chip we use regfile 89s8252 dat crystal attached crystal 12000000 baud rate baud 4800 wait for 500 mili secs Waitms 500 the pins we use 2007 MCS Electronics BASCOM Language Reference 85 connect 4 7 resistor from the data pin to Config lwire P1 0 need an array of 8 bytes to hold the result Dim Ar 8 As Byte we also need a counter variable and a word variable Dim I As Byte W As Word some ids of lwire chips I tested V 01 53 BS 8D 101 OO 00 56 01 84 8D 01 00 00 5 Print start get the number of connected 1 device W lwirecount 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 1 device on the bus Ar 1 1wsearchfirst print the ID For I 1 To 8 Printhex Ar i Next Print assume that there are more than 1 lwire devices Do get the next device Ar 1 lwsearchnext For I 1 To 8 Printhex Ar i Next Print Loop Until Err 1 when ERR is 1 it means there are no more devices IMPORTANT lwsearchfirst and next fu
242. to 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 COUNTERO COUNTER variables You can not use the TIMERO TIMER1 in it s place but it does the same thing assigning retrieving the timer counter Port 3 is a unique port because it has alternative functions That is you can use it as a port like P3 1 1 or SET P3 1 or you can make use of the double function of this port lalternative function RxD receive data for RS 232 xD transmit data for RS 232 2007 MCS Electronics 254 BASCOM 8051 P3 2 interrupt 0 input timer gate control P3 3 interrupt 1 input timer 1 gate control 0 timer O input or counter input 1 timer 1 input or counter input 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 INTO 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 SET TCON O Falling edge generates interrupt for INTO RESET TCON O Low signal generates interrupt for INTO SET TCON 2 Falling edge generates interrupt for RESET TCON 2 Low signal generates interrupt for When TCON x is RESET the interrupt
243. to wait 1 255 2007 MCS Electronics BASCOM Language Reference 235 The delay time is based on the used X tal frequency The use of interrupts can slow down this routine This statement is provided for the I2C statements When you write to an EEPROM you must wait for 10 mS after the write instruction See also DELAY 4h WAIT 237 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 he number of milliseconds to wait 1 65535 The delay time is based on the used X tal frequency So it is important that you provide the right CRYSTALI 9 value The use of interrupts can slow down this routine For a real precise delay you should use a timer The WAITMS statement can only delay for 255 mS That is why the WAITMSE statement was added it can give a longer delay See also DELAY 14h WAIT 257 WAITMS 231 Example WAITMSE 1000 wait for 1000 mS Print 6 198 WATCHDOG Action Start and stop the watchdog timer Syntax 2007 MCS Electronics 236 5 8051 START WATCHDOG will start the watchdog timer STOP WATCHDOG will stop the watchdog timer RESET WATCHDOG will reset the watchdog timer Remarks The 8958252 has a built in watchdog timer A watchdog timer is a timer that will reset the uP when it reaches a certain value So
244. tructions where be jumped to a label like SJMP internal buffer of 16 bytes This has the advantage that no stack handling is needed 246 BASCOM 8051 LIMP DJNZ etc Internal buffer for string conversion The string conversion routines used for PRINT num STR and VAL use but the disadvantage that a fixed space is used Of course you can use this buffer It can be referenced with TMP_S1 So when you need a temp string you can use this buffer Note that this buffer is only available with the mentioned statements Example Dim s as single s 1 1 Print s now the buffer is needed ___TMP_Si Use this space Print ___ _51 Comment The sign can be used or the BASIC comment sign Mov a 1 comment Mov a 2 comment 7 2 Internal registers You can manipulate the register values directly from BASIC They are also reserved words The internal registers are BIT addressable registers IE P3 p presse BYTE addressable register SP tack pointer DPL pointer low word DPH pointer high word TMOD imer counter mode control 2007 MCS Electronics Using assembly 247 imer counter 0 low byte imer counter 1 low byte imer counter 0 high byte imer counter 1 high byte Serial data port Port 1 latch Port 3 latch 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
245. unter uses external pulses to increment its count The external pulses are received at alternative pin P3 4 for TIMERO and P3 5 for TIMER1 The timer counter can be controlled by the run bit TRO You can stop a timer counter with the statement STOP TIMERO z5 COUNTERO You can start a timer counter with the statement START TIMERO 22 TIMER1 The timer counter can also be controlled with the alternative pin P3 2 This pin is labeled for its alternative INTO 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 INTO is active low provided that the timer is started The timer counter can operate in four modes e mode 0 13 bit counter An interrupt is generated when the counter overflows So it takes 8192 pulses to generate the next interrupt e mode 1 16 bit counter 2007 MCS Electronics Additional Hardware 253 Mode 1 is similar to mode It implements a 16 bit counter It takes 65536 input pulses to generate the next interrupt e mode 2 8 bit auto reload TLO serves as an 8 bit timer counter When the timer counter overflows the number stored in THO is copied into TLO and the count continues An interrupt is generated each time the counter overflows and a reload is performed e mode is inactive and holds its count TIMER1 For TIMERO in timer mode two 8 bit timers are available and in counter m
246. up here you can enter a short name for the uP e IRAM the amount of available internal memory 128 or 256 bytes e org the hexadecimal address where the code can start This is 3 bytes after the last interrupt entry address because the last interrupt will have a LIMP to an ISR and a LJMP needs 3 bytes e I xxx where xxx is the name of the additional interrupt The name must be no 2007 MCS Electronics 248 BASCOM 8051 7 3 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 INTO INT1 TIMERO TIMER1 and SERIAL are already handled by the compiler e 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 EO B FO BYTE ADCH C6 ADCON C5 CTCON EB MISC up 80552 I_TIMER2 2B I_CTO 33 I CT1 I_CT2 43 I_CT3 4B I_ADC 53 I_CMO 5B I_CM1 63 I_CM2 6B I_T2 73 org 76 IRAM 256 CLOCKDIV 12 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 9 The only initialization that is always done is the setting of the stack point
247. uration 2007 MCS Electronics 130 5 8051 After 20 mS the pulses will be sent again to the port pins 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 6 69 CONFIG SPI Action Configures the SPI related statements 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 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 ill send the LS bit first SPIOUTEDGE Falling or Rising Falling is the default The edge specifies if the he 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 th
248. 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 SRAMSIZE amp H size Remarks Size of external RAM memory chip size Constant See also RAMSTART 108 Example ROMSTART amp H4000 SRAMSTART 0 RAMSIZE amp 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 Remarks address he hex address where the data is stored Or the lowest address which enables the RAM chip 2007 MCS Electronics 102 BASCOM 8051 ou can use this option when you want to run your code in systems ith 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 var
249. 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 The benefit of the 1w bus Each device is individual and you can communicate with it over the media of 2 wires Still you can address one individual device if you like Get its value There are 64 2 unique identifications numbers Naturally if lot of cables are unwanted this is a big benefit And you only occupy 1 processor pin 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 The disadvantages of the 1w bus So far as I know DS is the only manufacturer of sensors for the bus Some people t
250. x D 251 These functions are provided as an addition to the I2CSEND 167 and I2CRECEIVE 166 functions See also I2CRECEIVE 165 I2CSEND he Example Writing and reading 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 2007 MCS Electronics BASCOM Language Reference 169 I2cwbyte 3 send a value I2cstop generate stop Waitms 10 wait 10 mS because that is the time that the chip needs to write the data now read the value back into the var I2cstart generate start I2cwbyte Adresw write slaveadres I2cwbyte 1 write adres of EEPROM to read I2cstart generate repeated start I2cwbyte Adresr write slaveadres of EEPROM I2crbyte A 9 receive value into a 9 means last byte to receive I2cstop generate stop Print A print received value End 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 20 Example IDLE 6 111 IF Action Allows conditional execution or branching based on the eva
251. xample Dim A As Byte A 65 Lcd A Lowerline Lcd End 6 46 BITWAIT Action Wait until a bit is set or reset Syntax BITWAIT x SET RESET Remarks x bi 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 2007 MCS Electronics BASCOM Language Reference 113 See also NONE Example Dim A As Bit Bitwait A Set wait until Bitwait P1 7 Reset wait until as 105 End ASM BITWAIT 1 0 SET will generate Jnb h 91 0 BITWAIT P1 0 RESET will generate Jb H O1 0 6 47 BREAK Action Generates a reserved opcode to pause the simulator Syntax BREAK Remarks bit a is set bit 7 of Port 1 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 The reserved opcode used is A5 See also NOBREAK 9 Example PRINT Hello BREAK the simulator will pause now End 6 48 CALL Action Call and execute a subroutine 2007 MCS Electronics 114 BASCOM 8051 Syntax CALL Test 1 var n Remarks Any BASCOM variable or constant var n Any BASCOM variable or constant Test Name of
252. you can simulate a compiled program When the source code is saved without compiling you will be warned that the debug file differs from the source code You have the option to compile it before you simulate or continue without recompiling F2BASCOM simulator IBI x Dim X As Xram Byte 10 As Xram Byte Reg Val 4 40 TCON Call Test 2 Call Test 1 Print B1 Call Testo ipL 1 1 The simulator window is divided few sections Toolbar with speed buttons e Variable watch modify window e Source code window e Terminal input output window e e Register window Status bar 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 2007 MCS Electronics 50 BASCOM 8051 a read dot indicating that a break line is set You can only set a breakpoint on a line that has a yellow dot gt a yellow arrow This arrow shows the line currently executing The register window On the right side the register window is visible You can change the value of a register by entering a new value The variable watch section The section below the toolbar is the variable watch section You can add a variable by entering one in an empty cell You can also add a new variable by selecting it from the source window and pressing return You can insert a new variable watc
Download Pdf Manuals
Related Search
bascom 8051 bascom 8051 bascom 8051 free download
Related Contents
CA Clarity PPM - Manuel du produit Accélérateur 組立説明図をPDFで確認 Abocom BUD200 User's Manual トレーニングテキスト Heaven Fresh HF 60 air purifier Fisher-Price PLANETHEROES L3770 User's Manual Pfister F-534-7CMS Installation Guide Diccionario español↔inglés - Franklin Electronic Publishers, Inc. IS 140 · IGA 140 User manual - Haier.com Worldwide - Select your local country or Copyright © All rights reserved.
Failed to retrieve file