⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avr-1k2k-21p.asm

📁 数码管显示接触式交流稳压器MCU21P
💻 ASM
📖 第 1 页 / 共 3 页
字号:
           NOP
           NOP
           NOP
           NOP
           NOP
           nop
           nop
           nop
           BS       AD_CTL1,7
           BC       IRQF,6
           NOP
           NOP
           BTSS     IRQF,6
           LGOTO    $-1
           BC       IRQF,6
           NOP
           NOP
           MOV	    AD_DAT,A
           MOVAM    temp1
           
           tmsc     sampletime
           lgoto    zero_continue
           ret     
                 
zero_continue:
           movla    .99
           sub      temp1,a
           btss     STATUS,C
           lgoto    negative_pulse
           mov      temp3,a
           sub      temp1,a
           btsc     STATUS,C
           lgoto    raising_edge
           mov      temp1,a
           movam    temp3
           decsz    temp2,m
           lgoto    delaying_500us                      
           ret
delaying_500us:
           lcall    delay_500us
           lgoto    start_adc
           
negative_pulse: 
raising_edge:
           clr      temp1
           movla    .5
           movam    temp2
           movla    0FFH
           movam    temp3
           lgoto    start_adc
           
           ret
;===========================================
delay_500us:
           MOVLA    .150
           MOVAM    TEMP4
CONTINUE_DELAY1:
           NOP
           NOP
           NOP

           DECSZ    TEMP4,M
           lgoto    CONTINUE_DELAY1

           RET
;===========================================
delay_9ms:

           MOVLA    .13;15
           MOVAM    TEMP1
CIRCLE_DELAY1:
           NOP
           lcall    delay_500us
           decsz    TEMP1,m
           lgoto    CIRCLE_DELAY1
        
           RET
;================================
delay_5ms:

           MOVLA    .3;9
           MOVAM    TEMP1
CIRCLE_DELAY2:
           NOP
           lcall    delay_500us
           decsz    TEMP1,m
           lgoto    CIRCLE_DELAY2
        
           RET
;===========================================
;===========================================
Display_Module:
           TMSC     disp_fresh
           ret           
           movla    _500ms
           movam    disp_fresh
           
           BTSC     sys_status1
           LGOTO    display_unusual
           BTSC     sys_status0
           LGOTO    display_normal
           ;----display delay_time
           bs       _work
           bc       _unusual
           
           btsc     bled1
           lgoto    clr_bled1
           bs       bled1
           bs       _delay
           ret
clr_bled1:
           bc       bled1
           bc       _delay
           ret
           
           ;=======================
display_normal:
           BTSC     temp_status
           LGOTO    display_unusual
           ;-----display normal        
           bs       _work
           bc       _delay
           bc       _unusual
           ret
           ;=======================
display_unusual:                   
           bs       _work
           bc       _delay
           btsc     flash
           lgoto    flsh_clr
           bs       flash
           bs       _unusual
           ret
flsh_clr:  
           bc       flash
           bc       _unusual
           ret

;===========================================
hex2dec:
;------TEMP4,TEMP5 is the value should be converted
	   clr      TEMP1
	   clr      TEMP2
	   clr      TEMP3
hex2dec_init:
           MOV      TEMP5,A
           MOVAM    TEMP7                  
	   movla    .100
	   sub      temp5,m
	   BTSS     STATUS,C
	   LGOTO    _step100
	   INC      TEMP1,M
	   LGOTO    hex2dec_init
_step100:
           mov      temp4,a
           btsc     STATUS,Z
           lgoto    next_step
           dec      temp4,m
           inc      temp1,m
           inc      temp1,m
           movla    .56
           add      temp7,a
           movam    temp5
           lgoto    hex2dec_init

next_step:
	   mov      temp7,a	   
	   movam    TEMP5
	   movla    .10
	   sub      temp7,m
	   btss     STATUS,C
	   lgoto    second_step
	   inc      temp2,m
	   lgoto    next_step
second_step:
	   mov      temp5,a
	   movam    temp3
	   ret
;==========================================
con_disp_code:
           MOVLA    07H
           movam    tab_bnk
           tabrdl   temp8
           movam    temp8
           
           MOVLA    07H
           movam    tab_bnk
           tabrdl   temp9
           movam    temp9

           MOVLA    07H
           movam    tab_bnk
           tabrdl   temp10
           movam    temp10

	   MOVLA    07H
           movam    tab_bnk
           tabrdl   temp1
           movam    temp1
	   btsc     bled0
	   bc       temp1,7
	   
	   MOVLA    07H
           movam    tab_bnk
           tabrdl   temp2
           movam    temp2
	   btsc     bled1
	   bc       temp2,7
	   
	   MOVLA    07H
           movam    tab_bnk
           tabrdl   temp3
           movam    temp3
	   btsc     bled2
	   bc       temp3,7
	
	   BC       IRQM,INTM
	   
	   mov      temp8,a
	   movam    disp_buf0
	   mov      temp9,a
	   movam    disp_buf1
	   mov      temp10,a
	   movam    disp_buf2
	   mov      temp1,a
	   movam    disp_buf3
	   mov      temp2,a
	   movam    disp_buf4
	   mov      temp3,a
	   movam    disp_buf5
	
	   BS       IRQM,INTM

	   ret
;===========================================
sample_INvol:
           clr      temp0
           clr      temp1
           clr      temp2;total samples times
           clr      temp3
           clr      temp4
           clr      temp6
           movla    MAX_SAMPLE_TIME
           movam    SAMPLETIME
           ;=============
sample_loop0:
           
           NOP
           MOVLA    00H
           MOVAM    AD_CTL1
           MOVLA    02H;01H
           MOVAM    AD_CTL2
           MOVLA    02H
           MOVAM    AD_CTL3
           NOP
           NOP
           BTSC     AD_CTL1,7
           LGOTO    $-1
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           nop
               ;BS     _RL1
           nop
           nop
           BS       AD_CTL1,7
           BC       IRQF,6
           NOP
           NOP
           BTSS     IRQF,6
           LGOTO    $-1
           BC       IRQF,6
           NOP
           NOP
           MOV	    AD_DAT,A
           MOVAM    temp1
           movam    temp0
           ;====================== 
               ;BC     _RL1        
           ;======================           
           MOVLA    .99
           SUB      temp1,m
           btss     STATUS,C
           lgoto    _smaller99
add_sumin:
           mov      temp1,a           
           add      temp4,m
           clra
           addc     temp3,m
           
           inc      temp2,m
           ;---------------
           tmsc     SAMPLETIME
           ;---------------           
           lgoto    sample_loop0
           lcall    caculate_vol           
           ret
           
_smaller99:
           movla    .99
           movam    temp1
           mov      temp0,a
           sub      temp1,m
           lgoto    add_sumin
;===========================================
sample_OUTvol:
           clr      temp0
           clr      temp1
           clr      temp2;total samples times
           clr      temp3
           clr      temp4
           clr      temp6
           movla    MAX_SAMPLE_TIME
           movam    SAMPLETIME
           ;=============
sampleOUT_loop0:
           
           NOP
           MOVLA    01H
           MOVAM    AD_CTL1
           MOVLA    02H;01H
           MOVAM    AD_CTL2
           MOVLA    02H
           MOVAM    AD_CTL3
           NOP
           NOP
           BTSC     AD_CTL1,7
           LGOTO    $-1
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           NOP
           nop
               ;BS     _RL1
           nop
           nop
           BS       AD_CTL1,7
           BC       IRQF,6
           NOP
           NOP
           BTSS     IRQF,6
           LGOTO    $-1
           BC       IRQF,6
           NOP
           NOP
           MOV	    AD_DAT,A
           MOVAM    temp1
           movam    temp0
           ;====================== 
               ;BC     _RL1        
           ;======================           
           MOVLA    .99
           SUB      temp1,m
           btss     STATUS,C
           lgoto    temp1_smaller99
add_sum:
           mov      temp1,a           
           add      temp4,m
           clra
           addc     temp3,m
           
           inc      temp2,m
           ;---------------
           tmsc     SAMPLETIME
           ;---------------           
           lgoto    sampleOUT_loop0
           lcall    caculate_vol           
           ret
           
temp1_smaller99:
           movla    .99
           movam    temp1
           mov      temp0,a
           sub      temp1,m
           lgoto    add_sum
;===========================================
;temp3,temp4/temp2-->temp0,temp1
caculate_vol:           
                      
           clr      temp6
           clr      temp1
           clr      temp0
sub_loop:
           MOV      TEMP4,A
           MOVAM    TEMP7                  

	   MOV      temp2,a
	   
	   sub      temp4,m
	   BTSS     STATUS,C
	   LGOTO    sub_next1
	   INCSZ    TEMP1,M
	   LGOTO    sub_loop
	   INC      TEMP0,M
	   lgoto    sub_loop
sub_next1:
           mov      temp3,a
           btsc     STATUS,Z
           lgoto    sub_ret
           dec      temp3,m
           movla    .255
           movam    temp6
           inc      temp7,m
sub_loop0:
           mov      temp6,a
           movam    temp8
           mov      temp2,a
           sub      temp6,m
           btss     STATUS,C
           lgoto    sub_next2
           incsz    temp1,m
           lgoto    sub_loop0
           inc      temp0,m
           lgoto    sub_loop0
sub_next2:
           mov      temp8,a
           add      temp7,a
           movam    temp4
           clr      temp6
           lgoto    sub_loop
sub_ret: 
           bc       STATUS,C
           rlc      temp1,m
           rlc      temp0,m
           
           mov      temp1,a
           movam    temp6
           mov      temp0,a
           movam    temp5
           
           bc       STATUS,C
           rlc      temp1,m
           rlc      temp0,m
           
           mov      temp6,a
           add      temp1,m
           mov      temp5,a
           addc     temp0,m           
           ;========adjust the voltage           
           tmsc     temp0
           lgoto    adjust06
           ;movla    .150
           ;sub      temp1,a
           ;btss     STATUS,C
           ;ret           
           movla    .160
           sub      temp1,a
           btsc     STATUS,C
           lgoto    adjust00
           ;dec      temp1,m
           ret
adjust00:
           movla    .170
           sub      temp1,a
           btsc     STATUS,C
           lgoto    adjust01
           dec      temp1,m
           ;dec      temp1,m
           ret
adjust01:
           movla    .210
           sub      temp1,a
           btsc     STATUS,C
           lgoto    adjust02
           movla    .2
           sub      temp1,m
           ret
adjust02:
           movla    .220
           sub      temp1,a
           btsc     STATUS,C
           lgoto    adjust03
           movla    .3
           sub      temp1,m
           ret
adjust03:
           movla    .230
           sub      temp1,a
           btsc     STATUS,C
           lgoto    adjust04
           movla    .4
           sub      temp1,m
           ret
adjust04:
           ;movla    .240
           ;sub      temp1,a
           ;btsc     STATUS,C
           ;lgoto    adjust05
           ;movla    .6
           ;sub      temp1,m
           ;ret
adjust05:
           movla    .5
           sub      temp1,m
           ret
adjust06:
           dec      temp0,m
           movla    .251;249
           add      temp1,m
           clra
           addc     temp0,m

           ret
;===========================================
DELAY:
           NOP
           DECSZ   50H,M
           LGOTO   $-1
           DECSZ   51H,M
           LGOTO   $-3
           NOP
           RET
;===========================================
dbl_divs:
_divs_do:
           bc       STATUS,C
           rrc      temp0,m
           rrc      temp1,m
           
           decsz    temp2,m
           lgoto    _divs_do
              
           ret           
;===========================================
        ORG    700H
        dw     0c0h		;num 0
        DW     0f9h		;    1
        DW     0a4h		;    2
        DW     0b0h		;    3
        DW     99h		;    4
        DW     92h		;    5
        DW     82h		;    6
        DW     0d8h		;    7
        DW     80h		;    8	
        DW     90h		;    9
        DW     89h		;H   10
        DW     0c7h 	        ;L   11
        DW     0ffh		;clrx	   12
        DW     00H		;ALL LIGHT 13
        DW     0a7h             ;c         14
        
        END
;===========================================
;===========================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -