📄 sci.s
字号:
.module SCI.c
.area text
; o -> 2,X
_SCISend1::
tsx
bra L3
L2:
; /*-----------------------------------------------------*
; *文件描述:本文件包含了串行通信的4子程序,分别为: *
; *(1)SCISend1:串行发送1字节 *
; *(2)SCISendN:串行发送n字节 *
; *(3)SCIRe1:串行接收1字节 *
; *(4)SCIReN:串行接收n字节 *
; *-------------《嵌入式应用技术基础教程》--------------*/
; //[以下为子程序源代码]
; //[包含头文件]
; #include "SCI.h"
; /*SCISend1:串行发送1个字节-----------------------------*
; *功 能:串行发送1个字节 *
; *参 数:要发送的数据 *
; *返 回:无 *
; *-----------------------------------------------------*/
; void SCISend1(unsigned char o)
; {//判断ReStatusR的第SendTestBit位是否为1,是1可以发送
; while(1)
; if ((ReSendStatusR & (1<<SendTestBit)) != 0)
brclr #7,0x16,L5
; { ReSendDataR=o;
lda 2,X
sta 0x18
; break;}
bra L4
L5:
L3:
bra L2
L4:
L1:
.dbline 0 ; func end
rts
; i -> 0,X
; ch -> 5,X
; n -> 4,X
_SCISendN::
ais #-2
tsx
; }
; /*SCISendN:串行发送N个字节-----------------------------*
; *功 能:发送数组中的N个字节数据 *
; *参 数:待发送的数据字节数及其要存放的数组首地址 *
; *返 回:无 *
; *-----------------------------------------------------*/
; void SCISendN(unsigned char n,unsigned char ch[])
; {int i;
; for(i=0;i<n;i++)
clr 1,X
clr ,X
bra L11
L8:
lda 1,X
add 6,X
sta *__r1
lda ,X
adc 5,X
sta *__r0
ldhx *__r0
lda ,x
psha
jsr _SCISend1
ais #1
tsx
L9:
lda 1,X
add #1
sta 1,X
lda ,X
adc #0
sta ,X
L11:
clr *__r0
lda 4,X
sta *__r1
lda 1,X
sta *__r3
lda ,X
sta *__r2
ldhx *__r2
cphx *__r0
tsx
blt L8
L7:
ais #2
.dbline 0 ; func end
rts
; i -> 0,X
; k -> 1,X
; p -> 5,X
_SCIRe1::
ais #-3
tsx
; SCISend1(ch[i]);
; }
; /*SCIRe1:串行收一个字节数据----------------------------*
; *功 能:从串行口接收1个字节的数据 *
; *参 数:标志指针p *
; *返 回:接收到的数据(若接收失败,返回0xff) *
; *说 明:参数*p带回接收标志=0收到数据,=1未收到数据 *
; *-----------------------------------------------------*/
; unsigned char SCIRe1(unsigned char *p)
; { unsigned int k;
; unsigned char i;
; //ReStatusR第ReTestBit位为1表示可接收数据
; for(k=0;k<0xfbbb;k++)
clr 2,X
clr 1,X
bra L16
L13:
; if ((ReSendStatusR & (1<<ReTestBit)) != 0)
brclr #5,0x16,L17
; {i=ReSendDataR;
lda 0x18
sta ,X
; *p=0x00;
lda 6,X
sta *__r1
lda 5,X
sta *__r0
clra
ldhx *__r0
sta ,x
tsx
; break;}
bra L15
L17:
L14:
lda 2,X
add #1
sta 2,X
lda 1,X
adc #0
sta 1,X
L16:
lda 2,X
sta *__r1
lda 1,X
sta *__r0
ldhx *__r0
cphx #-1093
tsx
blo L13
L15:
; if(k>=0xfbbb)
lda 2,X
sta *__r1
lda 1,X
sta *__r0
ldhx *__r0
cphx #-1093
tsx
blo L19
; {i=0xff;
lda #-1
sta ,X
; *p=0x01;}
lda 6,X
sta *__r1
lda 5,X
sta *__r0
lda #1
ldhx *__r0
sta ,x
tsx
L19:
; return i; //返回接收到的数据
lda ,X
L12:
ais #3
.dbline 0 ; func end
rts
; fp -> 0,X
; m -> 1,X
; ch -> 6,X
; n -> 5,X
_SCIReN::
ais #-3
tsx
; }
; /*SCIReN:HC08串行接收N个字节---------------------------*
; *功 能:接收N个字节数据,并存放在ch数组中 *
; *参 数:待接收的数据字节数及其存放的数组首地址 *
; *返 回:接收标志=0收到数据,=1未收到数据 *
; *-----------------------------------------------------*/
; unsigned char SCIReN(unsigned char n,unsigned char ch[])
; {int m;
; unsigned char fp;
; m=0;
clr 2,X
clr 1,X
bra L23
L22:
; while (m<n)
; {
; ch[m]=SCIRe1(&fp);
pshx
pshh
jsr _SCIRe1
ais #2
tsx
sta *__r1
lda 2,X
add 7,X
sta *__r3
lda 1,X
adc 6,X
sta *__r2
lda *__r1
ldhx *__r2
sta ,x
tsx
; if (fp==1) return 1;
lda ,X
cmp #1
bne L25
lda #1
bra L21
L25:
lda 2,X
add #1
sta 2,X
lda 1,X
adc #0
sta 1,X
L23:
clr *__r0
lda 5,X
sta *__r1
lda 2,X
sta *__r3
lda 1,X
sta *__r2
ldhx *__r2
cphx *__r0
tsx
blt L22
; m++;
; }
; return 0;
clra
L21:
ais #3
.dbline 0 ; func end
rts
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -