| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 458 人关注过本帖
标题:怎么把下段汇编转换为C语言,请高手指导!!!
只看楼主 加入收藏
yf199004
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-5-3
结帖率:0
收藏
 问题点数:0 回复次数:0 
怎么把下段汇编转换为C语言,请高手指导!!!
BIT_COUNT     DATA 07FH
         TIMER0         DATA 07EH
         TIMER          DATA 048H
         DATA_OUT      DATA 021H
         TEN1           DATA 022H
         TEN2           DATA 023H
         DAT             BIT   P2.0
         CLK            BIT   P2.1
         CS              BIT   P2.2
         KEY            BIT   P2.3
         ORG    000H
         LJMP   MAIN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
         ORG   0060H
MAIN:   CLR    RS0                        ;粗略测量转速。
         CLR    RS1
         MOV   R1, #40H
         MOV   R2, #14H  
         MOV   38H, #00H
         MOV   39H, #00H
    MOV   TMOD, #15H                ;设定T0,T1的工作方式:T0为计数方
    MOV    TL0, #00H                      式,对P3.4输入脉冲信号进行计数,T1为
         MOV   TH0, #00H                    定时/计数器都以方式1工作。   
         MOV   TL1, #00H                  
         MOVTH1,#4CH                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        CLR    EA
         JB      P3.4, $                     ;等待信号变低。
         SETB   TR1                        ;开始定时。
         SETB   TR0                       ;开始计数。
  M1:    JBC    TF1, M2                      ;T1定时溢出。
         SJMP   M1
  M2:    MOV   TL1, #00H                   ;T1溢出20次即定时1s。
         MOV   TH1, #4CH
         DJNZ   R2, M1
         CLR    TR0                         ;停止定时、计数。
         CLR    TR1
 CYC:   CLR      RS0                           ;测周期法测转速。
         CLR     RS1
         MOV    R1,#40H
         MOV    TMOD, #90H                   ;设定定时/计数器的工作方式:T1
             MOV    TH1, #00H                     为定时方式,工作方式1,由P3.3   
    MOV   TL1, #00H                     和TR1共同控制计数的启动和停止。   
   C0:   JB       P3.3, C0
         SETB    TR1
   C1:   JNB      P3.3,C1
   C2:   JB       P3.3, C2
         CLR     TR1
SAMP1:  MOV   A, R4                         ;采样程序。
         RL     A
         ADD   A, R1
         MOV   R1, A
         MOV   @R1, TH1
          INC   R1
         MOV   @R1, TL1
         INC    R4
 SAM1:  CJNE   R4, #04H, CYC
         MOV   R4, #00H
         MOV   SP,#50H
    LCALL   APIG                         ;调用滤波程序。
NDIV1:  SETB   RS1                            ;多字节除法程序,将所测周期转换
         SETB   RS0                             成转速。
         MOV   R2, #00H
         MOV   R3, #0D2H
         MOV   R4, #0F0H
         MOV   R5, #00H
         MOV   R6, 38H
         MOV   R7, 39H
         MOV   A, R3
         CLR   C
         SUBB   A, R7
          MOV    A, R2
          SUBB   A, R6
          JNC   NDVE1
          MOV   B, #10H
NDVL1:   CLR    C
          MOV   A, R5
          RLC    A
          MOV   R5, A
          MOV   A, R4
          RLC    A
          MOV   R4, A
          MOV   A, R3
          RLC    A
          MOV   R3, A
          MOV   A, R2
          RLC    A
          MOV   R2, A
          MOV   F0, C
          CLR    C
          MOV   A, R3
          SUBB   A, R7
          MOV   R1, A
          MOV   A, R2
          SUBB   A, R6
          JB     F0, NDVM1
          JC     NDVD1
NDVM1:  MOV   R2, A
          MOV   A, R1
          MOV   R3, A
          INC    R5
 NDVD1:  DJNZ   B, NDVL1
          CLR    F0
          MOV   38H, R4
          MOV   39H, R5
          CLR    RS0
          LJMP   DISPLAY
 NDVE1:  SETB   F0
          RET
 FRE:     CLR   RS0                              ;频率法测转速。
          CLR    RS1
          MOV   R4, #00H
          MOV   TMOD, #15H
          MOV   TL0, #00H        
          MOV   TH0, #00H
           MOV   TL1, #00H
           MOVTH1,#4CH                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          CLR   EA
           JB     P3.4, $
           SETB   TR1            
           SETB   TR0
  F1:      JBC   TF1, F2
           SJMP   F1
  F2:      MOV   TL1, #00H
           MOV   TH1, #4CH
           DJNZ   R2, F1
           CLR   TR0
           CLR   TR1
 SAMP2:   MOV   A, R4                           
           RL    A
           ADD   A, R1
           MOV   R1, A
           MOV   @R1, TH0
           INC    R1
           MOV   @R1, TL0
           INC     R4
  SAM2:   CJNE R4, #04H, FRE
           MOV R4, #00H
           MOV SP,#50H
    CALL   APIG
           JMP    DISPLAY
APIG:     SETB   RS0                          ;滤波程序。
          CLR   A
          MOV   R2, A
          MOV   R3, A
          MOV   R6, A
          MOV   R7, A
          MOV   R4, #0FFH                     ;各值进行初始化。
          MOV   R5, #0FFH
          MOV   TIMER, #04H
  API1:   LCALL   LOADX                    
          SETB     RS0
          MOV     R1, A
          ADD     A, R7                        ;累加输入值。
          MOV     R7, A
              MOV     A, B
              ADDC    A, R6
              MOV     R6, A
             CLR      C                         ;输入值与最大值R2R3比较。
             MOV     A, R3
             SUBB    A, R1
             MOV     A, R2
             SUBB    A, B
             JNC     API2
             MOV    A, R1                          ;输入值大于最大值。
             MOV    R3, A
             MOV    R2, B
      API2:  CLR      C                                ;输入值与最小值作比较。
             MOV    A, R1
             SUBB   A, R5
         MOV   A, B
         SUBB   A, R4
         JNC    API3
         MOV   A, 1
         MOV   R5, A
         MOV   R4, B
  API3:  DJNZ   TIMER, API1
         CLR    C
         MOV   A, R7                              ;累加和中减去最大值。
         SUBB   A, R3
         XCH    A, R6
         SUBB   A, R2
         XCH    A, R6                             ;累加和中减去最小值。
         SUBB   A, R5
         XCH    A, R6
         SUBB   A, R4
         CLR    C
         RRC    A                                  ;求平均值,将平均值存入38H,39H。
         XCH    A, R6                 
         RRC    A
         MOV   R7, A
         MOV   39H, R7
         MOV   38H, R6
         MOV   3BH,39H                         ;将本次测量值作为下次的比较值。         
         MOV   3AH,38H
         CLR   RS0
         MOV   R4, #00H
         RET
LOADX:  CLR   RS0                               ;调用数据程序。   
         MOV   R1, #40H
         MOV   A, R4   
         RL     A
           ADD   A, R1
           MOV   R1, A
           MOV   A,@R1
           MOV   B, A
           INC   R1
           MOV   A,@R1
           INC   R4
           RET
DISPLAY:  CLR        RS0
          SETB       RS1
    MOV        R0, #30H                ;显示程序。
          MOV        TEN1, #11001100B        
          MOV        TEN2, #05H
          MOV        P1, #0FFH
          MOV        P2, #0CBH                 ;I/O初始化。(0CBH)
START_DELAY0:  MOV   DATA_OUT, #0A4H      ;复位指令。
          CALL     SEND
          SETB     CS                              ;恢复CS为高电平。   
          LCALL    BD                              ;调用16进制——BCD码
          MOV      R0, #30H                          转换。         
          MOV      A, R6
          LCALL    PTDS
          MOV      A, 30H
          XCH      A, 31H
          MOV      30H, A
          MOV      A, R5
          LCALL    PTDS
          MOV      A, 32H
          XCH      A, 33H
          MOV      32H, A
          MOV      A, R4
          LCALL    PTDS
          MOV      A, 34H
          XCH      A, 35H
          MOV      34H, A
          MOV      R0, #31H
          CJNE     @R0, #00H, DIS1             ;判断显示数字的位数。
          MOV      R0, #32H
          CJNE     @R0, #00H, DIS2
          MOV      R0, #33H
          MOV      TEN1, #11001010B           ;显示数字为百位数,
          MOV      TEN2, #03H                   方式1译码第百、十、个位。
          JMP      START_DELAY1
DIS1:           MOV      TEN1,#11001100B          ;显示数字为万位数,方式1译码
                MOV      TEN2,#05H                  第万、千、百、十、个位。
                JMP      START_DELAY1
DIS2:           MOV      TEN1,#11001011B          ;显示数字为千位数,方式1译码
                MOV      TEN2,#04H                  第千、百、十、个位。
START_DELAY1: MOV  DATA_OUT,TEN1
                CALL     SEND
                MOV      DATA_OUT,@R0
                CALL     SEND
START_DELAY2: SETB   CS
               INC      R0
               DEC      TEN1
               DJNZ     TEN2, START_DELAY1   
               SETB     CS
               LJMP     MAIN
SEND:         MOV      BIT_COUNT,#8               ;发送1个字节到HD7279,高位
               CLR      CS                              在前。
               CALL     LONG_DELAY
SEND_LOOP:  MOV      C, DATA_OUT.7
              MOV      DAT, C
              SETB      CLK
              MOV      A, DATA_OUT
              RL        A
              MOV      DATA_OUT, A
              CALL     SHORT_DELAY
              CLR      CLK
              CALL     SHORT_DELAY
              DJNZ     BIT_COUNT, SEND_LOOP    ;检查8位数据是否发送完毕。
              CLR      DAT                        ;发送完毕,返回。
              RET
BD:           CLR    A                           ;多字节16进制整数转换成BCD
              MOV    R4, A                         码。
                 MOV    R5, A
              MOV    R6, A
              MOV    R7, #10H
  BD1:        CLR    C
              MOV    A, 39H
              RLC    A
              MOV    39H, A
              MOV    A, 38H
              RLC     A
              MOV    38H, A
              MOV    A, R4
              ADDC   A, R4
                 DA      A
                 MOV    R4, A
                 MOV    A, R5
                 ADDC   A, R5
                  DA      A
                 MOV    R5, A
                 MOV    A, R6
                 ADDC   A, R6
                 DA      A
                 MOV    R6, A
                 DJNZ   R7, BD1
                 RET
PTDS:            MOV    R1, A
                 ACALL   PTDS1
                 MOV    A, R1
                 SWAP   A
   PTDS1:        ANL    A, #0FH
                 MOV    @R0, A
                 INC    R0
                 RET
LONG_DELAY:   MOV    TIMER0, #25                ;延时程序。
DELAY_LOOP:   DJNZ     TIMER0, DELAY_LOOP
                 RET
SHORT_DELAY:  MOV      TIMER0, #4
SHORT_LOOP:   DJNZ     TIMER0, SHORT_LOOP
                RET
 END
2012-05-03 16:28
快速回复:怎么把下段汇编转换为C语言,请高手指导!!!
数据加载中...
 
   



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

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