155
М.Л.Кулиш СПРАВОЧНИК ПО ПРОГРАММИРОВАНИЮ BASCOM-8051® Краснодар 2001 ® Торговая марка «BASCOM-8051» принадлежит фирме MSC Electronics, Нидерланды. (http:\www.mcselec.com) Редакция 1.5 - 29.3.01

СПРАВОЧНИК ПО ПРОГРАММИРОВАНИЮ BASCOM-8051mega-avr.tk/file/LITERATURA/PROGRAM/MK/Spravochnik po... · bascom-8051 ® Краснодар ... bascom-8051

  • Upload
    letram

  • View
    244

  • Download
    1

Embed Size (px)

Citation preview

  • ..

    BASCOM-8051

    2001

    BASCOM-8051 MSC Electronics, . (http:\www.mcselec.com)

    1.5 - 29.3.01

    ..

    BASCOM-8051

    2001

    BASCOM-8051 MSC Electronics, . (http:\www.mcselec.com)

    1.5 - 29.3.01

    .

    Bascom-8051 ( , , )

    1-1

    ( Bascom-8051)

    2-1

    ( )

    3-1

    , Bascom-8051

    4-1

    Bascom-8051

    5-1

    6-1

    , Bascom

    7-1

    8-1

    9-1

    Bascom

    10-1

    11-1

    12-1

    13-1

    14-1

    15-1

    16-1

    17-1

    18-1

    c Microwire

    19-1

    I2C

    20-1

    21-1

    -

    22-1

    23-1

    24-1

    25-1

    26-1

    Bascom

    27-1

    EEPROM AT89S82252

    28-1

    Bascom

    29-1

    Bascom

    30-1

    Bascom

    31-1

    32-1

    A.

    A-1

    B. 8051

    B-1

    C. MCS-51

    C-1

    K_MGBC_INTR.DOC

  • .

    Bascom-8051 ( , , )

    1-1

    ( Bascom-8051) 2-1 ( ) 3-1 , Bascom-8051 4-1 Bascom-8051

    5-1

    6-1 , Bascom

    7-1

    8-1 9-1 Bascom 10-1 11-1 12-1 13-1 14-1 15-1 16-1 17-1 18-1 c Microwire 19-1 I2C 20-1 21-1 - 22-1 23-1 24-1 25-1 26-1 Bascom 27-1 EEPROM AT89S82252 28-1 Bascom 29-1 Bascom 30-1 Bascom 31-1 32-1 A. A-1 B. 8051 B-1 C. MCS-51 C-1

  • ===================================== Bascom-8051 ==

    1. Bascom-8051 ( ) , , , . , .

    , .

    Bascom-8051

    = , , 3-1, 3-2 + - * / \ 3-1,3-2 = < > = 3-2 ; : , 3-1

    BIT 3-1 BYTE ( ) 3-1 CONST ( ) 3-1,20 INTEGER 3-1 LONG 3-1 SINGLE 3-1 STRING ( ) 3-1 WORD 3-1 Array(n) () 3-1

    (), Bascom-8051

    10, 12345, -100 3-1 &h00FF, &h10 (-, - ) 3-1 &b01010101 (-, - ) 3-1 123.456, 0.12 , 3-1 String Data ( 254 ) 3-1

    Bascom-8051

    $ASM 4-1 $BAUD = 4-1 $CRYSTAL = 4-1 $DEFAULT XRAM 4-1 $END ASM 4-1 $EXTERNAL 4-1 $INCLUDE [] 4-1 $IRAMSTART = 4-2 $LARGE 4-2 $LCD = - 4-2 $LIB 4-2 $MAP 4-2 $NOBREAK ( ) 4-2 $NOINIT 4-3 $NOLCDINIT LCD 4-3 $NONAN NAN 0.0 4-3 $NOSP 4-3 $OBJ 4-3 $RAMSIZE = 4-3 $RAMSTART = 4-3 $REGFILE=[] 4-3 $ROMSTART = 4-3

    =============================================================================

    1-1

    ===================================== Bascom-8051 ==

    1. Bascom-8051

    ( ) , , , . , .

    ,

    .

    Bascom-8051

    =

    , ,

    3-1, 3-2

    + - * / \

    3-1,3-2

    = < > =

    3-2

    ; : ,

    3-1

    BIT

    3-1

    BYTE

    ( )

    3-1

    CONST

    ( )

    3-1,20

    INTEGER

    3-1

    LONG

    3-1

    SINGLE

    3-1

    STRING

    ( )

    3-1

    WORD

    3-1

    Array(n)

    ()

    3-1

    (), Bascom-8051

    10, 12345, -100

    3-1

    &h00FF, &h10

    (-, - )

    3-1

    &b01010101

    (-, - )

    3-1

    123.456, 0.12

    ,

    3-1

    String Data

    ( 254 )

    3-1

    Bascom-8051

    $ASM

    4-1

    $BAUD =

    4-1

    $CRYSTAL =

    4-1

    $DEFAULT XRAM

    4-1

    $END ASM

    4-1

    $EXTERNAL

    4-1

    $INCLUDE []

    4-1

    $IRAMSTART =

    4-2

    $LARGE

    4-2

    $LCD =

    -

    4-2

    $LIB

    4-2

    $MAP

    4-2

    $NOBREAK

    ( )

    4-2

    $NOINIT

    4-3

    $NOLCDINIT

    LCD

    4-3

    $NONAN

    NAN 0.0

    4-3

    $NOSP

    4-3

    $OBJ

    $RAMSIZE =

    4-3

    $RAMSTART =

    4-3

    $REGFILE=[]

    4-3

    $ROMSTART =

    4-3

    $SERIALINPUT =

    4-4

    $SERIALOUTPUT =

    4-4

    $SERIALINPUT2LCD

    - ( . LCD)

    4-4

    $SIM

    ( )

    4-4

    , Bascom-8051 ( )

    1WIRE

    :

    4-4,4-7

    COUNTER0, 1 2

    0, 1 2

    4-10

    EEPROM

    AT89S8252

    4-11

    DEBOUNCE

    19,4-7

    I2C: I2CDELAY

    I2C

    4-7

    LCD, LCDBUS, LCDPIN

    LCD-: (), ()

    4-7

    I2C: SDA, SCL

    I2C :

    4-8

    Microwire: DIN, DOUT, CS, CLOCK

    4-8,4-28

    SERVOS

    4-8,4-34

    SPI: DIN, DOUT, CS, CLK

    SPI :

    4-8

    TIMER0, 1 2

    0, 1 2

    4-8,4-9

    WATCHDOG

    AT89S8252

    4-9

    INT0

    0

    4-13,4-33

    INT1

    0

    4-13,4-33

    PCA

    851FA

    4-13,4-33

    SERIAL

    4-13,4-33

    TIMER0

    0

    4-13,4-33

    TIMER1

    1

    4-13,4-33

    TIMER2

    2

    4-13,4-33

    SOUND

    4-35

    RC

    ( RC-)

    4-15

    RC5

    RC5

    4-16

    Bascom-8051

    .. ALIAS ..

    4-5

    BITWAIT bit Set(Reset)

    ( )

    4-5

    BREAK

    4-5

    CALL

    ()

    4-6

    CASE n :

    n

    4-6

    CASE IS :

    , ,

    4-6

    CLOSE ..

    ()

    4-30

    CONFIG

    4-7 ... 4-9

    CONST

    4-9

    DATA

    4-10

    DEBOUNCE

    4-11

    DECLARE SUB

    ()

    4-12

    DEFBIT

    4-12

    DEFBYTE

    4-12

    DEFINT

    ( )

    4-12

    DEFWORD

    4-12

    DEFLCDCHAR

    4-12

    DELAY

    4-12

    DIM .. AS ..

    4-13

    DISABLE

    4-13

    DO ..

    4-13

    .. ELSE ..

    4-20

    .. ELSEIF..

    ,

    4-20

    ENABLE

    4-13

    END

    ()

    4-14

    .. END IF

    4-20

    ERASE

    ( )

    4-14

    EXIT ..

    4-14

    ForTo/Downto...Step...

    4-14

    GET

    ()

    4-30

    GOSUB

    4-16

    GOTO

    4-16

    .. LOOP

    4-13

    .. NEXT

    4-14

    IDLE

    4-14

    IF ..

    4-20

    INPUT

    4-22

    INPUTHEX

    4-22

    INPUTBIN

    ( )

    4-22

    INKEY

    4-23

    LCD

    4-23

    LCDHEX

    4-23

    LOAD TIMER0, 1 2

    ,

    4-25

    MODE0, 1, 2, 3, 4, 5

    ,

    4-13

    NOSAVE

    4-29

    ON [Interrupt]

    4-30

    ON x GOTO (GOSUB)

    () x

    4-30

    OPEN ..

    ()

    4-30

    POWERDOWN

    4-32

    PRINT

    4-32

    PRINTHEX

    .

    4-32

    PRINTBIN

    4-33

    PRIORITY ON(OFF) ..

    ()

    4-33

    PUT

    ()

    4-30

    READEEPROM

    EEPROM AT89S8252

    4-11

    READ

    DATA

    4-33

    REM

    4-34

    RESET

    ( 0) .

    4-34

    RESTORE

    DATA READ

    4-33

    RETURN

    4-34

    ROTATE ..

    ( LEFT / RIGHT)

    4-34

    SELECT CASE x

    x

    4-6

    SET

    ( 1) .

    4-34

    SERVO

    4-34

    SHIFTIN

    4-35

    SHIFTOUT

    4-35

    SOUND

    4-35

    SPIIN

    SPI

    4-36

    SPIOUT

    SPI

    4-36

    START TIMER0, 1, 2

    0, 1 2

    4-37

    STOP TIMER0, 1, 2

    0, 1 2

    4-37

    STOP

    4-37

    SUB

    4-38

    SWAP

    4-39

    .. THEN ..

    4-20

    .. UNTIL ..

    4-12

    WAIT

    4-12

    WAITKEY

    4-23

    WAITMS

    4-12

    WHILE .. WEND

    , ,

    4-39

    WRITEEEPROM

    EEPROM AT89S8252

    4-11

    Bascom-8051

    X AND Y

    :

    4-5

    X OR Y

    :

    4-5

    NOT Y

    4-5

    X XOR Y

    :

    4-5

    Bascom-8051

    ABS(x)

    4-5

    ASC(s)

    4-5

    BDC(x)

    -

    4-5

    HR(x)

    ( )

    4-6

    CPEEK(x)

    4-10

    DECR x

    4-12

    INCR x

    4-12

    FUSING()

    . .

    4-15

    GETRC()

    RC-

    4-15

    GETRC5

    ()

    4-16

    HEX()

    4-16

    HEXVAL()

    4-17

    HIGH()

    4-17

    HIGHW()

    4-17

    INP()

    4-21

    INSTR ()

    4-21

    LCASE()

    ( )

    4-23

    LEFT()

    ,

    4-25

    LOW()

    4-17

    LOWW()

    4-17

    LEN()

    4-25

    LOOKUP

    4-26

    LOOKUPSTR

    4-26

    MAKEBCD(x)

    -

    4-26

    MAKEDEC(x)

    -

    4-26

    MAKEINT()

    4-26

    MAX()

    4-27

    MID()

    ( )

    4-25

    MIN()

    4-27

    MOD

    4-27

    OUT

    4-21

    PEEK()

    ,

    4-32

    POKE

    4-32

    RIGHT()

    ,

    4-25

    SPACE()

    ,

    4-36

    STRING()

    ,

    4-36

    STR()

    4-16,4-37

    VAL()

    4-17,4-39

    VARPTR()

    , .

    4-39

    UCASE()

    ( . )

    4-23

    Bascom-8051

    1WREAD

    4-4

    1WRESET

    4-4

    1WWRITE

    4-4

    Bascom-8051 I2C

    I2CRECEIVE

    I2C

    4-18

    I2CSEND

    I2C

    4-18

    I2CSTART

    I2C

    4-19

    I2CSTOP

    - I2C

    4-19

    I2CRBYTE

    I2C-

    4-19

    I2CWBYTE

    I2C-

    4-19

    Bascom-8051 Microwire

    MWINIT

    Microwire

    4-28

    MWREAD

    Microwire

    4-28

    MWWRITE

    Microwire

    4-28

    MWWOPCODE

    Microwire.

    4-28

    Bascom-8051

    SHIFTIN

    4-35

    SHIFTOUT

    4-35

    SPIIN

    SPI

    4-36

    SPIOUT

    SPI

    4-36

    Bascom-8051 (UART)

    CLOSE ..

    ()

    4-31

    GET

    ()

    4-31

    INKEY

    4-23

    INPUT

    4-22

    INPUTHEX

    4-22

    INPUTBIN

    ( )

    4-22

    OPEN ..

    ()

    4-31

    PRINT

    4-32

    PRINTHEX

    .

    4-32

    PRINTBIN

    4-32

    PUT

    ()

    4-31

    WAITKEY

    4-23

    Bascom-8051

    .. BLINK

    ( )

    4-24

    CURSOR ..

    ( - ON / - OFF)

    4-24

    DISPLAY ..

    ( - ON / - OFF)

    4-24

    HOME ..

    4-24

    ..FOURTH .. F

    4-24

    FOURTHLINE

    4-24

    LCD ..

    4-23

    LCDHEX ..

    4-23

    LOCATE y , x

    y, x

    4-24

    ..LOWER .. L

    4-24

    LOWERLINE

    4-24

    .. NOBLINK

    ( )

    4-24

    SHIFTLCD ..

    ( - LEFT / RIGHT)

    4-24

    SHIFTCURSOR ..

    ( LEFT / RIGHT)

    4-24

    .. THIRD .. T

    4-24

    THIRDLINE

    4-24

    .. UPPER .. U

    4-24

    UPPERLINE

    4-24

    Bascom-8051

    BITWAIT bit Set(Reset)

    ( )

    4-5

    DEBOUNCE port ..

    4-7,4-11

    IF bit = 0 THEN ..

    0

    4-20

    IF bit = 1 THEN ..

    1

    4-20

    SET bit

    1.

    4-34

    RESET bit

    0.

    4-34

    Bascom-8051, 1.0.0.19

    $MAP

    4-2

    $NONAN

    NAN 0.0

    4-3

    $REGFILE=[]

    4-3

    LCASE()

    ( )

    4-23

    UCASE()

    ( . )

    4-23

    Bascom-8051, 1.0.0.19

    CONST

    4-9

    SHIFTIN

    4-35

    FUSING()

    . .

    4-15

    Bascom-8051, 1.0.0.20

    $EXTERNAL

    4-1

    $LIB

    4-2

    $NOLCDINIT

    LCD

    4-3

    CONFIG Microwire

    Microwire

    4-8

    HIGHW()

    4-17

    INSTR ()

    4-21

    LOWW()

    4-17

    MIN(), MAX()

    4-26

    MWINIT

    Microwire

    4-28

    MWREAD

    Microwire

    4-28

    MWWRITE

    Microwire

    4-28

    MWWOPCODE

    Microwire.

    4-28

    Bascom-8051, 1.0.0.20

    INPUT

    TIMEOUT

    4-22

    IF X=A

    4-20

    ON .. , PRIORITY ..

    PCA (8051FA),

    4-29,4-33

    , Bascom-8051, 2.04

    $BGF=[]

    BMP

    *

    $NONULL = x

    4-3

    $TIMEOUT

    TIMEOUT

    4-4

    CONFIG GRAPGLCD

    CONFIG PRINT

    RS-485

    4-9

    PSET

    REPLACE

    4-35

    RND()

    4-31

    SHOWPIC

    SPC()

    Print Lcd

    4-37

    Bascom-8051, 2.04

    IF THEN ELSE

    4-20

    OPEN INVERTED

    UART

    4-32

    NOCS = x

    NOCS CONFIG SPI

    4-9

    NOINT

    4-37

    TIMEOUT = x

    4-23

    CLS TEXT, CLS GRAPH

    CLS BOTH

    * -

    1

    1-6

    =============================================================================

    K_MGBC_P01.DOC

  • ===================================== Bascom-8051 ==

    $SERIALINPUT = 4-4 $SERIALOUTPUT = 4-4 $SERIALINPUT2LCD - ( . LCD) 4-4 $SIM ( ) 4-4

    , Bascom-8051 ( )

    1WIRE : 4-4,4-7 COUNTER0, 1 2 0, 1 2 4-10 EEPROM AT89S8252 4-11 DEBOUNCE 19,4-7 I2C: I2CDELAY I2C 4-7 LCD, LCDBUS, LCDPIN LCD-: (), () 4-7 I2C: SDA, SCL I2C : 4-8 Microwire: DIN, DOUT, CS, CLOCK

    4-8,4-28

    SERVOS 4-8,4-34 SPI: DIN, DOUT, CS, CLK SPI : 4-8 TIMER0, 1 2 0, 1 2 4-8,4-9 WATCHDOG AT89S8252 4-9 INT0 0 4-13,4-33 INT1 0 4-13,4-33 PCA 851FA 4-13,4-33 SERIAL 4-13,4-33 TIMER0 0 4-13,4-33 TIMER1 1 4-13,4-33 TIMER2 2 4-13,4-33 SOUND 4-35 RC ( RC-) 4-15 RC5 RC5 4-16

    Bascom-8051

    .. ALIAS .. 4-5 BITWAIT bit Set(Reset) ( ) 4-5 BREAK 4-5 CALL () 4-6 CASE n : n 4-6 CASE IS : , , 4-6 CLOSE .. () 4-30 CONFIG 4-7 ... 4-9 CONST 4-9 DATA 4-10 DEBOUNCE 4-11 DECLARE SUB () 4-12 DEFBIT 4-12 DEFBYTE 4-12 DEFINT ( ) 4-12 DEFWORD 4-12 DEFLCDCHAR 4-12 DELAY 4-12 DIM .. AS .. 4-13 DISABLE 4-13 DO .. 4-13 .. ELSE .. 4-20 .. ELSEIF.. ,

    4-20

    ENABLE 4-13 END () 4-14 .. END IF 4-20

    =============================================================================

    1-2

  • ===================================== Bascom-8051 ==

    ERASE ( ) 4-14 EXIT .. 4-14 ForTo/Downto...Step... 4-14 GET () 4-30 GOSUB 4-16 GOTO 4-16 .. LOOP 4-13 .. NEXT 4-14 IDLE 4-14 IF .. 4-20 INPUT 4-22 INPUTHEX 4-22 INPUTBIN ( ) 4-22 INKEY 4-23 LCD 4-23 LCDHEX 4-23 LOAD TIMER0, 1 2 , 4-25 MODE0, 1, 2, 3, 4, 5 , 4-13 NOSAVE 4-29 ON [Interrupt] 4-30 ON x GOTO (GOSUB) () x 4-30 OPEN .. () 4-30 POWERDOWN 4-32 PRINT 4-32 PRINTHEX . 4-32 PRINTBIN 4-33 PRIORITY ON(OFF) .. () 4-33 PUT () 4-30 READEEPROM EEPROM AT89S8252 4-11 READ DATA 4-33 REM 4-34 RESET ( 0) . 4-34 RESTORE DATA READ 4-33 RETURN 4-34 ROTATE .. ( LEFT / RIGHT) 4-34 SELECT CASE x x 4-6 SET ( 1) . 4-34 SERVO 4-34 SHIFTIN 4-35 SHIFTOUT 4-35 SOUND 4-35 SPIIN SPI 4-36 SPIOUT SPI 4-36 START TIMER0, 1, 2 0, 1 2 4-37 STOP TIMER0, 1, 2 0, 1 2 4-37 STOP 4-37 SUB 4-38 SWAP 4-39 .. THEN .. 4-20 .. UNTIL .. 4-12 WAIT 4-12 WAITKEY 4-23 WAITMS 4-12 WHILE .. WEND , , 4-39 WRITEEEPROM EEPROM AT89S8252 4-11

    Bascom-8051

    X AND Y : 4-5 X OR Y : 4-5

    =============================================================================

    1-3

  • ===================================== Bascom-8051 ==

    NOT Y 4-5 X XOR Y : 4-5

    Bascom-8051

    ABS(x) 4-5 ASC(s) 4-5 BDC(x) - 4-5 HR(x) ( ) 4-6 CPEEK(x) 4-10 DECR x 4-12 INCR x 4-12 FUSING() . . 4-15 GETRC() RC- 4-15 GETRC5 () 4-16 HEX() 4-16 HEXVAL() 4-17 HIGH() 4-17 HIGHW() 4-17 INP() 4-21 INSTR () 4-21 LCASE() ( ) 4-23 LEFT() , 4-25 LOW() 4-17 LOWW() 4-17 LEN() 4-25 LOOKUP 4-26 LOOKUPSTR 4-26 MAKEBCD(x) - 4-26 MAKEDEC(x) - 4-26 MAKEINT() 4-26 MAX() 4-27 MID() ( ) 4-25 MIN() 4-27 MOD 4-27 OUT 4-21 PEEK() , 4-32 POKE 4-32 RIGHT() , 4-25 SPACE() , 4-36 STRING() , 4-36 STR() 4-16,4-37 VAL() 4-17,4-39 VARPTR() , . 4-39 UCASE() ( . ) 4-23

    Bascom-8051

    1WREAD 4-4 1WRESET 4-4 1WWRITE 4-4

    Bascom-8051 I2C

    I2CRECEIVE I2C 4-18 I2CSEND I2C 4-18 I2CSTART I2C 4-19 I2CSTOP - I2C 4-19 I2CRBYTE I2C- 4-19 I2CWBYTE I2C- 4-19

    =============================================================================

    1-4

  • ===================================== Bascom-8051 ==

    Bascom-8051 Microwire

    MWINIT Microwire 4-28 MWREAD Microwire 4-28 MWWRITE Microwire 4-28 MWWOPCODE Microwire. 4-28

    Bascom-8051

    SHIFTIN 4-35 SHIFTOUT 4-35 SPIIN SPI 4-36 SPIOUT SPI 4-36

    Bascom-8051 (UART)

    CLOSE .. () 4-31 GET () 4-31 INKEY 4-23 INPUT 4-22 INPUTHEX 4-22 INPUTBIN ( ) 4-22 OPEN .. () 4-31 PRINT 4-32 PRINTHEX . 4-32 PRINTBIN 4-32 PUT () 4-31 WAITKEY 4-23

    Bascom-8051

    .. BLINK ( ) 4-24 CURSOR .. ( - ON / - OFF) 4-24 DISPLAY .. ( - ON / - OFF) 4-24 HOME .. 4-24 ..FOURTH .. F 4-24 FOURTHLINE 4-24 LCD .. 4-23 LCDHEX .. 4-23 LOCATE y , x y, x 4-24 ..LOWER .. L 4-24 LOWERLINE 4-24 .. NOBLINK ( ) 4-24 SHIFTLCD .. ( - LEFT / RIGHT) 4-24 SHIFTCURSOR .. ( LEFT / RIGHT) 4-24 .. THIRD .. T 4-24 THIRDLINE 4-24 .. UPPER .. U 4-24 UPPERLINE 4-24

    Bascom-8051

    BITWAIT bit Set(Reset) ( ) 4-5 DEBOUNCE port .. 4-7,4-11 IF bit = 0 THEN .. 0 4-20 IF bit = 1 THEN .. 1 4-20 SET bit 1. 4-34 RESET bit 0. 4-34

    =============================================================================

    1-5

  • ===================================== Bascom-8051 ==

    Bascom-8051, 1.0.0.19

    $MAP 4-2 $NONAN NAN 0.0 4-3 $REGFILE=[] 4-3 LCASE() ( ) 4-23 UCASE() ( . ) 4-23

    Bascom-8051, 1.0.0.19

    CONST 4-9 SHIFTIN 4-35 FUSING() . . 4-15

    Bascom-8051, 1.0.0.20

    $EXTERNAL 4-1 $LIB 4-2 $NOLCDINIT LCD 4-3 CONFIG Microwire Microwire 4-8 HIGHW() 4-17 INSTR () 4-21 LOWW() 4-17 MIN(), MAX() 4-26 MWINIT Microwire 4-28 MWREAD Microwire 4-28 MWWRITE Microwire 4-28 MWWOPCODE Microwire. 4-28

    Bascom-8051, 1.0.0.20

    INPUT TIMEOUT 4-22 IF X=A 4-20 ON .. , PRIORITY .. PCA (8051FA), 4-29,4-33

    , Bascom-8051, 2.04

    $BGF=[] BMP * $NONULL = x 4-3 $TIMEOUT TIMEOUT 4-4 CONFIG GRAPGLCD CONFIG PRINT RS-485 4-9 PSET REPLACE 4-35 RND() 4-31 SHOWPIC SPC() Print Lcd 4-37

    Bascom-8051, 2.04

    IF THEN ELSE 4-20 OPEN INVERTED UART 4-32 NOCS = x NOCS CONFIG SPI 4-9 NOINT 4-37 TIMEOUT = x 4-23 CLS TEXT, CLS GRAPH CLS BOTH

    * -

    =============================================================================

    1-6

  • ===================================== Bascom-8051 ==

    2.

    Bascom-8051 - 8051.

    Bascom-8051 , . Bascom , - ( , , EEPROM), ( ), - . , .. . Bascom, Windows (ANSI).

    Bascom : - ,

    ; , ; , , -, -

    ( ), , . ( );

    8051. ;

    () . , Bascom 25-50 %

    . 30-50 %, 10-25 %. , Bascom . , , , . , Bascom (60-80 % ). Bascom - . , .

    , 8051. 8051 8052. , , , .

    , Bascom, . , . , . , , .

    HEX-. ( ) .

    Bascom-8051 . , , ( 1- ). , , . , ( 100 %, ).

    2. 1. 5-7 %.

    =============================================================================

    2-1

    ===================================== Bascom-8051 ==

    2.

    Bascom-8051 - 8051. Bascom-8051 , . Bascom , - ( , , EEPROM), ( ), - . , .. . Bascom, Windows (ANSI).

    Bascom :

    - , ;

    , ;

    , , -, - ( ), , . ( );

    8051. ;

    () .

    , Bascom 25-50 % . 30-50 %, 10-25 %. , Bascom . , , , . , Bascom (60-80 % ). Bascom - . , .

    , 8051. 8051 8052. , , , .

    , Bascom, . , . , . , , .

    HEX-. ( ) .

    Bascom-8051 . , , ( 1- ). , , . , ( 100 %, ).

    2. 1. 5-7 %.

    1

    2-1

    =============================================================================

    K_MGBC_P02.DOC

  • ===================================== Bascom-8051 ==

    3.

    Bascom

    09, @, #, $, %, !, &, (, ), {, }, _, AZ ( az )

    * + , - . / : ; < = > \

    (blank or space) (Single quotation mark apostrophe) (asterisks) (plus sign) - (comma) (minus sign) (period or decimal point) (slash or division symbol) - , (colon) - (double quotation mark) (semicolon) - , - (less than) (equal sign) - (greater than) (backslash) -

    Bit

    Byte Word

    Integer

    Long

    String

    Single

    Array

    , ( 0 255). 0 1. , , 8-, 16- 32- . , , , , ( ). 8 - 0 255 (00 FFh) 16 - 0 65535 (0000 FFFFh) 16 ( ) 0 32767 (0000 7FFFh) 1 32768 (FFFFh 8000h) 32 ( ) 0 2147483647 (00000000 - 7FFFFFFFh) 1 2147483648 (FFFFFFFFh 80000000h) 00h, . 254 . 00h . IEEE. 127 +127. 24 . , , 1, .. . 31 30________23 22______________________________0 . . , , - (index). () . , (integer word). 65535 . , , Ar Ar(1) Ar(10). ! .

    , , . , . . , , , , , . , . .

    1, 23, 4567 , . . &HA, &HFEE, &H001023F0 &H. &B0001, &10111101- &B 12.34 . . -123, -10000 . . Single,

    =============================================================================

    3-1

    ===================================== Bascom-8051 ==

    3.

    Bascom

    09, @, #, $, %, !, &, (, ), {, }, _, AZ ( az )

    *

    +

    ,

    -

    .

    /

    :

    ;

    \

    (blank or space)

    (Single quotation mark apostrophe)

    (asterisks)

    (plus sign)

    - (comma)

    (minus sign)

    (period or decimal point)

    (slash or division symbol)

    - , (colon)

    - (double quotation mark)

    (semicolon) - ,

    - (less than)

    (equal sign)

    - (greater than)

    (backslash) -

    Bit

    Byte

    Word

    Integer

    Long

    String

    Single

    Array

    , ( 0 255). 0 1. , , 8-, 16- 32- . , , , , ( ).

    8 - 0 255 (00 FFh)

    16 - 0 65535 (0000 FFFFh)

    16 ( ) 0 32767 (0000 7FFFh) 1 32768 (FFFFh 8000h)

    32 ( ) 0 2147483647 (00000000 - 7FFFFFFFh) 1 2147483648 (FFFFFFFFh 80000000h)

    00h, . 254 . 00h .

    IEEE. 127 +127. 24 . , , 1, .. .

    31 30________23 22______________________________0

    .

    . , , - (index). () . , (integer word). 65535 . , , Ar Ar(1) Ar(10). ! .

    , , . , . . , , , , , . , . .

    1, 23, 4567 , . . &HA, &HFEE, &H001023F0 &H. &B0001, &10111101- &B 12.34 . . -123, -10000 . . Single, . , , , Data, . 0 , 1 , 2 , 3 , 4 , 20, &HFF, &B00101111 - , , . 1000% , 2000% , &hAD1C%. - (word integer). 1000& , 20000000& - (long). 1111! , 10000000! - (single).

    ,

    , Bascom, 32 . A Z, _ ( ). . (SFR) , . SFR type.dat, . .

    =

    : ( ), ( ), ( ). = ! !

    =

    =

    ( ):

    (Equality) - X = Y. (Const, Bit, Byte, Word, Integer, Long, String, Single)

    (Inequality) - X Y. (Const, Bit, Byte, Word, Integer, Long, String, Single)

    (Less than) - X < Y. (Const, Byte, Word, Integer, Long, Single)

    (Greater than) - X > Y. (Const, Byte, Word, Integer, Long, Single)

    (Less than or equal) - X = Y. (Const, Byte, Word, Integer, Long, Single)

    NOT

    AND

    OR

    XOR

    ( onst, Bit, Byte, Word, Integer, Long):

    (complement): 0 = NOT 1, 1 = NOT 0

    (Conjunction) : 1 = 1 AND 1, 0 = 1 AND 0 = 0 AND 0

    (Disjunction): 1 = 1 OR 1 = 0 OR 0, 0 = 0 OR 0

    (Exclusive or): 1 = 1 XOR 0, 0 = 0 XOR 0 = 1 XOR 1

    +

    -

    *

    / \

    ( ):

    . (Const, Byte, Word, Integer, Long, String*, Single).

    . (Const, Byte, Word, Integer, Long, Single)

    . (Const, Byte, Word, Integer, Long, Single)

    (Const, Byte, Word, Integer, Long, Single)

    * - .

    1

    3-2

    =============================================================================

    K_MGBC_P03.DOC

  • ===================================== Bascom-8051 ==

    . , , , Data, . 0 , 1 , 2 , 3 , 4 , 20, &HFF, &B00101111 - , , . 1000% , 2000% , &hAD1C%. - (word integer). 1000& , 20000000& - (long). 1111! , 10000000! - (single).

    ,

    , Bascom, 32 . A Z, _ ( ). . (SFR) , . SFR type.dat, . .

    =

    : ( ), ( ), ( ). = ! !

    = < >

    =

    ( ): (Equality) - X = Y. (Const, Bit, Byte, Word, Integer, Long, String, Single) (Inequality) - X Y. (Const, Bit, Byte, Word, Integer, Long, String, Single) (Less than) - X < Y. (Const, Byte, Word, Integer, Long, Single) (Greater than) - X > Y. (Const, Byte, Word, Integer, Long, Single) (Less than or equal) - X = Y. (Const, Byte, Word, Integer, Long, Single)

    NOT AND OR XOR

    ( onst, Bit, Byte, Word, Integer, Long): (complement): 0 = NOT 1, 1 = NOT 0 (Conjunction) : 1 = 1 AND 1, 0 = 1 AND 0 = 0 AND 0 (Disjunction): 1 = 1 OR 1 = 0 OR 0, 0 = 0 OR 0 (Exclusive or): 1 = 1 XOR 0, 0 = 0 XOR 0 = 1 XOR 1

    + - *

    / \

    ( ): . (Const, Byte, Word, Integer, Long, String*, Single). . (Const, Byte, Word, Integer, Long, Single) . (Const, Byte, Word, Integer, Long, Single) (Const, Byte, Word, Integer, Long, Single) * - .

    =============================================================================

    3-2

  • ===================================== Bascom-8051 ==

    4. , Bascom-8051

    $ASM - $END ASM : ,

    . $ASM $END ASM. : $asm Mer:

    Mov r0,#{C} ;address of c Mov a,#1 Mov @r0,a ;store 1 into var c $end Asm .

    $BAUD, $CRYSTAL :

    $BAUD (UART). PRINT, INPUT . () $CRYSTAL ( ). ! PRINT INPUT, - , (. ).

    : $BAUD = var1 ; $CRYSTAL = var2 var1, var2 , ( ).

    : $Baud = 2400 $Crystal = 12000000 12 MHz crystal Config Timer2 = Timer , Gate = Internal , Mode = 2 Timer2 Scon = &h52 : Rcap2h = &hff : Rcap2l = &h64 : Start Timer2 '* Timer1 Config Timer1 = Timer , Gate = Internal , Mode = 2 Timer1 Scon = &h52 : Pcon = &H80 : Th1 = &he6 : Start Timer1 '* '* - , ' Print Input, . '

    $DEFAULT XRAM :

    . - , IRAM

    : $default Xram Dim X As byte XRAM Dim Y As Integer XRAM Dim Z As IRAM Integer IRAM

    $EXTERNAL : ,

    . , . , .

    : $EXTERNAL myrout [, other] myrout . : $LIB "mylib.lib"

    $EXTERNAL _dec76 $INCLUDE : ASCII () .

    , BASCOM. : $INCLUDE : $include [c:\bascom\]123.bas [ ]

    =============================================================================

    4-1

    ===================================== Bascom-8051 ==

    4. , Bascom-8051

    $ASM - $END ASM

    :

    , . $ASM $END ASM.

    :

    $asm Mer:

    Mov r0,#{C} ;address of c

    Mov a,#1

    Mov @r0,a ;store 1 into var c

    $end Asm

    .

    $BAUD, $CRYSTAL

    :

    $BAUD (UART). PRINT, INPUT . () $CRYSTAL ( ). ! PRINT INPUT, - , (. ).

    :

    $BAUD = var1 ; $CRYSTAL = var2 var1, var2 , ( ).

    :

    $Baud = 2400 $Crystal = 12000000 12 MHz crystal

    Config Timer2 = Timer , Gate = Internal , Mode = 2 Timer2

    Scon = &h52 : Rcap2h = &hff : Rcap2l = &h64 : Start Timer2 '*

    Timer1

    Config Timer1 = Timer , Gate = Internal , Mode = 2 Timer1

    Scon = &h52 : Pcon = &H80 : Th1 = &he6 : Start Timer1 '*

    '* - ,

    ' Print Input, .

    '

    $DEFAULT XRAM

    :

    . - , IRAM

    :

    $default Xram

    Dim X As byte XRAM

    Dim Y As Integer XRAM

    Dim Z As IRAM Integer IRAM

    $EXTERNAL

    :

    , . , . , .

    :

    $EXTERNAL myrout [, other] myrout .

    :

    $LIB "mylib.lib"

    $EXTERNAL _dec76

    $INCLUDE

    :

    ASCII () . , BASCOM.

    :

    $INCLUDE

    :

    $include [c:\bascom\]123.bas [ ]

    $IRAMSTART

    :

    . $NOINIT $NOSP, .

    :

    $IRAMSTART = constant Constant - (0-255)

    :

    $NOINIT

    $NOSP

    $IRAMSTART = &H60

    SP = 80

    $LARGE

    :

    ( 2 ). Lcall Ljmp.

    :

    $LARGE 148,

    $LCD

    :

    8- , D0D7 ( LCDBUS = 4 4- D4D7). E Wr(P3.6). RS A0 (, ALE). RW , ..

    :

    $LCD = [&H] address address - 16-.

    :

    $LCD = &ha000 a000h,a001h

    LCD Hello world

    $LIB

    :

    , ( /LIB), . .

    :

    $LIB myfile.lib myfile.lib .

    :

    $LIB "mylib.lib"

    $EXTERNAL _dec76

    $MAP

    :

    . .

    :

    $MAP

    A = A F

    Print "Hello"

    Print "Test"

    :

    Code map

    -----------------------------------------------------------

    Line Address(hex)

    -----------------------------------------------------------

    2 152

    3 169

    5 180

    $NOBREAK

    :

    Break, , .

    :

    $Nobreak

    $NOINIT

    :

    , Options - Compiler Bascom. , , ( Iramstart). ( Config) $Noinit.

    :

    $NOINIT

    $IRAMSTART = &H60

    $NOLCDINIT

    :

    , LCD.

    :

    $NOLCDINIT

    $NONAN

    :

    NAN 0.0 , ( , .. ).

    :

    $NONAN ' NAN

    $NONULL

    :

    $NONULL = 0 - ( ). $NONULL = -1 - .

    :

    $NONULL = -1 '

    DATA

    $NONULL = 0$ '

    DATA

    $NOSP

    :

    . (SP). , 07h.

    :

    $NOSP

    SP = 80

    $OBJ

    :

    :

    $OBJ obj obj -

    :

    $obj D29122 SETB P1.1, RET

    $RAMSIZE

    :

    :

    $RAMSIZE = [&H] size size - .

    :

    $Ramsize = &h4000 16

    $RAMSTART

    :

    .

    :

    $RAMSTART = [&H] adress adress - .

    :

    $Ramstart = &h1000 1000h

    $REGFILE

    :

    . . . ! .

    :

    $REGFILE = [File]

    :

    '

    $REFILE = "8052.DAT"

    $ROMSTART

    :

    . ORG, . $Romstart, , ! .

    :

    $ROMSTART = [&H] adress adress - .

    :

    $Romstart = &h8000 8000h

    $SERIALINPUT

    :

    INPUT .

    :

    $SERIALINPUT = label label - , .

    :

    $Serialinput = Myinput !myinput:

    ;

    Mov A , Sbuf ;. Acc Sbuf

    Ret

    $SERIALOUTPUT

    :

    PRINT

    :

    $SERIALOUTPUT = label label - , .

    :

    $SERIALOUTPUT = Myioutput . !myoutput: ; Mov Sbuf , A ;. Acc Sbuf

    Ret

    $SERIALINPUT2LCD

    :

    LCD-, .

    :

    $SERIALINPUT2LCD

    :

    $SERIALINPUT2LCD

    $SIM

    :

    , ( WAIT, WAITMS, DELAY), .

    :

    $SIM

    :

    $SIM

    $TIMEOUT

    :

    , TIMEOUT INPUT, INPUTHEX

    :

    $TIMEOUT

    :

    $TIMEOUT TIMEOUT

    1WRESET, 1WREAD, 1WWRITE

    :

    Dallas Semiconductors, 1- (1Wire-devices).

    1WRESET 1w-.

    1WWRITE var1 var1 .

    :

    1WRESET

    1WWRITE var1

    var2 = 1WREAD()

    var2 = 1WREAD() - var2 .

    var1 - Byte, Integer, Word, Long, Constant. var2 - Byte, Integer, Word, Long.

    :

    --------------------------------------------------

    1wreset, 1wwrite and 1wread()

    4K7 DS2401 +5 V

    --------------------------------------------------

    Config 1wire = P1.1

    Dim Ar(8) As Byte , A As Byte , I As Byte

    1wreset

    Print Err ,

    1wwrite &H33

    For I = 1 To 8

    Ar(I) = 1wread() 8 Ar

    Next

    For I = 1 To 8

    Printhex Ar(I);

    Next

    Print

    End

    ABS(x)

    :

    . .

    :

    var = ABS(var2) var - Byte, Integer, Word, Long. var2 Integer, Long.

    :

    Dim a as Integer, c as Integer , e as Single

    a = -1000 : c = Abs(a) c=1000

    e = -1000

    $asm

    Anl {e + 3} , &H7f Single e=1000

    $end Asm

    ALIAS

    :

    . .

    :

    Newvar ALIAS Oldvar Oldvar - . Newvar - .

    :

    In_dir Alias P1.1

    Ri Alias Scon.0

    ASC(s)

    :

    ASCII ( ). .

    :

    var = ASC(string) var - Byte, Integer, Word, Long. String - String, Constant.

    :

    Dim a as byte, s as String * 10

    s = ABC : a = Asc(s)

    Print a 65 (41h) -

    AND, OR, XOR, NOT

    :

    : AND- (1 And 0 = 0, 1 And 1 = 1), OR- (1 Or 0 =1, 0 Or 0 =0), XOR- (1 Xor 1 = 0, 0 Xor 1 = 1, 0 Xor 0 = 0), NOT

    :

    Var3 = var AND var2, var3 = var OR var2 Var3 = var XOR var2, var3 = var NOT var2 var, var2 Bit, Byte, Integer, Word, Long Constant var3 Bit, Byte, Integer, Word, Long

    :

    Dim d As Byte , e As Byte Dim c As Const &B10011001

    e = 12 : e = Not e : d = e Or c : d = d And &b00001000

    BDC()

    :

    () - .

    :

    Bcd(var) Var - ( Byte, Word, Integer, Long Constant).

    :

    Print arb 10h, 21h, 40h 16, 33, 64

    Print Bcd(arb) 10h, 21h, 40h 10, 21, 40

    BITWAIT

    :

    ,

    :

    BITWAIT x SET/RESET x -

    :

    Bitwaim a , Set , . a

    Bitwait P1.7, Reset , 0

    BREAK

    :

    . Break A5h, .

    :

    Break

    Bit, Byte, Integer, Long, Word, Single, String()

    :

    , BASCOM. Dim.

    :

    Dim B1 As Bit , A As Byte , C As Integer

    Dim D As Word , E As Long , G As Single

    Dim S As string * 16 16

    Dim F(10) As Byte

    CALL

    :

    . 10 . ( ).

    :

    CALL Test [(var1, var-n)] Test var1 , var-n

    Var1, var-n - . Test- .

    :

    Dim A as byte, B1 as byte

    Declare Sub Test(b1 as byte)

    A = 65

    Call test (a) / test A

    Test a

    End

    SUB Test(b1 as byte)

    LCD b1

    Lowerline : LCD BCD(b1)

    End SUB

    CASE, SELECT CASE, CASE IS ..

    :

    :

    SELECT CASE var -

    CASE test1 : statements - : var=test1?

    [CASE test2 : statements ] - : var=test2?

    CASE ELSE : statements ?

    END SELECT

    Var Byte. Test1, Test2 , . Statements (). Bascom (IS >=) - (TO). , .

    Dim b2 as byte

    SELECT CASE b2 '

    CASE 2 : PRINT 2

    CASE 4 : PRINT 4

    CASE IS >=5 : PRINT >5 '

    ' IS.

    CASE 6 TO 19 : PRINT 6-19 ' . TO

    CASE ELSE : PRINT Other '

    END SELECT '

    END

    CHR()

    :

    Byte, Integer/Word . , , . , .

    :

    PRINT CHR(var) : LCD CHR(var) S = CHR(var) : S = Date= + CHR(var) var Byte, Integer/Word . s - .

    :

    Dim a as byte, s as string * 10

    a = 110 : LCD a 110

    LCDHEX a 6E

    LCD Chr(a) n

    LCD Bdc(a) 6> -

    S = Byte= : S = S + Chr(a) !!!

    Print S Byte=n

    End

    CLS

    :

    LCD

    :

    CLS

    LCD Hello

    CONFIG 1WIRE

    :

    , 1-

    :

    CONFIG 1WIRE = pin pin - .

    :

    Config 1WIRE = P1.0 P1.0 is used for the 1-wire bus

    1WRESET reset the bus

    CONFIG DEBOUNCE

    :

    DEBOUNCE. , , 25 .

    :

    CONFIG DEBOUNCE = time time , ( 12 ).

    :

    Config Debounce = 50 50 mS

    CONFIG I2CDELAY

    :

    SCL I2C. 5 .

    :

    CONFIG I2CDELAY = 0 1 0 ( 400 12 ). 1 - 5 ( - 100 ).

    :

    CONFIG I2CDELAY = 0

    CONFIG LCD, CONFIG LCDBUS, CONFIG LCDPIN

    :

    CONFIG LCD

    CONFIG LCDBUS ( $LCD). 4- D4-D7 . MOVX A,@DPTR. CONFIG LCDPIN ( ).

    :

    CONFIG LCD = LCDtype LCDtype ( * ). : 40 * 4, 16 * 1, 16 * 2, 16 * 4, 16 * 4, 20 * 2 20 * 4. - 16 * 2.

    CONFIG LCDBUS = 4 - 4- .

    CONFIG LCDBUS = 8 - 8- ( ).

    CONFIG LCDPIN=PIN , DB4=pin, DB5=pin, DB6=pin, DB7=pin, E=pin, RS=pin ( ).

    pin - . , . CONFIG LCDPIN, .

    1:

    '! , _ ():

    CONFIG LCDPIN = PIN , DB4 = P1.1 , DB5 = P1.2 , DB6 = P1.3, _

    DB7 = P1.4 , E=P1.5 , RS=P1.6

    . . RW-Gnd

    CONFIG LCD = 40 * 4 40 , 4

    2:

    . . RW-Gnd. RS-A0. E-. Wr(P3.6)

    $LCD = &ha000 A000h A001h

    CONFIG LCDBUS = 8 8- (. D0-D7 . P0.0-Po.7)

    CONFIG MICROWIRE

    :

    4- Microwire

    :

    Config Microwire=Pin, Cs=pin, Din=pin, Dout=pin, Clock=pin, Al=7

    Pin - , Microwire. , . DIN . DOUT - . CS - . CLK . AL . (bytes or words). Org .

    Chip ( )

    93C46

    93C56

    93C57

    93C66

    Data bits ( )

    8

    16

    8

    16

    8

    16

    8

    16

    AL ()

    7

    6

    9

    8

    8

    7

    9

    8

    :

    '! , _ ():

    Config Microwire = Pin , Cs = P1.1 , Din = P1.2 , Dout = P1.4 , _ Clock = P1.5 , Al = 7

    CONFIG PRINT, PRINTMODE

    :

    Print RS-485,

    :

    Config Print = Pin Pin - , .

    Printmode = Set (Reset) (1 0 ),

    :

    Config Print = P1.7 : Printmode = Reset

    CONFIG SERVOS

    :

    :

    Config SERVOS=number, SERVO1=pin, SERVO2=pin, SERVO3=pin

    Number . 16

    servo 1, servo2, servo 2, servo3 , .

    0 .

    :

    Config SERVOS = 3, SERVO1 = P1.1 , SERVO2 = P1.2 , SERVO3 = P1.4

    CONFIG SDA, CONFIG SCL

    :

    , 2- I2C.

    :

    CONFIG SCL = pin pin - . CONFIG SDA = pin

    :

    CONFIG SDA = P1.7 : CONFIG SCL = P1.6 P1.7 SDA, P1.6 is the SDA

    CONFIG SPI

    :

    , 4- SPI. Bascom , . SPI AT89S8252 .

    :

    CONFIG SPI = SOFT, DIN = Pin, DOUT = Pin , CS = Pin, CLK = Pin , Nocs=1

    Pin - SPI. , . DIN . DOUT - . CS - . CLK . Nocs = 0 CS . Nocs = 1 CS.

    :

    Config SPI=SOFT , DIN=P1.0 , DOUT=P1.1 , CS=P1.2 , CLK=P1.3

    SPIOUT var , 1 send 1 byte

    CONFIG TIMER0, TIMER1

    :

    0 1:

    CONFIG TIMERx = COUNTER C/Tx=1

    CONFIG TIMERx = TIMER (F/12) C/Tx=0

    GATE = INTERNAL - GATEx=0

    GATE = EXTERNAL - GATEx=1

    GATE = MODE=0,1,2 3 ( 8051)

    :

    Config Timer0=Counter, Mode=1, Gate=Internal

    Counter0 = 0 (Tl0 Th0)

    Start Counte

    CONFIG TIMER2

    :

    2:

    CONFIG TIMER2 = COUNTER C/T2=1

    CONFIG TIMER2 = TIMER (F/12 F/2) C/T2=0

    ]GATE = INTERNAL - EXEN2=0

    GATE = EXTERNAL - EXEN2=1

    MODE = 0 - CP/RL2=0

    MODE = 1 - CP/RL2=1

    MODE = 2 - RCLK=1 TCLK=1

    MODE = 3 - . RCLK=1 TCLK=0

    MODE = 4 - . RCLK=0 TCLK=1

    MODE = 5 - T2OE=1

    DIRECTION=UP - () DCEN=1

    DIRECTION=DOWN - () DCEN=0

    :

    CONFIG TIMER2=COUNTER , GATE=INTERNAL , MODE=0 CONFIG TIMER2=COUNTER , GATE=INTERNAL , MODE=0 , DIRECTION=UP

    CONFIG TIMER2 = COUNTER , GATE = INTERNAL , MODE = 1 CONFIG TIMER2=TIMER , GATE=INTERNAL , MODE=2 CONFIG TIMER2=TIMER , GATE=INTERNAL , MODE=3 . . CONFIG TIMER2=TIMER , GATE=INTERNAL , MODE=4 .. CONFIG TIMER2=TIMER , MODE=5

    CONFIG WATCHDOG

    :

    AT89S8252

    :

    Config Watchdog = Time Time : 16 , 32, 64 , 128 , 256 , 512 , 1024 2048.

    :

    Config Watchdog = 1024 1024

    CONST

    :

    (). (). DATA. , . , .

    :

    DIM Symbol AS Const Value Symbol - . Value -

    Const Symbol = Value

    :

    Dim Ar As Const 5 Ar = 5

    Dim Br As Const &B1001 Br = 9

    Dim Cr As Const &hab00 Cr = AB00H

    ' ( .1.0.0.19)

    Const Cbyte = &HF

    Const Cint = -1000

    Const Csingle = 1.1

    Const Cstring = "test"

    COUNTERx

    :

    . ( TRx=0), ( TRx=1).

    :

    COUNTERX = var var = COUNTERX

    Var - byte, Integer/Word variable ( ). CounterX - COUNTER0 , COUNTER1 COUNTER2. ounterX = 0 .. 0 255 2 (8- ) 65535 1 (16-).

    :

    Dim A As Byte , C As Integer

    Config Timer0 = Counter , Gate = Internal , Mode = 1

    Counter0 = 0

    Start Counter0

    Do

    A = Inkey

    C = Counter0

    Print C

    Loop Until A = 27 escape

    End

    :

    COUNTER0 = 1000

    :

    Clr TCON.4

    Mov tl0,#232

    Mov th0,#3

    Setb TCON.4

    CPEEK()

    :

    . .. 8051 , CPOKE, , .

    :

    var = CPEEK( address ) Var - (), . Address - ( Word Integer).

    :

    Dim I As Integer , B1 As Byte

    For I = 0 To 127

    B1 = peek(i)

    Printhex B1 ; ;

    Next

    DATA

    :

    :

    DATA var , var2, var3[, varn] var , var2, var3[, varn] - . , Bascom. Integer Word - %. Long - &. - !. . .

    :

    tab_byte: byte data

    Data 0 , 1 , 2 , 20 , &hFF , &b000101010

    _tab_word: integer

    data Data 100% , 200% , 32345% , &ha0df , &b0001010001010101 _tab_long: long data

    Data 1000& , 22222222& , &h125690bc

    _tab_sing: single data

    Data 1000! , 2000! , 3000! , 4000! , 5000!

    _tab_string: string data

    Data 0123456789 , $35 and new format of the string data

    _tab_mix: mix of constant types on one line DATA TEST , 5 , 1000% , -1& , 1.1!

    DATA EEPROM: WRITEEEPROM , READEEPROM

    :

    AT89S8252 EEPROM 2 . : WRITEEEPROM - READEEPROM .

    :

    WRITEEEPROM var [, address ] READEEPROM var [, address ] Var - BASCOM. Address - EEPROM 0 2047. , . , , () . , 000 . , , , , , EEPROM.

    :

    Dim S As String * 15 , S2 As String * 10

    S = Hello : S2 = test

    Dim L As Long

    L = 12345678 Writeeeprom S : Writeeeprom S2 Writeeeprom L

    S = : S2 = : L = 0

    Readeeprom L : Print L

    Readeeprom S : Print S

    Readeeprom S2 : Print S2

    End

    DEBOUNCE

    :

    , , . . CONFIG DEBOUNCE = ms.

    :

    DEBOUNCE Px.y , state , label [ , SUB]

    Px.y . state = 0 state = 1 . Label - (GOTO) , SUB. , () . , , .

    :

    CONFIG DEBOUNCE = 30 30mS

    Do Debounce P1.1 , 1 , Pr . Debounce P1.0 , 0 , Pr , SUB

    ^-----

    ^-----

    ^---------- ( 0)

    ^---------------- ,

    Loop

    End

    Pr: Print P1.0 was/is low : Return

    DECLARE SUB

    :

    ( ). . . , . , , . DIM . .

    :

    DECLARE SUB Test[(var as type, var1 as type)] Test .

    Var, var1 - . 10.

    - Bit, Byte, Word/Integer, Long String.

    :

    Dim a As Byte, b1 As Byte, c As Byte

    Declare Sub Test(a As Byte)

    A = 1 : b1 = 2: c = 3

    Print a ; b1 ; c

    Call Test(b1) Test b1

    Print a ;b1 ; c

    End

    Sub Test(a as byte)

    A = b1 ; b1 = c ; c = a + b1

    End Sub

    DECR, INCR

    :

    . , : var = var - 1. .

    :

    DECR var INCR var Var : Byte, Integer, Word, Long, Single.

    :

    Dim A As Byte A = 5

    Decr A : Print A 4

    Incr A : Print A 5

    DefBit, DefByte, Defint, DefWord

    :

    . Dim, , .

    :

    DEFBIT b1 b1 .

    DEFBYTE c C

    DEFINT I I Integer ( ).

    DEFWORD x X

    :

    Defbit b : DefInt c (integer)

    Set b1set bit to 1

    C = 10let c = 10

    DEFLCDCHAR

    :

    0 7 8 15 ( ). , , CLS. Chr().

    :

    DEFLCDCHAR char,r1,r2,r3,r4,r5,r6,r7,r8 Char - () (0-7). r1-r8- . Char: Byte, Integer, Word, Long, Constant. r1-r8: Constant.

    :

    Deflcdchar 0,1,2,3,4,5,6,7,8 .

    Cls

    Lcd Chr(0)

    End

    DELAY, WAIT , WAITMS

    :

    . ( 12 ): Delay - 100 . WAIT - . WAITMS -

    :

    DELAY , WAIT time ( ) , WAITMS time ( ) time , .

    :

    WAIT 3 3

    WAITMS 200 200

    DIM

    :

    :

    DIM var AS [XRAM/IRAM] type

    Var - , . , ar(n), n . Type - . : Bit, Byte, Word, Integer, Long, Single String

    XRAM , .

    IRAM ( ).

    , :

    Dim s As XRAM String * n.

    n+1 . , , . , , , ( ) . . , .. , , .

    :

    Dim B1 As Bit : 0 1

    Dim A As Byte 0 255

    Dim C As Integer integer -32768 - +32767

    Dim D As String * 10 10

    Dim ar(10) As Byte 10

    Dim E As Const 5

    Dim F As Const &B1001B1

    B1 = 1 : Set B1 (assign bits)

    A = 12 : A = A + 1

    C = -12 : C = C + 100

    Waitms E 5

    Print F : Print B1

    End

    DISABLE, ENABLE

    :

    . , IE

    :

    DISABLE interrupt , ENABLE interrupt Interrupt - : INTERRUPTS, INT0, INT1, SERIAL, TIMER0, TIMER1, TIMER2 PCA.

    :

    ENABLE INTERRUPTS enable the setting of interrupts

    ENABLE TIMER0 enable TIMER0

    DISABLE SERIAL disables the serial interrupt.

    DISABLE INTERRUPTS disable all interrupts

    DO .. LOOP

    :

    . DO LOOP , . , UNTIL. , GOTO EXIT IF END IF.

    :

    DO

    LOOP [ UNTIL expression ]

    Expression - . , EXIT DO GOTO.

    :

    Dim A As Byte

    DO

    A = A + 1 : PRINT A

    LOOP UNTIL A = 10 A = 10

    Print A , 10

    END

    :

    . Stop. JMP .

    :

    END

    ERASE

    :

    . . () , . , . , .. , (). , , , . , , .

    :

    ERASE var Var -

    :

    Dim a1 as byte,a2 as byte,a3 as byte,a4 as byte,

    F(var3,var4)

    ERASE a3 : ERASE a4 .

    Dim a5 as Byte

    vars a1 and a2

    EXIT

    :

    : FOR..NEXT, DO..LOOP, WHILE ..WEND SUB..END SUB. - . EXIT GOTO , , .

    :

    : EXIT [FOR] [DO] [WHILE] [SUB]

    :

    DO DO..LOOP

    A = A + 1

    IF A = 100 THEN a = 100?

    EXIT DO DO..LOOP

    END IF IF..THEN

    LOOP DO

    FOR .. TO/DOWNTO .. STEP, NEXT

    :

    . FORNEXT .

    :

    FOR var = start TO/DOWNTO end [STEP value]

    NEXT

    Var - . Start - . End - . Value - . . , TO DOWNTO. NEXT - - . , , STEP . : 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.

    1:

    y = 10 y=10

    FOR a = 1 TO 10 10

    FOR x = y DOWNTO 1

    PRINT x ; a

    NEXT x ( )

    NEXT a ( )

    2:

    Dim S as Single

    For S = 1 To 2 Step 0.1

    Print S

    Next

    END

    FUSING()

    :

    . . , . ! Fusing , . .

    :

    var = Fusing( source, mask)

    var , .

    Source single, .

    Mask . , ###.##, . (). # . , &. , # 0 ( )

    :

    $large

    Dim X As Single , Y As Single , Result As Single

    Dim I As Integer, Buf As String * 16

    Input Enter x , X

    Input Enter y , Y

    Print X+Y= ; : Result = X + Y : Print Result

    Print X-Y= ; : Result = X - Y : Print Result

    Print X/Y= ; : Result = X / Y : Print Result

    Print X*Y= ; : Result = X * Y : Print Result

    Buf = Fusing(result , ##.##)

    Buf = Fusing(result , 000.##) c .

    Buf = Fusing(result , ##.&&)

    Buf = Fusing(result , 000.&&)

    Print Buf

    GETRC()

    :

    Getrc ( ) RC-, . 0, . RC- . . ( ) 1. . : , .

    :

    Var = GETRC( pin )

    Var (), . pin - .

    :

    ' GETRC() 0 -

    Config Timer0 = Timer , Gate = Internal , Mode = 1

    $baud = 9600 '

    $crystal = 11059200

    Dim W As Word '

    Do '

    W = Getrc(p1.7) '

    Print W : Wait 1 ' ,

    Loop ' C=10nF : 250 10K9, 198 - 9K02 '182 - 8K04, 166 - 7K, 154 - 6K02, 138 - 5K04, 122 - 4K04 '106 - 3K06, 86 - 2K16, 54 - 1K00 - . '

    GETRC5

    :

    , - RC5. INT0 P3.2. INT0 ( ).

    :

    Getrc5(Subaddress, command) Subaddress , . ommand .

    :

    Dim New As Bit Dim Command As Byte , Subaddress As Byte

    clr tcon.0

    On Int0 Receiverc5 Nosave Nosave - !!!

    Enable Int0 E

    nable Interrupts

    Do

    If New = 1 Then '1

    Print Command ; " " ; Subaddress

    New = 0 '

    End If

    Loop

    Receiverc5: ' Int0

    Getrc5(Subaddress, command) : New = 1 ' - .

    Return

    GOSUB

    :

    .

    :

    GOSUB label label - ()

    :

    GOSUB Routine

    Routine:

    x = x + 2

    RETURN

    GOTO

    :

    .

    :

    GOTO label label - () .

    :

    GOTO Exec

    Exec:

    X = x + 2

    HEX(), STR()

    :

    Hex() . Str() , .

    :

    S = Hex( var )

    Var : Byte, Integer, Word. S - .

    S = Str(x)

    X : Byte, Integer, Word, Long, Single.

    :

    Dim a as byte, s As string * 10

    a = &h6d : s = Hex(a)

    Print s 6D

    a = 123 : s = Str(a) : Print s 123

    HEXVAL(), VAL()

    :

    :

    VAL(x) , ;

    HEXVAL(x) , . , .

    :

    var = HEXVAL(x) Var Byte, Integer, Word, Long. x .

    var = VAL(s). Var Byte, Integer, Word, Long, Single. S .

    :

    Dim Ar As Integer, S As String * 10

    S = 000A : Ar = Hexval(s) : Print Ar 10

    S = 123 : Ar = Val(s) : Print Ar 123

    HIGH(), LOW()

    :

    . .

    :

    Var = HIGH(s)

    Var = LOW(s)

    Var . S .

    :

    Dim I As Integer , Z As Byte

    I = &H1001

    Z = High(I) 16

    HIGHW(), LOWW()

    :

    .

    HIHGW

    LOWW -

    :

    Var = LOWW( s )

    var = HIGHW( s )

    var , S.

    S

    :

    Dim L As Integer , Z As Long

    L = &H101001

    Z = LowW(L) Z = 1001h

    Z = HighW(L) Z = 0010h

    I2C: I2CRECEIVE, I2CSEND

    :

    I2CRECEIVE - I2C.

    I2CSEND - I2C.

    , , . : I2CSTART, I2CSTOP, I2CRBYTE, I2CWBYTE.

    :

    I2CRECEIVE slave, var

    I2CRECEIVE slave, var ,b2W, b2R

    2CSEND slave, var

    I2CSEND slave, var , bytes

    Slave - I2C byte, Word/Integer .

    Var - , I2C.

    b2W - . !

    b2R - . !

    Bytes - .

    :

    x = 0 reset variable

    slave = &H40 PCF8574

    I2CRECEIVE slave, x

    PRINT x

    ------------

    Dim buf(10) as String 10-

    buf(1) = 1 : buf(2) = 2 2 .

    I2CRECEIVE slave , buf() , 2 , 1 .

    Print buf(1) ,

    ------------

    x = 5

    I2CSEND slave , x 5

    ------------

    Dim ax(10) As Byte

    For a = 1 to 10

    ax(a) = a 1 10

    Next

    Bytes = 10 ? - . BASCOM

    I2CSEND slave , ax() , bytes 10

    I2C: I2START, I2CSTOP, I2CRBYTE, I2CWBYTE

    :

    I2CSTART - .

    I2CSTOP - - .

    I2CRBYTE - I2C-.

    I2CWBYTE I2C-.

    :

    I2CSTART

    I2CSTOP

    I2CRBYTE var, 8/9

    I2CWBYTE val

    Var - I2C-. 8/9 - . 8 - (ACK), , .. . 9 - (NACK), . Val - - . , .

    :

    Dim Addressw As Const 160 24Cxx

    Dim Wadr As Word

    Dim Fld As Single

    / 4-. AT2401A,AT24c02 - AT24c16

    Rds_24c: $asm mov A , {wadr + 1} ; , c

    Rl A ;

    Orl A , #{Addressw} ;

    Mov B , A

    $end Asm

    I2cstart

    I2cwbyte B

    $asm

    mov A , {wadr + 0}

    $end Asm

    I2cwbyte Acc EEPROM

    Set B.0

    I2cstart

    I2cwbyte B

    I2crbyte Acc , 8 1- ACK (8)

    $asm

    mov {Fld + 0} , A

    $end Asm

    I2crbyte Acc , 8 2-

    $asm

    mov {Fld + 1} , A

    $end Asm

    I2crbyte Acc , 8 3-

    $asm

    mov {Fld + 2} , A

    $end Asm

    I2crbyte Acc , 9 NOACK (9)

    $asm

    mov {Fld + 3} , A

    $end Asm

    I2cstop

    Return

    IDLE

    :

    (IDLE), .

    :

    IDLE

    :

    Mc: ,

    Do

    Idle

    If Bit_a=1 Then : ?

    Bit_a=0 : Goto Wba

    End If

    Loop

    Wba:

    Set P1.1 ,

    Goto Mc

    IF, ELSE , ELSEIF, END IF

    :

    , . , -, - !!!

    :

    1- . Action 1 expression 1:

    IF expression 1 THEN

    Action 1

    END IF

    2- . Action 1 expression 1 Action 2 :

    IF expression 1 THEN

    Action 1

    ELSE

    Action 2

    END IF

    3- . Action 1, expression 1, Action 2 , expression 2, Action 3, . :

    IF expression 1 THEN

    Action 1

    ELSEIF expression 2 THEN

    Action 2

    ELSE

    Action 3

    END IF

    1:

    DIM A AS INTEGER

    A = 10

    IF A = 10 THEN

    PRINT This part is executed.

    ELSE PRINT This will never be executed. END IF IF A = 10 THEN PRINT New in BASCOM IF A = 10 THEN GOTO LABEL1 ELSE PRINT A10 LABEL1: REM IF THEN IF A.15 = 1 THEN

    PRINT BIT 15 IS SET

    END IF

    REM

    IF THEN IF A.15 = 0 THEN PRINT BIT 15=0

    ELSE PRINT BIT 15=1

    END IF

    2:

    Dim X As Integer

    If X = "A" Then 'when X = 65 the test will pass

    3:

    If X = 10 Then Goto M1 Else Goto M2

    INP(), OUT

    :

    , - . .

    :

    var = INP(address)

    OUT address, value

    Var - . Address - . - . Value - , .

    :

    Dim a As Byte

    a = INP(&H8000) 8000h

    PRINT a

    OUT &H8000,1 1 8000h

    :

    Mov A,#1

    Mov dptr,#h8000

    Movx @dptr,a

    INSTR ()

    :

    , (). .

    :

    var = INSTR( start , string , substr )

    var = INSTR( string , substr )

    Var , byte 0, . Start , , . , 1.

    String , .The string to search.

    Substr , .

    :

    Dim S As String * 10 , Z as String * 5

    Dim bP as Byte

    s = "This is a test" ',

    Z = "is"

    BP = Instr(s,z) : Print bP ' 6

    bP = Instr(4,s,z) : Print bP ' 3

    End

    INPUT, INPUTHEX, INPUTBIN

    :

    INPUT , RS-232. ( , ) ( ). BASCOM INPUTHEX HEX-, ( ). (0dh).

    INPUTBIN . , , .. ( , ).

    :

    INPUT [prompt] , var [, varn] [NOECHO] [ TIMEOUT = xx]

    INPUTHEX [prompt] , var [, varn] [NOECHO] [ TIMEOUT = xx]

    INPUTBIN var1 [,varn] Prompt - (, ).

    Var, varn - ( ), .

    NOECHO - , ( ).

    TIMEOUT , . 2.01 $TIMEOUT

    XX 2^31, . 100 ( 12 ). .

    :

    $baud = 1200

    $crystal = 12000000

    $timeout -!

    Dim V As Byte , B1 As Byte

    Dim C As Integer , D As Byte

    Dim S As String * 15 XRAM

    Input V , V

    Input B1

    Inputhex Enter hex number (4 bytes) , C .

    Print C

    Inputhex Enter hex byte (2 bytes) , D 2 .

    Print D Input More variables , C , D

    Print C ; ; D

    Input C Noecho

    Input Enter your name , S

    Print Hello ; S

    Input S Noecho Timeout = 10000

    400

    Print S

    INKEY, WAITKEY

    :

    INKEY ASCII . , .

    WAITKEY , .

    :

    var = INKEY

    var = WAITKEY

    var Byte, Integer, Word, Long String. ,

    :

    DO

    A = INKEY

    IF A > 0 THEN ? (>0)

    PRINT A ,

    END IF

    LOOP

    A = Waitkey

    LCASE(), UCASE()

    :

    ( ). . .

    :

    dest = LCASE(source) dest = UCASE(source)

    dest -. Source -.

    :

    Dim S as string * 12 , Z as string * 12

    S = asDFv 'assign string

    Z = LCASE(s) 'convert to lowercase

    Print Z 'asdfv

    Z = UCASE(s) 'convert to upper case

    Print Z 'ASDFV

    LCD, LCDHEX

    :

    LCD.

    LCD PRINT. . :

    Acc = $h33 3 ACC

    Call Write_lcd

    LCDHEX ( 00 - FF).

    :

    LCD var

    LCDHEX var

    Var . : Byte, Integer, Word, Long, Single, Constant. , ; :

    LCD a ; b1 ; constant

    :

    Ar = 65 : Locate 2 , 1

    Lcd * : Lcd = ; Ar * = A

    Ar = &HBF : Clr : LCDHEX Ar BF

    LCD: CURSOR, DISPLAY, HOME, LOCATE, SHIFTLCD, SHIFTCURSOR

    FOURTHLINE, LOWERLINE, THIRDLINE, UPPERLINE

    FOURTH, LOWER, THIRD, UPPER

    :

    LCD:

    CURSOR ON - ( )

    CURSOR OFF - ( )

    CURSOR BLINK - ( )

    CURSOR NOBLINK - ( )

    HOME -

    HOME LOWER HOME L

    HOME UPPER HOME U

    HOME THIRD HOME T

    HOME FOURTH HOME F

    LOCATE y,x y, x

    SHIFTCURSOR LEFT

    SHIFTCURSOR RIGHT

    LOWERLINE ( )

    UPPERLINE ( )

    THIRDLINE ( )

    FOURTHLINE ( )

    (OFF) (NOBLINK).

    LCD:

    DISPLAY ON ( )

    DISPLAY OFF ( )

    SHIFTLCD LEFT ( )

    SHIFTLCD RIGHT

    :

    CURSOR ON/OFF, CURSOR BLINK/NOBLINK

    CURSOR ON/OFF, DISPLAY ON/OFF , LOCATE y , x

    X - (1-64*)

    Y - (1-4*)

    *

    :

    Dim a As Byte

    Cursor Blink

    a = 255 : Lcd a : Cursor Off

    Display Off : Wait 1 : DISPLAY On 1

    Locate 1 , 10 : LCD Hello 10

    Cls : LCD Very long text

    Shiftlcd Left : Wait 1 : Shiftlcd Right : LCD a : Lowerline CD a : Upperline

    LEFT(), MID(), RIGHT()

    :

    () : LEFT() - ( c). MID() - ( ). . RIGHT - ( ). , , , .. . , , .

    :

    var = Left(var1 , n )

    var = RIGHT(var1 ,st )

    var = MID(var1 ,st [,l] )

    MID(var ,st [, l] ) = var1

    var . Var1 . N . n : Byte, Integer, Word, Long, Constant. St ( . ). L .

    :

    Dim s As XRAM String * 15, z As XRAM String * 15

    S = ABCDEFG : z = Left(s,5) : Print z ABCDE

    S = ABCDEFG : z = Right(s,2) : Print z FG

    S = ABCDEFG : z = Mid(s,2,3): Print z BCD

    Z = 12345 : Mid(s,2,2) = z : Print s A12DEFG

    LEN()

    :

    . , , , . .

    :

    Var = LEN( string ) Var , . String , .

    :

    Dim S As String * 12 , A As Byte 12

    S = test : A = Len(s) : Print A 4

    LOAD TIMER

    :

    , ( , ).

    :

    LOAD TIMER , value

    TIMER : TIMER0, TIMER1 TIMER2.

    Value . ( ON TIMERx MODE 2), . 1 255 TIMER0, TIMER1 1 65535 TIMER2. LOAD : TLx = THx = (256 - value) ! ! RCAP2L , RCAP2H = (65536 - value) ( ) COUNTERx .

    :

    LOAD TIMER0, 100 100

    :

    Mov tl0,#h9C

    Mov th0,#h9C

    LOAD TIMER2, 1000

    :

    Mov RCAP2L,#24

    Mov RCAP2H,#252

    LOOKUP, LOOKUPSTR

    :

    LOOKUP - , .

    LOOKUPSTR - , ( ).

    :

    Var = LOOKUP(value , label)

    Var = LOOKUPSTR(value , label)

    Var , . var: Byte, Integer, Word, Long, Single

    Value , ( ). () = 0 ( ). ! ! - . BASCOM ! LOOKUPSTR 256, . : value: Byte, Integer, Word, Long, Constant.

    Label ().

    :

    DIM b1 As Byte , I as Integer

    b1 = Lookup(1, dta) b1=2 - 0-!!!

    I = Lookup(0,DTA2) I=1000

    Dim s as string, idx as Byte

    Idx = 0 : s = LookupStr(idx,Sdata)

    Print s S=This

    DTA:

    Data 1,2,3,4,5

    DTA2: integer data

    Data 1000% , 2000%

    Sdata:

    Data This , is , a test

    MAKEBCD(x)

    :

    ( , ) - .

    :

    Var1 = Makebdc(var2) Var1 - , - ( Byte, Word, Integer, Long Constant). Var2 - , .

    :

    Arb = Makebdc(arb) 10h, 21h, 40h . 16h, 33h, 64h

    MAKEDEC(x)

    :

    , - , .

    :

    Var1 = Makedec(var2) var1 - , . Var2 , ( Byte, Word Integer).

    :

    Arb = Makedec(arb) 10h, 21h, 40h . 0ah, 15h, 2ah

    MAKEINT()

    :

    ( word integer).

    :

    Varn = MAKEINT(LSB , MSB) Varn . LSB - , . MSB - , . : varn = (256 * MSB) + LSB

    :

    Dim a As Integer , I As Integer

    a = 2 : I = Makeint(a , 1) I = (1 * 256) + 2 = 258

    MAX(), MIN()

    :

    MAX() .

    MIN() . .

    :

    var = MAX( ar(1) )

    var = MIN( ar(1) )

    var , . ar(1) ( ).

    :

    Dim ar(10) As Byte

    Dim Bp as Byte

    For Bp = 1 to 10

    ar(Bp) = Bp

    Next

    Bp = Max(ar(1)) : Print Bp ' 10

    Bp = Min(ar(1)) : Print Bp ' 1

    End

    MOD

    :

    :

    ret = var1 MOD var2 ret - , . var1 - - (variable to divide). var2 - - (The divisor). Byte, Word, Integer, Long.

    :

    a = 10 MOD 310/3

    PRINT aa=1

    MWINIT, MWREAD, MWWRITE, MWWOPCODE

    :

    MWINIT - , Microwire .

    MWREAD - Microwire.

    MWWRITE Microwire.

    MWWOPCODE Microwire.

    :

    MWINIT

    MWREAD variable , opcode , address, bytes

    MWWRITE variable , opcode , address, bytes

    MWWOPCODE opcode , bits

    Variable , . Opcode . . MWWOPCODE (. ). Address . Byte Word.. Bytes . (1 2). Bits ( ).

    1:

    Dim Dta As Byte, Adr As Byte

    ' EEPROM 93C46 (Org = 0), (AL=7)

    Config Microwire=Pin, Cs=P1.1, Din=P1.2, Dout= P1.4, Clock=P1.5, Al=7

    Mwinit '

    ' EEPROM

    ' , :

    - (1), (00) (11) + (, 0)

    Mwwopcode &B1001100000 , 10

    Dta = 10 : Adr = 8 '

    Mwwopcode &B1001000000 , 10 '

    ' Dta EEPROM , Adr

    ' : 1 + (01). : (1)

    Mwwrite Dta , &B101 , Adr , 1

    ' Micriwire ' 2 5 , .. '

    Waitms 10 : Dta = 0

    '

    ' : 1 + (10). : (1)

    Mwread Dta , &B110 , Adr , 1

    '

    '- (1), (00) (00) + (, 0)

    Mwwopcode &B1000000000 , 10

    End

    2:

    16-

    Dim Dta As Word, Adr As Byte

    ' EEPROM 93C46 (Org = 1), (AL=6)

    Config Microwire=Pin, Cs=P1.1, Din=P1.2, Dout= P1.4, Clock=P1.5, Al=6

    Mwinit '

    ' EEPROM

    ' , :

    Mwwopcode &B100110000 , 9 '

    Dta = &h1000 : Adr = 8 '

    Mwwopcode &B100100000 , 9 '

    ' Dta EEPROM , Adr

    ' : 1 + (01). : (2)

    Mwwrite Dta , &B101 , Adr , 2

    Waitms 10 : Dta = 0

    ' : 1 + (10). : (2)

    Mwread Dta , &B110 , Adr , 2 '

    '

    Mwwopcode &B100000000 , 9

    End

    NOSAVE

    :

    NOSAVE ON Interrupt . , .. BASCOM 0 11h, Acc, B, PSW, DPL DPH ( 21 ). .. , BASCOM ( ). , , , . : ) , , , Push Pop; ) .

    :

    Config Timer0 = Timer, Gate = Internal, Mode = 1 : Start Timer0

    On Timer0 Timer_0_int Nosave

    Enable Interrupts

    Enable Timer0 0

    ------------------------------------------

    0

    Timer_0_int:

    Counter0 = &HD8FD D8fdh - . 10

    $asm

    Push Psw ;

    Push Acc ;

    Jb {B_ctmp} , Intt2 ; ?

    Mov A , {R_ot} ; -

    Cjne A , #{Cit} , Intt1 ; ?

    Sjmp Intte ; -

    Intt1:

    Inc A ; - .

    Cjne A , #{cit} , Intt3 ;

    Setb {b_ot} ; -

    Sjmp Intt3

    Intt2:

    Mov A , {R_ot} ;

    Jz Intte ; ?

    Dec A ; -

    Intt3:

    Mov {R_ot} , A ; - .

    Intte:

    Pop Acc ;

    Pop Psw

    Reti

    $end Asm

    ON Interrupt

    :

    , . ON Interrupt - ( ) , .

    :

    ON interrupt label [NOSAVE]

    Interrupt - : INT0, INT1, SERIAL, TIMER0 ,TIMER1, TIMER2 PCA. . .

    Label - , , .

    NOSAVE - . . RETURN, .. RETI . INT0 INT1 , :

    SET TCON.0 INT0 .

    RESET TCON.0 INT0 .

    SET TCON.2 INT1 .

    RESET TCON.2 INT1 .

    :

    ENABLE INTERRUPTS

    ENABLE INT0 INT0

    ON INT0 Label2 label2

    SET TCON.0 INT0

    DO

    LOOP

    END

    Label2: PRINT An hardware interrupt occurred! RETURN

    ON Value

    :

    , . : (GOTO) (GOSUB). , .

    :

    ON var [GOTO] [GOSUB] label1 [, label2] Var - SFR, P1. Label1, label2 - , . .

    :

    X = 2

    ON x GOSUB lbl1, lbl2,lbl3 / lbl3

    X = 0

    ON x GOTO lbl4, lbl5 lbl4

    END

    Lbl1: PRINT lbl1 : RETURN

    Lbl2: PRINT lbl2 : RETURN

    lbl3: PRINT lbl3 : RETURN

    Lbl4: PRINT lbl4 : STOP

    Lbl5: PRINT lbl5 : STOP

    OPEN - CLOSE , GET, PUT

    :

    ()

    :

    OPEN device,[Inverted] for Mode As #channel

    CLOSE #channel

    Device - . : COM1 () COM2 ( 80517 80537 UART). , , COM3.0:9600 ( P3.0 9600 ).

    Mode - . BINARY (), INPUT ( ) OUTPUT ( ) COM1 COM2. INPUT OUTPUT. Inverted , .

    Channel - ( ). CLOSE #channel. PRINT, PRINTHEX, INPUT NPUTHEX. GET PUT ( 1- ) .

    GET #channel , var PUT #channel , var - . , , , .

    1:

    CONFIG BAUD = 9600

    OPEN COM1: FOR BINARY AS #1

    PRINT #1, Hello 1

    PRINT Hello

    CLOSE #1

    2:

    . !

    P3.0 COM3.0:(P )

    . 9600 baud

    COM3.0:9600

    OUTPUT

    INPUT

    PUT GET.

    PRINT .

    p3.0 p3.1,

    Dim A As Byte , S As String * 16 , I As Byte , Dum As Byte

    Open com3.1:9600 For Output As #1

    Open com3.0:9600 For Input As #2

    S = test this

    Dum = Len(s)

    For I = 1 To Dum

    A = Mid(s , I , 1)

    Put #1 , A com-

    Next

    Do

    Get #2 , A com-

    Put #1 , A

    Print A

    Loop

    Close #1

    Close #2

    End

    2:

    Open "com1.2:9600 , Inverted" For Input As #1 ' p1.2

    Print #1, Hello ' 1

    Close #1 '

    PEEK()

    :

    (), .

    :

    var = PEEK( address ) var - , . Address - 0 255.

    :

    DIM a As Byte

    a = Peek( 0 ) R0

    POKE

    :

    .

    :

    POKE address , value Address - . 0 255. Value - (0-255). POKE , , . , , BASCOM. .

    :

    POKE 127, 1 1 127

    POWERDOWN

    :

    . - INT0. (i87c51fa .). , . . , ( ). , .

    :

    P0 = 0 : P1 = 0 : P2 = 0 : P3 = 0 : POWERDOWN

    PRINT, PRINTHEX

    :

    (RS-232 port). PRINT - . ( - ). PRINTHEX - (HEX - ). . , , Options.

    :

    PRINT var ; constant

    PRINTHEX var

    Var - , . . , ( ; ) , . PRINTHEX : Byte, Word, Integer, Long. (, ). PRINT (, ).

    :

    Dim A As Byte , B1 As Byte , C As Integer

    A = 1

    Print print variable a= ; A

    Print

    Print Text to print.

    B1 = 10 : Printhex B1

    C = &HA000 : Printhex C HEX-

    Print C

    C = -32000

    Print C -32000!

    Printhex C 8300

    PRINTBIN

    :

    , , (0Dh, 0Ah). PRINTBIN PRINT CHR(var), , ( ).

    :

    PRINTBIN var [,varn] Var , . Varn - . . , ( , ), .

    :

    Dim a(10) as Byte, c as Byte

    For c = 1 To 10

    A() =

    Next

    PRINTBIN a(1)

    PRIORITY

    :

    . , . : INT0 - 1 ( ); TIMER0 - 2; INT1 - 3; TIMER1 - 4; PCA 5; SERIAL 6; TIMER2 7 ( ). , . ( ) , . , IP.

    :

    PRIORITY SET / RESET interrupt

    SET .

    RESET - () .

    Interrupt - , . : INT0, INT1, SERIAL, TIMER0, TIMER1 and TIMER2.

    :

    PRIORITY SET SERIAL . -

    :

    RESTORE READ , ( DATA). , RESTORE . READ , RESTORE. READ , .. . ( ) LOOKUP.

    :

    READ var

    var , . , .

    RESTORE label

    Label - DATA, READ.

    :

    Dim a As Byte, I As Integer

    Restore Dta1

    For a = 1 TO 3

    Read a : Print a

    Next

    Restore Dta2 : Read I : Print I : Read I : Print I

    End

    Dta1: Data 5, 10, 100

    Dta2: Data -1%, 1000% Integers % (Integer : 255)

    REM

    :

    . .

    ( ).

    REPLACE

    :

    :

    REPLACESET String , Old , New String . Old , . New , .

    :

    Dim S1 as String

    S1 = 123.456

    Replace S1 , . , ,

    Print S1 123,456

    RESET, SET

    :

    Reset ( 0) Set ( 1) . , -, - .

    :

    RESET bit , RESET var.x , SET bit , SET var.x Bit - . X (x=0-7), (x=0-15) (x=0-31). Var , . : Byte, Integer, Word Long.

    :

    Dim b1 as bit, b2 as byte, I as Integer

    RESET P1.3 3 1

    RESET b1

    RESET b2.0 0 b2

    RESET I.15 MS () I

    RETURN

    :

    ( RET) ( RETI). RET RETI. RETI Return, . , RETI. , , , RETURN.

    :

    RETURN

    :

    GOSUB Pr

    PRINT result -

    END

    Pr:

    result = 5 * y : result = result + 100 -

    RETURN

    RND()

    :

    :

    Var = RND(Lim) Var Word, .

    Lim ,

    :

    Dim Ar As Word

    Do

    Ar = Rnd(1000) : Print Br

    Loop

    ROTATE

    :

    :

    ROTATE var , LEFT/RIGHT [, Shifts] Var Byte, Integer/Word or Long. Shifts - , . , (carry) . .. ROTATE RLC RRC. , (carry) CLR C.

    :

    Dim a as Byte

    a = 128 : ROTATE a, LEFT , 2 : Print a 1

    ;

    Mov R7,#2 ;

    Mov R0,#h21 ;

    Mov a,@r0

    M1: Rlc a

    Djnz r7,M1

    Mov @r0,a

    SERVOx

    :

    , 100 . 20 , .. 50 .

    :

    ServoX = NN

    X 1 16. NN , .

    :

    Servo1 = 8 ' 800 uS

    Servo2 = 12 '1200 uS

    SHIFTIN. SHIFTOUT

    :

    :

    SHIFTIN pin , pclock , var , option [PRE}

    SHIFTOUT pin , pclock , var , option

    Pin - , .

    Pclock - , .

    Var .

    Option (). :

    0 - (0 - 1 - 0).

    1 - (1 - 0 - 1).

    2 - (0 - 1 - 0).

    3 - (1 - 0 - 1).

    SHIFTIN 4 7 , 0 3. . .

    PRE , ( 0 3).

    Byte, Word, Integer Long.

    :

    Dim Temp as byte , R_bd As Long

    B_data Alias P1.5 : B_clk Alias P1.3

    B_fqud Alias P1.4 : B_res Alias P1.7

    ---------------------

    Sload_9850:

    Set B_fqud : Reset B_fqud

    Set B_clk : Reset B_clk .

    Set B_fqud : Reset B_fqud .

    R_bd 3 (. , /\)

    Shiftout B_data , B_clk , R_bd , 3

    Temp = 0 : Shiftout B_data , B_clk , Temp , 3

    Set B_fqud : Reset B_fqud

    Return

    SOUND

    :

    . , - .

    :

    SOUND pin, duration, frequency [,NOINT]

    Pin - -.

    Duration - ( , ). : Byte, integer, word . 1 32768.

    Frequency , .

    NOINT . .

    :

    SOUND P1.1 , 10000, 10 BEEP

    SPACE(), STRING(), SPC()

    :

    Space() , .

    String() , .

    Spc() Print Lcd

    A = A = 11111 , , , , . .

    :

    var = SPACE(x) x - . . Var . x=0 255 .

    var = STRING(m,n) m . n ()

    SPC(x) x .

    :

    Dim s as XRAM String * 15, z as XRAM String * 15

    S = Space(5)

    S = String(5,65) A

    S = 123

    Print S ; Spc(3) ; S 123 123

    Lcd {; S ; Spc(2) ; } {123 }

    Acall _sStr_String ; ---- -----

    _sStr_String:

    Mov @r1 , a

    Inc r1

    Djnz r2 ,_sStr_String

    Clr a

    Mov @r1 , a

    Ret

    SPIIN, SPIOUT

    :

    SPI- () SPI- (). .

    :

    SPIIN var, bytes

    SPIOUT var , bytes

    Var - , .

    Bytes - .

    :

    Dim a(10) as Byte , X As Byte

    CONFIG SPI=SOFT , DIN=P1.0 , DOUT=P1.1 , CS=P1.2 , CLK=P1.3

    SPIIN a(1) , 4 4

    SPIOUT a(1) , 5 5

    SPIOUT X , 1

    START TIMER, STOP TIMER

    :

    (0, 1 2):

    Start Timer - TRx=1. Stop Timer TRx=0

    :

    START timer, STOP timer

    Timer TIMER0, TIMER1, TIMER2, COUNTER0 COUNTER1.

    :

    Dim Count As Byte , Gt As Byte

    Config Timer0 = Timer , Gate = Internal , Mode = 2

    On Timer0 Timer_0_int

    Load Timer0 , 100

    Enable Interrupts

    Enable Timer0

    Priority Set Timer0

    Start Timer0

    Count = 0

    Do

    Input Number , Gt

    Print You entered : ; Gt

    Loop Until Gt = 1 , ESC

    Stop Timer0

    End Rem Timer0

    Timer_0_int:

    Inc Count

    If Count = 2 Then

    Print Timer0 Interrupt occured

    Count = 0

    End If

    Return

    STOP

    :

    :

    PRINT var

    STOP

    STR()

    :

    , . , Val(). .

    :

    var = Str(x) var - , . X : Byte, Integer, Word, Long, Single.

    :

    Dim a as Byte, S as XRAM String * 10

    A = 123 : S = Str(a) : Print S

    S = S= + Str(a)

    SUB

    :

    , . Declare Sub . , . DIM. - , , . .

    :

    SUB Name[(var1)]

    , .

    END SUB

    Name - , . var1 - (, , ). , ( 10 ). ( , ). Return , .. . , - , EXIT SUB.

    :

    Declare Sub Test(a As Byte , B1 As Byte)

    Declare Sub Test2

    Declare Sub Test3(cl As Bit)

    Declare Sub Test4(x As Xram Byte)

    Declare Sub Test5(a as byte)

    Dim A As Byte , B1 As Byte , Cl As Bit .

    Dim X As Xram Byte , Xa(10) As Xram Byte

    B1 = 3 : Call Test2 sub

    Call Test(1 , B1) : Print B1 sub

    Call Test3(p1.1) .

    Xa(1) = 1 : Call

    Test4 Xa(1)

    Call test5 (a) A

    Test5 a A End

    . ,

    Sub Test(a As Byte , B1 As Byte) sub

    Print A ; ; B1 .

    B1 = 3

    End Sub

    Sub Test2 sub *

    Print No parameters

    End Sub

    Sub Test3(bl As Bit) bit

    Print Bl

    End Sub

    Sub Test4(x As Xram Byte)

    Print X

    End Sub

    SUB Test5(b1 as byte) , ,

    LCD b1 : LCD BCD(b1) - LCD

    End SUB

    SWAP

    :

    . !

    :

    SWAP var1, var2 var1 var2 - : bit, byte, integer/word

    :

    Dim a as integer,b1 as integer

    a = 1 : b1 = 2 assign two integers

    SWAP a , b1 swap them

    VAL()

    :

    , ().

    :

    var = Val( s )

    Var - : Byte, Integer, Word, Long, Single. S .

    :

    Dim a as byte, s As XRAM string * 10

    s = 123 : a = Val(s)

    Print a 123

    VARPTR()

    :

    , (0-255). ().

    :

    var = VARPTR( var2 )

    var , var2.

    var2 ,

    :

    Dim I As Integer , B1 As Byte

    B1 = Varptr(I)

    :

    Mov h23 , #h21 ;23h - b1, 21h - I

    WHILE .. WEND

    :

    , , . , () WEND. DO...LOOP UNTIL.

    :

    WHILE condition Condition - . WEND

    :

    a=0

    WHILE a

  • ===================================== Bascom-8051 ==

    $IRAMSTART : .

    $NOINIT $NOSP, .

    : $IRAMSTART = constant Constant - (0-255) : $NOINIT

    $NOSP $IRAMSTART = &H60 SP = 80

    $LARGE : ( 2 ).

    Lcall Ljmp. : $LARGE 148,

    $LCD : 8- ,

    D0D7 ( LCDBUS = 4 4- D4D7). E Wr(P3.6). RS A0 (, ALE). RW , ..

    : $LCD = [&H] address address - 16-. : $LCD = &ha000 a000h,a001h

    LCD Hello world $LIB : , ( /LIB),

    . .

    : $LIB myfile.lib myfile.lib . : $LIB "mylib.lib"

    $EXTERNAL _dec76 $MAP :

    . .

    : $MAP A = A F Print "Hello" Print "Test" : Code map ----------------------------------------------------------- Line Address(hex) ----------------------------------------------------------- 2 152 3 169 5 180

    $NOBREAK : Break,

    , . : $Nobreak

    =============================================================================

    4-2

  • ===================================== Bascom-8051 ==

    $NOINIT : ,

    Options - Compiler Bascom. , , ( Iramstart). ( Config) $Noinit.

    : $NOINIT $IRAMSTART = &H60

    $NOLCDINIT : , LCD. : $NOLCDINIT $NONAN : NAN 0.0 ,

    ( , .. ).

    : $NONAN ' NAN $NONULL : $NONULL = 0 - (

    ). $NONULL = -1 - .

    : $NONULL = -1 ' DATA $NONULL = 0$ ' DATA

    $NOSP : .

    (SP). , 07h.

    : $NOSP SP = 80

    $OBJ : : $OBJ obj obj - : $obj D29122 SETB P1.1, RET

    $RAMSIZE : : $RAMSIZE = [&H] size size - . : $Ramsize = &h4000 16

    $RAMSTART : . : $RAMSTART = [&H] adress adress - . : $Ramstart = &h1000 1000h

    $REGFILE : .

    . . ! .

    : $REGFILE = [File] : '

    $REFILE = "8052.DAT"

    =============================================================================

    4-3

  • ===================================== Bascom-8051 ==

    $ROMSTART : .

    ORG, . $Romstart, , ! .

    : $ROMSTART = [&H] adress adress - . : $Romstart = &h8000 8000h

    $SERIALINPUT : INPUT . : $SERIALINPUT = label label - ,

    . : $Serialinput = Myinput

    !myinput: ; Mov A , Sbuf ;. Acc Sbuf Ret

    $SERIALOUTPUT : PRINT : $SERIALOUTPUT = label label - ,

    . : $SERIALOUTPUT = Myioutput .

    !myoutput: ; Mov Sbuf , A ;. Acc Sbuf Ret

    $SERIALINPUT2LCD : LCD-, . : $SERIALINPUT2LCD : $SERIALINPUT2LCD

    $SIM : ,

    ( WAIT, WAITMS, DELAY), . : $SIM : $SIM

    $TIMEOUT : ,

    TIMEOUT INPUT, INPUTHEX : $TIMEOUT : $TIMEOUT TIMEOUT

    =============================================================================

    4-4

  • ===================================== Bascom-8051 ==

    1WRESET, 1WREAD, 1WWRITE : Dallas Semiconductors,

    1- (1Wire-devices). 1WRESET 1w-. 1WWRITE var1 var1 .

    : 1WRESET 1WWRITE var1 var2 = 1WREAD() var2 = 1WREAD() - var2 . var1 - Byte, Integer, Word, Long, Constant. var2 - Byte, Integer, Word, Long.

    : -------------------------------------------------- 1wreset, 1wwrite and 1wread() 4K7 DS2401 +5 V -------------------------------------------------- Config 1wire = P1.1 Dim Ar(8) As Byte , A As Byte , I As Byte 1wreset Print Err , 1wwrite &H33 For I = 1 To 8 Ar(I) = 1wread() 8 Ar Next For I = 1 To 8 Printhex Ar(I); Next Print End

    ABS(x) : .

    . : var = ABS(var2) var - Byte, Integer, Word, Long. var2 Integer, Long. : Dim a as Integer, c as Integer , e as Single

    a = -1000 : c = Abs(a) c=1000 e = -1000 $asm Anl {e + 3} , &H7f Single e=1000 $end Asm

    ALIAS : .

    . : Newvar ALIAS Oldvar Oldvar - . Newvar - . : In_dir Alias P1.1

    Ri Alias Scon.0 ASC(s) : ASCII ( ).

    . : var = ASC(string) var - Byte, Integer, Word, Long. String - String, Constant. : Dim a as byte, s as String * 10

    s = ABC : a = Asc(s)