最新三星单片机应用

S3F9488带校验位UATR通信方式编程子程序(汇编)

Published:2008.10.06 NewsFrom:ZHANHENG TECHNOLOGY(HK)CO.,LTD/SHENZHEN ZHANHENGLONG ELECTRONIC CO,LTD Views:
ERRFLAG EQU 00H
UART_IP EQU 01H
;----------------------------------------------------
;UARTCON标志位定义
TB8 BIT UARTCON.3
RB8 BIT UARTCON.2
TIE BIT UARTCON.0
RIE BIT UARTCON.1
RPE BIT UARTPND.4 ;奇偶校验位检查标示
;UARTPND标志位定义
UTIP BIT UARTPND.0
URIP BIT UARTPND.1
TIP BIT UART_IP.0
RIP BIT UART_IP.1

ERRFLAG EQU 00H
UART_IP EQU 01H
;-----------------------------------------------------

        ;注意事项:
        ;如果P3.1作为RXD输入,则必须设定其为RXD_INPUT MODE
        LD P3CONH,#11111010B ;set P3.6,P3.5 as open-drain output
        LD P3CONL,#01100010B ;set P3.4,P3.3 as push-pull output
                                                ;set P3.2 as TXD
                                                ;set P3.1 as RXD
                                                ;set P3.0 as input with pull-up
        ;配置芯片各复用功能
        ;注意设置波特率必须切换到RAM BANK1页面
        LD SYM,#01H ;选择REG PAGE1
        LD 14H,#00H ;BRDATAH
        LD 15H,#0FH ;BRDATAL
                                ;10MHZ clock,set BAUT=38400 bit/s
        LD SYM,#00H ;选择REG PAGE0
        LD UARTPND,#00100000B ;enable parity bit
        LD UARTCON,#10010011B ;set 9bit UART,BAUT=Fxx/16*(BRDATA+1)
                                                ;set Even parity,enable tx/rx interrupt
        LD TACON,#01H ;set TA input clock=Fosc/1024=102.4us
                                                ;set TA as interval timer mode
                                                ;最大计时26MS
                                                ;disable TA interrupt
;-------------------------------------------------------------
;接收一个数据的过程,最长接收等待时间为1MS*100=100MS
;接收成功则数据在R0中
RX_ONE_DATA:
        PUSH R5
        EI
        CLR ERRFLAG
        OR TACON,#08H ;复位TA定时器
        LD R5,#64H
WAIT_RX_DATA:
        LD BTCON,#02H
        TMBIT RIP
        JR NZ,CHK_RX_DATA
        ;检查接收定时
        CP TACNT,#0AH
        JR ULE,WAIT_RX_DATA
        OR TACON,#08H ;复位TA定时器
       
        DEC R5
        JR NZ,WAIT_RX_DATA
        JR RX_FAIL_BACK ;如果时间溢出,接收失败
CHK_RX_DATA:
        ;检查奇偶校验位是否错
        TMBIT RPE
        JR NZ,RX_FAIL_BACK
        CLRBIT RIP
        LD R0,RX_DATA
        ;接收数据成功返回
        CLR ERRFLAG
        JR RX_DATA_EXIT
RX_FAIL_BACK:
        LD ERRFLAG,#ER_COM
RX_DATA_EXIT:
        POP R5
        RET
;-------------------------------------------------------------
;向主机发送一个字节数据的过程,该字节可以是任何二进制数据
;数据在R0中
TX_ONE_DATA:
        CLRBIT TIP
        EI
        LD UDATA,R0
WAIT_TX:
        LD BTCON,#02H
        LD WDTCON,#0AH
        TMBIT TIP
        JR Z,WAIT_TX
        CLRBIT TIP
        DI
        RET
;---------------------------------------------------------------
UART_INT:
        TMBIT URIP
        JR NZ,RX_INT
        TMBIT UTIP
        JR NZ,TX_INT
        JR END_INT
RX_INT:
        LD RX_DATA,UDATA
        CLRBIT URIP ;清接收中断标志
        SETBIT RIP ;设置已接收标志
        JR END_INT
TX_INT:
        CLRBIT UTIP ;清发送中断标志
        SETBIT TIP ;设置已发送完成标志
END_INT:
        LD WDTCON,#0AH
        LD BTCON,#02H
        IRET
Development tools for MCU
Programming console for MCU
Development tools for ARM
the C compiler
Contact
Samsung SCM:

ic168@zh-ic.COM

Development Tools:

B6078S@163.com

Site suggestions:

zh-ic@163.com

  Service
 MSN