Вы находитесь на странице: 1из 155

..

BASCOM-8051

2001

BASCOM-8051
. (http:\www.mcselec.com)
1.5 - 29.3.01

MSC

Electronics,

Bascom-8051 ( , ,
)
( Bascom-8051)
( )
, Bascom-8051

Bascom-8051

,
Bascom


Bascom








c Microwire
I2C

-




Bascom
EEPROM AT89S82252
Bascom
Bascom
Bascom

A.
B. 8051
C. MCS-51

1-1
2-1
3-1
4-1
5-1
6-1
7-1
8-1
9-1
10-1
11-1
12-1
13-1
14-1
15-1
16-1
17-1
18-1
19-1
20-1
21-1
22-1
23-1
24-1
25-1
26-1
27-1
28-1
29-1
30-1
31-1
32-1
A-1
B-1
C-1

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

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

Bascom-8051
=
+ - * / \
= < > <= >= <>
; : ,

, ,


3-1, 3-2
3-1,3-2
3-2
3-1


BIT
BYTE
CONST
INTEGER
LONG
SINGLE
STRING
WORD
Array(n)

( )
( )



( )

()

3-1
3-1
3-1,20
3-1
3-1
3-1
3-1
3-1
3-1

(), Bascom-8051
10, 12345, -100
&h00FF, &h10
&b01010101
123.456, 0.12
String Data


(-, - )
(-, - )
,
( 254 )

3-1
3-1
3-1
3-1
3-1

Bascom-8051
$ASM
$BAUD =
$CRYSTAL =
$DEFAULT XRAM
$END ASM
$EXTERNAL
$INCLUDE []
$IRAMSTART =
$LARGE
$LCD =
$LIB
$MAP
$NOBREAK
$NOINIT
$NOLCDINIT
$NONAN
$NOSP
$OBJ
$RAMSIZE =
$RAMSTART =
$REGFILE=[]
$ROMSTART =










-


( )

LCD
NAN 0.0





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

4-1
4-1
4-1
4-1
4-1
4-1
4-1
4-2
4-2
4-2
4-2
4-2
4-2
4-3
4-3
4-3
4-3
4-3
4-3
4-3
4-3
4-3
1-1

===================================== Bascom-8051 ==
$SERIALINPUT =
$SERIALOUTPUT =
$SERIALINPUT2LCD
$SIM



- ( . LCD)
( )

4-4
4-4
4-4
4-4

, Bascom-8051 ( )
1WIRE
COUNTER0, 1 2
EEPROM
DEBOUNCE
I2C: I2CDELAY
LCD, LCDBUS, LCDPIN
I2C: SDA, SCL
Microwire:
DIN, DOUT, CS, CLOCK
SERVOS
SPI: DIN, DOUT, CS, CLK
TIMER0, 1 2
WATCHDOG
INT0
INT1
PCA
SERIAL
TIMER0
TIMER1
TIMER2
SOUND
RC
RC5

:
0, 1 2
AT89S8252

I2C
LCD-: (), ()
I2C :

4-4,4-7
4-10
4-11
19,4-7
4-7
4-7
4-8
4-8,4-28


SPI :
0, 1 2
AT89S8252
0
0
851FA

0
1
2

( RC-)
RC5

4-8,4-34
4-8
4-8,4-9
4-9
4-13,4-33
4-13,4-33
4-13,4-33
4-13,4-33
4-13,4-33
4-13,4-33
4-13,4-33
4-35
4-15
4-16

Bascom-8051
.. ALIAS ..
BITWAIT bit Set(Reset)
BREAK
CALL
CASE n :
CASE IS :
CLOSE ..
CONFIG
CONST
DATA
DEBOUNCE
DECLARE SUB
DEFBIT
DEFBYTE
DEFINT
DEFWORD
DEFLCDCHAR
DELAY
DIM .. AS ..
DISABLE
DO ..
.. ELSE ..
.. ELSEIF..
ENABLE
END
.. END IF


( )

()
n
, ,
()




()


( )







,


()

4-5
4-5
4-5
4-6
4-6
4-6
4-30
4-7 ... 4-9
4-9
4-10
4-11
4-12
4-12
4-12
4-12
4-12
4-12
4-12
4-13
4-13
4-13
4-20
4-20

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

4-13
4-14
4-20
1-2

===================================== Bascom-8051 ==
ERASE
EXIT ..
ForTo/Downto...Step...
GET
GOSUB
GOTO
.. LOOP
.. NEXT
IDLE
IF ..
INPUT
INPUTHEX
INPUTBIN
INKEY
LCD
LCDHEX
LOAD TIMER0, 1 2
MODE0, 1, 2, 3, 4, 5
NOSAVE
ON [Interrupt]
ON x GOTO (GOSUB)
OPEN ..
POWERDOWN
PRINT
PRINTHEX
PRINTBIN
PRIORITY ON(OFF) ..
PUT
READEEPROM
READ
REM
RESET
RESTORE
RETURN
ROTATE ..
SELECT CASE x
SET
SERVO
SHIFTIN
SHIFTOUT
SOUND
SPIIN
SPIOUT
START TIMER0, 1, 2
STOP TIMER0, 1, 2
STOP
SUB
SWAP
.. THEN ..
.. UNTIL ..
WAIT
WAITKEY
WAITMS
WHILE .. WEND
WRITEEEPROM

( )


()








( )



,
,


() x
()


.

()
()
EEPROM AT89S8252
DATA

( 0) .
DATA READ

( LEFT / RIGHT)
x
( 1) .




SPI
SPI
0, 1 2
0, 1 2








, ,
EEPROM AT89S8252

4-14
4-14
4-14
4-30
4-16
4-16
4-13
4-14
4-14
4-20
4-22
4-22
4-22
4-23
4-23
4-23
4-25
4-13
4-29
4-30
4-30
4-30
4-32
4-32
4-32
4-33
4-33
4-30
4-11
4-33
4-34
4-34
4-33
4-34
4-34
4-6
4-34
4-34
4-35
4-35
4-35
4-36
4-36
4-37
4-37
4-37
4-38
4-39
4-20
4-12
4-12
4-23
4-12
4-39
4-11

Bascom-8051
X AND Y
X OR Y

:
:

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

4-5
4-5
1-3

===================================== Bascom-8051 ==
NOT Y
X XOR Y

4-5
4-5

Bascom-8051
ABS(x)
ASC(s)
BDC(x)
HR(x)
CPEEK(x)
DECR x
INCR x
FUSING()
GETRC()
GETRC5
HEX()
HEXVAL()
HIGH()
HIGHW()
INP()
INSTR ()
LCASE()
LEFT()
LOW()
LOWW()
LEN()
LOOKUP
LOOKUPSTR
MAKEBCD(x)
MAKEDEC(x)
MAKEINT()
MAX()
MID()
MIN()
MOD
OUT
PEEK()
POKE
RIGHT()
SPACE()
STRING()
STR()
VAL()
VARPTR()
UCASE()



-
( )



. .
RC-
()






( )
,





-
-


( )



,

,
,
,


, .
( . )

4-5
4-5
4-5
4-6
4-10
4-12
4-12
4-15
4-15
4-16
4-16
4-17
4-17
4-17
4-21
4-21
4-23
4-25
4-17
4-17
4-25
4-26
4-26
4-26
4-26
4-26
4-27
4-25
4-27
4-27
4-21
4-32
4-32
4-25
4-36
4-36
4-16,4-37
4-17,4-39
4-39
4-23

Bascom-8051
1WREAD
1WRESET
1WWRITE

4-4
4-4
4-4

Bascom-8051 I2C
I2CRECEIVE
I2CSEND
I2CSTART
I2CSTOP
I2CRBYTE
I2CWBYTE

I2C
I2C
I2C
- I2C
I2C-
I2C-

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

4-18
4-18
4-19
4-19
4-19
4-19
1-4

===================================== Bascom-8051 ==
Bascom-8051 Microwire
MWINIT
MWREAD
MWWRITE
MWWOPCODE

Microwire
Microwire
Microwire
Microwire.

4-28
4-28
4-28
4-28

Bascom-8051
SHIFTIN
SHIFTOUT
SPIIN
SPIOUT



SPI
SPI

4-35
4-35
4-36
4-36

Bascom-8051 (UART)
CLOSE ..
GET
INKEY
INPUT
INPUTHEX
INPUTBIN
OPEN ..
PRINT
PRINTHEX
PRINTBIN
PUT
WAITKEY

()
()



( )
()

.

()

4-31
4-31
4-23
4-22
4-22
4-22
4-31
4-32
4-32
4-32
4-31
4-23

Bascom-8051
.. BLINK
CURSOR ..
DISPLAY ..
HOME ..
..FOURTH .. F
FOURTHLINE
LCD ..
LCDHEX ..
LOCATE y , x
..LOWER .. L
LOWERLINE
.. NOBLINK
SHIFTLCD ..
SHIFTCURSOR ..
.. THIRD .. T
THIRDLINE
.. UPPER .. U
UPPERLINE

( )
( - ON / - OFF)
( - ON / - OFF)





y, x


( )
( - LEFT / RIGHT)
( LEFT / RIGHT)



4-24
4-24
4-24
4-24
4-24
4-24
4-23
4-23
4-24
4-24
4-24
4-24
4-24
4-24
4-24
4-24
4-24
4-24

Bascom-8051
BITWAIT bit Set(Reset)
DEBOUNCE port ..
IF bit = 0 THEN ..
IF bit = 1 THEN ..
SET bit
RESET bit

( )

0
1
1.
0.

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

4-5
4-7,4-11
4-20
4-20
4-34
4-34
1-5

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

Bascom-8051, 1.0.0.19
$MAP
$NONAN
$REGFILE=[]
LCASE()
UCASE()


NAN 0.0

( )
( . )

4-2
4-3
4-3
4-23
4-23

Bascom-8051, 1.0.0.19
CONST
SHIFTIN
FUSING()



. .

4-9
4-35
4-15

Bascom-8051, 1.0.0.20
$EXTERNAL
$LIB
$NOLCDINIT
CONFIG Microwire
HIGHW()
INSTR ()
LOWW()
MIN(), MAX()
MWINIT
MWREAD
MWWRITE
MWWOPCODE



LCD
Microwire




Microwire
Microwire
Microwire
Microwire.

4-1
4-2
4-3
4-8
4-17
4-21
4-17
4-26
4-28
4-28
4-28
4-28

Bascom-8051, 1.0.0.20
INPUT
IF X=A
ON .. , PRIORITY ..

TIMEOUT

PCA (8051FA),

4-22
4-20
4-29,4-33

, Bascom-8051, 2.04
$BGF=[]
$NONULL = x
$TIMEOUT
CONFIG GRAPGLCD
CONFIG PRINT
PSET
REPLACE
RND()
SHOWPIC
SPC()

BMP

TIMEOUT

RS-485




Print Lcd

*
4-3
4-4

4-9

4-35
4-31

4-37

Bascom-8051, 2.04
IF THEN ELSE
OPEN INVERTED
NOCS = x
NOINT
TIMEOUT = x
CLS TEXT, CLS GRAPH
CLS BOTH
* -


UART
NOCS CONFIG SPI


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

4-20
4-32
4-9
4-37
4-23

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 ==
3.

*
+
,
.
/
:

;
<
=
>
\

Bit

Byte
Word
Integer
Long
String
Single

Array

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) -
, ( 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 ==

=
<>
<
>
<=
>=

NOT
AND
OR
XOR

+
*
/ \

. ,
, ,
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)
(Greater than or equal) - X >= Y. (Const, Byte, Word, Integer, Long, Single)
( 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 ==
$IRAMSTART
.
:
$NOINIT $NOSP,
.
: $IRAMSTART = constant Constant - (0-255)
$NOINIT

:
$NOSP

$IRAMSTART = &H60
SP = 80

$LARGE
:
:
$LCD
:

:
:
$LIB
:
:
:
$MAP
:
:

( 2 ).
Lcall Ljmp.
$LARGE 148,

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 myfile.lib myfile.lib .
$LIB "mylib.lib"
$EXTERNAL _dec76

.
.
$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
:

:
$NONULL
:

$NOSP
:
:

NAN 0.0 ,

( , ..
).
$NONAN ' NAN
$NONULL = 0 - (
). $NONULL = -1 -
.
$NONULL = -1
'
DATA
$NONULL = 0$
'
DATA
.

(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
:
:
:
$TIMEOUT
:
:
:

,
( WAIT, WAITMS, DELAY), .
$SIM
$SIM
,
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)
:
:
:

ALIAS
:
:
:
ASC(s)
:
:
:

.
.
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
.
.
Newvar ALIAS Oldvar Oldvar - . Newvar - .
In_dir Alias P1.1

Ri Alias Scon.0

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) -

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

4-5

===================================== Bascom-8051 ==
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()
:
:
:
BITWAIT
:
:
:
BREAK
:
:

() - .
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 x SET/RESET x -
Bitwaim a , Set
, . a
Bitwait P1.7, Reset , 0
. 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

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

4-6

===================================== Bascom-8051 ==
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 .
time ,
: CONFIG DEBOUNCE = time
( 12 ).
Config Debounce = 50 50 mS
:

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

4-7

===================================== Bascom-8051 ==
CONFIG I2CDELAY
SCL I2C.
:
5 .
I2CDELAY = 0 1 0 (
: CONFIG
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
. . RW-Gnd. RS-A0. E-. Wr(P3.6)
2:
$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

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

4-8

===================================== Bascom-8051 ==
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

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

4-9

===================================== Bascom-8051 ==
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"

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

4-10

===================================== Bascom-8051 ==
COUNTERx
:
:

CPEEK()
:
:
:

DATA
:
:

.
( 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
. ..
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 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!

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

4-11

===================================== Bascom-8051 ==
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

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

4-12

===================================== Bascom-8051 ==
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 b1
set bit to 1
C = 10
let c = 10
DEFLCDCHAR
0 7 8 15 (
:
). , ,
CLS. Chr().
char,r1,r2,r3,r4,r5,r6,r7,r8 Char - ()
: DEFLCDCHAR
(0-7). r1-r8
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
=============================================================================

4-13

===================================== Bascom-8051 ==
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
Interrupt -
: DISABLE interrupt , ENABLE 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

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

4-14

===================================== Bascom-8051 ==
END
:
:
ERASE
:

:
:

EXIT
:

:
:

. Stop.
JMP .
END

.
. () ,
. ,
. , ..
,
(). , , ,
.
, , .
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
: 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.
y = 10
y=10
1:
FOR a = 1 TO 10
10
FOR x = y DOWNTO 1
PRINT x ; a

NEXT
x ( )
NEXT
a ( )
Dim S as Single

2:
For S = 1 To 2 Step 0.1
Print S
Next
END
=============================================================================

4-15

===================================== Bascom-8051 ==
FUSING()
:

GETRC()
:

:
:

.
.

, . ! 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 ( ) 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 - . '

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

4-16

===================================== Bascom-8051 ==
GETRC5
:

:
:

GOSUB
:
:
:

GOTO
:
:
:

, -
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 label label - ()
GOSUB Routine

Routine:

x = x + 2

RETURN

.
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

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

4-17

===================================== Bascom-8051 ==
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

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

4-18

===================================== Bascom-8051 ==
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

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

4-19

===================================== Bascom-8051 ==
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

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

4-20

===================================== Bascom-8051 ==
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
DIM A AS INTEGER
1:
A = 10
IF A = 10 THEN

PRINT This part is executed.



ELSE
PRINT This will never be executed.
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
Dim X As Integer
2:

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

3:
If X = 10 Then Goto M1 Else Goto M2

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

4-21

===================================== Bascom-8051 ==
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 , .
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

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

4-22

===================================== Bascom-8051 ==
INPUT, INPUTHEX, INPUTBIN
INPUT , RS-232.
:
( ,
)
( ). BASCOM
INPUTHEX HEX-, (
). <RETURN> (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

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

4-23

===================================== Bascom-8051 ==
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

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

4-24

===================================== Bascom-8051 ==
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

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

4-25

===================================== Bascom-8051 ==
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

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

4-26

===================================== Bascom-8051 ==
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

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

4-27

===================================== Bascom-8051 ==
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 3 10/3
PRINT a
a=1

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

4-28

===================================== Bascom-8051 ==
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 (
).
Dim Dta As Byte, Adr As Byte
1:
' 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
16-
2:
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

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

4-29

===================================== Bascom-8051 ==
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

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

4-30

===================================== Bascom-8051 ==
ON Interrupt
:

ON Value
:
:
:

, . 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
, .
: (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

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

4-31

===================================== Bascom-8051 ==
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
Open "com1.2:9600 , Inverted" For Input As #1 ' p1.2
2:
Print #1, Hello
' 1
Close #1
'

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

4-32

===================================== Bascom-8051 ==
PEEK()
:
:
:
POKE
:
:

(), .
var = PEEK( address ) var - , .
Address - 0
255.
DIM a As Byte
a = Peek( 0 ) R0
.
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

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

4-33

===================================== Bascom-8051 ==
PRINTBIN
:

PRIORITY
:

, ,
(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)
. ,
.
: 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 . -

READ, RESTORE
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 : <0 >255)

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

4-34

===================================== Bascom-8051 ==
REM
:

REPLACE
:
:
:

RESET, SET
:
:

RETURN
:

:
:

RND()
:
:
:

. .

( ).

REPLACESET String , Old , New String . Old
, . New
, .
Dim S1 as String
S1 = 123.456
Replace S1 , . , ,
Print S1
123,456

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
( RET)
( RETI). RET RETI.
RETI Return,
.
, RETI.
, , ,
RETURN.
RETURN
GOSUB Pr

PRINT result -
END

Pr:

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


RETURN

Var = RND(Lim) Var Word, .
Lim ,
Dim Ar As Word
Do
Ar = Rnd(1000) : Print Br
Loop

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

4-35

===================================== Bascom-8051 ==
ROTATE
:
:

SERVOx
:
:
:


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
, 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
=============================================================================

4-36

===================================== Bascom-8051 ==
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

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

4-37

===================================== Bascom-8051 ==
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
:
:
STR()
:
:
:


PRINT var
STOP

, .
, 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)

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

4-38

===================================== Bascom-8051 ==
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

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

4-39

===================================== Bascom-8051 ==
SWAP
:
:
:

VAL()
:
:
:

VARPTR()
:
:
:

.
!
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
, ().
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
, (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.
Condition - .
: WHILE condition
a=0
:
WHILE a <= 10 , a 11
PRINT a : INC a
WEND
WATCHDOG AT898252: START WATCHDOG, STOP WATCHDOG, RESET WATCHDOG
:
CONFIG WATCHDOG -
START WATCHDOG - ( )
STOP WATCHDOG - ( )
RESET WATCHDOG -
: Config Watchdog = Time
Time - : 16 , 32, 64 , 128 , 256 , 512 , 1024 2048.
START WATCHDOG
STOP WATCHDOG
RESET WATCHDOG
Config Watchdog = 2048
2048
:
Start Watchdog

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

4-40

===================================== Bascom-8051 ==
5.
Bascom-8051
1 8051.
SWAP, Bascom.
SWAP ! ( - !Swap)
: R0-R7, @R0, @R1, A, DPTR; C; #. , ,
(type.dat), .
, .
2 , , ,
.
3 ,
( DS) ( DW).
DB, :
T_asd:
$asm
Db #&hfd , 23 , 5 , 6
$end Asm
4 Bascom $Asm $End Asm.
. . $Asm
$End Asm .
. $Asm $End Asm .
' 0 Timer_0_int:
$asm
Mov
Tl0 , #&hfd 'd8fdh -
Mov
Th0 , #&hd8 ;. . 10 $end Asm
Return

5 .
( ).
.
'
Ser_int:
$asm
Jbc {Ri} , Intsr
Jbc {Ti} , Intst
Reti
Intsr:
Mov {rbuf} , Sbuf
Setb {B_enrx}
;
Reti
Intst:
Setb {B_entx}
;
Reti
$end Asm
,
:
) ,
( );
) ,
! . ,
. :
'
Ser_int:
=============================================================================

5-1

===================================== Bascom-8051 ==
$asm

Jbc {Ri} , Intsr


Jbc {Ti} , Intst

$end Asm
Goto Ser_Ret
!Intsr:
Rbuf = Sbuf : Set B_enrx : Goto Ser_Ret '
!Intst:
Set B_entx :
'
Ser_Ret:
Return
'!!!
6 , , ,
, { }.
! , { ), .
, type.dat, .
Mov {R_ch} , Sbuf
Setb {B_kl}

Mov {R_ch+3} , Sbuf
. Integer
. , . !
7 (#) .
, .
Mov {R_cch} , #{R_lin} -
Mov {R_cch} , # {R_lin} -
8 , ,
A.
Cjne A , #&h0d , Ints3
Orl A , direct
Addc A , #&B00010001
, , Acc.
Push Acc
Setb Acc.2
, , ,
( ).
Mov A , R0

Mov A , direct

Mov Acc , R0
Mov Acc , direct

9 - .
- .
:
) : ;
) - ;
) : .
10 (2.)
$Asm $End Asm. .

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

5-2

===================================== Bascom-8051 ==
6.
Bascom, ,
.
.
- . , Options Environment,
, ( ) .
, . ,
, .
Bascom.
LEFT ARROW
RIGHT ARROW
UP ARROW
DOWN ARROW
HOME
END
PAGE UP
PAGE DOWN
CTRL+LEFT
CTRL+RIGHT
CTRL+HOME
CTRL+END
CTRL+ Y
INS
F1
F2
F3
F4
F5
F7
CTRL+F7
F8
SHIFT + F8
F9
F10
CTRL+G
CTRL+O
CTRL+S
CTRL+P
CTRL+T
CTRL+F
CTRL+W
CTRL+L
CTRL+X
CTRL+C
CTRL+V
CTRL+Z
CTRL+SHIFT+Z
CTRL+SHIFT+I
CTRL+SHIFT+U
SHIFT+















( - , )



( )
( )
( )
( )
( )






( )
LCD ( )
Clipboard
Clipboard
Clipboard




() ()


, .
(_). .

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

6-1

===================================== Bascom-8051 ==
7. , Bascom
, Bascom-8051 .

00 1Fh

00 11h

12 1Fh

20 2Fh

00 09h*
09 7Fh*
$ - ($+11h)

30 7Fh

($+12h) $$

80
FFh

Bascom,
. ,
$NOSP
, .
,
. 3

R0 - R7 ( ).
Bascom.
.
.
Bascom
.
.
Bit: Byte,
Word/Integer, Long, Single, String, Array ().

,
, ,
, (
). , -
c
. Long, Single, String, Array
,
7Fh.

(Mov SP,#$$)
* - . $ - , . $$ - ,
.
$$+1
7F(FFh)

Bascom ,
( ), .
, ,
.
, .
( 00h) . ,
. ,
,
.
, .
, (00h)
. , , .
,
, .
( 254 ).

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

7-1

===================================== Bascom-8051 ==
, Bascom
.

0000h
0003h

002E*

$$

- LJMP $$
(),
.
Reti.
(
) ,
, .

( , LCD).
,
,
( ) ,
.

, .. .

$$$

* - 8052. type.dat . $$ Bascom. $$$ -


.

Bascom . ,
, 8051,
. :
5000. .
1000.
.
(Alias) - 128.
120*.
,
Bascom. .
20*.
10*.
10*.
5*.
* - ,
8052 ( 256 ).
. 8051(128 )
60-70 . 8052(256 )
150-180 .
, ,
Bascom.

:
FOR .. NEXT
50
IF .. THEN
50
DO .. LOOP
50
WHILE .. WEND 50
SELECT .. CASE 25
.
.

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

7-2

===================================== Bascom-8051 ==
8.
Bascom
. ( ) :
, .. .
. ,

. ,
, . ,
, , .

, :
, , , ,
, , ,
( ) ,
.
, ()
$REFILE.
2
$large.
$IRAMSTART=&H[adres]
.
!!!
: Bit,
Byte, Word, Integer, Long, Single, String, Array. ,
EEPROM, .
,
, : B_art, B_ovr , R_dat, R_cnt , W_adr
, I_data , L_bd ,
F_frq , S_inbuf , A_mes - , P_clk,
P_osnd .
,
( ).
,
.
. , -
, ,
Options - Compiler.
$Nosp
.
SP=&H[adress].

$NOINIT,
, Bascom,
.
,
, , . , ,
, Options - Compiler.
, .
-.

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

(LCD). ,

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

8-1

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

Cls.
( Cls).
, , ,
, .
- , , EEPROM.

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

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

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

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

8-2

===================================== Bascom-8051 ==
9.
Bascom 8051.
, , Option - Compiler Misc.
, /BASCOM-8051.
,
. , .
.
[BIT] - . (SFR),
.
[BYTE] SFR,
.
[MISC] :
- ( );
- .
8052 INT0, INT1, TIMER0, TIMER1, SERIAL TIMER2
;
- ,
;
- (128 256 ).
. ,
,
, .
, , . Bascom
SFR. ,
, Alias.
87C51FA.
,
. 80c51fa.dat:
[BIT]
TCON = 88 P1 = 90 SCON = 98 IE = A8 P3 = B0 IP = B8 PSW = D0
ACC = E0 B = F0 P0 = 80 P2 = A0 T2CON = C8
[BYTE]
SP = 81 DPL = 82 DPH = 83 PCON = 87 TMOD = 89 TL0 = 8A
TL1 = 8B TH0 = 8C TH1 = 8D SBUF = 99 T2MOD = C9 TL2 = CC
TH2 = CD RCAP2L = CA RCAP2H = CB IPH = BF CH = F9 CL = E9
CCAP0H = FA CCAP0L = EA CCAP1H = FB CCAP1L = EB CCAP2H = FC
CCAP2L = EC CCAP3H = FD CCAP3L = ED CCAP4H = FE CCAP4L = EE
CMOD = D9 CCAPM0 = DA CCAPM1 = DB CCAPM2 = DC CCAPM3 = DD
CCAPM4 = DE SADEN = B9 SADDR = A9
[MISC]
up = 8051FA PCA = 33 org = 36 IRAM = 256
( 2.01) DAT-. 2B
TIMER2. , 8052.
2B xxx.DAT [MISC].

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

9-1

===================================== Bascom-8051 ==
10. Bascom
Bascom , ,
, :
- Options Compiler Communication
.
TIMER1;
- Options Compiler I2C , I2C.
RC5 (
, , );
- Options Compiler LCD ,
(LCD). ,
LCD . ,

RS ( ) E (). Bascom
LCD, RW
( );
- Options Compiler Misc ,
.
Bascom-LT;
- Options Compiler Misc
.
.
, Bascom, ,
-,
. , ,
,
.

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

10-1

===================================== Bascom-8051 ==
11.

:
) , .. :
. , ,
;
) , , .
, ,
, , ,
( ), ..
, , ,
;
) , ,
. - ,
, , ,
. , AT89C8252, ,
;
)
: Micro-Cap, Mathcad, Quick-Basic
..;
) -, ,
, .
, , ( )
. , ,
. .




() 12 . () . .
() 12 . () . .
() EEPROM I2C
(4-/8- )
10 9.6

,
470
2100
2500
250
30
10000(500)
300/150
13


, , .
, ,
, ,
. , ,
:
)
, .. ( 8751)
, ,
, .
, ;
)
, ,
;
) , .. -

Bascom-8051, .
( )
,
( ). , ,
.
.
, .
=============================================================================

11-1

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

(.1)

(.2)

P1.0(T2)

(.3)

(.1)

P3.5(T1)

(.1)

(.2)

P3.2(INT0)


16

SPI

7-

P0.0 P0.3,
P0.4 P0.7
P2.0 P2.3,
P2.4, P2.5
P3.3
P1.5, P1.6, P1.7

P1.0(T2)

P1.5,
P1.6, P1.7
P0.0 P0.7,
P2.0 - P2.2


2 . :
. .
,
, .
.
. . .

. .
Sound Bascom.
.
0 - (
). 1 .
0 1.
1
.
0
. 0 - F/12.
2 . 0
,
2. 0 - F/12.
4 4.
.
4-.
, .
SPI Micro-Wire.
.
- .
SPI, AT89C8252.
.
UART 3 (
)
300 1000
,
.
P0, P2.0 - P2.2.

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

11-2

===================================== Bascom-8051 ==
12.
,
,
.
, .

.
,
. , OptionCompiler-Misc.
$Regfile "8052.DAT "
2 .
$large
'
, .
'-------- -------Dim Cit As Const &H10
' *10
Const Cit = &H10
'
': -------Dim N_dat As Bit
' " "
Dim B_entx As Bit
'
Dim B_temp As Bit
'
, SFR.
Ri Alias Scon.0
' RI
Ti Alias Scon.1
' TI
Ren Alias Scon.4
' Ren
'-------- ---------Dim Temp As Byte
'
Dim R_ch As Byte
'
Dim R_cch As Byte
'
Dim Rang As Byte
' ()
Dim Frng As Byte
'
'-------- ---Dim R_bw As Integer
'16-.
Dim R_rd As Integer
'16-.
'-------- Dim R_bd As Long
'32-.
Dim Tmpl As Long
'32-.
'--------
Dim R_frq As Single
'
Dim R_fld As Single
'
'--------
Dim R_lin As String * 6
'
Dim R_tmp As String * 5
'
'-------------------- .
'Declare Sub Wrb_24c01(badr As Byte , Value As Byte)
'Declare Sub Rdb_24c01(badr As Byte , Value As Byte)
'-------------------- , .
' AD9850
B_data Alias P1.3 : B_clk Alias P1.4 : B_fqud Alias P1.5 : B_ress Alias P1.7
'--------------------' AD766
B_datu Alias P1.0 : B_clku Alias P1.1 : B_ldu Alias P1.2
'-------------------- : (),
, - 80C51GB, P5 P0,
P4 P2.
' 87C52
'B_dar0 Alias P0.0 : B_dar1 Alias P0.1 : B_dar2 Alias P0.2 : B_dar3 Alias P0.3
'B_cor0 Alias P2.7 : B_cor1 Alias P0.4 : B_cor2 Alias P0.5 : B_cor3 Alias P0.6
=============================================================================

12-1

===================================== Bascom-8051 ==
'--------------------'!!! 80C51GB
B_dar0 Alias P5.0 : B_dar1 Alias P5.1 : B_dar2 Alias P5.2 : B_dar3 Alias P5.3
B_cor0 Alias P4.7 : B_cor1 Alias P5.4 : B_cor2 Alias P5.5 : B_cor3 Alias P5.6
'-------------------- ,
. - , ,
. , ,
, .
$Nosp
Sp = &h7f
' 80h
'--------------------
Bascom.
'$Noinit
'
'Tcon = &h50 : Tmod = &h22 : T2con = &h34 : Scon = &h70 : Load Timer2 = &hffd9
'-------------------- .
'TIMER0 16-. . .
Config Timer0 = Timer , Gate = Internal , Mode = 1 : Start Timer0
'-------------------- .
'TIMER2 16-. . . UART
$baud = 9600
' 9.6
$crystal = 12000000
' 12
Config Timer2 = Timer , Gate = Internal , Mode = 2
Print Input
.
' 1
'TIMER1 8-. . . UART
Config Timer1 = Timer , Gate = Internal , Mode = 2
Scon = &H52
'
Th1 = 243
'
Pcon = &H80 : Start Timer1
' . 2
'--------------------' 2
'Timer2 16 -. . . Uart
Config Timer2 = Timer , Gate = Internal , Mode = 2
Scon = &H52
'
Rcap2h = &HFF : Rcap2l = &HA5 : Start Timer2
'-------------------- .
, ,
. ,
, .
'
On Timer0 Timer_0_int Nosave
'
On Serial Ser_int Nosave
' .
Enable Timer0
' 0
Enable Serial
' .
Priority Set Serial
' .
Enable Interrupts
'
'-------------------- , , ,
.
'!!! ----------------' 80C51GB
Th0 = &HD8 : Tl0 = &HFD
' . 10
Oscr = &HE1 : Oscr = &H1E
'
Wdtrst = &H1E : Wdtrst = &HE1
'
P4 = &HFF : P5 = &HFF
'.
'--------------------
=============================================================================

12-2

===================================== Bascom-8051 ==
Clr_mem:
$asm
Mov R0 , #&hff
;
;
Mov R0 , Sp
; ( )
Clrmem:
Mov @r0 , #0
Djnz R0 , Clrmem
;
$end Asm
'-------------------- ,
. , ,
.
'
N_dat = 1
' " "
R_cch = Varptr(r_lin)
'
R_ot = 0
' -
'-------------------- ,
( , ).
'
Reset B_data : Reset B_clk : Reset B_fqud : Reset B_ress
'
Set B_datu : Set B_clku : Set B_ldu
'
'-------------------- ,
. ,
. 100
,
.
'
Config Lcd = 16 * 2
'
Config Lcdpin, Db4 = P1.4, Db5 = P1.5, Db6 = P1.6, Db7 = P1.7, E = P3.2, Rs = P3.4
'
Deflcdchar 0 , 31 , 17 , 17 , 17 , 17 , 17 , 31 , 0
Deflcdchar 1 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 31
Deflcdchar 2 , 241 , 234 , 228 , 224 , 228 , 234 , 241 , 224
Deflcdchar 3 , 241 , 234 , 228 , 241 , 234 , 228 , 224 , 224
Deflcdchar 4 , 228 , 234 , 241 , 228 , 234 , 241 , 224 , 224
Deflcdchar 5 , 228 , 234 , 241 , 234 , 228 , 224 , 224 , 224
Deflcdchar 6 , 228 , 234 , 241 , 234 , 245 , 241 , 241 , 224
Deflcdchar 7 , 238 , 234 , 234 , 234 , 255 , 241 , 241 , 224
Cls
'
Lcd V7-64 ver.3_7
'-------------------- , ,
, .
Print 1_ON

'-------------------- . ,
( ),
.
, (
, ). -
, , .
Gosub Test_CS_EEPROM
'
If b_ER = 1 Then
' ?
Print Error_CS_Mem! : Waitkey '
Gosub Ini_EEP
'
End If
'-------------------- , , , , ..
, ,
.
=============================================================================

12-3

===================================== Bascom-8051 ==
Gosub Self_Cal : Gosub Init_DAC : Gosub Reset_Relay '. .
'-------------------- , , ,
, ,
() . ,
.

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

12-4

===================================== Bascom-8051 ==
13.
Bascom , ,
. Bascom : ( ),
( ),
(SPI, Micro-Wire ..), I2C 1Wire, ,
RC5 - (),
RC- ( , ).
Bascom ,
.
. .
- ():
Config 1wire = P1.1
Config Sda = P1.5
Config Scl = P1.4

'P1.1
'P1.5 - SDA
'P1.4 SCL

SPI , :
CONFIG SPI = SOFT, DIN = P1.0, DOUT = P1.1, CS = P1.2, CLK = P1.3
Bascom, SPI
, . SHIFTIN
SHIFTOUT, -, - (
SPI ). SHIFTIN SHIFTOUT .
Getrc , .
Getrc5 P3.2, .. Int0. ,
Getrc Getrc5 . ,
1 0, .
Int0 ( ).

( , - 50 )
:
Config SERVOS = 3, SERVO1 = P1.1 , SERVO2 = P1.2 , SERVO3 = P1.4
,
:
CONFIG LCD = 40 * 4
'
CONFIG LCDPIN=PIN ,DB4=P1.1,DB5=P1.2,DB6=P1.3,DB7=P1.4,E=P1.5,RS=P1.6 '
P0,
:
$LCD = &H8000
Config LCDBUS = 4
Config LCDBUS = 8

'
' 4-
' 8-

(, ) ,
.

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

13-1

===================================== Bascom-8051 ==
14.
8051
. ,
,
. Bascom ,
. :
) ,
.
. ,
.
(
) Bascom ( ),

;
) Bascom
. ,
. Bascom, ,
, ;
) .
,
, .
:
) ;
) - ()
, ,
( , ) , ,
( , );
) ();
) , ,
, .
- .
;
) , Bascom, , ..
( ) RETI.
RETURN. , RETURN
RETI. , RETI
RETURN, , , ;
) 3.
, PSW RS0 RS1 (Psw = &h18).
,
18H (R0 ).
Bascom ,
, . ,
, , , ,
. Bascom
:
) ( ),
, ,
. SFR, ,
;
) ,
, .
(, , ).
.
, .
(
) ;
) .
Bascom, , .
(PRINT, LCD).
=============================================================================

14-1

===================================== Bascom-8051 ==
.
( ?)
, . ,

,
;
) , , WAIT INPUT.
, , ;
)
RESTORE READ;
)
(OPEN .. CLOSE, DO .. LOOP, WHILE .. WEND, SELECT .. CASE). ;
) (IF .. THEN),
(FOR .. NEXT), INCR, DECR .
- ,
,
. ,
, ;
) GET PUT, ,
, ;
)
.
.
.
. .
INT0 ( INT1) :
On Int0 Int_0_int
' INT0 (INT1 )
Rem On Int0 Int0_int Nosave ' .
Rem Set Tcon.0
', (Tcon.0 = 1)
Enable Int0
' INT0 (Ie.0 = 1)
Enable Interrupts
' (Ie.7 = 1)
'------------------------------'
Int_0_int:
Reset P1.7 : Buf = P0 : Set P1.7 : Set New_data
Return
'------------------------------ 0 ( 1):
Config Timer0 = Timer , Gate = Internal , Mode = 1 ' 16-
On Timer0 Timer_0_int ' 0 (Timer1 )
Counter = 0
' 65
Enable Timer0
' INT0 (Ie.1 = 1)
Enable Interrupts
' (Ie.7 = 1)
'------------------------------'
Timer_0_int:
Counter0 = &hD8F0 ' 10 ( 12 )
Incr Rtime : Set B_10_mc
', 10
Return
'------------------------------ .
.
, .
Nosave, .
Ri Alias Scon.0
' RI
Ti Alias Scon.1
' TI
Dim R_ch As Byte
'
Dim R_cch As Byte
'
Dim R_lin As String * 6
'
'-------'TIMER2 16-. . . UART
$crystal = 12000000
' 12
=============================================================================

14-2

===================================== Bascom-8051 ==
$baud = 9600
' 9.6
Config Timer2 = Timer , Gate = Internal , Mode = 2
Timer2 = &HFFA5 : Start Timer2
'
On Serial Ser_int Nosave
' .
Enable Serial
' .
Enable Interrupts
'
'
Ser_int:
$asm
Jbc {Ri} , Intsr ;
Jbc {Ti} , Intst ;
Reti
Intsr:
Push Psw
;
Push Acc
Mov {R_ch} , Sbuf ;
Mov A , {R_ch}
Ints1:
Cjne A , #&h0d , Ints3
Setb {N_dat}
;0Dh -
Ints2:
Mov A , {R_cch}
;
Xch A , R0
; R0
Mov @R0 , #&h00
;
Xch A , R0
; R0
Mov {R_cch} , #{R_lin} ;
Intse:
Pop Acc
Pop Psw
Reti
Ints3:
Cjne A , #&h0a , Ints4
Sjmp Intse
;0Ah -
Ints4:
Mov A , {R_cch}
;
Xch A , R0
Mov @R0 , {R_ch} ;
Xch A , R0
Mov A , #{R_lin+6}
Cjne A , {R_cch} , Ints5
Sjmp Intse
Ints5:
Inc {R_cch}
;
Sjmp Intse
Intst:
Setb {B_entx}
;
$end Asm
Return ' , Reti
'------------------------------ 2 ,
0:
Config Timer2 = Timer , Gate = Internal , Mode = 0
On Timer2 Timer_2_int
' 2
Load Timer2 , 10000
' 10 ( 65536-10000)
Enable Interrupts
'
Enable Timer2
' 2
'------------------------------' 2
Timer_2_int:
Reset T2con.7
' ,
Incr Rtime : Set B_10_mc
', 10
=============================================================================

14-3

===================================== Bascom-8051 ==
Return
'------------------------------ , , PCA 87C51FA.
,
, :
' 8051fa.dat !!!
On Pca Pca_int
' PCA
Cmod = &h01
' PCA
Enable Interrupts
'
Ch = &hD8 : Cl = &hF0
' 10 ( 12 )
Ccon.6 = 1
'
'------------------------------' PCA
Pca_int:
Reset Ccon.7
' ,
Ch = &hD8 : Cl = &hF0
' 10
Incr Rtime : Set B_10_mc
', 10
Return
'------------------------------
( ).
.
Bascom
If Bn = 1 Then
' 1
Reset Bn : Goto Mf '
End If
If Rn = 0 Then Goto Mf '?
End If
Rb = High (Rw) 'Rw .

, , R_Long.
,
:
Tmpw = Loww(R_Long) : Acc = Hi(Tmpw)


Jbc {Bn} , Mf
Mov A , {Rn}
Jz Mf
Mov {Rb} , {Rw + 1}
Mov {R_long + 2} , #&hf0 ;
Mov A , {R_long + 1}

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

14-4

===================================== Bascom-8051 ==
15.
Bascom-8051, ,
()
. Bascom-8051
. , , ,
.

. Bascom :
( = ), ( <> ), ( < ), ( > ), ( <=
) (>=). , ,
,
. .
0 1 .
Bascom -, - ,
.
.
, ,
. ,
, GOTO.
RETURN ( RET) IFEND IF , ..
.
'--------------------------------'
'--------------------------------Dim Bt1 As Bit , Bt2 As Bit , Bd As Byte , Wd As Word , Ld As Long
Dim Sd1 As Single , Sd2 As Single
Dim Temp As String * 16 , Tmp1 As String * 16
M1:
Input Sd1 : Sd2 = 2.345
If Sd1 < Sd2 Then
' .
Print "ok" : Goto M2
End If
Print "no"
M2:
Input Temp : Input Tmp1
'
If Temp = Tmp1 Then
Print "equ" : Goto M3 ' -
Elseif Temp = "stop" Then
Goto Mend
' "stop" -
End If
Print "no"
M3:
'
Input Bd : Input Wd : Input Ld '
If Bd = &H0A Then
'
Print "=" : Goto M4
Else
' 10,
If Wd >= 1000 Then ' 1000?
Print ">>" : Goto M4
' -
Elseif Ld <= 1000000 Then ' -
Print "<<<<"
' 1000000
End If
End If
M4:
'
Bt1 = 0 : Bt2 = 1
If Bt1 = Bt1 Then
Print "ok"
End If
Goto M1
Mend:
End
=============================================================================

15-1

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

.
- .

:
If Wd >= 1000 Then Goto M4
:
If Wd >= 1000 Then

Print ">>" Else Print "<<"

' 1000000

,
.
, . .
Bascom 2.xx .
:
Dim X As Byte
X = 6
If P2.X=1 Then
P2.X = 0
End If

'X = 0 7
'
'

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

15-2

===================================== Bascom-8051 ==
16.
Bascom
.
, , .
, ,
.
,
. ,
. ,
, ,
:
) , (). ,
, , ,
-.
- ( );
) , ();
) (
, , );
) , ,
. ,
( 7Fh) ;
) .
,
. ( ),
() .
. ,
. , , ,
() ,
. ()
;
) .
( ): 16 2 , 20 2, 20 4,
16 1, 24 2, 40 4. , , (
). , ,
.
( )
.
, (
);
) .
, ,
( ), 32
8- , (
);
) ( )
.
, , , ,
.
.
:
) , ,
. ,
. ,

, ( ).
,
. -
( , ).
5-10 ( ),
;
=============================================================================

16-1

===================================== Bascom-8051 ==
) . - ,
. -
( ), (
), , ,
( ). -
40 , ,
.
,
.
'-------------------------------------------------------------'
' ,
' - ,
' .
' 0 24 ( ).
' ,
' Rang, .
' ( 2 )
'
'
XXX: XXXXXX XX
' _______^
^ ^
^
' . _| |
|
' ____________________|
|
' ______________________|
'
'-------------------------------------------------------------$large
'
Dim B_nd As Bit
' " "
Dim B_tim As Bit
' " 10 "
Dim Cnt As Byte
'
Dim Tmp As Byte
'
Dim Rang As Byte
' !!!
Dim Fld As Single
' "" -
Dim Rfld As Single
'
Dim Temp As String * 10
' .
'!!! Temp .
'-------------------------------------------------------------'
'-------------------------------------------------------------Config Lcd = 16 * 2
'
Config Lcdpin, Db4=P1.4, Db5=P1.5, Db6=P1.6, Db7=P1.7, E=P3.2, Rs=P3.4
' P3.3
'-------------------------------------------------------------Config Timer0 = Timer , Gate = Internal , Mode = 1 : Start Timer0
On Timer0 Timer_0_int Nosave
'
Enable Interrupts
'
Enable Timer0
' 0
'!!! -------------------------------------Start Timer0 : Cnt = 100 : Rang = 0 : B_nd = 1 : B_tim = 1
Deflcdchar 1,228,228,234,234,241,241,255,224
'
Deflcdchar 2,238,241,241,241,234,234,251,224
'
Cls
'
Cursor Off
'
Lcd " Multimeter"
'
Wait 1
Mc:
Do
'
If B_nd = 1 Then
' 2
Reset B_nd : Goto Disp
End If
If B_tim = 1 Then
' 10
Reset B_tim : Decr Cnt
=============================================================================

16-2

===================================== Bascom-8051 ==
If Cnt = 0 Then
Set B_nd : Cnt = 200
Fld = Lookup(rang , _tab_mes) : Incr Rang
If Rang = 25 Then
Rang = 0
End If
End If
End If
Loop
'-------------------------------------------------------------'
Disp:
Fld = Lookup(rang , _tab_mes) '
Rfld = Lookup(rang , _tab_zc) '
Rfld = Rfld * Fld
'
Cls
' LCD
Gosub Lcd_attr1
'
Tmp = Lookup(rang , _tab_polar)' ?
If Tmp = 0 Then
' , . = 0
$asm
Anl {rfld + 3} , #&H7f ;
$end Asm
Locate 1 , 7
'
Goto Lcd_fp
'
End If
'
Locate 1 , 6
'
If Rfld < 0 Then
' ?
Goto Lcd_fn
' -
End If
Lcd "+"
' - "+"
Lcd_fp:
' . ,
' (
'
On Rang Gosub F4 , F2 , F3 , F4 , F5 , F4 , F2 , F3 , _
F4 , F5 , F4 , F2 , F3 , F4 , F2 , F4 , _
F2 , F3 , F4 , F2 , F4 , F2 , F3 , F4 , F2
Goto Lcd_dat
Lcd_fn:
' . ,
' ( )
On Rang Gosub M4 , M2 , M3 , M4 , M5 , M4 , M2 , M3 , _
M4 , M5 , M4 , M2 , M3 , M4 , M2 , M4 , _
M2 , M3 , M4 , M2 , M4 , M2 , M3 , M4 , M2
'
Temp = Mid(temp , 2 , 6 ) : Lcd "-"
Lcd_dat:
' Bascom:
' . .
'
Tmp = Len(temp)
If Tmp = 5 Then
' = 5 -
Lcd "0"
'
Goto Lcd_od
End If
If Tmp = 4 Then
' = 4 -
Lcd "00"
'
Goto Lcd_od
End If
If Tmp = 3 Then
' = 3 -
Lcd "000"
'
End If
=============================================================================

16-3

===================================== Bascom-8051 ==
Lcd_od:
Lcd Temp
'
Gosub Lcd_attr2
'
Goto Mc
'-------------------------------------------------------------' 0
Timer_0_int:
$asm
Mov Th0 , #&HD8
Mov Tl0 , #&HFD
;. . 10
$end Asm
Set B_tim
' 10
Return
'-------------------------------------------------------------'
Lcd_attr1:
Temp = Lookupstr(rang , _tab_att1)
'
Locate 1 , 1 : Lcd Temp : Lcd ":"
'
Return
'-------------------------------------------------------------'
Lcd_attr2:
Temp = Lookupstr(rang , _tab_att2)
'
Locate 1 , 13 : Lcd Temp
'
Return
'-------------------------------------------------------------'
'DCV: 000.00 mV 0.0000 V 00.000 V 000.00 V 0000.0 V
'ACV: 000.00 mV 0.0000 V
00.000 V
000.00 V
0000.0 V
'Ohm: 000.00 W
0.0000 kW 00.000 kW 000.00 kW 0.0000 MW
'DCI: 000.00 uA 0.0000 mA 00.000 mA 000.00 mA 0.0000 A
'ACI: 000.00 uA 0.0000 mA 00.000 mA 000.00 mA 0.0000 A
'-------------------------------------------------------------'
F2:
Temp = Fusing(rfld , #.####) : Return
F3:
Temp = Fusing(rfld , ##.###) : Return
F4:
Temp = Fusing(rfld , ###.##) : Return
F5:
Temp = Fusing(rfld , ####.#) : Return
'
' .
M2:
Temp = Fusing(rfld , ##.####) : Return
M3:
Temp = Fusing(rfld , ###.###) : Return
M4:
Temp = Fusing(rfld , ####.##) : Return
M5:
Temp = Fusing(rfld , #####.#) : Return
'-------------------------------------------------------------' -
_tab_att1:
Data "DCV" , "DCV" , "DCV" , "DCV" , "DCV"
Data "ACV" , "ACV" , "ACV" , "ACV" , "ACV"
Data "Ohm" , "Ohm" , "Ohm" , "Ohm" , "Ohm"
Data "DCI" , "DCI" , "DCI" , "DCI" , "DCI"
Data "ACI" , "ACI" , "ACI" , "ACI" , "ACI"
'-------------------------------------------------------------' : 0 - , 1 -
_tab_polar:
=============================================================================

16-4

===================================== Bascom-8051 ==
Data 1 , 1 , 1 , 1 , 1
Data 0 , 0 , 0 , 0 , 0
Data 0 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1
Data 0 , 0 , 0 , 0 , 0
'-------------------------------------------------------------' -
_tab_att2:
Data " mV" , " V" , " V" , " V" , " V"
Data " mV" , " V" , " V" , " V" , " V"
'
' : " W", " kW", " kW"
Data &H20 , &H20 , 2 , 0 , &H20 , 107 , 2 , 0 , &H20 , 107 , 2 , 0
' : " kW", " MW". W - ( 2)
Data &H20 , 107 , 2 , 0 , &H20 , 77 , 2 , 0
Data " uA" , " mA" , " mA" , " mA" , " A"
Data " uA" , " mA" , " mA" , " mA" , " A"
'-------------------------------------------------------------' ,
' .
_tab_zc:
Data 1000! , 1! , 1! , 1! , 1!
'
Data 1000! , 1! , 1! , 1! , 1!
'
Data 1000! , 1! , 1! , 1! , 0.001!
'
Data 1000! , 1! , 1! , 1! , 0.001!
'
Data 1000! , 1! , 1! , 1! , 0.001!
'
'-------------------------------------------------------------'
_tab_mes:
Data 0.001! , -1.9999! , -1.999! , 199.99! , 1999.9! 'DCV:
Data 0.001! , 0.0123! , 10.000! , 100.00! , 1000.0!
'ACV:
Data 0.09999! , 1.9999! , 19.9! , 199.99! , 1999.9!
'Ohm:
Data 0.20000! , -2.0000! , -20.0! , -19.00! , 20.0!
'DCI:
Data 0.12345! , 1.2345! , 12.345! , 123.45! , 1234.5! 'ACI:
'------------------------------------------------------------- ( COM- ) ,
.
,
, . 0.000012 %,
. ( )
, , ..
. , , , INPUT
Single, . , 100
, 99.999993. ,
, , , . ,
, . , ,
, 100 , 99. ,
.
. ,
, 100 0.5. ,
, , .
, .
,
( ).
, ,
. ,
.
Dim R_fld As Single
Dim Temp As String * 16
R_fld = -345.678
Locate 1 , 6

'
'
'

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

16-5

===================================== Bascom-8051 ==
If R_fld < 0 Then
' ?
Goto Lcd_fn
' -
End If
': R_fld : +xxx.xx
R_fld = R_fld + 1000.005 '
Temp = Str(r_fld)
'
Temp = Mid(temp , 2 , 6) ' , 6
Lcd "+" ; Temp
'
Goto Lcd_e
Lcd_fn:
': R_fld : -xxx.xx
R_fld = R_fld - 1000.005 '
$asm
Anl {r_fld + 3} , #&H7f ;
$end Asm
Temp = Str(r_fld) : Temp = Mid(temp , 2 , 6) : Lcd "-" ; Temp
Lcd_e:
End
Fusing.
.
. ,
, .
.
$large
Dim X As Single , Y As Single , Result As Single
Dim I As Integer , Buf As String * 16
X = 142 : Y = 3.157
Print "X+Y=" : Result = X + Y
'
Print Result
' "145.69977"
Buf = Fusing(result , 000000.#)
' c
Print Buf
' "00145.2"
Buf = Fusing(result , 0000.&&)
'
Print Buf
' "145.15"
X = -12 : Y = 3.157
Print "X+Y=" : Result = X + Y
'
Print Result
' "-8.8430004"
Buf = Fusing(result , 000000.#)
' c
Print Buf
' "000-8.8"
Buf = Fusing(result , ####.&&)
',
Print Buf
' "-8.84"
End

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

16-6

===================================== Bascom-8051 ==
17.

. , , (
) , .
8051 ,
, . ,
,
.
(), () .
,
SBUF- ( ) SBUF- (
). ,
. ,
.

, , COM-
.
,
. ,
, ,
.
- , , .

.
-
. , , .
, , , , ,
. , ,
, , ,
. .
, (
).
0Dh ( - ) 0Ah ( - ).
, . . ,
, .

(
). , ()
, , Bascom8051.
, ,
( ),
( ) , ,
.
, -
, .

,
. ,

, ,
. , Bascom,
, . ,
.
,
.
( ) : ,
, ,
, , .
( ) ,
=============================================================================

17-1

===================================== Bascom-8051 ==
.
, ( )
, .
-,
. , ,
3 .
'---------------------------------------------' -
' .
'---------------------------------------------' , :
'"R" -
'"Lxxxxx" -
'"Sx" -
' : "SxLxxxxxTxxx"
'
_____^ ^
^
'
_______|
|
'
_____________|
'---------------------------------------------$large
'
Dim B_nd As Bit
' " "
Dim B_sd As Bit
' " "
Dim B_entx As Bit
' " "
Ri Alias Scon.0
' RI
Ti Alias Scon.1
' TI
Dim Rang As Byte
'
Dim Tmp As Byte
'
Dim Cnt As Byte
'
Dim R_ch As Byte
'
Dim R_bui As Byte
'
Dim R_buo As Byte
'
Dim Udac As Integer
'
Dim Temp As String * 6
'
Dim Inp_buf As String * 10
'
Dim Out_buf As String * 32
'
'--------------------' AD766
B_datu Alias P1.0 : B_clku Alias P1.1 : B_ldu Alias P1.2
'---------------------------------------------Config Timer0 = Timer , Gate = Internal , Mode = 1 : Start Timer0
'--------------------'TIMER2 16-. . . UART
Config Timer2 = Timer , Gate = Internal , Mode = 2
$baud = 9600
' 9.6
$crystal = 12000000
' 12
' ,
Scon = &H52
'
Rcap2h = &HFF : Rcap2l = &HD9 : Start Timer2 ',
'--------------------On Timer0 Timer_0_int Nosave
'
On Serial Ser_int Nosave
'
Enable Interrupts
'
Enable Timer0
' 0
'!!! -------------------------------------B_entx = 0 : Reset Ri : Reset Ti
Enable Serial
' .
Out_buf = "Test_com" + Chr(13) + Chr(10)
R_buo = Varptr(out_buf)
'
Tmp = Peek(r_buo) : Sbuf = Tmp '
Incr R_buo
'
'! !
Waitms 100
'
=============================================================================

17-2

===================================== Bascom-8051 ==
'
'
B_entx = 1 : B_nd = 0 : B_sd = 1 : Cnt = 0 : Rang = 0 : Udac = 0
R_bui = Varptr(inp_buf)
'
Mc:
Do
'
If B_nd = 1 Then
'
Reset B_nd : Goto N_dat
End If
If B_sd = 1 Then
'
Goto S_dat
End If
'Idle
Loop
'-----------------------------------------'
N_dat:
Temp = Left(inp_buf , 1) '
'----If Temp = "R" Then
' ?
Set B_sd : Goto Mc
' -
End If
'----If Temp = "L" Then
' ?
Temp = Mid(inp_buf , 2 , 5)
Udac = Val(temp)
'.
Gosub Sload_766
'
Goto Mc
' -
End If
'----If Temp = "S" Then
' ?
Temp = Mid(inp_buf , 2 , 1)
Rang = Val(temp)
'
P2 = Rang
' P2
Goto Mc
' -
End If
Goto Mc
'-----------------------------------------'
S_dat:
If B_entx = 1 Then
',
Reset B_sd
' , .
Reset B_entx
' . . .
' : "SxLxxxxxTxxx,,"
Out_buf="S"+Str(rang)+"L"+Str(udac)+"T"+Str(cnt)+Chr(13)+Chr(10)
R_buo = Varptr(out_buf)
'
Tmp = Peek(r_buo) : Sbuf = Tmp '
'
'
Incr R_buo

End If
Goto Mc
'--------------------' AD766, AD1851
Sload_766:
' Udac 0 (. , -_-)
Shiftout B_datu , B_clku , Udac , 0
Reset B_ldu : Set B_ldu
'
Return
'---------------------------------------------' 0
Timer_0_int:
$asm
=============================================================================

17-3

===================================== Bascom-8051 ==
Mov Th0 , #&HD8
Mov Tl0 , #&HFD
;. . 10
$end Asm
Incr Cnt
'
Return
'---------------------------------------------'
Ser_int:
$asm
Jbc {Ri} , Intsr ;
Jbc {Ti} , Intst ;
$end Asm
Return
$asm
;
Intsr:
Push Psw
Push Acc
Mov {R_ch} , Sbuf ;
Mov A , {R_ch}
Ints1:
Cjne A , #&h0d , Ints3
Setb {B_nd}
;0Dh -
Ints2:
Mov A , {R_bui}
;
Xch A , R0
; R0
Mov @R0 , #&h00
;
Xch A , R0
; R0
Mov {R_bui} , #{inp_buf} ;
Intse:
Pop Acc
Pop Psw
Reti
Ints3:
Cjne A , #&h0a , Ints4
Sjmp Intse
;0Ah -
Ints4:
Mov A , #{inp_buf + 10}
Cjne A , {R_bui} , Ints5
Sjmp Intse
Ints5:
Mov A , {R_bui}
;
Xch A , R0
Mov @R0 , {R_ch} ;
Xch A , R0
Inc {R_bui}
; -
Sjmp Intse
;
Intst:
Push Psw
Push Acc
Mov A , {R_buo}
;
Xch A , R0
Mov {R_ch} , @R0
Xch A , R0
Mov A , #{out_buf + 10} ;
Cjne A , {R_bui} , Ints6 ;
Sjmp Ints7
Ints6:
Mov A , {R_ch}
; 0?
Jz ints7
Mov Sbuf , {R_ch}
Inc {R_buo}
;
=============================================================================

17-4

===================================== Bascom-8051 ==
Ints7:

Sjmp Intse
Setb {B_entx}
Sjmp Intse

;
; " "

$end Asm
'----------------------------------------- ,
, ,
Print.
. , ,
B_entx, R_bui Out_buf. :
Enable Serial
Print "Test_com"
'

' .

:
'-----------------------------------------'
S_dat:
' , :
'
"SxLxxxxxTxxx,,"
Reset B_sd : Print "S" ; Rang ; "L" ; Udac ; "T" ; Cnt
Goto Mc
.
. Ti
Print.
.
'-----------------------------------------'
Ser_int:
$asm
Jbc {Ri} , Intsr
Reti
Intsr:
Push Psw
;
Push Acc
Mov {R_ch} , Sbuf ;
Mov A , {R_ch}
;
Add A , #&h9f
; 'a'? ( )
Jnc Ints0
;(.not.'a'+1)
Mov A , {R_ch}
; 'z'? ( )
Add A , #&h85
;(.not.'z')
Jc Ints0
Mov A , {R_ch}
;
Anl A , #&hdf
Mov {R_ch} , A
Sjmp Ints1
Ints0:
Mov A , {R_ch}
Ints1:
Cjne A , #&h0d , Ints3
Setb {B_nd}
;0Dh -
Ints2:
Mov A , {R_bui}
;
Xch A , R0
; R0
Mov @R0 , #&h00
;
Xch A , R0
; R0
Mov {R_bui} , #{inp_buf} ;
Intse:
Pop Acc
Pop Psw
=============================================================================

17-5

===================================== Bascom-8051 ==
Ints3:
Ints4:

Ints5:

Reti
Cjne A , #&h0a , Ints4
Sjmp Intse
;0Ah -
Mov A , #{inp_buf + 10}
Cjne A , {R_bui} , Ints5
Sjmp Intse
Mov A , {R_bui}
Xch A , R0
Mov @R0 , {R_ch}
Xch A , R0
Inc {R_bui}
Sjmp Intse

$end Asm
'----------------------------------------- , .
, HEX-.
. ,
, ,
.
'-------------------------------------------------------------' ,
' .
'-------------------------------------------------------------$large
'
Dim Tmp As Byte
'
Dim R_ch As Byte
'
Dim L_adr As Word
'
Dim H_adr As Word
'
Dim S_adr As Word
'
Dim Big_buf As String * 64
' -
'--------------------'TIMER2 16-. . . UART
Config Timer2 = Timer , Gate = Internal , Mode = 2
$baud = 9600
' 9.6
$crystal = 12000000
' 12
'--------------------Print "Monitor"
'
Goto Begin
'
_error:
'
Gosub Dis_err
'
Begin:
' "BC>"
Gosub _promt
R_ch = Waitkey
'
If R_ch = &H0D Then
' ?
Goto Ignore
' -
End If
Beg1:
Printbin R_ch
' !
Select Case R_ch
'
Case &H44 : Goto Dump_mem
' D?
Case &H4C : Goto List_mem
' L?
Case &H48 : Goto Help
' H?
Case Else : Goto _error
'
End Select
' ! - .
' ,
'
=============================================================================

17-6

===================================== Bascom-8051 ==
Ignore:
Waitms 50
' 50
R_ch = Inkey
'
If R_ch = 0 Then
' ,
Goto _error
'
Elseif R_ch = &H0A Then
'
Goto _error
' ,
Elseif R_ch = &H0D Then
'
Goto Ignore
'
End If
' -
Gosub Dis_err
'
Gosub _promt
'
Goto Beg1
'
'-------------------------------------------------------------' HEX-
Dump_mem:
Print " - Damp of memory"
'
Gosub Inp_ladr : Gosub Inp_hadr
' .
S_adr = L_adr
'
D_mem0:
Big_buf = Hex(s_adr) + " "
'
Goto D_mem2
'
D_mem1:
Tmp = Low(s_adr)
': ?
If Tmp = 0 Then
' -
Gosub E_cnk
': ?
If R_ch = &H1B Then
' ESC,
Goto Begin
'
End If
End If
Tmp = Tmp And &H0F
':
If Tmp = 0 Then
' 0?
Print Big_buf
' -
Goto D_mem0
'
End If
D_mem2:
Tmp = Cpeek(s_adr)
'
Big_buf = Big_buf + " " + Hex(tmp)
'
Incr S_adr
'
If S_adr > H_adr Then
' ?
Goto D_mem3
' -
End If
Goto D_mem1
' -
D_mem3:
Print Big_buf
'
Goto Begin
'-------------------------------------------------------------'
List_mem:
Print " - List of memory"
'
Gosub Inp_ladr : Gosub Inp_hadr
'
S_adr = L_adr
'
L_mem0:
Big_buf = Hex(s_adr) + " "
'
Goto L_mem2
'
L_mem1:
Tmp = Low(s_adr)
': ?
If Tmp = 0 Then
' -
Gosub E_cnk
': ?
If R_ch = &H1B Then
' ESC,
Goto Begin
End If
End If
=============================================================================

17-7

===================================== Bascom-8051 ==
Tmp = Tmp And &H0F
':
If Tmp = 0 Then
' 0
Print Big_buf
' -
Goto L_mem0
'
End If
L_mem2:
Tmp = Cpeek(s_adr)
'
If Tmp > 127 Then
'
Tmp = &H2E
' 7fh
Elseif Tmp < &H20 Then
' 20h
Tmp = &H2E
' Elseif
End If
Big_buf = Big_buf + Chr(tmp)
'
Incr S_adr
'
If S_adr > H_adr Then
':
Goto L_mem3
' -
End If
Goto L_mem1
' -
L_mem3:
Print Big_buf
'
Goto Begin
'-------------------------------------------------------------'
Help:
Print ""
Print " ------ MONITOR ------ "
Print "| D - Display memory |"
Print "| L - List memory
|"
Print "| H - This help
|"
Print " --------------------- "
Print ""
Goto Begin
'-------------------------------------------------------------': ,
'-------------------'
Inp_ladr:
Inputhex "Begin=" , L_adr : Return
'-------------------'
Inp_hadr:
Inputhex "End=" , H_adr : Return
'-------------------': ?
E_cnk:
Print "Exit - Esc, Continue - any key"
R_ch = Waitkey : Return
'
'-------------------'
Dis_err:
Print "" : Print "Error" : Return
'-------------------' "BC>"
_promt:
Printbin &H42 ; &H43 ; &H3E : Return
'
'-------------------------------------------------------------End
,
. ,
( ). ,
, , ,
Printbin.
=============================================================================

17-8

===================================== Bascom-8051 ==
,
. ,
LCD-.

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

17-9

===================================== Bascom-8051 ==
18.
, ,
- (), - ().
.
, ,
- .
, ,
.
, ,
. , ,
.
:
) ;
) ;
) ;
)

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

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

. ,
.
. ,
, . ,
, , ,
, , () .
, .
() .
8051 ,
-
. ,
.
, ( ) ( )
Bascom . SHIFTIN,
=============================================================================

18-1

===================================== Bascom-8051 ==
SHIFTOUT, SPIIN, SPIOUT. , ,
, ( )
. . ,
, ,
. , ,
, ,
( ) .
- , ,
.
, .. Bascom (50 - 70 %
). , ,
.
SHIFTOUT SPIOUT.
'-------------------------------------------------------------' AD8400 -2,-3
'-------------------------------------------------------------Dim Badr As Byte
'
Dim Value As Byte
'
Dim Wtmp As Byte
'
Pdin Alias P1.0
'
Pcs Alias P1.2
Pclk Alias P1.3
'--------------------Config Spi = Soft , Din = P1.0 , Dout = P1.1 , Cs = P1.2 , Clk = P1.3
'--------------------'TIMER2 16-. . . UART
Config Timer2 = Timer , Gate = Internal , Mode = 2
$baud = 9600
' 9.6
$crystal = 12000000
' 12
'--------------------Set Pcs : Reset Pclk
'
Mc:
Input "Enter number of DAC" , Badr
'
Input "Enter code for DAC" , Value
'
Value = Value And &B00000011
'
Print "DAC=" ; Badr ; " " ; "Code=" ; Value
'
'--------------------' _

_
' |__________________________________________| CS
' ___ ____ ____ ____ ____ ____ ____ ____ ____ __
' ___X____X____X____X____X____X____X____X____X__ Data
'
_
_
_
_
_
_
_
_
' ____| |__| |__| |__| |__| |__| |__| |__| |____ Clk
'--------------------'
Gosub Ser_out
'
Wtmp = Makeint(value , Badr) ' : +
'
Spiout Wtmp , 2
' :
Goto Mc
'--------------------'
Ser_out:
Acc = Badr
'
Pcs = 0
Pdin = Acc.1 : Set Pclk : Reset Pclk '
Pdin = Acc.0 : Set Pclk : Reset Pclk '
' Shiftout Pdin , Pclk , Badr , 1
' 8-
Shiftout Pdin , Pclk , Value , 1
' ( - )
Pcs = 1
Return
'-----------------------------------------=============================================================================

18-2

===================================== Bascom-8051 ==
12-
. SHIFTIN.
, ,
.
'-------------------------------------------------------------'
AD7893-3 ( +-2.5 )
'-------------------------------------------------------------$large
' 2
Dim B_dat As Bit
' " "
Dim Mes As Byte
'
'--------------------Dim Temp As Integer
'
Dim R_bd As Integer
'16-.
'--------------------Dim R_fld As Single
'
'--------------------B_acnv Alias P1.0
'
B_aclk Alias P1.1
B_adat Alias P1.2
'-------------------------------------------------------------'TIMER0 16-.
Config Timer0 = Timer , Gate = Internal , Mode = 1 : Start Timer0
'--------------------'TIMER2 16-. . . UART
Config Timer2 = Timer , Gate = Internal , Mode = 2
$baud = 9600
' 9.6
$crystal = 12000000
' 12
'--------------------'
On Timer0 Timer_0_int Nosave
'
Enable Interrupts
'
Enable Timer0
' 0
'-----------------------------------------Set B_acnv : Reset B_aclk
Mes = 16
'
'-----------------------------------------Mc:
Do
If B_dat = 1 Then
' ?
Reset B_dat
'
R_bd = R_bd + Temp
Decr Mes
If Mes = 0 Then
R_fld = R_bd : R_bd = 0 '
R_fld = R_fld * 0.0000763
'
Print R_fld : Mes = 16 ' .
End If
End If
Loop
'-----------------------------------------' 0
Timer_0_int:
Th0 = &HD8 : Tl0 = &HFD 'Ffffh-10000 = D8fdh - . 10
Set B_dat
Return
'-----------------------------------------'
Convert:
Reset B_acnv : Reset B_acnv : Set B_acnv
'
' 6
'--------------------=============================================================================

18-3

===================================== Bascom-8051 ==
' _
__
' |________________________________________|
CS
' ___ ____ ____ ____ ____ ____ ____ ____ ____ _
' ___X____X____X____X____X____X____X____X____X_ Data
'
__
__
__
__
__
__
__
__
' __| |_| |_| |_| |_| |_| |_| |_| |____ Clk
'--------------------Shiftin B_adat , B_aclk , Temp , 1
' 1
Return
'---------------------------------------------
. ,
, , ( )
, . , , ,
, 3.5-
10000 20000 . , ,
10.00 020.0 . ,
.
. ,
. Bascom
( ) , ,
, .
, ( )
Integer Long, () ,
( AD7711A) ROTATE.
,
, .

.
(
). ,
, .
, . 24 , .
( ).
.
(, .. ) 20
, 20 . ,
,
. , 320 (3 ) .

, . ,
.
'-------------------------------------------------------------'
24-. AD7711A (+-2.5 )
'-------------------------------------------------------------$large
' 2
Dim B_dat As Bit
' " "
Dim Mes As Byte
'
Dim R_ch As Byte
'
'--------------------Dim Temp As Long
'
Dim R_bd As Long
'32-.
'--------------------Dim R_fld As Single
'
Dim R_zero As Single
'
Dim R_scal As Single
'
'-------------------------------------------------------------'TIMER0 16-.
Config Timer0 = Timer , Gate = Internal , Mode = 1 : Start Timer0
'--------------------=============================================================================

18-4

===================================== Bascom-8051 ==
'TIMER2 16-. . . UART
Config Timer2 = Timer , Gate = Internal , Mode = 2
$baud = 9600
' 9.6
$crystal = 12000000
' 12
'--------------------On Int0 Int0_int Nosave
' INT0
Enable Interrupts
'
'-----------------------------------------Gosub Str_adc
'
Mes = 16
'
R_zero = 0
'
R_scal = 1
'
Print " - MONITOR FOR ADC AD7711A - "
Print " Calb zero - Z @ Uinp = 0 V "
Print " Calb scale - S @ Uinp = + 2 V"
Enable Int0
' 0
'-----------------------------------------Mc:
Do
If B_dat = 1 Then
' ?
Reset B_dat
'
Rotate R_bd , Left , 4
' 16
' , 16- 32-.
R_fld = R_bd : R_bd = 0
'
R_fld = R_fld * 0.00000000116415322
'
R_ch = Inkey
If R_ch <> 0 Then
' -
Gosub Makeclb
'
End If
Gosub Calbr
'
Print R_fld
'
End If
Loop
'-----------------------------------------' 0
Int0_int:
$asm
Push Psw
Push Acc
$end Asm
Psw.3 = 1 : Psw.4 = 1 ' - Bascom
Gosub Rd_adc
$asm
djnz {Mes} , Int0_1
;
Setb {B_dat}
; Mes=0,
mov {Mes} , #16
;
Int0_1:
Pop Acc
Pop Psw
$end Asm
Return
'---------------------------------------------'
- AD7711A
'---------------------------------------------' AD7711
'
'
--------- MD2 0 . 0 .
'
-------- MD1 0 . 0 .
'
------- MD0 0
1
'
------ G2 0
0
0
0
1
1
1
1
'
----- G1 0=1 0=2 1=4 1=8 0=16 0=32 1=64 1=128
'
---- G0 0
1
0
1
0
1
0
1
'
--- CH 0-AIN1, 1-AIN2
=============================================================================

18-5

===================================== Bascom-8051 ==
'
-- PD 0-, 1-
'
--------- WL : 0-16 , 1-24
'
-------- IO . RTD 0-, 1-
'
------- BO . BO 0-, 1-
'
------ B/U : 0-, 1-.
'
------------- FS11=0
'
------------ FS10
5 :
'
----------- FS9

50 FS=135 (03h)
'
---------- FS8

(f/512)
'
--------- FS7
- FS = ---------------------'
-------- FS6


'
------- FS5

'
------ FS4
- FS -
'
----- FS3

19 2000
'
---- FS2

'
--- FS1

'
-- FS0 --'C_M2B equ 00000000b
' :
'C_M1B equ
10000000b
' 50 , G=1, +-2.5
'C_M0B equ
11000011b ' CH1, 24 ,
'--------'C_2B equ 00100000b
' :
'C_1B equ
10000000b
' 50 , G=1, +-2.5
'C_0B equ
11000011b ' CH1, 24 ,
'---------------------------------------------'
Dim C_m2b As Const &B00000000
Dim C_m1b As Const &B10000000
Dim C_m0b As Const &B11000011
Dim C_c2b As Const &B00100000
Dim C_c1b As Const &B10000000
Dim C_c0b As Const &B11000011
'---------------------------------------------' ,
B_aa0 Alias P1.0
' : 0-. 1-
B_atfs Alias P3.5
'
B_arfs Alias P1.3
'
B_aclk Alias P1.1
'
B_adat Alias P1.2
'
B_ardy Alias P1.4
'
'---------------------------------------------' 8
Wrb_adc:
$asm
Mov
R0 , #8
Wrb_adc1:
Rlc
A
; SDATA
Mov
{B_adat} , C
Setb {B_aclk}
; - SCLK "1"
Clr
{B_aclk}
;SCLK "0"
Djnz R0 , Wrb_adc1
$end Asm
Return
'---------------------------------------------' 8
Rdb_adc:
$asm
Mov
R0 , #8
Rdb_adc1:
Setb {b_aclk}
; - SCLK "1"
Mov
c , {B_adat}
Clr
{B_aclk}
;SCLK "0"
Rlc
A
; Acc
=============================================================================

18-6

===================================== Bascom-8051 ==
$end Asm

Djnz

R0 , Rdb_adc1

Return
'---------------------------------------------' :
' -
'--------Str_adc:
Reset B_aclk : Reset B_aa0 : Reset B_atfs 'SCLK=0, A0=0,
Acc = C_c2b : Gosub Wrb_adc '
Acc = C_c1b : Gosub Wrb_adc
Acc = C_c0b : Gosub Wrb_adc
Set B_atfs : Wait 2
' 2
Reset B_atfs
'
Acc = C_m2b : Gosub Wrb_adc '
Acc = C_m1b : Gosub Wrb_adc
Acc = C_m0b : Gosub Wrb_adc
Set B_atfs : Set B_adat
'
Return
'---------------------------------------------'
' -
'
Rd_adc:
B_adat = 1 : B_aclk = 0
'
B_aa0 = 1 : B_arfs = 0
'
'--------Mov R1 , #{Temp + 3}
Mov @R1 , #0
Dec R1
Gosub Rdb_adc
Mov @r1 , A
;
Dec R1
Gosub Rdb_adc
Mov @r1 , A
;
Dec R1
Gosub Rdb_adc
Mov @r1 , A
;
'--------B_arfs = 1
'
'
$asm
Mov R0 , #{R_bd} ;
Mov R1 , #{Temp} ;
Mov R2 , #4
;
Clr C
Rd_adc1:
Mov A , @R1
;
Addc A , @R0
Mov @R0 , A
Inc R0
Inc R1
Djnz R2 , Rd_adc1
$end Asm
Return
'--------'
Calbr:
R_fld = R_fld - R_zero
'
R_fld = R_fld * R_scal
'
Return
'--------'
=============================================================================

18-7

===================================== Bascom-8051 ==
Makeclb:
If R_ch = &H5B Then
' Z -
R_zero = R_fld
' -
End If
If R_ch = &H53 Then
' S -
R_fld = R_fld R_zero'
R_scal = 2 / R_fld
'
End If
R_ch = 0
Return
'------------------------------ - .
,
,
. ,
.
40.
'-------------------------------------------------------------'
AD9850
'
. = 60
'-------------------------------------------------------------Dim N_dat As Bit
' " "
N_inp Alias Scon.0
' " " (RI)
'--------------------Dim Temp As Byte
'
'--------------------Dim R_bd As Long
'32-.
'--------------------Dim R_frq As Single
'
Dim R_fld As Single
'
'--------------------'
B_data Alias P1.5 : B_clk Alias P1.3 : B_fqud Alias P1.4 : B_res Alias P1.7
'--------------------' TIMER2 16-. . . UART
Config Timer2 = Timer , Gate = Internal , Mode = 2
$baud = 9600
' 9.6
$crystal = 12000000
' 12
'--------------------'
Reset B_data : Reset B_clk : Reset B_fqud : Reset B_res
'--------------------'
Mc:
Do
If N_dat = 1 Then
' ?
N_dat = 0
' RI
Gosub Sload_9850
'
End If
If N_inp = 1 Then
'- ?
N_inp = 0
'
Input "Enter value of frequency [kHz] f= " , R_frq '
Print R_frq
'
' :
R_fld = R_frq * 71582.788 ' 2^32 / Fclk = 4294967296 / 60000 kHz
R_bd = R_fld
'. 32-.
Printhex "Hex " ; R_bd
' hex
Set N_dat
'
End If
Loop
'-----------------------------------------=============================================================================

18-8

===================================== Bascom-8051 ==
'
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
'----------------------------------------- .
, -
. , ,
. ,
- ()
. , ,
(, ), .
, .
, , ,
. . -,
. -, ,
. , ,
. . ,
, ,
. ,
,
. (
), .
:
) ( ). ,
, , , ,
, ;
) ( ).
,
, .
,
, (U = 0).
,
, .
AD7711A, , .
, .
, (
, ).
, , ,
. ,
.
- , .
, (
).
,
. ,
, 3 - 5 .
, ,
. ,
. ( 14 16 ), .
,
. ,
( ), ,
, - .
=============================================================================

18-9

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

, .. ,
. ,
, , ,
( ). ,
.
. .
- ( )
, ,
() .
'-----------------------------------------------------------------------'

'

'-----------------------------------------------------------------------Dim B_stan As Bit
'
Dim Uav As Single
'
Dim R_an As Single
'
Dim Uc As Single
'
Dim Tmp As Single
'
Dim N_m As Const 0.9
'
Dim N_f As Const 0.3
' R_an
R_an = 1
B_stan = 0

'
'

'
Uav = Uav(1-1/N) + Uc/N -
'
Uav = Uav(1-n) + Uc*n
-
' (
' )
'
' : n
- (R_an)
'
Uc -
'
Uav -
' ,
' 1,
' 1.11 (1/N_m) (N_f). N_m N_f
' ,
', .
Comp_av:
If B_stan = 1 Then
' ?
Goto C_av2
' ?
End If
R_an = R_an * N_m
'
If R_an < N_f Then
' ?
Set B_stan
' -
End If
C_av2:
Tmp = 1 - R_an
'
Uav = Uav * Tmp
'
Tmp = Uc * R_an
'
Uav = Uav + Tmp
'
Return
Bascom ,
.
, , .

, .
Bascom (
). ,
(
). , , , , ..
=============================================================================

18-10

===================================== Bascom-8051 ==
.
:
) , .
,
, ;
) ,
;
)
;
) , ;
) .

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

18-11

===================================== Bascom-8051 ==
19. Microwire
Bascom ( 1.20) ,
Microwire. Microwire SPI
(DI , DO , CS , Clk ). ,
SPI . ,
Microwire SPI SPI .
Microwire 9306 9357,
.
Microwire ( 45)
.
Microwire 8- 16- .
ORG (16 ) (8 ).
.
AL ( ) Config Microwire ( 4).
.
Microwire :
) MWINIT , Microwire,
. , ;
) MWREAD Microwire.
, .
.
- ;
) MWWRITE Microwire.
. -
. 2-10
(. ), .. , ,
;
) MWWOPCODE Microwire.
, .
( ) () .
, ,
, .
, , :
Set Cs : Bitwait Dout Set : Reset Cs
, ,
16- 8- .
Microwire.
EEPROM , .
Bascom 9346 8-
, .
, .
(Mwrdyw),
, .
, 10 ,
EEPROM,
.

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

19-1

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

Mwwopcode &B100110000 , 9


( 9346 ORG=1)
Mwwopcode &B100000000 , 9


( 9346 ORG=1)
Mwread X , &B110 , 0 , 2

0 X (
)
( 9346 ORG=1)

Mwwrite X , &B101 , 0 , 2

X ( )
0
( 9346 ORG=1)


16-
_____________________________________
__|

|__ CS
_

____| |_| |_| |_| |_| |_| |_| |_| |_| |____ Clk
___
___ ___
___|
|___ ___|
|___ ___ ___ ___ ___ DI
SB OP1 OP2 1
1
0
0
0
0
_____________________________________
__|
|__ CS
_
_
_
_
_
_
_
_
_
____| |_| |_| |_| |_| |_| |_| |_| |_| |____ Clk
___
___|
|___ ___ ___ ___ ___ ___ ___ ___ ___ DI
SB OP1 OP2 0
0
0
0
0
0
_________________________________________________
__|
_
_
_
_
_
_
_
_
_
_
_
_
____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_
___ ___
___ ___ ___ ___ ___ ___
___|
|___X___X___X___X___X___X___\____________
SB OP1 OP2 A5 A4 A3 A2 A1 A0
0
0
0
0
0
0
___ ___ ___
-------------------------------------__X___X___X___X
0 D15 D14 D13
_________________________________________________
__|
_
_
_
_
_
_
_
_
_
_
_
_
____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_
___
___ ___ ___ ___ ___ ___ ___ ___ ___ ___
___|
|___|
X___X___X___X___X___X___X___X___X___X
SB OP1 OP2 A5 A4 A3 A2 A1 A0 D15 D14 D13
0
0
0
0
0
0

_ __________
|__ CS
_

_ __| |_| |____ Clk


_ _________ ___ DI
_ _ ___ ___
_ _X___X___X___
D1 D0
_ __________
|__
_
_
_ __| |_| |____
_ _ ___ ___
_ _X___X___X___
D1 D0

DO
CS
Clk
DI

8-
Mwwopcode &B1001100000,10


( 9346 ORG=0)

Mwwopcode &B1000000000,10


( 9346 ORG=0)

Mwread Y , &B110 , 0 , 1

0 Y
(1 )
( 9346 ORG=0)

Mwwrite Y , &B101 , 0 , 1

Y ( 1 )
0
( 9346 ORG=0)

________________________________________
__|

|__ CS
_

____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |____ Clk
___
___ ___
___|
|___ ___|
|___ ___ ___ ___ ___ ___ DI
SB OP1 OP2 1
1
0
0
0
0
0
________________________________________
__|

|__ CS
_

____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |____ Clk
___
___|
|___ ___ ___ ___ ___ ___ ___ ___ ___ ___ DI
SB OP1 OP2 0
0
0
0
0
0
0
_________________________________________________ _ __________
__|

|__ CS
_

____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_ _ __| |_| |____
___ ___
___ ___ ___ ___ ___ ___ ___
___|
|___X___X___X___X___X___X___X___\_________ _ ____________
SB OP1 OP2 A6 A5 A4 A3 A2 A1 A0
0
0
0
0
0
0
0
___ ___ _ _ ___ ___
-----------------------------------------__/___X___X _ _X___X___X___
0 D7
D6
D1 D0
_________________________________________________ _ __________
__|
|__
_
_
_
_
_
_
_
_
_
_
_
_
_
_
____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_ _ __| |_| |____
___
___ ___ ___ ___ ___ ___ ___ ___ ___ ___ _ _ ___ ___
___|
|___|
X___X___X___X___X___X___X___X___X___X _ _X___X___X___
SB OP1 OP2 A6 A5 A4 A3 A2 A1 A0 D7 D6
D1 D0
0
0
0
0
0
0
0

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

Clk
DI

DO
CS
Clk
DI

19-2

===================================== Bascom-8051 ==
'------------------------------------------------------------'
Microwire
'------------------------------------------------------------Dim Tmp1 As Byte , Tmp2 As Byte
Dim Tmp3 As Byte , Tmp4 As Byte , Tmpw As Word
Dim Tmp(20) As Word
'-------------------------------' 93C46 8-
Config Microwire = Pin , Cs = P1.0 , Din = P1.1 , Dout = P1.2 , _
Clock = P1.3 , Al = 7
Mw_cs Alias P1.0 : Mw_dout Alias P1.2 ' Cs Dout
'-------------------------------Mwinit
Mwwopcode &B1001100000 , 10 '
Mwwopcode &B1001000000 , 10 '
Gosub Mwrdyw
'
For Tmp1 = 1 To 20
'
Tmpw = Tmp1 : Tmpw = Tmpw * Tmpw
'
Tmp(tmp1) = Tmpw
Next
'
'-------------------------------Tmp2 = 0
' EEPROM
For Tmp1 = 1 To 20
'
Tmpw = Tmp(tmp1)
' EEPROM
Mwwrite Low(tmpw) , &B101 , Tmp2 , 1 : Incr Tmp2 : Gosub Mwrdyw
Mwwrite High(tmpw) , &B101 , Tmp2 , 1 : Incr Tmp2 : Gosub Mwrdyw
Next
'
'-------------------------------For Tmp1 = 1 To 20
'
Tmp(tmp1) = 0
Next
'-------------------------------Tmp2 = 0
' EEPROM
For Tmp1 = 1 To 20
'
Mwread Tmp3 , &B110 , Tmp2 , 1 : Incr Tmp2
'
Mwread Tmp4 , &B110 , Tmp2 , 1 : Incr Tmp2
Tmpw = Makeint(tmp4 , Tmp3) : Tmp(tmp1) = Tmpw '
Next
'
Mwwopcode &B1000000000 , 10 '
'-------------------------------/ Microwire
Mwrdyw:
$asm
Setb {mw_cs}
;
Mov A , #100
; 10
Mwrw1:
Mov B , #50
; 100
Mwrw2:
Djnz B , Mwrw2
Jb {mw_dout} , Mwrw3
;
Djnz A , Mwrw1
; 10
Mwrw3:
Clr {mw_cs}
;
$end Asm
Return
End

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

19-3

===================================== Bascom-8051 ==
20. I2C
, I2C, Bascom :
) , I2CSEND
I2CRECEIVE;
) I2CSTART, I2CSTOP, I2CRBYTE I2CWBYTE
I2C.
, , ,
, .. I2CSEND I2CRECEIVE .
, , ( ),
, , -, .
I2CSTART,
I2CSTOP, I2CRBYTE I2CWBYTE, ,
. ,
. EEPROM,
:
) ( I2C);
) .
( ) ( );
) .
I2CSEND I2CRECEIVE, .
, ,
Bascom. ,
.
I2CRBYTE I2CWBYTE, , .
,
( ). ,
B , I2.
, ,
, .

80C51GB. , ,
.
'------------------------------------------------------------' I2C EEPROM - 24c16 (2k*8)
' I2C
' , "!!!" ,
' 80C51GB
'------------------------------------------------------------' /
' /
' . . . . /
Declare Sub Write_eeprom(wadr As Word , Value As Byte)
Declare Sub Read_eeprom(wadr As Word , Value As Byte)
Declare Sub Wrb_24c01(badr As Byte , Value As Byte)
Declare Sub Rdb_24c01(badr As Byte , Value As Byte)
'--------------------Dim Addressw As Const 160 , Addressr As Const 161 '
Dim Badr As Byte
'
Dim Temp As Byte
'
Dim Value As Byte
'
Dim Wadr As Word
'
Dim Fld As Single
'
'--------------------Config Sda = P1.5
'P1.5 SDA
Config Scl = P1.4
'P1.4 SCL
Config I2cdelay = 0
' I2C
Config Timer0 = Timer , Gate = Internal , Mode = 1 : Start Timer0
'--------------------'
On Timer0 Timer_0_int Nosave
'
=============================================================================

20-1

===================================== Bascom-8051 ==
Enable Interrupts
'
Enable Timer0
' 0
'!!! -------------------------------------' 80C51GB
Th0 = &HD8 : Tl0 = &HFD
' 10
Oscr = &HE1 : Oscr = &H1E
'
Wdtrst = &H1E : Wdtrst = &HE1'
P4 = &HFF : P5 = &HFF '
'--------------------'
'
Mc:
For Wadr = 0 To 1024 Step 3
'
Value = Low(wadr)
'
Call Write_eeprom(wadr , Value)
' EEPROM
Next
For Wadr = 0 To 1024 Step 3
'
Read_eeprom Wadr , Value ' EEPROM
Print Value ; "=" ; Value '
Waitms 50
Next
Goto Mc
'--------------------'
'Mc:
For Wadr = 0 To 2044 Step 4
'
Fld = Wadr
Fld = 3 * Fld
'
Gosub Wrs_24c
' EEPROM
Next
For Wadr = 0 To 2044 Step 4
'
Gosub Rds_24c
' EEPROM
Print Wadr ; "=" ; Fld
'
Waitms 50
Next
Goto Mc
'-----------------------------------------' 0
Timer_0_int:
Th0 = &HD8 : Tl0 = &HFD
'Ffffh-10000 = D8fdh - . 10
'!!! 80C51GB
Wdtrst = &H1E : Wdtrst = &HE1
'
Return
'-----------------------------------------'/ EEPROM AT2401A,AT24c02 - AT24c16
Sub Write_eeprom(wadr As Word , Value As Byte)
$asm
Mov A , {wadr + 1}
; ,
Rl A
;
Orl A , #{Addressw}
;
Mov B , A
$end Asm
I2cstart
'
I2cwbyte B
'
$asm
Mov A , {wadr + 0}
$end Asm
I2cwbyte Acc
' EEPROM
I2cwbyte Value
'
I2cstop
'
Waitms 10
' 10
End Sub
'-----------------------------------------=============================================================================

20-2

===================================== Bascom-8051 ==
'/ EEPROM AT2401A,AT24c02 - AT24c16
Sub Read_eeprom(wadr As Word , Value As Byte)
$asm
Mov A , {wadr + 1}
; ,
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 Value , 9
'
I2cstop
'
End Sub
'-----------------------------------------'/ EEPROM AT2401A,AT24c02 - AT24c16
Wrs_24c:
$asm
Mov A , {wadr + 1}
; ,
Rl A
;
Orl A , #{Addressw}
;
Mov B , A
$end Asm
I2cstart
'
I2cwbyte B
'
$asm
Mov A , {wadr + 0}
$end Asm
I2cwbyte Acc
' EEPROM
$asm
Mov A, {Fld + 0}
$end Asm
I2cwbyte Acc
'
$asm
Mov A , {Fld + 1}
$end Asm
I2cwbyte Acc
'2-
$asm
Mov A , {Fld + 2}
$end Asm
I2cwbyte Acc
'3-
$asm
Mov A , {Fld + 3}
$end Asm
I2cwbyte Acc
'4-
I2cstop
'
Waitms 10
' 10
Return
'-----------------------------------------'/ EEPROM AT2401A,AT24c02 - AT24c16
Rds_24c:
$asm
Mov A , {wadr + 1}
; ,
Rl A
;
Orl A , #{Addressw}
;
Mov B , A
$end Asm
=============================================================================

20-3

===================================== Bascom-8051 ==
I2cstart
'
I2cwbyte B
'
$asm
Mov A , {wadr + 0}
$end Asm
I2cwbyte Acc
' EEPROM
Set B.0
'
I2cstart
'
I2cwbyte B
'
I2crbyte Acc , 8
' 1- ASC (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
' NOASC (9)
$asm
Mov {Fld + 3} , A
$end Asm
I2cstop
'
Return
'-----------------------------------------'/ EEPROM AT2401
Sub Wrb_24c01(badr As Byte , Value As Byte)
Acc = Badr
'
$asm
Rl A
; ------------------------------Mov B , A
; | a6| a5| a4| a3| a2| a1| a0| 0 |
$end Asm
I2cstart
'
I2cwbyte B
'
I2cwbyte Value
'
I2cstop
'
Waitms 10
' 10
End Sub
'-----------------------------------------'/ EEPROM AT2401
Sub Rdb_24c01(badr As Byte , Value As Byte)
Acc = Badr
'
$asm
Setb c
; ------------------------------Rlc A
; | a6| a5| a4| a3| a2| a1| a0| 1 |
Mov {Value} , A
$end Asm
I2cstart
'
I2cwbyte Value
'
I2crbyte Value , 9
'
I2cstop
'
End Sub

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

20-4

===================================== Bascom-8051 ==
21.
Bascom
. .
, ,
.
, ..
Bascom ,
. , , Bascom,
. , .,
,
, .
Bascom-8051
Load Timer0 , 100


MOV TL0,#9CH
MOV TH0,#9CH

Load Timer1 , 1000

MOV
MOV
MOV
MOV
MOV
MOV
CLR
MOV
MOV
CLR
MOV
MOV
INC
MOV
CLR
MOV
MOV
INC
MOV
SETB
MOV
MOV
MOV
MOV

Load Timer2 , 1024


Counter0 = 8192
Counter2 = 10

Buf_ = Counter1

Buf_ = Capture

Var1 = Tl0
Var2 = Th0
Tl0 = &h00
Th0 = &hF0

TL1,#18H
TH1,#18H
RCAP2L,#00H
CAP2H,#0FCH
TL0,#00H
TH0,#20H
TR2
TL2,#0AH
TH2,#00H
TR1
R0,#23H
@R0,TL1
R0
@R0,TH1
TR2
R0,#23H
@R0,RCAP2L
R0
@R0,RCAP2H
TR2
Var1,TL0
Var2,TH0
TL0,#00H
TH0,#F0H

0 1 2.

,
!

.
2

.
1.
2
.
Buf_
0, 1 2 .
,
.
Buf_
2 .
.


. .

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

21-1

===================================== Bascom-8051 ==
22. -
-
. , . , , . ,
- Shiftin Shiftout Bascom, ?
(Shiftin
Shiftout). ,
. ,
( )
. ( )
( ) 12 . Shiftin
Shiftout .
,

Shiftout, mode 0

Shiftout, mode 1

Shiftout, mode 2

Shiftout, mode 3


___ _____ _____ _____ _____ __
___X_____X_____X_____X_____X__ Out_Data
msb _____
___
___
___
____ lsb
|_|
|_|
|_|
|_|
Clk

100 ,

80

___ _____ _____ _____ _____ __


___X_____X_____X_____X_____X__ Out_Data
msb _
_
_
_ lsb
_____| |___| |___| |___| |____ Clk

100 ,

80

___ _____ _____ _____ _____ __


___X_____X_____X_____X_____X__ Out_Data
lsb _____
___
___
___
____ msb
|_|
|_|
|_|
|_|
Clk

100 ,

80

___ _____ _____ _____ _____ __


___X_____X_____X_____X_____X__ Out_Data
lsb _
_
_
_ msb
_____| |___| |___| |___| |____ Clk

100 ,

80

Shifin.
(
).
PRE.
. !
, Shiftin
( ).
, ,
Shiftin. ,
.

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

22-1

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


___ ____ ____ ____ ____ ____
___X____X____X____X____X____ In_Data
msb __
_
_
_
_
__ lsb
|__| |__| |__| |__| |__|
Clk

100 ,

80

___ ____ ____ ____ ____ ____


___X____X____X____X____X____ In_Data
msb
__
__
__
__
__ lsb
__| |_| |_| |_| |_| |__ Clk

100 ,

80

Shiftin, mode 2

___ ____ ____ ____ ____ ____


___X____X____X____X____X____ In_Data
lsb __
_
_
_
_
__ msb
|__| |__| |__| |__| |__|
Clk

100 ,

80

Shiftin, mode 3

___ ____ ____ ____ ____ ____


___X____X____X____X____X____ In_Data
lsb
__
__
__
__
__
msb
__| |_| |_| |_| |_| |__ Clk

100 ,

80

Shiftin, mode 0

Shiftin, mode 1

Shiftin, mode 4

Shiftin, mode 5

Shiftin, mode 6

Shiftin, mode 7

___ _____ _____ _____ _____ __


___X_____X_____X_____X_____X__ Out_Data
msb
_
_
_
_
lsb
_____| |___| |___| |___| |____ Clk External

100 ,

80

___ _____ _____ _____ _____ __


___X_____X_____X_____X_____X__ Out_Data
msb_____
___
___
___
____ lsb
|_|
|_|
|_|
|_|
Clk External

100 ,

80

___ _____ _____ _____ _____ __


___X_____X_____X_____X_____X__ Out_Data
lsb
_
_
_
_
msb
_____| |___| |___| |___| |____ Clk External

100 ,

80

___ _____ _____ _____ _____ __


___X_____X_____X_____X_____X__ Out_Data
lsb_____
___
___
___
____ msb
|_|
|_|
|_|
|_|
Clk External

100 ,

80

Bascom Spiin Spiout,


SPI-.
( ). ,
Shiftin Shiftout, 1, . ,
Spiin Spiout , ..
. ( )
Spiin Spiout.

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

22-2

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

Spiout

Spiin


_
_
|__________________________|
CS
___ _____ _____ _____ _____ __
___X_____X_____X_____X_____X__ Out_Data
msb _
_
_
_ lsb
_____| |___| |___| |___| |____ Clk
_
__
|_________________________|
CS
___ ____ ____ ____ ____ ____
___X____X____X____X____X____ In_Data
msb __
__
__
__
__ lsb
__| |_| |_| |_| |_| |__ Clk


12

100 ,

80

100 ,

80

, ,
. , Spiin Spiout
. Shftin Shiftout ,
.
, Shftin Shiftout ,
.
; SPIOUT
; : R0-, R7-
;F0=0 - , F0=1 -
Spiout:
CLR
P1.2
;
Spio1:
ACALL
Rdda
;
MOV
R2,#08H
;
Spio2:
RLC
A
;
MOV
P1.1,C
;
SETB
P1.3
;
NOP
CLR
P1.3
DJNZ
R2,Spio2
;
ACALL
Incinx
;
DJNZ
R7,Spio1;,
SETB
P1.2
;
RET
;
Rdda:
JB
F0,Rda1
MOV
A,@R0
RET
Rda1:
MOVX
A,@DPTR
RET
;
Wrda:
JB
F0,Wrd1
MOV
@R0,A
RET
Wrd1:
MOVX
@DPTR,A
RET
;
Incinx:
JB
F0,Iinx1
=============================================================================

22-3

===================================== Bascom-8051 ==
INC
R0
RET
Iinx1:
INC
DPTR
RET
;----------------------------; SHIFTOUT 1
Shiftout1:
CLR
P1.3
; Clk
MOV
R0,#Dat ;
MOV
R2,#01H ;
Sho1_1:
MOV
A,@R0
MOV
R3,#08H
Sho1_2:
RLC
A
MOV
P1.0,C
SETB
P1.3
NOP
NOP
CLR
P1.3
NOP
NOP
DJNZ
R3,Sho1_1
DEC
R0
DJNZ
R2,Sho1_2
;----------------------------; SHIFTIN 0
Shiftin0:
SETB
P1.1
MOV
R0,#34H
MOV
R2,#02H
INC
R0
Shi0_1:
MOV
R3,#08H
Shi0_2:
CLR
P1.1
NOP
NOP
MOV
C,P1.2
RLC
A
SETB
P1.1
NOP
NOP
DJNZ
R3,Shi0_2
MOV
@R0,A
DEC
R0
DJNZ
R2,Shi0_1:
;----------------------------; SHIFTIN 1
Shiftin1:
CLR
P1.1
MOV
R0,#34H
MOV
R2,#02H
INC
R0
Shi1_1:
MOV
R3,#08H
Shi1_2:
SETB
P1.1
NOP
NOP
MOV
C,P1.2
RLC
A
=============================================================================

22-4

===================================== Bascom-8051 ==
CLR
P1.1
NOP
NOP
DJNZ
R3,Shi1_2
MOV
@R0,A
DEC
R0
DJNZ
R2,Shi1_1
;---------------------------- , Bascom (
8051) , , ,
. , , ,
( 4 Shiftin),
, 1 10 . ,
.
, , ,
, AD7711A ( ).
, ( )
P0.0, P3.6 P3.7 .
,
MOVX.
Mov A
Rl
Movx
Rl
Movx
Rl
Movx
Rl
Movx
Rl
Movx
Rl
Movx
Rl
Movx
Rl
Movx

, Data
A
@DPTR ,
A
@DPTR ,
A
@DPTR ,
A
@DPTR ,
A
@DPTR ,
A
@DPTR ,
A
@DPTR ,
A
@DPTR ,

A
A

;
;
;
;

A
A
A
A
A
A

(F / 12) ,
, 3, P3.0
P3.1, . AT89S8252,
SPI-, F / 4.
Bascom ,
, .

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

22-5

===================================== Bascom-8051 ==
23.
Bascom (, , ) (-, ) . .

(Byte)

(Word, Integer)

(Long)

(Single)_


(Adr*)




(Adr+1)
(Adr+2)

1-
2-
3-
()
1-
2-
3-
()
()
, 1 2,
( 1).

,

00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00

80
00
80
00
80
00
80
00
20
20

3F
40
40
41
41
42
42
43
C1
C0


(Adr+3)
-

=
=
=
=
=
=
=
=
=
=

1
2
4
8
16
32
64
128
-10
-2.5

4-
()

.

0127+p, p
1:
2^p +

* Adr
Bascom ( Integer
Long) ( Byte Word) .
. , . 8- 8-. 16- 32- .
, , .
, ( )
. , .
, , , . .
( ) ( ). . , ( ),
, .. , . , , , , , .. - .
, ,
, , .
. , , - ;
, , Bascom.
'---------------------------------------------------=============================================================================

23-1

===================================== Bascom-8051 ==
'
'---------------------------------------------------$large
Dim Cnt As Const 5
' 5
Dim Bt As Bit
'
Dim Byt As Byte , Byt1 As Byte
Dim Wrd As Word , Wrd1 As Word
Dim Intg As Integer , Intg1 As Integer
Dim Lng As Long , Lng1 As Long
Dim Sng As Single , Sng1 As Single
'---------------------------------------------------Set Bt
'
'---------------------------------------------------'
Byt = Bt
'
Byt = Cnt
' ()
Wrd = Byt
' , 00
Intg = Wrd
'
Intg = Not Intg
'
Wrd = Intg
'
Sng = Wrd : Print Sng
' Sng = 65550.0
Sng = Intg : Print Sng
' Sng = -6.0
'---------------------------------------------------'
Intg = Intg * 5 : Print Intg
' Intg = -30
Intg = Intg / 5 : Print Intg
' Intg = -6
Intg1 = 1000
Intg = Intg1 / Intg : Print Intg' Intg = -166
Intg = Intg * -1
' .
Intg = Not Intg : Intg = Intg + 1 ',
Intg = Not Intg : Incr Intg
'
Lng = Intg
' 32-. ,
Lng = Lng * Intg
' 32-.
Lng = 1000000 : Lng = Not Lng
'
Incr Lng
'-1000001 + 1 = -1000000
Print Lng
' Lng = -1000000
Lng = Lng / 1000
'
Print Lng
' Lng = -1000
Wrd = Lng / 1000
' ,
Lng = Lng / 1000 : Wrd = Lng
'
Intg1 = -10
Lng = Lng / Intg1
'
Print Lng
' Lng = 100
'---------------------------------------------------' .
Sng = Sng * Lng
'
Print Sng
' Sng = -600.0
Sng1 = 0.15 : Sng = Sng * Sng1 '
Print Sng
' Sng = -90.0
Sng = Sng / -10
'
Print Sng
' Sng = 9.0
$asm
Xrl {Sng+3} , #&h80
' .
Anl {Sng+3} , #&h7f
'
Prl {Sng+3} , #&h80
'
$end asm
'---------------------------------------------------'
Byt = 10 : Byt1 = 15 : Wrd = &H1234
'
Wrd = Byt * Byt1
'
Printhex Wrd
' Wrd = 1296h -
Byt = Byt * Byt1
' ,
Wrd = Byt
'
=============================================================================

23-2

===================================== Bascom-8051 ==
Byt1 = Wrd
'
Print Byt ; " " ; Byt1 ; " " ; Wrd ' = 150
'---------------------------------------------------'
Byt = 50 : Byt1 = 10
'
Byt = Byt + Byt1
' - 11
Byt = 50 : Byt1 = 10
'
Byt = Byt - Byt1
' - 12
Byt = 20 : Byt1 = 10
'
Byt = Byt * Byt1
' - 10
Byt = 50 : Byt1 = 10
'
Byt = Byt / Byt1
' - 10
'---------------------------------------------------Wrd = 500 : Wrd1 = 100
'
Wrd = Wrd + Wrd1
' - 20
Wrd = 500 : Wrd1 = 100
'
Wrd = Wrd - Wrd1
' - 21
Wrd = 200 : Wrd1 = 100
'
Wrd = Wrd * Wrd1
' - 63
Wrd = 500 : Wrd1 = 100
'
Wrd = Wrd / Wrd1
' - 560
'---------------------------------------------------Intg = 500 : Intg1 = -100
'
Intg = Intg + Intg1
' - 20
Intg = 500 : Intg1 = -100
'
Intg = Intg - Intg1
' - 21
Intg = 200 : Intg1 = -100
'
Intg = Intg * Intg1
' - 95
Intg = 500 : Intg1 = -100
'
Intg = Intg / Intg1
' - 620
'---------------------------------------------------Lng = -5000 : Lng1 = 1000
'
Lng = Lng + Lng1
' - 74
Lng = -5000 : Lng1 = 1000
'
Lng = Lng - Lng1
' - 74
Lng = -2000 : Lng1 = 1000
'
Lng = Lng * Lng1
' - 2500
Lng = -5000 : Lng1 = 1000
'
Lng = Lng / Lng1
' - 3200
'---------------------------------------------------Sng = 50 : Sng1 = 10
'
Sng = Sng + Sng1
' - 240
Sng = 50 : Sng1 = 10
'
Sng = Sng - Sng1
' - 290
Sng = 20 : Sng1 = 10
'
Sng = Sng * Sng1
' - 2000
Sng = 50 : Sng1 = 10
'
Sng = Sng / Sng1
' - 2300
'---------------------------------------------------'
Byt = 100 : Sng = Byt
' - 490
'
Wrd = 10000 : Sng = Wrd
' -370
Wrd = Sng
' -340
Intg = -1000 : Sng = Intg
' . - 470
Intg = Sng
' - 420
Lng = 1000000 : Sng = Lng
' . - 280
Lng = Sng
' - 250
'---------------------------------------------------End
. , , ..
=============================================================================

23-3

===================================== Bascom-8051 ==
, , . / \ .
16- ,
32- .
;---------------------------------------------; .
; 52 .
; : R3-.,R2-. R1-.,R0-. R7-.,R6,R5,R4
;---------MUL2B: ;
MOV
A,R2
MOV
B,R0
MUL
AB
MOV
R4,A
MOV
R5,B
;
MOV
A,R2
MOV
B,R1
MUL
AB
;
ADD
A,R5
MOV
R5,A
CLR
A
ADDC
A,B
MOV
R6,A
;
MOV
A,R3
MOV
B,R0
MUL
AB
;
ADD
A,R5
MOV
R5,A
MOV
A,R6
ADDC
A,B
MOV
R6,A
CLR
A
RLC
A
MOV
R7,A
;
MOV
A,R3
MOV
B,R1
MUL
AB
;
ADD
A,R6
MOV
R6,A
MOV
A,R7
ADDC
A,B
MOV
R7,A
;---------------------------------------------------Bascom , . , .
, .
, , , . ,
, .
. , .
'---------------------------------------------------'
Dim X As Single , Y As Single , Z As Single
'
=============================================================================

23-4

===================================== Bascom-8051 ==
Do
Input "x=" , X
X = X + 0.00001

' ,
'
' ( 50 )
'

Gosub Sqr
Print Y
Loop
'----------------------------'
' :
'
Yi+1 = (X / Yi + Yi) * .5
' () :
'
Y0 = X / 200 + 2
Sqr:
' ,
Y = X * 0.005 : Y = Y + 2
Do
' Y = (X / Y + Y) * .5
Z = Y : Y = X / Y : Y = Y + Z : Y = Y * 0.5
' IF ABS(Y1 - Y) > Y / 1000 GOTO srq_1
' Bascom ABS
Z = Z - Y : Z = Z / Y
' . .
$asm
Anl {z + 3} , #&H7f
;
$end Asm
Loop Until Z < 0.001
' (0.1 %)
Return
'
'---------------------------------------------------
. , (2 3 ).
'-------------------------------------------------------------------------' . Log(x) Ua Ua
'-------------------------------------------------------------------------Log:
' ( ),
' 1 2
$asm
Mov R0 , #{ua + 2}
Mov A , @R0
Mov C , Acc.7
Clr Acc.7
Mov @R0, A
Inc R0
Mov A , @r0
Rlc A
Mov {tmpb} , A
Mov @R0 , #&H40
$end Asm
' :
'ln(2)= 0,69314718, 1/ln(2)=1.442695, ln(10)=2.3025851, 1/ln(10)=0.4342945
Gosub Ln
'
Ua = Ua * 1.442695
'
Ub = Tmpb : Ub = Ub - 128 : Ua = Ua + Ub '
'
Ua = Ua * 0.30103001
'
Return
'-------------------------------------------------------------------------' . Ln(x) Ua Ua
' x = 1 x = 3 ( 0.003 %)
=============================================================================

23-5

===================================== Bascom-8051 ==
' x = 5 0.02 %, x = 10 - 0.7 %
'
'
3
5
7
9
11
13
n
'
p
p
p
p
p
p
p
x-1
' ln(x)=2*[p + - + - + - + - + -- + -- ...+-] p = ----'
3
5
7
9
11
13
n
x+1
'
'-------------------------------------------------------------------------Ln:
Ub = Ua - 1 : Ua = Ua + 1
Ua = Ub / Ua
Ub = Ua * Ua : Uc = Ub * Ua : Ud = Uc * 0.3333333 : Gosub Add_aad
Gosub Mul_cbc : Ud = Uc * 0.2 : Gosub Add_aad
Gosub Mul_cbc : Ud = Uc * 0.14285714 : Gosub Add_aad
Gosub Mul_cbc : Ud = Uc * 0.1111111111 : Gosub Add_aad
Gosub Mul_cbc : Ud = Uc * 0.09090909 : Gosub Add_aad
Gosub Mul_cbc : Ud = Uc * 0.07692308 : Gosub Add_aad ' 0.003 %
'
Gosub Mul_cbc : Ud = Uc * 0.06666667 : Gosub Add_aad
'
Gosub Mul_cbc : Ud = Uc * 0.05882353 : Gosub Add_aad
'
Gosub Mul_cbc : Ud = Uc * 0.05263158 : Gosub Add_aad
Ua = Ua + Ua : Return
'--------------------'
Mul_cbc:
Uc = Ub * Uc : Return
'--------------------Add_aad:
Ua = Ua + Ud : Return
'--------------------'-------------------------------------------------------------------------' Ua Ua
' 90 ( 0.0002 %)
' 180 4 %!!!
Sin:
Ub = Ua : Ua = Ua * Ua
Uc = Ua
Ua = Ua * 0.013888889
' 1/72
Gosub Sub_aa1
Gosub Mul_aac
Ua = Ua * 0.0238095243
'1/42
Gosub Add_aa1
Gosub Mul_aac
Ua = Ua * .05
'1/20
Gosub Sub_aa1
Gosub Mul_aac
Ua = Ua * 0.16666667
'1/6
Gosub Add_aa1
Gosub Mul_aab
Return
'--------------------Add_aa1:
Ua = Ua + 1
Return
'--------------------Sub_aa1:
Ua = Ua - 1
Return
'--------------------Mul_aac:
Ua = Ua * Uc
Return
'--------------------=============================================================================

23-6

===================================== Bascom-8051 ==
Mul_aab:
Ua = Ua * Ub
Return
'-------------------------------------------------------------------------' Ua Ua
' 90 ( 0.003 % )
' 180 3 %!!!
Cos:
Ua = Ua * Ua
'angle squared
Ub = Ua
'save
Ua = Ua * 0.017857144
'1/56
Gosub Sub_aa1
Gosub Mul_aab
Ua = Ua * 0.033333333
'1/30
Gosub Add_aa1
Gosub Mul_aab
Ua = Ua * 0.083333333
'1/12
Gosub Sub_aa1
Gosub Mul_aab
Ua = Ua * 0.5
'1/2
Gosub Add_aa1
Return
'-------------------------------------------------------------------------' e^x Ua Ua
' x = 3 ( 0.002 %)
' x = 4 ( 0.07 %), x = 10 - 4 %
Exp:
Ub = Ua + 1
'1+x/1!
Gosub Mul_cac : Ud = Uc * 0.5 : Gosub Add_bbd
'+x^2/2!
Gosub Mul_cac : Ud = Uc * 0.16666667 : Gosub Add_bbd
'+x^3/3!
Gosub Mul_cac : Ud = Uc * 0.041666667 : Gosub Add_bbd
'+x^4/4!
Gosub Mul_cac : Ud = Uc * 0.008333333 : Gosub Add_bbd
'+x^5/5!
Gosub Mul_cac : Ud = Uc * 0.0013888889 : Gosub Add_bbd
'+x^6/6!
Gosub Mul_cac : Ud = Uc * 0.0001984127 : Gosub Add_bbd
'+x^7/7!
Gosub Mul_cac : Ud = Uc * 0.000024801587 : Gosub Add_bbd '+x^8/8!
Gosub Mul_cac : Ud = Uc * 0.000002755732 : Gosub Add_bbd '+x^9/9!
Gosub Mul_cac : Ud = Uc * 0.0000002755732 : Gosub Add_bbd '+x^10/10!
Return
'--------------------Add_bbd:
Ub = Ub + Ud : Return
'--------------------Mul_cac:
Uc = Uc * Ua : Return
'--------------------Add_cad:
Ua = Ua + Ud : Return
'------------------------------------------------------------------------- . .
( 120 ).
W77E58, DS89C420). AVR
50 (
BasAVR).
'-------------------------------------------------------------------------' 5-10 500
' ( ). :
'
1
1
' = ----------------------- * --------'
0.006*p^2 + 0.111*p + 1
0.1*p + 1
=============================================================================

23-7

===================================== Bascom-8051 ==
'
Const _a = 0.013869625
Const _b = -0.83217753
Const _c = 1.8183079
Const _d = 0.09090909
Const _e = 0.9090909
'--------------------Dim Ux As Single
'
Dim Uy As Single
'
Dim Uy1 As Single
'
Dim Uy2 As Single
'
Dim Uz As Single
'
Dim Uz1 As Single
'
'-----------------------'

'
2- 1- :
' Uy = Ux * a + Uy2 * b + Uy1 * c -
' Uz = Uy * d + Uz1 * e -
'----Filtr_3p:
Uy = Ux * _a : Uz = Uy2 * _b : Uy = Uy + Uz '
Uz = Uy1 * _c : Uy = Uy + Uz
Uy2 = Uy1 : Uy1 = Uy
'----Uz = Uy * _d : Uy = Uz1 * _e : Uz = Uy + Uz '
Uz1 = Uz : Return
'-----------------------------------------Bascom 2. .
. , . :
Dim X As Byte , Y As Byte
X.3 = Y.2 : P2.1 = Y.4 '
For X = 0 To 7
'
Set P3.X
Next
If P2.X=1 Then
'
P2.X = 0
End If

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

23-8

===================================== Bascom-8051 ==
24.

, , . Bascom ,
, .
().
().
N 1234.
AF
Adr
30H
41H

, : Dim S As String * N
Adr+1
Adr+2
Adr+3
Adr+4

Adr+N
31H
32H
33H
00H
00H
00H
46H
00H
33H
00H
00H
00H

Adr+N+1
00H
00H

. :
) MID(), LEFT(), RIGHT();
) ( .. + ..);
) MID();
) VAL(), HEXVAL();
) STR(), HEX(), CHR().
( INPUT)
( PRINT) . ,
. ,
.
'------------------------------Dim R_rd As Integer
'
Dim R_frq As Single
'
Dim R_lin As String * 6
'
Dim R_tmp As String * 20
'
Mc:
Input "Input six characters" , R_lin
' R_lin : +XXXXX, -XXXXX, HXXXXX R
R_tmp = Left(r_lin , 1)
'
If R_tmp = "+" Then
' ?
R_tmp = Mid(r_lin , 2 , 5) '
R_rd = Val(r_tmp)
'
Goto Mc
' -
End If
If R_tmp = "-" Then
' ?
R_rd = Val(r_lin)
'
Goto Mc
' -
End If
If R_tmp = "H" Then
' ?
R_tmp = Mid(r_lin , 2 , 5) '
R_frq = Val(r_tmp)
' .
R_frq = R_frq * 0.001
'
Goto Mc
' -
End If
If R_tmp = "R" Then
'
Print "H" ; R_frq ; "D" ; R_rd '
'
R_tmp = "H" + Str(r_frq) + "D" + Str(r_rd) '
Print R_tmp
'
Goto Mc
' -
End If
Goto Mc
'
'------------------------------ LCASE UCASE,
. ( ),
, (). ,
=============================================================================

24-1

===================================== Bascom-8051 ==
20h, , .
.
1.20 INSTR(),
.
, . ,
.
, ..
.
.
'---------------------------------------------'
'---------------------------------------------' ( "r",
' :
' Axx -
' Bxxxx -
' Cxxxxxxxx -
' : "A12B1234C00123456", "A30", "c00004055" "a05b0010"
Dim P_a As Byte , P_b As Word , P_c As Long
Dim Tmp1 As Byte , Tmps As String * 10
Dim In_buf As String * 20
'---------------------------------------------P_a = 0 : P_b = 0 : P_c = 0
'
Do
'
Input "r" , In_buf :
'
In_buf = Ucase(in_buf)
'
'
Tmps = "A" : Tmp1 = Instr(1 , In_buf , Tmps)
If Tmp1 <> 0 Then
' ,
Tmps = Mid(in_buf , Tmp1 , 2)
'
P_a = Val(tmps)
'
End If
'
Tmps = "B" : Tmp1 = Instr(1 , In_buf , Tmps)
If Tmp1 <> 0 Then
' ,
Tmps = Mid(in_buf , Tmp1 , 4) : P_b = Val(tmps)
End If
'
Tmps = "C" : Tmp1 = Instr(1 , In_buf , Tmps)
If Tmp1 <> 0 Then
Tmps = Mid(in_buf , Tmp1 , 8) : P_c = Val(tmps)
End If
Wait 1
'
Loop

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

24-2

===================================== Bascom-8051 ==
25.
, , ,
. , -, -

. , ..
, , .
.
, .. .
(). ,
.
. .
( ) .
'---------------------------------------------------'

'---------------------------------------------------$large
Dim Cnt As Const 5
' 5
Dim Bt As Bit Dim , Byt1 As Byte '
Dim Byt As Byte , Byt1 As Byte
Dim Wrd As Word , Wrd1 As Word
Dim Intg As Integer , Intg1 As Integer
Dim Lng As Long , Lng1 As Long
Dim Sng As Single , Sng1 As Single
'---------------------------------------------------Set Bt : Reset Bt1
'
Bt = Bt And Bt1 : Bt = Not Bt
'
Print Bt
'
'---------------------------------------------------Byt = Byt Or Bt
'
Byt1 = Byt1 Or &HAA
'
Byt1 = Byt And Byt1
'
Wrd1 = &H1234 : Byt = &H77 : Intg = 0
Intg1 = Byt Or Wrd1
'.
' Intg = 1277H
Intg = &H1234 : Wrd1 = &H77
Intg1 = Byt : Intg1 = Wrd1 Or Intg1
'
': Intg = 0077H
Wrd = 1234 Or 5678
'
Wrd1 = Wrd Xor 131112
'
Lng = Lng Xor &H10000000
'
'---------------------------------------------------Sng = -1 : Sng1 = 1000
' . . .
Sng1 = Not Sng1
' !
'---------------------------------------------------'
Byt = Byt And Byt1
'11
Byt = Byt Or Byt1
'11
Byt = Byt Xor Byt1
'11
Wrd = Wrd And Wrd1
'20
Intg = Intg And Intg1
'20
Lng = Lng And Lng
'93
End
'----------------------------------------------------

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

25-1

===================================== Bascom-8051 ==
26.
Bascom .
:
) , .
DO LOOP
. ,
( );
) , , , .
WHILE WEND. , , ,
;
) , DO LOOP UNTIL,
, , ,
.
, ,
. , ,
,
. (V H).
, .
: , (
), , .
.
, . ,
, 10 . ,
,
, ,
.
'-----------------------------------------'

'-----------------------------------------Dim B_tim As Bit
' " "
Dim Temp As Byte
'
Dim R_tim As Byte
'
Dim Frng As Byte
'
Dim R_bw As Integer
' 16-
Dim R_bd As Long
'32-
Dim R_fld As Single
'
Dim R_frq As Single
'
Dim Ibuf As String * 16
'
'--------------------' AD9850
B_data Alias P3.3:B_clk Alias P3.2:B_fqud Alias P3.1:B_ress Alias P3.4
'--------------------' AD766
B_datu Alias P1.0 : B_clku Alias P1.2 : B_ldu Alias P1.1
'--------------------'TIMER1 8-. . . UART
Config Timer1 = Timer , Gate = Internal , Mode = 2
$crystal = 12000000
' 12
$baud = 4800
' 4.8
Th1 = 243 : Start Timer1
'
'--------------------'
On Timer0 Timer_0_int Nosave
'
Enable Timer0
' 0
Enable Interrupts
'
Th0 = &HD8 : Tl0 = &HFD
' 10
'--------------------Mc:
Do
'
Input Ibuf
'
=============================================================================

26-1

===================================== Bascom-8051 ==
Temp = Asc(ibuf)
'
If Temp = &H48 Then
' "HXXXXXXXX"?
Goto Herz
End If
If Temp = &H56 Then
' "VXXXXXXXX"?
Goto Volt
End If
Loop
'--------------------'
Volt:
Temp = Len(ibuf)
'
Ibuf = Mid(2 , Temp)
' "V"
R_fld = Val(ibuf)
' ( )
R_fld = R_fld * 10922.67
'2^15/3 = 10922.67 .
R_bw = R_fld
'
Gosub Sload_766
' AD766, AD1851
Goto Mc
'--------------------'
Herz:
Temp = Len(ibuf)
'
Ibuf = Mid(2 , Temp)
' "H"
R_frq = Val(ibuf)
' ( )
R_fld = R_frq * 71582.788
'2^32 / Fclk = 4294967296 / 60000 kHz
R_bd = R_fld
'. 32-.
Gosub Sload_9850
' AD9850
Gosub Sel_rf
'. , .
Gosub Set_com
'
Goto Mc
'-----------------------------------------' . Frng:
'0 - DC ( 5 ), 1 - 0.005-110 kHz, 2 - 110-175 kHz, 3 - 175-280 kHz
'4 - 280-440 kHz, 5 - 440-700 kHz, 6 - 700-1100 kHz, 7 1.1-1.75 Hz
'8 1.75-2.8 Hz, 9 2.8-4.4 , 10 4.4-7 Hz, 11 - 7-11 Hz
'----Sel_rf:
Frng = 0
'
Do
R_fld = Lookup(frng , Hlim_fr)'
If R_fld > R_frq Then
'
Goto S_rfe
' -
End If
Incr Frng
'
Loop Until Frng = 12
'
S_rfe:
Return
'
Hlim_fr:
Data 0.005! , 110! , 175! , 280! , 440! , 700!
Data 1100! , 1750! , 2800! , 4400! , 7000!
'-----------------------------------------' AD9850
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
=============================================================================

26-2

===================================== Bascom-8051 ==
'--------------------' AD766, AD1851
Sload_766:
' R_bw 0 (. , -_-)
Shiftout B_datu , B_clku , R_bw , 0
Reset B_ldu : Set B_ldu
'
Return
'-----------------------------------------'
'
Set_com:
Set P2.3 : Gosub Wait_30ms ' 30
R_bw = Lookup(frng , Tab_com)
'
P2 = High(r_bw) : P0 = Low(r_bw) '
Gosub Wait_30ms
' 30
P2 = &b11110000 : P0 = 0
'
Return
'----Tab_com:
' . . ,
'
2
0
' . 4.4 --
-- 2.8
' . 7 --
-- 1.75
' . 11 -
-- 1.1
' -
-- 700
' 1
-
-- 440
' 1
-
-- 280
' 1
-
-- 175
' 1
-|||||||
||||||| -- 110
Data &B11110000 , &B00000001
'DC
Data &B11110000 , &B00000001
'5-110
Data &B11110000 , &B00000010
'110-175
Data &B11110000 , &B00000100
'175-280
Data &B11110000 , &B00001000
'280-440
Data &B11110000 , &B00010000
'440-700
Data &B11110000 , &B00100000
'700-1100
Data &B11110000 , &B01000000
'1.1-1.75
Data &B11110000 , &B10000000
'1.75-2.8
Data &B11110001 , &B00000000
'2.8-4.4
Data &B11110010 , &B00000000
'4.4-7
Data &B11110100 , &B00000000
'7-11
'-----------------------------------------' 0
Timer_0_int:
Counter0 = &HD8FD : Start Timer0 ; . 10
' , :
'Th0 = &HD8 : Tl = &HFD
'Ffffh-10000 = D8fdh - . 10
$asm
Jnb {b_tim} , Tim0_i1 ;
Djnz {r_tim} , Tim0_i1 ;
Clr B_tim
; -
Tim0_i1:
$end Asm
Return
'-----------------------------------------' ,
Wait_30ms:
Set B_tim : R_tim = 3
While B_tim = 1
' , B_tim
Idle
'
Wend
Return
'-----------------------------------------=============================================================================

26-3

===================================== Bascom-8051 ==
, , Bascom
, :
) WAIT, WAITMS, DELAY - . (
) ;
) BITWAIT - .
;
) DEBOUNCE - .
;
) WAITKEY - . ;
) INPUT, INPUTHEX - .
;
) INPUTBIN - .
.
FOR NEXT , , ,
. Bascom
. ,
FOR NEXT, ( ),
, . ,
FOR NEXT .
.
, ( 10 ),
. FOR
NEXT.

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

26-4

===================================== Bascom-8051 ==
27. Bascom
Bascom ,
. ,
. () , -
. .
, .
. ,

, .. ,
, .
.
.
'--------------------------------------------------'
'--------------------------------------------------Dim Ni As Const 5
'
Dim Nm As Byte , Jm As Byte , Jmd As Byte , Tmp As Byte
Dim Stmp As String * 8
Dim Ar(ni) As Byte
'
Dim Sa(ni) As String * 8
'
For Nm = 1 To Ni
'
Ar(nm) = Lookup(nm , Da)
'
Sa(nm) = Lookupstr(nm , Ds) '
Stmp = Lookupstr(nm , Ds) : Sa(nm) = Stmp '
Next
' "" - ( )
For Nm = 2 To Ni
'
For Jm = Ni Downto Nm
'
Jmd = Jm - 1
'
'
If Ar(jmd) < Ar(jm) Then '
If Ar(jmd) > Ar(jm) Then '
Tmp = Ar(jmd) : Ar(jmd) = Ar(jm) : Ar(jm) = Tmp '
'
Swap Ar(jmd) , Ar(jm) ' !
End If
Next
Next
',
For Nm = 1 To Ni : Print Sa(nm) ; Ar(nm) : Next
End
' ,
Da:
Data 0 , 12 , 222 , 45 , 6 , 78 , 4 , 5 , 99 , 45 , 146 , 100
' ,
Ds:
Data "1=" , "2=" , "3=" , "4=" , "5=" , "6=" , "7=" , "8=" , "9=" , "10="

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

27-1

===================================== Bascom-8051 ==
28. EEPROM AT89S82252
AT89S8252 EEPROM
( 2 ), . EEPROM
,
. Bascom (WRITEEEPROM READEEPROM),
.
( ).
:
) EEPROM.

, .. EEPROM (
). , - ,
, ;
) EEPROM.
.
EEPROM.
. EEPROM
. EEPROM
, , , .
'-------------------------------------------' EEPROM AT89S8252
'-------------------------------------------Dim Byt As Byte , Wrd As Word , Intg As Integer , Lng As Long , Sng As Single
' .
Byt = 10 : Wrd = 2000 : Intg = -10000 : Lng = 10000000 : Sng = 3.3333
' EEPROM
Writeeeprom Byt : Writeeeprom Wrd : Writeeeprom Intg
Writeeeprom Lng : Writeeeprom Sng
'
Byt = 0 : Wrd = 0 : Intg = 0 : Lng = 0 : Sng = 0
'
Readeeprom Byt : Readeeprom Wrd : Readeeprom Intg
Readeeprom Lng : Readeeprom Sng
',
Print Byt ; "_" ; Wrd ; "_" ; Intg ; "_" ; Lng ; "_" ; Sng
End
WRITEEEPROM READEEPROM
, EEPROM,
, .
. ,
( ),
, , .
,
, EEPROM.
.
, ,
- .
:
) . ,
, , - 5AH
( );
)
;
) ( )
, .
'--------------------------------------------------------' EEPROM AT89C8252
'--------------------------------------------------------Dim K0 As Const 0
' 8-
=============================================================================

28-1

===================================== Bascom-8051 ==
Dim K1 As Const 4
'
Dim K2 As Const 8
'
Dim K3 As Const 12
' EEPROM
Dim K4 As Const 16
'
Dim K5 As Const 20
' 4
Dim K6 As Const 24
Dim K7 As Const 28
Dim End_dae As Const 31
'
Dim Csum As Const 32
'
Dim End_eep As Const 32
'
Dim N_cs As Const A5
'
'
Dim Nm As Byte , Tmp As Byte , Sum As Byte , Sng As Single
' EEPROM
For Nm = 0 To 7
Sng = Lookup(nm , Dvs) : Tmp = Lookup(nm , Dva) '
Writeeeprom Sng , Tmp
Next
'
Sum = 0
For Nm = 0 To End_dae
'
Readeeprom Tmp , Nm : Sum = Sum + Tmp
Next
Sum = N_cs - Sum '
Writeeeprom Sum , Csum '
'
Sum = 0
'
For Nm = 0 To End_eep
Readeeprom Tmp , Nm : Sum = Sum + Tmp
Next
If Sum <> N_cs Then
': ?
Print "Error EEPROM!" ' , -
End If
',
For Nm = 0 To 7
Tmp = Lookup(nm , Dva) : Readeeprom Sng , Tmp
Print Tmp ; "-" ; Nm ; "-" ; Sng
Next
'
Dva:
'Data K0 , K1 , K2 , K3 , K4 , K5 , K6 , K7 '
Data 0 , 4 , 8 , 12 , 16 , 20 , 24 , 28
'
'
Dvs:
Data 1.1! , 1.2! , 1.3! , 1.4! , 1.5! , 1.6! , 1.7! , 1.8!
, ..
EEPROM
0.000001 ( - 0.002 EEPROM 2 ).
- . , , ,
. .
.
, ..
, (
).
, .
:
) ;
) -
, . , ,
.
;
) ;
) .
=============================================================================

28-2

===================================== Bascom-8051 ==
,
, (
EEPROM). 24Cxx
93Cxx, I2C- SPI-, , Bascom
.

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

28-3

===================================== Bascom-8051 ==
29. Bascom
, ..
, ,
.
, .
, .
,
. .
:
) ;
) ;
) , ;
) .
.
:
) , , ,
..;
) - ;
) , () ;
) ;
) ;
) ;
) ,
;
) Bascom.
:
) , ,
- . , ,
, ;
) (), .
.
.
;
) ( ) Bascom,
. , ,
.
Bascom
, .. .
Bascom ,
. , , , ,
. , Bascom,
. ,
Bascom
.
, ,
, . :
) .
,
;
) .
( ), ;
) ;
) .
;
) LOOKUP LOOKUPSTR;
) , ,
SELECT CASE x ON x GOTO (GOSUB),
(IF THEN );
) , ;

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

29-1

===================================== Bascom-8051 ==
) ( )
(- );
) .
.

. ,
, , ,
.
(). , ,
. Bascom ( ERASE) ()
. , .. .
, ,
.
( ). ,
- .

.

.
. Bascom
. ,
.
,
(, ) 50 .
, , ,
.
, .
, , ,
.
- . (
) :
) ( GOTO);
) ( CALL, GOSUB);
) ( IF THEN ) -
(IF THEN ELSE / IFELSE );
) ( SELECT CASE ON GOTO ON
GOSUB);
) ( WHILE WEND);
) ( DO LOOP UNTIL );
) (FOR TO/DOWNTO NEXT).

, ,
. , CALL RET,
.
,
.
,
. ,
, ..
.

.
, ,
, . .
, ,
.

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

29-2

===================================== Bascom-8051 ==
30. Bascom
Bascom, , ,
. ,
,
. , , :
) ;
)
;
) , ,
;
)
, (SOIC, TQFP ..).
, Bascom.
. Bascom ,
, , .
:
) , ,
.
, .
Bascom.
,
.
, , .
, , .
, ( )
;
) ,
, , - .
. (
), .
, . ,
, . ,
- (
), .
, (
). ,
, , ;
) ,
, , .
,
. ,
( ), , ,
, , . ,
,
( ).
,
;
) - , ,
, EEPROM. ,
,
;
) ( ) ,
( , ,
..).

. ,
, .
:
) , ,
, ;
=============================================================================

30-1

===================================== Bascom-8051 ==
) ( ) ,
, , ;
) , , - ,
, ;
) ;
) , ;
) (, , ).

( , , ,
, ,
). () (
).
( ) .
, ,
.
,
.
, (, , )
, (
) ( ).
, Bascom:
)
. .
DO
INPUT Input value A , _A
INPUT Input value B , _B
,

PRINT C= ; _C
LOOP
) , , ,
DO

PRINT C= ; _C
,
CLS
' LCD
LCD C

LOOP
) , ,
.
DO
FOR V = 10 TO 100
, V
NEXT
LOOP
) ,
.
RESET P1.1 : SET P1.1 ( )
,
) .
( ) GOTO
;
) ( ) ,
. . ,
, .
, .
, ;
)
. ,
.
=============================================================================

30-2

===================================== Bascom-8051 ==
SET B_NEW_DATA : ADC_DATA = 4000
) ,
COM-.
. ,
. , ,
- Bascom, ,
. Bascom,
EEPROM ( AT89S8252),
.
() ,
Bascom, :
) (HEX- BIN-) Bascom
( , Bascom);
) Bascom ,
. ;
) ,
Bascom, , , , ,
, Bascom . , ,
, ,
, ,
, ;
) ,
, .
TxD RxD COM- ,

( );
) , Bascom ,
, ,
, Flash- ( )
( ).
(- , ).
, , ( 15 - 30 ),
. ,

. ( ),
, .

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

30-3

===================================== Bascom-8051 ==
31. Bascom
1 $BAUD $CRYSTAL PRINT, INPUT.
! PRINT, INPUT,
- , SCON
PCON (. . ).
2 IF .. End If Return:
:
If Tmp = 0 Then
Goto Lcd_pe
End If

Lcd_pe: Return

:
If Tmp = 0 Then
Return
End If

Return .
.
3 Fusing , ,
( ), , . ,
: +
+ + ( ). Bascom
( ) 16 .

+ , .
!
4 Fusing ,
, .
. , ,
. $NONAN.
5 Fusing ,
, ,
.
: , ,
(
).
6 Fusing , (
003.45 ###.## 3.45). ,
. (1.0.0.19 )
. .
7 , ,
, .
, , ,
, , , .
, .
, . , ,
(
). , Bascom,
, 16 Single.
,
.
8 255 ,
. . ,
. ,
:
=============================================================================

31-1

===================================== Bascom-8051 ==
Printbin &H42 ; &H41 ; &H42 ; &H43 ; &H44 ; &H45 ; &H46

; &H4A ; &H4B

:
Out_buf = "S" + Str(rang) + "L" +Str(udac) + "T" + Chr(13) + Chr(10)
9 (, - ),
( ).
, . , , ,
Long, ,
. , .
, , , , .
Dim Byt As Byte, Byt1 As Byte, Wrd As Word , Wrd1 As Word , Lng As Long
Byt = 10 : Byt1 = 15 : Wrd = &H1234
'
Wrd = Byt * Byt1
'
Printhex Wrd
' Wrd = 1296h -
Wrd = 16 : Wrd1 = 32 : Lng = &h12345678
Lng = Wrd * Wrd1
'
Printhex Lng
' Lng = 12340200h
,
, .
Byt = 10 : Byt1 = 15 : Wrd = &H1234
'
Byt = Byt * Byt1
'
Wrd = Byt : Printhex Wrd ' Wrd = 0096h -
Wrd = 16 : Wrd1 = 32 : Lng = &h12345678
Wrd = Wrd * Wrd1
'
Printhex Lng
' Lng = 00000200h
, , , .
10 Bascom ( ),
, , 16 16
, 32- . (32
), 32- (). ,
. ,
, , .
Wrd = 50 : Lng = 2000 '
L ng = Wrd * Lng
'
Printhex Lng
' Lng = 100000
11 Bascom ,
. . , ,
, .
,
. , SWAP
Ar(1), Ar(3) , : Temp =
Ar(1) : Ar(1) = Ar(3) : Ar(3) = Temp. , , ,
.. , , .
12 , DATA, () ()
. .
, ,
.
13 LOOKUP
. ( ) 63(3FH), (
- ,
). .
=============================================================================

31-2

===================================== Bascom-8051 ==
14 ( : ) . ,
,
. <, > , .
, ( 1.20)
, .

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

31-3

===================================== Bascom-8051 ==
32.
, Bascom
. , Bascom
. .
, (,
), ,
. , ,
, (8051
8052). ,
.
, AT89C2051.
. 50 ( 70 ),
, .
( ).
1.1
. ,

.
1.2 .
.
1.3 ,
() .
, .
1.4 .
.
( ). ,
, , . 1000 (
6 8 ) . 1 1.5
.
( ) .
( ).
. ( )
! -
, , , , .
( ).
4.1 . .
, .
4.2 , . , ,
. ,
.
4.3 1000 .
- , .
-, - . . ,
+ ,
(, , , ..).
, , , .
.
4.4 . ( )
.
4.5 . -
, ,
.
( ). , .
. .
, , ( ,
, -).
( AVR). 8051
Bascom-8051. . , ,
. AVR- BasAVR,
95 % Bascom-8051, .
=============================================================================

32-1

===================================== Bascom-8051 ==
( ).
7.1 , .
7.2
.
7.3 ,
.
7.4
.
.
, .
7.5 .
, , .
, , .
, , , ,
, ( ..) .
. ,
, , .
.
'------------------------------------' Ub
' Ub(Single) , Ranga(Byte)
Get_nom_sc:
Ub = Lookup(ranga , Tab_nom_sc) : Return
'------------------------------------'
Tab_nom_sc:
Data 0.0003!
'0 - 0.2mv
Data 0.0005!
'1 - 0.5mv
Data 0.001!
'2 - 1mv
Data 0.003!
'3 - 2mv
Data 0.005!
'4 - 5mv
Data 0.01!
'5 - 10mv
Data 0.03!
'6 - 20mv
Data 0.05!
'7 - 50mv
Data 0.1!
'8 - 100mv
Data 0.3!
'9 - 200mv
Data 0.5!
'10 - 500mv
Data 1!
'11 - 1v
'------------------------------------ .
ON var GOTO , , . , Ranga
.
SELECT CASE var ,
, . ,
1.20, .
_.
'------------------------------------' Flda
Wr_c_sc:
On Ranga Goto Ws0 , Ws1 , Ws2 , Ws3 , Ws4 , Ws5 , Ws6 , Ws7 , _
Ws8 , Ws9 , Ws10 , Ws11 , Ws12 , Ws13 , Ws14
'
Ws0:
Wadr = Varptr(dc__2mv) : Goto Wsend
' 0.2
Ws1:
Wadr = Varptr(dc__5mv) : Goto Wsend
' 0.5
Ws2:
Wadr = Varptr(dc_1mv) : Goto Wsend
' 1
Ws3:
Wadr = Varptr(dc_2mv) : Goto Wsend
' 2
Ws4:
Wadr = Varptr(dc_5mv) : Goto Wsend
' 5
Ws5:
Wadr = Varptr(dc_10mv) : Goto Wsend
' 10
Ws6:
Wadr = Varptr(dc_20mv) : Goto Wsend
' 20
Ws7:
Wadr = Varptr(dc_50mv) : Goto Wsend
' 50
=============================================================================

32-2

===================================== Bascom-8051 ==
Ws8:
Wadr = Varptr(dc_100mv) : Goto Wsend
Ws9:
Wadr = Varptr(dc_200mv) : Goto Wsend
Ws10: Wadr = Varptr(dc_500mv) : Goto Wsend
Ws11: Wadr = Varptr(dc_1v)
Wsend: Flda = Rscl : Goto Wr_cal_c
'-------------------------------------

'
'
'
'

100
200
500
1

,
Bascom. Wadr
Varptr().
( ) , Bascom
.
'------------------------------------' !!!
Wadr = Lookup(ranga , Tab)
Tab:
Data Dc_2mv%
' 0000h
Data Dc_5mv%
Data Dc_10mv%
Data Dc_20mv%
Data Dc_50mv%
Data Dc_100mv%
Data Dc_200mv%
Data Dc_500mv%
Data Dc_1v%
7.6 ON var GOTO , , SELECT CASE var
( ) - -
var. SELECT CASE ,
, , .
ON GOTO . ,
, - (Mcz_mes). ,
Buf_kl 0 16.
'------------------------------------'
Comzkl:
On Buf_kl Goto Mcz_mes , Mcz_mes , To_next_step , To_prev_step , End_of_c , _
Mcz_mes , Mcz_mes , Mcz_mes , Mcz_mes , _
Mcz_mes , Mcz_mes , Mcz_mes , Mcz_mes , _
Mcz_mes , Mcz_mes , Mcz_mes , Mcz_mes
'------------------------------------7.7 .
,
. ,
Ua = Ub + Uc Ua = Ua + 10.123
50 . , (
) 3 . ,
. ( -
), .
().
8.1 .
. , ,
- 8xC51Rx 512 1280 .
8.2 , ,
, ( ). Single
(
). ,
( ) .
Byte, Word, Integer Long 7fh.
( ).
9.1 .
. 32 , 48 (
=============================================================================

32-3

===================================== Bascom-8051 ==
). , . ,
.
9.2 .
. , , ,
.
:
Clr_mem:
$asm
Mov R0 , #&hff
Mov @r0 , Sp
Dec R0
Clrmem:
Mov @r0 , #0
Djnz R0 , Clrmem
$end Asm

'
'

, :
$asm
Mov R0 , #&hff
Mov Sp , @r0
$end Asm

'

, .
( ).
10.1 . -,
(, ). If
Then Else End If.
.
10.2 . ,
. , If Then Elseif Then End If).
10.3 , Bit, Byte
Single.
10.4 .
10.5 , . ,
.
10.6
( Single). . ,
, .
( ).
11.1 .
, .
, .
.
, . ,
, . : Do Loop Until ,
While Wend For Next. Select Case ,
If Then .
11.2 .
. , .
11.3 , .
. , .
11.4
. , ,
.
11.5 , (, , )
, .
.
( ). Restore Varptr()
.
Bascom
, .
=============================================================================

32-4

===================================== Bascom-8051 ==
(, ) .
, , .
Dim X As Byte , Y As Byte , W As Word
$Ramstart = &H1000
Dim Var1 As XRAM Single
W = Varptr(Var1)
Print W
4096
M1:
Restore M1
'
Gosub Read_restore
Print W
240 M1
End
---------- , Restore
Read_restore:
X = Peek(&H47) : Y = Peek(&H48)
'&h47 = (SP)-2, &H48 = (SP)-1
W = Makeint(x , Y)
Return
Restore ( Word),
. 2. ,
( = (SP) - 2 ).
( Ctrl+W). .
, Restore
$Asm
Pop Acc
-
Mov {W + 1} , A
Pop Acc
Mov {W} , A
Inc SP
Inc SP
$End Asm
Varptr() .
(6-20 ), ,
.

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

32-5

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



(Adessr + 3)

7
1
1/8
1

Single

2
2
4

(Adress = 2)

0 1

0 255

100

0
655535

32768
32767
2147483648

2147483647

5,8E-39
1,7E+38

1000

-1000

(Adress)
-

7 6 5 4 3 2 1 0
1
1

20000

-20000

Bit

Byte

Word
Integer

Long

(Adress = 2)

(
127 +127

24- 1 2 .
,

128

-2.5

Dim S1 As String * 20
Dim S1 As String * 16
Dim S1 As String * 8

21
17
9

123 S5.5+12
1S.5
ST2

0
31
31
53

1
32
53
54

2
33
2E
32

3
20
35
00

4
53
00
xx

Hex-, (Adress)
5
6
7
8
9
10 11 12 13 14 15 16
35 2E 35 2B 31 32 00 xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx xx xx
xx xx xx xx

17
xx

18
xx

19
xx

20
xx

xx .

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

A-1

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

B
8051

(16)


MOV A,R0
E8
MOV A,R1
E9
MOV A,R2
EA
MOV A,R3
EB

MOV A,R4
EC
MOV A,R5
ED
MOV A,R6
EE
MOV A,R7
EF
MOV A, direct
E5,da

MOV A,@R0
E6

MOV A,@R1
E7

MOV A, #data
74,dt
MOV R0,A
F8
MOV R1,A
F9
MOV R2,A
FA
MOV R3,A
FB

MOV R4,A
FC
MOV R5,A
FD
MOV R6,A
FE
MOV R7,A
FF
MOV R0,direct
A8,da
MOV R1,direct
A9,da
MOV R2,direct
AA,da
MOV R3,direct
AB,da

MOV R4,direct
AC,da
MOV R5,direct
AD,da
MOV R6,direct
AE,da
MOV R7,direct
AF,da
MOV R0,#data
78,dt
MOV R1,#data
79,dt
MOV R2,#data
7A,dt
MOV R3,#data
7B,dt

MOV R4,#data
7C,dt
MOV R5,#data
7D,dt
MOV R6,#data
7E,dt
MOV R7,#data
7F,dt
MOV direct, A
F5,da
MOV direct,@R0
86,da


MOV direct,@R1
87,da

MOV direct, #data
75,da,dt


MOV direct, direct
85,da,da.

(A)(R0)
(A)(R1)
(A)(R2)
(A)(R3)
(A)(R4)
(A)(R5)
(A)(R6)
(A)(R7)
(A)(direct)
(A)((R0))
(A)((R1))
(A)#data
(R0)(A)
(R1)(A)
(R2)(A)
(R3)(A)
(R4)(A)
(R5)(A)
(R6)(A)
(R7)(A)
(R0)(direct)
(R1)(direct)
(R2)(direct)
(R3)(direct)
(R4)(direct)
(R5)(direct)
(R6)(direct)
(R7)(direct)
(R0)(#data)
(R1)(#data)
(R2)(#data)
(R3)(#data)
(R4)(#data)
(R5)(#data)
(R6)(#data)
(R7)(#data)
(direct)(A)
(direct)((R0))
(direct)((R1))

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
2
2

(direct) #data

(direct)(direct)

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

B-1

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

(16)

()
MOV direct,R0
88,da
MOV direct,R1
89,da
MOV direct,R2
8A,da
MOV direct,R3
8B,da

MOV direct,R4
8C,da
MOV direct,R5
8D,da
MOV direct,R6
8E,da
MOV direct,R7
8F,da
F6
MOV @R0, A
A
MOV @R1, A
F7
A6,da
MOV @R0, direct

MOV @R1, direct
A7,da
MOV @R0, #data
76,dt

MOV @R1, #data


77,dt
16
MOV DPTR #data16
90,dt

MOVC A, @A+DPTR
93
A
MOVC A, @A+PC
83

MOVX A,@R0
MOVX A,@R1
MOVX A,@DPTR
MOVX @R0,A
MOVX @R1,A
MOVX @DPTR,A

E2
E3
E0
F2
F3
F0

PUSH direct

C0,da

POP direct

D0,da

XCH A,R0
XCH A,R1
XCH A,R2
XCH A,R3
XCH A,R4
XCH A,R5
XCH A,R6
XCH A,R7
XCH A, direct
XCH A,@R0
XCH A,@R1
XCHD A,@R0
XCHD A,@R1

C8
C9
CA
CB
CC
CD
CE
CF
CA,da
C6
C7
D6
D7

(direct)(R0)
(direct)(R1)
(direct)(R2)
(direct)(R3)
(direct)(R4)
(direct)(R5)
(direct)(R6)
(direct)(R7)
((R0))(A)
((R1))(A)
((R0))(direct)
((R1))(direct)
((R0))#data
((R1))#data

2
2
2
2
2
2
2
2
1
1
2
2
1
1

(DPTR)#data15..0

(A)((A)+(DPTR))
(PC)(PC)+1
(A)((A)+(PC))
(A)((R0))
(A)((R1))
(A)((DPTR))
((R0))(A)
((R1))(A)
((DPTR))(A)
(SP)(SP)+1
((SP))(direct)
(direct)((SP))
(SP)(SP)-1
(A)(R0)
(A)(R1)
(A)(R2)
(A)(R3)
(A)(R4)
(A)(R5)
(A)(R6)
(A)(R7)
(A)(direct)
(A)((R0))
(A)((R1))
(A3..0)((R0)3..0)
(A3..0)((R1)3..0)

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

2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1

B-2

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

(16)

LCALL addr16

12,adr16

ACALL 0XX
ACALL 1XX
ACALL 2XX
ACALL 3XX
ACALL 4XX
ACALL 5XX
ACALL 6XX
ACALL 7XX

11,adr8
31,adr8
51,adr8
71,adr8
91,adr8
B1,adr8
D1,adr8
F1,adr8

2-

127

(
Z)

RET

22

RETI

32

LJMP addr16
AJMP 0XX
AJMP 1XX
AJMP 2XX
AJMP 3XX
AJMP 4XX
AJMP 5XX
AJMP 6XX
AJMP 7XX
SJMP rel
JMP @A+DPTR

02,adr16
01,adr8
21,adr8
41,adr8
61,adr8
81,adr8
A1,adr8
C1,adr8
E1,adr8
80,rel
73

JZ rel

60,rel

JNZ rel

70,rel


127

CJNZ A,#direct, rel

B5,dt,rel


127

CJNZ A, #data, rel

B4,dt,rel

CJNZ R0,#data,rel
CJNZ R1,#data,rel
CJNZ R2,#data,rel
CJNZ R3,#data,rel
CJNZ R4,#data,rel
CJNZ R5,#data,rel
CJNZ R6,#data,rel
CJNZ R7,#data,rel
CJNZ@R0,#data,rel

B8,dt,rel
B9,dt,rel
BA,dt,rel
BB,dt,rel
BC,dt,rel
BD,dt,rel
BE,dt,rel
BF,dt,rel
B6,dt,rel

CJNZ@R1,#data,rel

B7,dt,rel


127


127

PCaddr16
SPSP+2

PCaddr11
(0..10)
SPSP+2

2
2
2
2
2
2
2
2

PC(SP)
SPSP-2
PC(SP)
SPSP-2 EA 1
PCaddr16

PC0..10addr11

PCPC+2+rel
PC(A+DPTR)
=0
PCPC+2+rel
0
PCPC+2+rel
direct
PCPC+3+rel
A > direct C1
data
PCPC+3+rel
A > data C1
Ridata
PCPC+3+rel
Ri > data C1
0

@Ridata
PCPC+3+rel
@Ri > data C1

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

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

2
2
2
2
2
2
2
2
2
2
2

B-3

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

(16)

()
DJNZ R0, rel
D8,rel
DJNZ R1, rel
D9,rel
DJNZ R2, rel
DA,rel
DJNZ R3, rel
DB,rel
,
DJNZ R4, rel
DB,rel
DJNZ R5, rel
DC,rel
DJNZ R6, rel
DE,rel
DJNZ R7, rel
DF,rel

DJNZ direct, rel
D5,da,rel
,

NOP
00

ANL A,R0
58
ANL A,R1
59
ANL A,R2
5A
ANL A,R3
5B

ANL A,R4
5C
ANL A,R5
5D
ANL A,R6
5E
ANL A,R7
5F

ANL A, direct
55,da

ANL A,@R0
56

ANL A,@R1
57

ANL A, #data
54,dt

ANL direct, A
52,da


ANL direct, #data
53,da,dt

ORL A,R0
48
ORL A,R1
49
ORL A,R2
4A
ORL A,R3
4B

ORL A,R4
4C
ORL A,R5
4D
ORL A,R6
4E
ORL A,R7
4F

ORL A, direct
45,da

ORL A,@R0
46


ORL A,@R1
47

ORL A, #data
44,dt

ORL direct, A
42,da


ORL direct, #data
43,da,dt

RiRi-1
Ri0
PCPC+2+rel

2
2
2
2
2
2
2
2

directdirect-1
direct0 PCPC+3+rel

2
1

(A)(A) AND (R0)


(A)(A) AND (R1)
(A)(A) AND (R2)
(A)(A) AND (R3)
(A)(A) AND (R4)
(A)(A) AND (R5)
(A)(A) AND (R6)
(A)(A) AND (R7)

1
1
1
1
1
1
1
1

(A)(A) AND (direct)

(A)(A) AND ((R0))


(A)(A) AND ((R1))
(A)(A) AND #data
(direct)(direct) AND
(A)
(direct)(direct) AND
#data
(A)(A) OR (R0)
(A)(A) OR (R1)
(A)(A) OR (R2)
(A)(A) OR (R3)
(A)(A) OR (R4)
(A)(A) OR (R5)
(A)(A) OR (R6)
(A)(A) OR (R7)

1
1
1

1
1
1
1
1
1
1
1

(A)(A) OR (direct)

(A)(A) OR ((R0))
(A)(A) OR ((R1))
(A)(A) OR #data

1
1
1

(direct)(direct)OR(A)

(direct)(direct) OR
#data

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

1
2

B-4

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

(16)

()
XRL A,R0
68
XRL A,R1
69
XRL A,R2
6A
XRL A,R3
6B
XRL A,R4
6C
XRL A,R5
6D
XRL A,R6
6E
XRL A,R7
6F













A

C
A

C

(A)(A) XOR (R0)


(A)(A) XOR (R1)
(A)(A) XOR (R2)
(A)(A) XOR (R3)
(A)(A) XOR (R4)
(A)(A) XOR (R5)
(A)(A) XOR (R6)
(A)(A) XOR (R7)

1
1
1
1
1
1
1
1

XRL A, direct

65,da

(A)(A) XOR (direct)

XRL A,@R0
XRL A,@R1
XRL A, #data

66
67
64,dt

1
1
1

XRL direct, A

62,da

(A)(A) XOR ((R0))


(A)(A) XOR ((R1))
(A)(A) XOR #data
(drect)(direct)XOR
(A)
(direct)(direct) XOR
#data
(A)0
(A) NOT (A)
(An+1)(An) (A0)(A7),
n=0..6
(An+1)(An)
(A0)(C), n=0..6
(C)(A7)
(An)(An+1) (A7)(A0),
n=0..6
(An)(An+1)
(A7)(C), n=0..6
(C)(A0)
(A3..0)(A7..4)

XRL direct, #data

63,da,dt

CLR A
CPL A

E4
F4

RL A

23

RLC A

33

RR A

03

RRC A

13

SWAP A

C4

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

1
2
1
1
1
1
1
1
1

B-5

(16)

( )
SETB C
D3
(C)1
SETB bit
D2,bit
(bit)1
CLR C
C3
(C)0
CLR bit
C2,bit
(bit)0
MOV C, bit
A2,bit
(C)(bit)
MOV bit, C
92,bit
(bit)(C)
ANL C, bit
82,bit
(C)(C)AND(bit)
ANL C, /bit
B0,bit
(C)(C)AND NOT(bit)
ORL C, bit
72,bit
(C)(C) OR (bit)
ORL C, /bit
A0,bit
(C)(C)OR NOT(bit)
=0
JZ rel
60,rel
Z
PCPC+2+rel
JNZ rel
70,rel
0 PCPC+2+rel
JC rel
40,rel
C=1 PCPC+2+rel

JNC rel
50,rel
C=0 PCPC+2+rel
JB bit, rel
20,bit,rel
bit=1 PCPC+3+rel
JNB bit, rel
30,bit,rel
bit=0 PCPC+3+rel

bit=C
JBC bit, rel
10,bit,rel
PCPC+3+rel , bit=0

CPL bit
B2,bit
(bit)NOT(bit)

CPL C
B3
(C)NOT(C)

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

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

1
1
1
1
1
2
2
2
2
2

+
+
+
+

2
2
2
2
2

0
+

2
1
1

B-6

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

(16)

OV AC


ADD A, R0
28
(A)(A)+(R0)
ADD A, R1
29
(A)(A)+(R1)
ADD A, R2
2A
(A)(A)+(R2)
ADD A, R3
2B
(A)(A)+(R3)
ADD A, R4
2C
(A)(A)+(R4)
ADD A, R5
2D
(A)(A)+(R5)
ADD A, R6
2E
(A)(A)+(R6)
ADD A, R7
2F
(A)(A)+(R7)

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

1
1
1
1
1
1
1
1

ADD A, direct

25,da

(A)(A)+(direct)

ADD A, @R0
ADD A, @R1

26
27

(A)(A)+((R0))
(A)(A)+((R1))

+
+

+
+

+
+

1
1

ADD A, #data

24,dt

(A)(A)+#data

ADDC A, R0
ADDC A, R1
ADDC A, R2
ADDC A, R3
ADDC A, R4
ADDC A, R5
ADDC A, R6
ADDC A, R7

38
39
3A
3B
3C
3D
3E
3F

(A)(A)+(C)+(R0)
(A)(A)+(C)+(R1)
(A)(A)+(C)+(R2)
(A)(A)+(C)+(R3)
(A)(A)+(C)+(R4)
(A)(A)+(C)+(R5)
(A)(A)+(C)+(R6)
(A)(A)+(C)+(R7)

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

1
1
1
1
1
1
1
1

C
()

C
()

C
()

C
()

ADDC A, direct

35,da

(A)(A)+(C)+(direct)

ADDC A, @R0

36

(A)(A)+(C)+((R0))

ADDC A, @R1

37

(A)(A)+(C)+((R1))

ADDC A, #data

34,dt

(A)(A)+(C)+#data

(A)(A)-(C)-(R0)
(A)(A)-(C)-(R1)
(A)(A)-(C)-(R2)
(A)(A)-(C)-(R3)
(A)(A)-(C)-(R4)
(A)(A)-(C)-(R5)
(A)(A)-(C)-(R6)
(A)(A)-(C)-(R7)

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

1
1
1
1
1
1
1
1

SUBB A, R0
SUBB A, R1
SUBB A, R2
SUBB A, R3
SUBB A, R4
SUBB A, R5
SUBB A, R6
SUBB A, R7

98
99
9A
9B
9C
9D
9E
9F

SUBB A, direct

95,da

(A)(A)-(C)-(direct)

SUBB A, @R0

96

(A)(A)-(C)-((R0))

SUBB A, @R1

97

(A)(A)-(C)-((R1))

SUBB A, #data

94,dt

(A)(A)-(C)-#data

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

B-7





DPTR

(16)

OV AC

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

()
INC A
04
(A)(A)+1
INC R0
08
(R0)(R0)+1
INC R1
09
(R1)(R1)+1
INC R2
0A
(R2)(R2)+1
INC R3
0B
(R3)(R3)+1
INC R4
0C
(R4)(R4)+1
INC R5
0D
(R5)(R5)+1
INC R6
0E
(R6)(R6)+1
INC R7
0F
(R7)(R7)+1

1
1
1
1
1
1
1
1
1

INC direct

55,da

(direct)(direct)+1

INC @R0
INC @R1
INC DPTR
DEC A
DEC R0
DEC R1
DEC R2
DEC R3
DEC R4
DEC R5
DEC R6
DEC R7

06
07
A3
14
18
19
1A
1B
1C
1D
1E
1F

((R0))((R0))+1
((R1))((R1))+1
(DPTR)(DPTR)+1
(A)(A)-1
(R0)(R0)-1
(R1)(R1)-1
(R2)(R2)-1
(R3)(R3)-1
(R4)(R4)-1
(R5)(R5)-1
(R6)(R6)-1
(R7)(R7)-1

1
1
2
1
1
1
1
1
1
1
1
1

(direct)(direct)-1

((R0))((R0))-1
((R1))((R1))-1
(B)15-8{(A)(B)}
(A)7-0{(A)(B)}
:
B0 OV1
(A){(A)/(B)}
(B)
B=0 OV1
(3..0)>9 ()=1
(3..0)(3..0)+6;
(7..4)>9 =1,
(7..4)(7..4)+6

1
1

DEC direct

15,da

DEC @R0
DEC @R1

16
17

MUL AB

A4

DIV AB

84

DA A

D4

.
adr8
adr16 . .
bit () 0 FF
da (direct) ( ) 0 FF
dt (data) 0 FF
rel 80 (-128) 7F (+127)
da da. 0 FF

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

B-8

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

MCS-51
0
0

NOP

JBC
bit,rel

JB bit,rel

JNB
bit,rel

JC rel

JNC rel

JZ rel

JNZ rel
0

1
AJMP
adr11
(p000)
ACALL
adr11
(p000)
AJMP
adr11
(p001)
ACALL
adr11
(p001)
AJMP
adr11

LJMP
addr16

RR A

INC A

INC
direct

INC
@R0

INC
@R1

INC R0

INC R1

INC R2

INC R3

INC R4

INC R5

INC R6

INC R7

LCALL
addr16

RRC A

DEC A

DEC
direct

DEC
@R0

DEC
@R1

DEC R0

DEC R1

DEC R2

DEC R3

DEC R4

DEC R5

DEC R6

DEC R7

RET

RL A

ADD A,
#data

ADD A,
direct

ADD
A,@R0

ADD
A,@R1

ADD
A,R0

ADD
A,R1

ADD
A,R2

ADD
A,R3

ADD
A,R4

ADD
A,R5

ADD
A,R6

ADD
A,R7

RETI

RLC A

ADDC
A,#data

ADDC
A,direct

ADDC
A,@R0

ADDC
A,@R1

ADDC
A,R0

ADDC
A,R1

ADDC
A,R2

ADDC
A,R3

ADDC
A,R4

ADDC
A,R5

ADDC
A,R6

ADDC
A,R7

ORL A,
#data

ORL A,
direct

ORL
A,@R0

ORL
A,@R1

ORL
A,R0

ORL
A,R1

ORL
A,R2

ORL
A,R3

ORL
A,R4

ORL
A,R5

ORL
A,R6

ORL
A,R7

ANL A,
#data

ANL A,
direct

ANL
A,@R0

ANL
A,@R1

ANL
A,R0

ANL
A,R1

ANL
A,R2

ANL
A,R3

ANL
A,R4

ANL
A,R5

ANL
A,R6

ANL
A,R7

XRL A,
#data

XRL A,
direct

XRL
A,@R0

XRL
A,@R1

XRL
A,R0

XRL
A,R1

XRL
A,R2

XRL
A,R3

XRL
A,R4

XRL
A,R5

XRL
A,R6

XRL
A,R7

MOV A,
#data

MOV
direct,
#data

MOV
@R0,
#data

MOV
@R1,
#data

MOV R0,
#data

MOV R1,
#data

MOV R2,
#data

MOV R3,
#data

MOV R4,
#data

MOV R5,
#data

MOV R6,
#data

MOV R7,
#data

ORL
direct,A

ACALL
adr11
(p010)
AJMP
adr11
(p011)
ACALL
adr11
(p011)

XRL
direct,A

ANL
direct,A

ORL C,
bit

ORL
direct,
#data
ANL
direct,
#data
XRL
direct,
#data
JMP
@A+
DPTR
3

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

C-1

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

MCS-51 ()
0

3
MOVC
A,@A+P
C
MOVC
A,@A+D
PTR

DIV AB

MOV
direct,
direct

MOV
direct,
@R0

MOV
direct,
@R1

MOV
direct,
R0

MOV
direct,
R1

MOV
direct,
R2

MOV
direct,
R3

MOV
direct,
R4

MOV
direct,
R5

MOV
direct,
R6

MOV
direct,
R7

SUBB A,
#data

SUBB A,
direct

SUBB A,
@R0

SUBB A,
@R1

SUBB A,
R0

SUBB A,
R1

SUBB A,
R2

SUBB A,
R3

SUBB A,
R4

SUBB A,
R5

SUBB A,
R6

SUBB A,
R7

MOV
@R0,
direct
CJNE
@R0,
#data,
rel

MOV
@R1,
direct

MOV R0,
direct

MOV R1,
direct

MOV R2,
direct

MOV R3,
direct

MOV R4,
direct

MOV R5,
direct

MOV R6,
direct

MOV R7,
direct

CJNE
@R0,
#data,rel

CJNE
R0,
#data,rel

CJNE
R1,
#data,rel

CJNE
R2,
#data,rel

CJNE
R3,
#data,rel

CJNE
R4,
#data,rel

CJNE
R5,
#data,rel

CJNE
R6,
#data,rel

CJNE
R7,
#data,rel

AJMP
adr11
(p100)
ACALL
adr11
(p100)
AJMP
adr11
(p101)

MOV bit,
C
MOV C,
bit

INC
DPTR

MUL AB

ANL C,
bit

SJMP rel

MOV
OPTR,
#data16

ORL
C,/bit

ANL
C,/bit

ACALL
adr11
(p101)

CPL bit

CPL C

CJNE A,
#data,
rel

CJNE A,
direct, rel

PUSH
direct

AJMP
adr11
(p110)

CLR bit

CLR C

SWAP A

XCH A,
direct

XCH A,
@R0

XCH A,
@R1

XCH A,
R0

XCH A,
R1

XCH A,
R2

XCH A,
R3

XCH A,
R4

XCH A,
R5

XCH A,
R6

XCH A,
R7

POP
direct

ACALL
adr11
(p110)

SETB bit

SETB C

PA A

DJNZ
direct, rel

XCHD A,
@R0

XCHD A,
@R1

DJNZ
R0,rel

DJNZ
R1,rel

DJNZ
R2,rel

DJNZ
R3,rel

DJNZ
R4,rel

DJNZ
R5,rel

DJNZ
R6,rel

DJNZ
R7,rel

MOVX
A,
@DPTR

AJMP
adr11
(p111)

MOVX
A,@R0

MOVX
A,@R1

CLR A

MOV A,
direct

MOV A,
@R0

MOV A,
@R1

MOV A,
R0

MOV A,
R1

MOV A,
R2

MOV A,
R3

MOV A,
R4

MOV A,
R5

MOV A,
R6

MOV A,
R7

MOVX
@DPTR,
A
0

ACALL
adr11
(p111)
1

MOVX
@R0,A

MOVX
@R1,A

CPL A

MOV
direct,A

MOV
@R0, A

MOV
@R1, A

MOV R0,
A

MOV R1,
A

MOV R2,
A

MOV R3,
A

MOV R4,
A

MOV R5,
A

MOV R6,
A

MOV R7,
A

( ) ( ). , INC DPTR
A3.

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

C-2

Оценить