纯软件单片机串口

贵州家电维修网 http://www.gz112.cn 2008-4-28 16:07:44 来源:贵阳蓝天整理



纯软件单片机串口(一)

                 ;Definition of variables
SEND_READ    EQU     00H    ;Bit for write(0) or read(1)
SEND_ENDS    EQU     01H    ;Bit for communiciating(1) or ends(0)
READ_ENDS    EQU     02H    ;Bit for reading(1) or ends(0)
BAUD_RAM_H   EQU     30H    ;Communite baud TH
BAUD_RAM_L   EQU     31H    ;Communite baud TL
AMEND_RAM_L  EQU     32H
AMEND_RAM_H  EQU     33H

SEND_CODE    EQU     34H    ;Byte  that  may be send
READ_CODE    EQU     34H    ;Read  ends value byte
READ_BUFF    EQU     35H    ;Read  bit  RRC
SEND_COUNT   EQU     36H    ;Send  bit  count
READ_COUNT   EQU     36H    ;Read  bit  count
SEND_FLAG    EQU     37H    ;Send  byte flag (0-->start send)
                 ;Definition of constants
TXD          EQU     P1.6   ;TXD  line
RXD          EQU     P3.2   ;RXD  line
BAUD_H       EQU     0FFH   ;9600   4800   2400   1200   600    300
BAUD_L       EQU     0A3H   ;FFA0   FF40   FE80   FD00   FA00   F400  AMEND=03H
AMEND_H      EQU     00H    ;0000   0040   0080   0100   0200   0400
AMEND_L      EQU     00H    ; 20H    40H    80H   100H   200H   400H

                ORG     0000H
                SJMP    MAIN
                ORG     0003H
                LJMP    INPUT_INT
                ORG     000BH
                LJMP    COMM_INT
                ORG     0013H
                LJMP    READ_BYTE_INT
                ORG     0040H
MAIN:           MOV     IE,#00H
                MOV     SP,#60H
                MOV     P1,#0FFH
                MOV     P3,#0FFH

                MOV     R1,#20H         ;Clr   CPU   RAM
                MOV     R2,#40H
       LOOP:    MOV     @R1,#00H
                INC     R1
                DJNZ    R2,LOOP

                MOV     BAUD_RAM_H,#BAUD_H
                MOV     BAUD_RAM_L,#BAUD_L
                MOV     AMEND_RAM_H,#AMEND_H
                MOV     AMEND_RAM_L,#AMEND_L
                MOV     TMOD,#01H
                MOV     TH0,BAUD_RAM_H
                MOV     TL0,BAUD_RAM_L
                SETB    ET0
                SETB    PT0
                SETB    EX0                     ;Read int
                SETB    PX0
                SETB    IT0
                SETB    EX1
                ;SETB    IT1
                SETB    EA
                CLR     SEND_READ
                MOV     SEND_FLAG,#0FFH
                SETB    TR0

                LCALL   SEND_TEST_CODE
                LCALL   SEND_LOOP
                ;LCALL   READ_ONE
                LCALL   READ_STRING
                LCALL   ONLY_READ

;************************************
ONLY_READ:      MOV     R0,#40H
                CLR     SEND_READ
                MOV     SEND_FLAG,#0FH
READ_LOOP_1:    MOV     R7,#20H
                MOV     R0,#40H
READ_LOOP_0:    SETB    READ_ENDS
                JB      READ_ENDS,$
                MOV     @R0,READ_CODE
                INC     R0
                MOV     A,READ_CODE
                CJNE    A,#3FH,NEXT_0_0
                LJMP    SEND_EX
NEXT_0_0:       DJNZ    R7,READ_LOOP_0
                LJMP    READ_LOOP_1
SEND_EX:        MOV     R0,#40H
                MOV     R7,#20H
                CLR     SEND_READ
SEND_LOOP_0:    MOV     SEND_CODE,@R0
                MOV     SEND_FLAG,#00H
                INC     R0
                SETB    SEND_ENDS
                JB      SEND_ENDS,$
                MOV     A,SEND_FLAG
                CJNE    A,#03H,READ_LOOP_1
                DJNZ    R7,SEND_LOOP_0
                LJMP    READ_LOOP_1
                RET

;************************************
SEND_LOOP:      MOV     SEND_CODE,#3DH
SEND_R:         MOV     SEND_FLAG,#00H
                SETB    SEND_ENDS
                JB      SEND_ENDS,$
                MOV     A,SEND_FLAG
                CJNE    A,#03H,N1
                SJMP    SEND_LOOP
N1:            SETB    READ_ENDS
                JB      READ_ENDS,$
                MOV     SEND_CODE,READ_CODE
                SJMP    SEND_R
                RET
;************************************
READ_ONE:       MOV     SEND_FLAG,#0AH
RRR1:           SETB    READ_ENDS
                JB      READ_ENDS,$
                MOV     SEND_CODE,READ_CODE
                MOV     SEND_FLAG,#00H
                SETB    SEND_ENDS
                JB      SEND_ENDS,$
                SJMP    RRR1
                RET
;***********************************
READ_STRING:    CLR     SEND_READ
READ:           MOV     SEND_FLAG,#0FH
                MOV     R1,#40H
                MOV     R2,#00H
READ_LOOP:      SETB    READ_ENDS
                JB      READ_ENDS,$
                MOV     @R1,READ_CODE
                INC     R1
                INC     R2
                MOV     A,READ_CODE
                CJNE    A,#3FH,NEXT1
                SJMP    SEND
NEXT1:         CJNE    R2,#20H,READ_LOOP

SEND:           MOV     R1,#40H
SEND_L:        MOV     SEND_FLAG,#00H
                MOV     SEND_CODE,@R1
                SETB    SEND_ENDS
                JB      SEND_ENDS,$
                MOV     A,SEND_FLAG
                CJNE    A,#03H,READ
                INC     R1
                DJNZ    R2,SEND_L
                SJMP    READ
                RET

;******************************
SEND_TEST_CODE: MOV     R6,#61H
                MOV     R7,#1AH
                CLR     SEND_READ
    SEND_LOOP1: MOV     SEND_CODE,R6
                MOV     SEND_FLAG,#00H
                SETB    SEND_ENDS
                INC     R6
                JB      SEND_ENDS,$
                DJNZ    R7,SEND_LOOP1
                RET
;**********************************************************
READ_BYTE_INT:  MOV     @R1,READ_CODE
                RETI


;*********************************************************************
;* SEND_READ    EQU     01H    Bit for send(0) or read(1)            *
;* SEND_ENDS    EQU     02H    Bit for communiciating(1) or ends(0)  *
;* READ_ENDS    EQU     03H    Bit for reading(1) or ends(0)         *
;* SEND_COED    EQU     31H    Byte  that  may be send               *
;* READ_CODE    EQU     32H    Read  ends value byte                 *
;* SEND_COUNT   EQU     33H    Send  bit  count                      *
;* READ_COUNT   EQU     33H    Read  bit  count                      *
;* READ_BUFF    EQU     34H    Read bit circulate                    *
;* SEND_FLAG    EQU     34H    Send  byte  flag (0-->start send)     *
;*                                                                   *
;* BAUD_RAM_H   EQU     35H    Communite buad TH                     *
;* BAUD_RAM_L   EQU     36H    Communite buad TL                     *
;* AMEND_RAM_H  EQU     37H    Read interrupt amend value            *
;* AMEND_RAM_L  EQU     38H    Read interrupt amend value            *
;* TXD          EQU     P1.4   Data TXD  line                        *
;* RXD          EQU     P1.3   Data RXD  line                        *
;* When send: MOV     SEND_CODE,Value_byte (Byte that will be send)  *
;*            MOV     SEND_FLAG,#00H                                 *
;*            SETB    SEND_ENDS                                      *
;*      if SEND_ENDS is 0 that shows completed send communiciation   *
;*      if SEND_FLAG isn‘t 03H that shows send communicating has     *
;*         beed interrupted by read_input,must jump to prosses       *
;*         read_input program.                                       *
;* When read: SETB    READ_ENDS                                      *
;*            SETB    EX0                                            *
;*      if READ_ENDS is 0 that shows completed read communiciation   *
;*         and return the value byte to READ_CODE.                   *
;*        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                        *
;*        %   PROGRAM      INITIALIZE       %                        *
;*        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                        *
;* Timer 0(or 1,2)must be worked with mode 1.                        *
;* INT_timer_0 and INT_exterior_0 be necessitated corwning priority. *
;*                  CPU Clock is 11.0592M      纯软件单片机串口贵州家电维修网欢迎您!">贵州家电维修网欢迎您!">

贵州家电维修网首页 --> 学习资料 --> 原码参考 --> 纯软件单片机串口

  • 学院评论:(评论内容只代表网友观点,与本站立场无关!)

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 0分

    内 容:

             (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码

    版权及免责声明:


    1 .贵州家电维修网所有内容的版权均属于作者或页面内声明的版权人。未经贵州家电维修网的许可,任何其他个人或组织均不得以任何形式将贵州家电维修网的各项资源转载、复制、编辑或发布使用于其他任何场合。

    2 .已经本网授权使用作品的,应在授权范围内使用,并注明 “ 来源:贵州家电维修网” 。

    3 .本网注明“ 来源:XXX (非贵州家电维修网)” 的作品,均转载自其他媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。

    4 .因作品内容、版权和其他问题需要同本网联系的,请 30日内进行。

    报修热线0851-85164808  
    蓝天电器:是贵州家电维修网指定家电维修单位。蓝天电器技术人员均经过专业培训,对家电维修知识有着坚实的基础,并取得了维修家用电器的资格证书。多年来我部在各社区和单位的维修中赢得了社会各界的广泛认可。源于顾客的厚爱,蓝天电器本着“技术取胜 服务社会”的宗旨,对产品的维修质量有保证,服务有跟踪。为便捷顾客,蓝天电器提供上门服务,让顾客更省心、放心。
    服务项目:各种彩电、功放、影碟、录象机等家庭影院。冰柜、空调、冷库、电冰箱等制冷设备。电脑、音箱、软件、显示器等电脑相关。风扇、电饭煲、洗衣机、微波炉、电热水器等家用电器。


    纯软件单片机串口


    纯软件单片机串口(一)

                     ;Definition of variables
    SEND_READ    EQU     00H    ;Bit for write(0) or read(1)
    SEND_ENDS    EQU     01H    ;Bit for communiciating(1) or ends(0)
    READ_ENDS    EQU     02H    ;Bit for reading(1) or ends(0)
    BAUD_RAM_H   EQU     30H    ;Communite baud TH
    BAUD_RAM_L   EQU     31H    ;Communite baud TL
    AMEND_RAM_L  EQU     32H
    AMEND_RAM_H  EQU     33H

    SEND_CODE    EQU     34H    ;Byte  that  may be send
    READ_CODE    EQU     34H    ;Read  ends value byte
    READ_BUFF    EQU     35H    ;Read  bit  RRC
    SEND_COUNT   EQU     36H    ;Send  bit  count
    READ_COUNT   EQU     36H    ;Read  bit  count
    SEND_FLAG    EQU     37H    ;Send  byte flag (0-->start send)
                     ;Definition of constants
    TXD          EQU     P1.6   ;TXD  line
    RXD          EQU     P3.2   ;RXD  line
    BAUD_H       EQU     0FFH   ;9600   4800   2400   1200   600    300
    BAUD_L       EQU     0A3H   ;FFA0   FF40   FE80   FD00   FA00   F400  AMEND=03H
    AMEND_H      EQU     00H    ;0000   0040   0080   0100   0200   0400
    AMEND_L      EQU     00H    ; 20H    40H    80H   100H   200H   400H

                    ORG     0000H
                    SJMP    MAIN
                    ORG     0003H
                    LJMP    INPUT_INT
                    ORG     000BH
                    LJMP    COMM_INT
                    ORG     0013H
                    LJMP    READ_BYTE_INT
                    ORG     0040H
    MAIN:           MOV     IE,#00H
                    MOV     SP,#60H
                    MOV     P1,#0FFH
                    MOV     P3,#0FFH

                    MOV     R1,#20H         ;Clr   CPU   RAM
                    MOV     R2,#40H
           LOOP:    MOV     @R1,#00H
                    INC     R1
                    DJNZ    R2,LOOP

                    MOV     BAUD_RAM_H,#BAUD_H
                    MOV     BAUD_RAM_L,#BAUD_L
                    MOV     AMEND_RAM_H,#AMEND_H
            &nbs;  ACC
                    RETI
    ;*******************************************************************
    ;*   The following subroutine is a exterior interrupt serve on     *
    ;*                  communiciated interrupt                        *
    ;*******************************************************************
    INPUT_INT:      PUSH    ACC
                    PUSH    PSW
                    CLR     EX0             ;=======================
                    CLR     SEND_ENDS       ;Interrup send commiciating
                    MOV     SEND_FLAG,#0AH  ;Alter the send_flag for main program
                    SETB    TXD

                    CLR     TR0             ;Setup for read
                    SETB    SEND_READ       ;Set INI_timer status for read
                    MOV     READ_COUNT,#08H
                    MOV     A,BAUD_RAM_L    ;Amend  start  bit  clock  cycle
                    SUBB    A,AMEND_RAM_L
                    MOV     TL0,A
                    MOV     A,BAUD_RAM_H
                    SUBB    A,AMEND_RAM_H
                    MOV     TH0,A
                    SETB    TR0
                    CLR     TF0
                    POP     PSW
                    POP     ACC
                    RETI

            END


    纯软件单片机串口(二)
    这是另外一个使用中断查寻的程序!
    www.ubicom.com or www.scenix.com
    到UBICOM看看,那里的串口都是纯软件的 

    SEND_READ    EQU     01H    ;Bit for write(0) or read(1)
    SEND_ENDS    EQU     02H    ;Bit for communiciating(1) or ends(0)  
    READ_ENDS    EQU     03H    ;Bit for reading(1) or ends(0)
    READ_INT     EQU     04H    ;Bit intettupt sending to reading
    BUAD_RAM_H   EQU     30H    ;Communite buad TH
    BUAD_RAM_L   EQU     31H    ;Communite buad TL
    SEND_TIME    EQU     32H    ;Send int times count
    READ_TIME    EQU     33H    ;Read int times count
    SEND_CODE    EQU     34H    ;Byte  that  may be send
    READ_CODE    EQU     35H    ;Read  ends value byte
    READ_BUFF    EQU     36H    ;Read  bit  RRC
    SEND_COUNT   EQU     37H    ;Send  bit  count
    READ_COUNT   EQU     38H    ;Read  bit  count
    SEND_FLAG    EQU     39H    ;Send  byte flag (0-->start send)
    READ_FLAG    EQU     3AH    ;Read  byte flag (0-->check start bit)
    TXD_LINE     EQU     P3.1;P1.6   ;TXD  line
    RXD_LINE     EQU     P3.0;P3.2   ;RXD  line
    BUAD_H       EQU     0FFH   ;9600   4800   2400   1200   600    300
    BUAD_L       EQU     0C3H   ;FFE0   FFC0   FF80   FF00   FE00   FC00

                    ORG     0000H
                    SJMP    MAIN
                    ORG     000BH
                    LJMP    COMM_INT
                    ORG     0040H
    MAIN:           MOV     IE,#00H
                    MOV     SP,#62H
                    MOV     P1,#0FFH
                    MOV     P3,#0FFH

                    MOV     R1,#30H         ;Clr   CPU   RAM
                    MOV     R2,#30H
           LOOP:    MOV     @R1,#00H
                    INC     R1
                    DJNZ    R2,LOOP

                    MOV     BUAD_RAM_H,#BUAD_H
                    MOV     BUAD_RAM_L,#BUAD_L
                    MOV     TMOD,#01H
                    MOV     TH0,BUAD_RAM_H
                    MOV     TL0,BUAD_RAM_L
                    SETB    TR0
                    SETB    ET0
                    SETB    PT0
                    SETB    EA
                    SETB    SEND_ENDS
                    SETB    READ_ENDS
                    LCALL   SEND_TEST_CODE
                    LCALL   TEST1


    LOOP0:          MOV    

    】 【返回上一页】 【打 印】 【  
    更多关于“纯软件单片机串口”的学院文章
    更多关于“学院”的新闻
    更多>>图片新闻