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

📄 sci_int.mod

📁 该应用软件可以实现大多数单片机的仿真实验
💻 MOD
📖 第 1 页 / 共 2 页
字号:
;**********************************************************************
;* Module    : SCI_INT.MOD
;* Programmer: Tony Papadimitriou
;* Purpose   : Interrupt-driven SCI RX and TX OS-called routines
;* Language  : MC68HC11 (ASM11 v1.83+)
;* Status    : FREEWARE, Copyright (c) 1999 by Tony Papadimitriou
;* Segments  : RAM    : Variables
;*           : ROM    : Code
;*           : SEG9   : OS definitions (this allows adding more functions)
;*           : VECTORS: SCI vector
;* Subsystems: Makes use of SCI interrupts
;* History   : 99.11.12 v1.00 Original (Started on 99.11.12)
;*           : 99.11.12 v1.01 Added fGetChar
;*           : 99.11.27 v1.02 Added fGetPossibleChar (doesn't wait for char)
;**********************************************************************

#ifmain ;---------- allows for separate compilation -------------------
                    #LISTOFF
                    #INCLUDE  811E2.INC
                    #INCLUDE  COMMON.INC
                    #INCLUDE  OS11/OSERRORS.INC
                    #LISTON

                    #SEG9
                    ORG       $FF00
#endif
                    #RAM
?MAXBUF             EQU       16                  ;RX and TX buffer lengths

; zero RX.index or TX.index indicates empty buffer

?RX.index           rmb       1                   ;offset into RX buffer
?RX.buffer          rmb       ?MAXBUF             ;buffer for received characters

?TX.index           rmb       1                   ;offset into TX buffer
?TX.buffer          rmb       ?MAXBUF             ;buffer for characters to transmit

                    #SEG9
#ifndef OSCommands
OSCommands          equ       *
#endif

fError              equ       *-OSCommands/2      ;Print error message on the SCI
                    dw        ?Error

fErrorJump          equ       *-OSCommands/2      ;fError and jump to address
                    dw        ?ErrorJump

fUsrErrorJump       equ       *-OSCommands/2      ;Like fErrorJump with User error
                    dw        ?UsrErrorJump

fSetBAUD            equ       *-OSCommands/2      ;Set SCI bps ("baud") rate
                    dw        ?SetBAUD

fPrint              equ       *-OSCommands/2      ;Print the following FCS string
                    dw        ?Print

fGetPossibleChar    equ       *-OSCommands/2      ;Read SCI char is present into RegA
                    dw        ?GetPossibleChar

fGetChar            equ       *-OSCommands/2      ;Read SCI char into RegA
                    dw        ?GetChar

fPutChar            equ       *-OSCommands/2      ;Write RegA character to the SCI
                    dw        ?PutChar

fWrite              equ       *-OSCommands/2      ;Write a "Pascal" string to SCI
                    dw        ?Write

fWriteln            equ       *-OSCommands/2      ;fWrite followed by CR,LF pair
                    dw        ?Writeln

fNewLine            equ       *-OSCommands/2      ;Send a CR,LF pair to the SCI
                    dw        ?NewLine

fWriteZ             equ       *-OSCommands/2      ;Write an ASCIZ string to SCI
                    dw        ?WriteZ

fWritelnZ           equ       *-OSCommands/2      ;fWriteZ followed by CR,LF pair
                    dw        ?WritelnZ

#PAGE ;Operating System routines expanded
**********************************************************************
*                 Operating System routines expanded                 *
**********************************************************************
                    #ROM

; Purpose: Print error message on the SCI and jump to address in X
; Input  : B holds error code
;        : X holds address to jump to after printing error
; Output : None
?ErrorJump          ldx       X_,y                ;get address to jump to
                    stx       PC_,y               ;and use it as return PC
          ; fall through to fError (do not change fError's location)

; Purpose: Print error message on the SCI
; Input  : B holds error code
; Output : None
; Note(s): Uses fPrint, fWritelnZ
?Error              ldb       B_,y                ;get error code
                    beq       ?Error.Exit         ;not an error
                    decb                          ;make error zero-based
                    clra                          ;we'll be using D
                    lsld                          ;multiply by size of table entries
                    cmpd      #?Error.Size        ;is it within our table size
                    bhs       ?Error.Exit         ;invalid error code, get out
                    addd      #?Error.Table       ;point to beginning of table
                    xgdx                          ;put pointer in X
                    ldx       ,x                  ;get pointer to error msg
                    os        fPrint              ;print standard error header
                    fcs       CR,LF,'OS ERROR('
                    os        fWritelnZ
?Error.Exit         clc
                    rts

?Error.Table        dw        ?Error.1
                    dw        ?Error.2
                    dw        ?Error.3
                    dw        ?Error.4
                    dw        ?Error.5
                    dw        ?Error.6
?Error.Size         equ       *-?Error.Table/2

?Error.1            fcs       '1): Other'
?Error.2            fcs       '2): Invalid Call'
?Error.3            fcs       '3): Bad Parameter'
?Error.4            fcs       '4): Failed'
?Error.5            fcs       '5): Out Of Range'
?Error.6            fcs       '6): Not found'

; Purpose: Print user error message on the SCI
; Input  : Y -> user error message
;        : X holds address to jump to after printing error
; Output : None
; Note(s): Uses fPrint, fWritelnZ
?UsrErrorJump       os        fPrint              ;print standard error header
                    fcs       CR,LF,'ERROR: '
                    ldx       Y_,y                ;get pointer to error msg
                    os        fWritelnZ
                    ldx       X_,y                ;set user address
                    stx       PC_,y               ;..to return to
                    clc
                    rts

; Purpose: Set SCI BAUD rate to one of the following values (in A_,y)
;          3(00), 12(00), 24(00), 48(00), 96(00), 125(000)
;          (use number outside parentheses for corresponding baud rate)
; Input  : RegA = Baud Rate (without trailing zeros)
; Note(s): Assumes 8MHz XTAL (2MHz E-Clock)
?BPS_Table          db        3,$35               ;300 bps (user value, MCU value)
                    db        12,$33              ;1200 bps
                    db        24,$34              ;2400 bps
                    db        48,$31              ;4800 bps
                    db        96,$30              ;9600 bps
                    db        125,$00             ;125000 bps
?BPS_Table.Entries  equ       *-?BPS_Table/2      ;number of entries in table

?SetBAUD            lda       A_,y                ;get user bps rate value
                    ldx       #?BPS_Table         ;point to table with MCU bps rates
                    ldb       #?BPS_Table.Entries ;get number of entries to test
?SetBAUD.BpsLoop    cmpa      ,x                  ;is it the same as in table?
                    beq       ?SetBAUD.SetBAUD    ;go set it
                    inx:2                         ;point to next entry
                    decb                          ;are we done with all entries?
                    bne       ?SetBAUD.BpsLoop    ;if not, try again
?SetBAUD.Error      ldb       #errBadParm         ;not found, return error code in B
                    sec
                    rts
?SetBAUD.SetBaud    lda       1,x                 ;get MCU bps rate value
                    clr       SCCR2               ;disable SCI while changing BAUD
                    sta       BAUD
                    clr       SCCR1
                    lda       #%00101100          ;Interrupt RX and TX mode
                    sta       SCCR2
; Clear the buffer to be used for transmission/receipt of data
                    ldx       #?RX.index          ;get pointer to beginning of vars
                    ldb       #?MAXBUF+1*2        ;get length for both buffers and indices
?SetBAUD.Loop       clr       ,x                  ;clear buffer
                    inx                           ;advance pointer
                    decb                          ;one less to go
                    bne       ?SetBAUD.Loop       ;repeat until done
                    clc                           ;no error exit
                    rts

; Purpose: Print constant ASCIZ string following OS instruction (with FCS)
; Parms  : None
?Print              ldx       PC_,y               ;get address following OS
?Print.Loop         lda       ,x                  ;get character to print
                    beq       ?Print.Exit         ;at the end of ASCIZ string, exit
                    bsr       ?PutChar.Local      ;send the character to SCI
                    inx                           ;point to next character
                    bne       ?Print.Loop         ;avoids infinite loops
?Print.Exit         inx                           ;point after NUL
                    stx       PC_,y               ;..to use as return address
                    clc                           ;no errors

⌨️ 快捷键说明

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