?? sci.s
字號:
.module SCI.c
.area text
; o -> 2,X
_SCISend1::
tsx
bra L3
L2:
; /*-----------------------------------------------------*
; *文件描述:本文件包含了串行通信的4子程序,分別為: *
; *(1)SCISend1:串行發(fā)送1字節(jié) *
; *(2)SCISendN:串行發(fā)送n字節(jié) *
; *(3)SCIRe1:串行接收1字節(jié) *
; *(4)SCIReN:串行接收n字節(jié) *
; *-------------《嵌入式應(yīng)用技術(shù)基礎(chǔ)教程》--------------*/
; //[以下為子程序源代碼]
; //[包含頭文件]
; #include "SCI.h"
; /*SCISend1:串行發(fā)送1個字節(jié)-----------------------------*
; *功 能:串行發(fā)送1個字節(jié) *
; *參 數(shù):要發(fā)送的數(shù)據(jù) *
; *返 回:無 *
; *-----------------------------------------------------*/
; void SCISend1(unsigned char o)
; {//判斷ReStatusR的第SendTestBit位是否為1,是1可以發(fā)送
; 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:串行發(fā)送N個字節(jié)-----------------------------*
; *功 能:發(fā)送數(shù)組中的N個字節(jié)數(shù)據(jù) *
; *參 數(shù):待發(fā)送的數(shù)據(jù)字節(jié)數(shù)及其要存放的數(shù)組首地址 *
; *返 回:無 *
; *-----------------------------------------------------*/
; 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:串行收一個字節(jié)數(shù)據(jù)----------------------------*
; *功 能:從串行口接收1個字節(jié)的數(shù)據(jù) *
; *參 數(shù):標(biāo)志指針p *
; *返 回:接收到的數(shù)據(jù)(若接收失敗,返回0xff) *
; *說 明:參數(shù)*p帶回接收標(biāo)志=0收到數(shù)據(jù),=1未收到數(shù)據(jù) *
; *-----------------------------------------------------*/
; unsigned char SCIRe1(unsigned char *p)
; { unsigned int k;
; unsigned char i;
; //ReStatusR第ReTestBit位為1表示可接收數(shù)據(jù)
; 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; //返回接收到的數(shù)據(jù)
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個字節(jié)---------------------------*
; *功 能:接收N個字節(jié)數(shù)據(jù),并存放在ch數(shù)組中 *
; *參 數(shù):待接收的數(shù)據(jù)字節(jié)數(shù)及其存放的數(shù)組首地址 *
; *返 回:接收標(biāo)志=0收到數(shù)據(jù),=1未收到數(shù)據(jù) *
; *-----------------------------------------------------*/
; 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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -