| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 861 人关注过本帖
标题:菜鸟请教高手……
只看楼主 加入收藏
ayyan
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-3-12
收藏
 问题点数:0 回复次数:0 
菜鸟请教高手……
下面是自己编得一个小程序,不是很懂汇编,所以整个程序不知道具体哪出问题了,还请高手指教,谢谢!

INCLUDE 'derivative.inc'
XDEF _Startup, main,SYS_Init
XREF __SEG_END_SSTACK  

            ORG    RAMStart              ;以下定义变量
AD_data:    DS.B   2                     ;$0060
D_data:     DS.B   4                     ;$0062
Count1:     DS.B   1                     ;$0066
Count2:     DS.B   1                     ;$0067
State:      DS.B   1                     ;$0068
TR_data:    DS.B   8                     ;$0069
Nm:         DS.B   1                     ;$0071
Nah:        DS.B   1                     ;$0072
Nal:        DS.B   1                     ;$0073
ch_data:    DS.B   1                     ;$0074
Temp:       DS.B   1                     ;$0075
            ORG    ROMStart
main:
_Startup:   SEI
            LDHX   #RAMEnd+1        ; initialize the stack pointer
            TXS
            BRA    SYS_Init
            CLI                     ; enable interrupts

mainLoop:   BRCLR 7,TPMSC,*
            BSR   AD_disp
            BRSET 5,SCIS1,TR_disp
            BRA   mainLoop
            
            ORG NVPROT              ;Flash保护寄存器
            DC.B $FF
            
            ORG NVOPT               ;Flash选项寄存器
            DC.B $7E
            
SYS_Init:   .
            .
            .
            .
;AD采样处理部分
AD_disp:    LDA   #$50                   ;after 50 samples then compare
            STA   Count2
AD_disp1:   LDA   #$04                   ;use 4 value method
            STA   Count1
            LDX   #$00
sample:     BRCLR 7,ADCSC1,*             ;sample
            LDA   ADCRL
            STA   $62,X
            INCX
            DBNZ  $66,sample
            BSR   compare1
            STA   $60
            DBNZ  $67,AD_disp1
compare2:   LDA   $61
            CMP   $60
            BLS   J1          ;Below then turn
            CMP   $72         ;fewer?
            BLS   J2
            CMP   $73         ;need change
            BLS   J3
            MOV   #$92,$68
            STA   Temp
            RTS
J1:         MOV   #$98,$68
            STA   Temp
            RTS
J2:         MOV   #$94,$68
            STA   Temp
            RTS
J3:         MOV   #$96,$68
            STA   Temp
            RTS   
p1:         LDX   #$02           ;clear AD_data
            CLR   $60,X
            DBNZX p1
            RTS

compare1:   LDA   $62
            CMP   $63
            BHI   s1        ;M0>M1,change              
            CMP   $64
            BHI   s2        ;M0>M2,change              
            CMP   $65
            BHI   s3        ;M0>M3,change
            LDA   $63
            CMP   $64
            BHI   s4        ;M1>M2,change
            CMP   $65
            BHI   s5        ;M1>M3,change
            LDA   $64
            CMP   $65      
            BHI   s6        ;M2>M3,change
            LDA   $63
            ADD   $64
            LSRA
p2:         LDX   #$04       ;Clean D_data
            CLR   $62,X
            DBNZX p2
            RTS
s1:         STA   $75       ;change M0&M1
            LDA   $63
            BSR   s0
            RTS  
s2:         STA   $75       ;change M0&M2
            LDA   $64
            BSR   s0
            RTS   
s3:         STA   $75       ;change M0&M3
            LDA   $65
            BSR   s0
            RTS
s0:         MOV   $75,$62    ;put M0 to Temp
            LDA   $62
            RTS
s4:         STA   $75        ;change M1&M2
            LDA   $64
            MOV   $75,$63
            LDA   $63
            RTS
s5:         STA   $75        ;change M1&M3
            LDA   $65
            MOV   $75,$63
            LDA   $63
            RTS
s6:         STA   $75        ;change M2&M3
            LDA   $65
            MOV   $75,$64
            RTS

   ;TR通信处理部分
TR_disp:    LDX   #$00
            BRA   TR1
            RTS
TR1:        LDA   SCID              ;Receive 8 bytes ,1 frame message
            STA   TR_data,X
            BRCLR 5,SCIS1,*
            INCX
            CMP   #$08
            BNE   TR1
TR3:        NOP
            BSR   TR2
            CBEQ  $70,TR4           ;check
            BSR   finish
TR2:        LDA   $69               ;Sum the fomer 7 bytes
            LDX   #$01
            ADD   $69,X
            INCX
            CMP   #$07
            BNE   TR2
            RTS
finish:     LDX   #$08                ;clear TR_data,and exit communicate
            CLR   $69,X
            DBNZX finish
            BRA   mainLoop            ;return mainLoop
TR4:        LDA   $69                 ;check the message of received frame
            CMP   #$EB
            BNE   finish
            LDA   $6A
            CMP   #$90
            BNE   finish
            LDA   $6B
            CMP   #$00
            BNE   finish
            LDA   $6C
            CBEQA #$01,set0            ;need to set the initation of transfusion bottle
            CBEQA #$03,sta_disp        ;enter sta_disp
            CBEQA #$05,da_disp         ;enter da_disp
            BSR   finish
set0:       MOV   $6D,$71              ;set Nm
            MOV   $6E,$72              ;set Nah
            MOV   $6F,$73              ;set Nal
            BSR   finish
TR5:        JSR   TR2               
sta_disp:   LDA   #$92                 ;normal?then go to finish
            CBEQ  $68,finish            
            LDA   #$98                 ;unnormal?then go to disp
            CBEQ  $68,disp           
            LDA   #$94                 ;fewer?then go to disp
            CBEQ  $68,disp            
            LDA   #$96
            CBEQ  $68,disp             ;need change?then go to disp
            BSR   finish
disp:       MOV   #$06,$6C             ;set funcation number =06
            MOV   $68,$6D              ;set TR_data+4=state
            MOV   #$00,$6E             ;set TR_data+5=0
            MOV   #$00,$6F             ;set TR_data+6=0
            BRA   TR2                  ;sum the former 7 bytes data
            STA   $70                  ;fill the latest byte
            RTS
send:       LDX   #$00                 ;send 8 bytes messages
            BRA   send0
            RTS
send0:      BRCLR 7,SCIS1,*
            LDA   $69,X
            STA   SCID
            BRCLR 6,SCIS1,*
            INCX
            CMP   #$08
            BNE   send0
            RTS
da_disp:    MOV   #$08,$6C             ;set funcation number = 08
            MOV   $75,$6D              ;fill TR_data+4=the weight transfusion bottle
            BSR   TR5
            STA   $70                  ;fill TR_data+7=the value of check
            BSR   send
            RTS
            ORG   $FFFE
            
            END
2008-03-12 14:48
快速回复:菜鸟请教高手……
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018918 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved