HT48R50A的 RS232串口示例程序
扫描二维码
随时随地手机看文章
;********************************************
;Function:基于HT48R50A的RS232串口示例程序*
;MICroProcessor:HT48R50A-1/28SKDIP-A*
;Author:www.picavr.com*
;Crystal:4MHz*
;********************************************
#INCLUDEHT48R50A-1.INC
TXDEQUPB.1
RXDEQUPB.0
BAUDRATEEQU135;2400,N,8,1
;--------------------------------------------------------------------
PUBLICTRANSMIT
PUBLICRECEIVE
;--------------------------------------------------------------------
DATA_RS232.SECTION’DATA’
COUNTERDB?
DELAY_COUNTERDB?
DELAY_COUNTER_1DB?
DELAY_COUNTER_2DB?
TRANSMIT_DATADB?
RECEIVE_DATADB?
;--------------------------------------------------------------------
TRANSMIT_CODE.SECTION’CODE’
TRANSMIT:
MOV TRANSMIT_DATA,A
SETPB
MOV A,00000001B
MOV PBC,A
MOV A,BAUDRATE
MOV DELAY_COUNTER,A
CLRTXD;SENDSTART
T_START_BIT:;BIT
SDZDELAY_COUNTER
JMPT_START_BIT
;-------------------------------------------------------
MOV A,08H
MOV COUNTER,A
T_DATA_BIT:
RRCTRANSMIT_DATA
SNZC
JMPT_SEND_LOW
SETTXD
JMPT_BIT_DELAY
T_SEND_LOW:
CLRTXD
T_BIT_DELAY:
MOV A,BAUDRATE
MOV DELAY_COUNTER,A
T_DELAY_SEND:
SDZDELAY_COUNTER
JMPT_DELAY_SEND
SDZCOUNTER
JMPT_DATA_BIT
;-------------------------------------------------------
TRANSMIT_END:
SETTXD;SENDSTOP
;BIT
MOV A,025H
MOV DELAY_COUNTER_1,A
MOV DELAY_COUNTER_2,A
T_STOP_DELAY:
SDZDELAY_COUNTER_2
JMPT_STOP_DELAY
SDZDELAY_COUNTER_1
JMPT_STOP_DELAY
RET
;--------------------------------------------------------------------
RECEIVE_CODE.SECTION’CODE’
RECEIVE:
SETPB
MOV A,00000001B
MOV PBC,A
R_START_BIT:
SZRXD;RECEIVE
JMPR_START_BIT;STARTBIT
MOV A,BAUDRATE+2
MOV DELAY_COUNTER,A
R_START_BIT_DELAY:
SDZDELAY_COUNTER
JMPR_START_BIT_DELAY
;-------------------------------------------------------
MOV A,08H
MOV COUNTER,A
R_DATA_8_BITS:
CLRC
SZRXD
SETC
RRCRECEIVE_DATA
MOV A,BAUDRATE+2
MOV DELAY_COUNTER,A
R_DATA_BIT_DELAY:
SDZDELAY_COUNTER
JMPR_DATA_BIT_DELAY
SDZCOUNTER
JMPR_DATA_8_BITS
;-------------------------------------------------------
MOV A,RECEIVE_DATA
;-------------------------------------------------------
RET
;--------------------------------------------------------------------