⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libdemo.bas

📁 82 sample programs written in BASCOM-8051 for 8051 developement
💻 BAS
字号:
'---------------------------------------------------------------------
'                         LIBDEMO.BAS
'                      (c) 2000 MCS Electronics
'This example shows how to make use of ASM libs
'---------------------------------------------------------------------
'First we tell the compiler about the lib
$lib "Ltc1091.lib"

'Second we tell which subroutine must be included from that lib
$external _ltc1091

'[ALIAS]
'It is a good idea to alias the used pins and to precede the clock and
'other pins with the chipname
Ltc1091_cs Alias P1.4
Ltc1091_clock Alias P1.3
Ltc1091_din Alias P1.2

'Now declare the subroutine
Declare Sub Ltc1091(w As Word)

'We pass a word to this routine
Dim W As Word

'call the sub routine with variable W
Ltc1091 W
Print W
End

'here we create the SUB
'this would normally not be needed but it is the only way to pass the address
'of the variable to the sub routine. This will be changed in the future and then
'you could ommit this code! So it is a good idea to store it into an include file
'when you have a buncg of them
Sub Ltc1091(w As Word)
    $asm
    ' We put the address of the MSB into register r0
    mov r0,#{w+1}                                             ; address of MSB W into r0
    'now call the actually routine in the lib
    lcall _ltc1091
    'the lib routine handles the rest
    $end Asm
End Sub

'(
The Lib Routine Is Shown Here But It Should Go Into The File
Ltc1091.lib
The Ltc1091.lib File Is Stored In The Lib Subdir
[_LTC1091]
_LTC1091:
   Setb {ltc1091_cs}        ; cs goes high
_ltcAgain:
   Mov a,#255               ; DIN word for LTC1091
   Clr {ltc1091_cs}         ; cs low
   Mov R4,#4                ; load counter
_ltcLoop1:
   Rlc a                    ; rotate DIN bit to carry
   Clr {ltc1091_clock}      ; clock goes low
   Mov {ltc1091_din}, c     ; output to ltc
   Setb {ltc1091_clock}     ; clock goes high
   Djnz r4, _ltcLoop1       ; do 4 bits
   Setb {ltc1091_din}       ; make DIN an input
   Clr {ltc1091_clock}      ; clock goes low
   Mov r4,#2                ; load bit counter
   Clr a                    ; clear accu
_ltcLoop:
   Mov c,{ltc1091_din}      ; read bit on DIN and store in carry
   Rlc a                    ; rotate left
   Setb {ltc1091_clock}     ; clock goes high
   Clr {ltc1091_clock}      ; clock goes low
   Djnz r4,_ltcLoop         ; do 2 bits
   Mov @r0,a                ; store MSB of word
   Dec r0                   ; point to LSB

   Mov r4,#8                ; and the LSB
_ltcLoop2:
   Mov c,{ltc1091_din}      ; read bit on DIN and store in carry
   Rlc a                    ; rotate left
   Setb {ltc1091_clock}     ; clock goes high
   Clr {ltc1091_clock}      ; clock goes low
   Djnz r4,_ltcLoop2        ; do 8 bits
   Mov @r0,a                ; store in LSB of W
   Setb {ltc1091_cs}        ; cs goes high
Ret
[END]

')

End

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -