嵌入式 > 技术百科 > 详情

三星单片机AD转换程序

发布时间:2024-10-14 发布时间:
|

ADR0       .EQU      05H 
ADR1       .EQU      06H 
ADR2       .EQU      07H 

ADR3       .EQU      08H 
CNTR0      .EQU      10H 

           ORG   0000H 
           VECTOR  00H,  INT_9454 
           ORG   003CH 
           DB      00H 
           DB      00H 
           DB      0E7H ;允许低电平复位LVR=2.3V  
           DB      00H  ;选用外部晶振4M 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;            
;          ORG   0040H 
;CODE_TABLE:DB 44H,46H,48H,4AH,4DH    ;0-4度 
;           DB 4FH,51H,54H,56H,58H    ;5-9度 
;           DB 5BH,5DH,60H,62H,64H    ;10-14度  
;            
;           LD    R4,  #00H 
;           LD    R5,  #3FH 
;AD_FIND:   INC   R5 
;           LDC   R10, @RR4 
;           CP    R10, A_DATA 
;           JR    ULT, AD_FIND 
;           SUB   R10, #40H 
;           LD    LED_D,R10          
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;              
             
             
           ORG    0044H  
CODE_TABLE:DB 0,0      ;44H-45H 
           DB 1,1      ;46H-47H 
           DB 2,2      ;48H-49H 
           DB 3,3,3    ;4AH-4BH-4CH 
           DB 4,4      ;4DH-4EH 
           DB 5,5      ;4FH-50H 
           DB 6,6,6    ;51H-52H-53H 
           DB 7,7      ;54H-55H 
           DB 8,8      ;56H-57H 
           DB 9,9,9    ;58H-59H-5AH  
           DB 10,10    ;5BH-5CH 
           DB 11,11,11 ;5DH-5EH-5FH 
           DB 12,12    ;60H-61H 
           DB 13,13,13 ;62H-63H-64H 
           DB 14,14    ;65H-66H 
           DB 15,15,15 ;67H-68H-69H  
           DB 16,16    ;6AH-6BH   
           DB 17,17    ;6CH-6DH     
           DB 18,18    ;6EH-6FH-70H 
           DB 19,19    ;71H-72H 
            
            
            
            
           ORG   0100H 
RESET:     DI 
           LD    SP,    #00C0H 
           LD    BTCON, #10100010B 
           LD    CLKCON,#00001000B ;允许外部晶振CPU分频 FOSC/8  
           CLR   P0 
           CLR   P1 
           CLR   P2 
           LD    P0CONL,#10101011B ;P0.0 AD输入转换   
           LD    P0CONH,#10100000B ;P0.6 P0.7 推拉式输出,数码管1选通、数码管2选通  
           LD    P1CON, #00001010B ;p0.0 p0.1输出 
           LD    P2CONL,#00001010B ;p2.0 p2.1 P2.2 P2.3 推拉式输出 a b c d 
           LD    P2CONH,#01001010B ;P2.4 P2.5 P2.6 推拉式输出      e f g 
           CLR   R10 
           CLR   R11 
           CLR   R12 
           LD    ADR0, #10         ;10*400us=4ms 
           LD    T0DATA,#200 
           LD    T0CON, #10001010B ;8/4*200=400us 
           
           LD    R0,    #0A0H 
CLRRAM:    CLR   @R0 
           DEC   R0 
           JR    NZ,    CLRRAM  
           CLR   @R0     
                       
           LD    ADCON,   #00000101B 
AD_WAIT:   TM    ADCON,   #00001000B 
           JR    Z,       AD_WAIT 
           LD    A_DATA,  ADDATAH 
            

            
MAIN:      EI 
           OR   BTCON,    #02H 
           CP   A_DATA,   #44H  ;超出范围,报错  
           JR   ULT,      LED_W 
           CP   A_DATA,   #72H  ;未定义  
           JR   UGT,      LED_W 

           LD    R4,  #00H 
           LD    R5,  A_DATA 
           LDC   R10, @RR4 
ADR10:     LD    CNTR0, @R10 
           XOR   CRTL_R0,  #04H 
           TM    CRTL_R0,  #04H 
           JR    NZ,       AD_H ;屏蔽低4位  
            
AD_L:      AND   CNTR0, #0FH                    
           LD    ADR1,  CNTR0 
           JR    LED_ 
            
AD_H:      AND   CNTR0, #0F0H 
           LD    ADR2,  CNTR0 
           RCF 
           RL ADR2    
           RL ADR2 
           RL ADR2 
           RL ADR2           
           RCF 
           JR   ADR10 
            
LED_W:     LD   ADR1,  #10 
           LD   ADR2,  #10         
           
LED_:      AND   P0,  #80H       ;P0.7高电平,个位数码管停止  
           OR    P0,  0BFH       ;P0.6低电平,十位数码管选通  
           LD    LED_D, ADR2 
            
LED_0:     LD    R2,  #0AH 
           LD    R3,  #LED_D 
           LDC   R12, @RR2 
           LD    P2,  R12        ;十位数送给p2口  
           CALL T0_WAIT 
           XOR   CRTL_R0,  #02H 
           TM    CRTL_R0,  #02H 
           JR    Z,        LED_      
           AND   P0,       #7FH  ; P0.7低电平,个位数码管选通  
           OR    P0,       #40H  ; P0.6高电平,十位数码管停止 
           LD    LED_D,    ADR1 
           JR    LED_0 
              
T0_WAIT:   TM    CRTL_R0,  #01H 
           JR    Z,        T0_WAIT 
           DEC   ADR0 
           JR    NZ,       T0_WAIT 
           RET                       
                                             
           ORG     0A00H   
CODE_LED:  DB 40H,7CH,24H,30H,19H,12H,02H,78H,00H,10H,06H 
             ;"0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "E" 

INT_9454:   OR     BTCON,  #02H 
            TM     T0CON,  #01H 
            JR     Z,      INTRET 
            OR     CRTL_R0,#01H   

INTRET:     IRET 

            .END  


 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
汽轮机旁路控制策略的研制与应用