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

📄 510_uart.dt

📁 台弯义隆芯片UART串行控制实例说明Application of UART 。
💻 DT
字号:
;****************************************************************;
; TILTE:       EM78P510 UART TRANSMISSION DEMO CODE              ;
; FUNCTION:    EM78P510 UART FUNCTION                            ;
; COMPANY:     ELAN MICROELECTRONICS (SZ) LTD.                   ;
;****************************************************************;
; ; This is an example of EM78P510 transmits 10byte data circularly, 
;and receiving data  at the same time, the time interval for a data transmission is 0.5S, 
;and the 10 sets datasent are FEH,FCH,F8H,F0H,E0H,C0H,80H,00H,55H and AAH.
; The main program doesn't doesn't enable UART interruption function, 
;and the interrupted son program is simply 
; Fmain: crystal, Fsub: crystal
;-----------------------------------------------------------------
R0          ==      0x00    ; Indirect Address Register
TCC         ==      0x01    ; Time Clock/Counter
PC          ==      0x02    ; Program Counter & Stack
STATUS      ==      0x03    ;
    C       ==      0       ; Carry flag
    Z       ==      2       ; Zero flag
R4          ==      0x04    ; RAM Select Register
TWTCR       ==      0x0D    ; TCC and WDT timer control register
RE          ==      0x0E    ; Interrupt mask register
RF          ==      0x0F    ; Interrupt status register
    URTIF   ==      3       ; Interrupt flag of UART
Data_Buf    ==      0x1F    ; Data buffer
; Bank 3
URC         ==      0x05    ; UART control register
    UTBE    ==      1       ; UART tranfer buffer empty flag
    TXE     ==      0       ; Enable transmission
URS         ==      0x06    ; UART status register
    URBF    ==      1       ; UART Read Buffer Full Flag
    RXE     ==      0       ; Enable receiving
URRD        ==      0x07    ; UART read buffer
URTD        ==      0x08    ; UART write buffer
; Bank 4
PIOCRA      ==      0x0A    ; PortA I/O control register
; Bank 5
UARC2       ==      0x06    ; UART control register 2
;-----------------------------------------------------------------
        ORG     0x00
        JMP     Main
        ORG     0X15            ; UART interrupt vector
        JMP     UART_INT        ; To UART interrupt program
        ORG     0x20
;-----------------------------------------------------------------
UART_INT:
        ; User code
        ; …
        BC      RF, URTIF
        RETI
;-----------------------------------------------------------------
Main:
        MOV     A, @0x0D        ; Disable WDT, TCC clock source is Fsub
        MOV     TWTCR, A        ; Tcc 0.5s overflow
        CLR     TCC             ; Clear TCC
        CLR     Data_Buf        ; Clear data_buf
        MOV     A, @0x01
        MOV     RE, A           ; Enable TCC interrupt
        Bank    3
        MOV     A, @10101000b   ; Select mode 2: 8bit, baud rate: 9600
        MOV     URC, A          ; and disable tranfer
        MOV     A, @00100000b   ; Select odd parity and enable parity
        MOV     URS, A
        BANK    5
        MOV     A, @00100000b   ; Enable uart function
        MOV     UARC2, A
;
        BANK    0
        CLR     Data_Buf
        MOV     A, @0xD0        ; The start address is 0x10
        MOV     R4, A
LOOP:
        BANK    3
        BS      URC, TXE        ; Enable transmission
        BS      URS, RXE        ; Enable receiving
        MOV     A, Data_Buf     ; To get data to transfer
        CALL    Data_Tbl
        MOV     URTD, A
        JBS     URC, UTBE
        JMP     $-1
;
        JBS     URS, URBF       ; Check receive
        JMP     $-1
        MOV     A, URS
        AND     A, @00011100b   ; Check error
        JBS     STATUS, Z
        JMP     LOOP            ; Error, repeat
        MOV     A, URRD         ; Read data received
        MOV     R0, A           ; Store the value
        BANK    0
        JBS     RF, 0           ; Wait for 0.5s to shift next data
        JMP     $-1
        CLR     RF              ; Clear TCC flag
        INC     R4
        INC     Data_Buf
        MOV     A, @0x0A        ; If shifting data less than 10 bytes, loop
        SUB     A, Data_Buf
        JBS     STATUS, C       ; Finish to receive 10 bytes data?
        JMP     LOOP            ; To transfer next byte data
        NOP
        NOP
        JMP     $
        ;-----------------------------------
Data_Tbl:
        ADD     PC, A
        RETL    0xFE        ; 0
        RETL    0xFC        ; 1
        RETL    0xF8        ; 2
        RETL    0xF0        ; 3
        RETL    0xE0        ; 4
        RETL    0xC0        ; 5
        RETL    0x80        ; 6
        RETL    0x00        ; 7
        RETL    0x55        ; 8
        RETL    0xAA        ; 9
        NOP
        NOP
        ;-----------------------------------
        END

⌨️ 快捷键说明

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