;***********************************************************
;单    位:苏州华芯微电子有限公司                           
;                                                          
;文件名称:	HS26P10_ADC例程							                   
;摘    要:	ADC例程
;当期版本:  V1.0                                             
;作    者:  Design-Digit
;开始日期: 	2022-00-00                                      
;完成日期:                                                 
;                                                          
;先前版本:                                                 
;作    者:                                                 
;创始日期:                                                 
;***********************************************************
;RC:	16MHz 2'
;RAM:	128 * 8
;ROM:	2K	*16(OTP)
;STACK:	8 level
;***********************************************************
;功能说明：
;	ADC使用例程
;***********************************************************
;========================================================
;               ---------------------------------
;        VCC   |1  VDD            VSS        14 | GND
;        SCL   |2  P0.3/XIN       P4.4/AIN4  13 | OUT
;        SDA   |3  P0.2/XOUT      P4.3/AIN3  12 | OUT1
;        RFIN  |4  P0.4/RST       P4.2/AIN2  11 | LIMIT_DOWN
;        RFEN  |5  P5.3/PWM1      P4.1/AIN1  10 | LIMIT_UP
;        LED   |6  P5.4/PWM0      P4.0/AIN0  9  | LCD_DATA
;        SW1   |7  P0.1           P0.0       8  | SW2
;               ---------------------------------
;                     MCU-SN8P2711
;========================================================
;===============================================
#include	"HS26P10.inc"
;===============================================
;=========================================
;管脚定义
;#define         WORK_OUT      P0.0 
;#define         UP_LED_G      P0.1 
;#define         DOWN_LED_G    P0.2 
;#define         DOWN_LED_R    P0.3
;#define         KEY           P0.4

;#define 	 	LED_OUT       P5.3
;#define         UP_LED_R      P5.4


#define 	TX_O	P0.3
;=============================================
;RAM定义
;=============================================
.data

TEMP_AVE_L              EQU     000H
TEMP_AVE_H              EQU     001H
AD_SAMPLE_TIMES         EQU     002H
AD_AVE_TIMES            EQU     003H
DELAY_TIME              EQU     004H
DELAY_TIME_CNT_M        EQU     005H

;TIME_CNT_AD             EQU     008H
ADC_AVE_L               EQU     00AH
ADC_AVE_H               EQU     00BH

DELAY_TIME_CNT_H2	EQU	00CH 

;----------------串口--------------
TXCNT                   EQU     010H
TXCLOCK                 EQU     011H
TXDATA                  EQU     012H

KEY_CNT_L               EQU     013H

GET_ADC_MODE                EQU     014H


;KEY_CNT_H               EQU     014H
CHECK_DATA              EQU     015H

AD_NORMAL_CNT           EQU     016H
AD_OVER_CNT             EQU     017H
AD_LESS_CNT             EQU     018H
FLAG                    EQU     019H



S_REG                   EQU     030H    ;限位开关关闭
TEMP0                   EQU     031H
TEMP                    EQU     032H
AD_OLD_L                EQU     033H
AD_OLD_H                EQU     034H
ADC_SAMP_L              EQU     035H
ADC_SAMP_H              EQU     036H
DELAY_INSIDE            EQU     037H
DELAY_TIME_CNT_L        EQU     038H    ;2MS计时
DELAY_TIME_CNT_H        EQU     039H    ;转动圈数计次

BUF0_TEMP               EQU     03CH
BUF1_TEMP               EQU     03DH

AD_SMOOTHING_0_L        EQU     03EH
AD_SMOOTHING_0_H        EQU     03FH



;-------------------------------------------- 
AD_AVERAGE_1_L        EQU     01CH
AD_AVERAGE_1_H        EQU     01DH

AD_AVERAGE_2_L        EQU     01EH
AD_AVERAGE_2_H        EQU     01FH

AD_AVERAGE_3_L        EQU     020H
AD_AVERAGE_3_H        EQU     021H

AD_AVERAGE_4_L        EQU     022H
AD_AVERAGE_4_H        EQU     023H

AD_AVERAGE_5_L        EQU     024H
AD_AVERAGE_5_H        EQU     025H

AD_AVERAGE_6_L        EQU     026H
AD_AVERAGE_6_H        EQU     027H

AD_AVERAGE_7_L        EQU     028H
AD_AVERAGE_7_H        EQU     029H

AD_AVERAGE_8_L        EQU     02AH
AD_AVERAGE_8_H        EQU     02BH

AD_AVERAGE_9_L        EQU     02CH
AD_AVERAGE_9_H        EQU     02DH

AD_AVERAGE_10_L       EQU     02EH
AD_AVERAGE_10_H       EQU     02FH

;----------------------------------------------
;/*'    PIN
AD_SMOOTHING_1_L        EQU     040H
AD_SMOOTHING_1_H        EQU     041H

AD_SMOOTHING_2_L        EQU     042H
AD_SMOOTHING_2_H        EQU     043H

AD_SMOOTHING_3_L        EQU     044H
AD_SMOOTHING_3_H        EQU     045H

AD_SMOOTHING_4_L        EQU     046H
AD_SMOOTHING_4_H        EQU     047H

AD_SMOOTHING_5_L        EQU     048H
AD_SMOOTHING_5_H        EQU     049H

AD_SMOOTHING_6_L        EQU     04AH
AD_SMOOTHING_6_H        EQU     04BH

AD_SMOOTHING_7_L        EQU     04CH
AD_SMOOTHING_7_H        EQU     04DH

AD_SMOOTHING_8_L        EQU     04EH
AD_SMOOTHING_8_H        EQU     04FH

AD_SMOOTHING_9_L        EQU     050H
AD_SMOOTHING_9_H        EQU     051H

AD_SMOOTHING_ADD_L      EQU     052H
AD_SMOOTHING_ADD_H      EQU     053H

SMOOTHING_TEMP1_L       EQU     054H
SMOOTHING_TEMP1_H       EQU     055H

SMOOTHING_TEMP2_L       EQU     056H
SMOOTHING_TEMP2_H       EQU     057H

KEEP_ADD_L              EQU     058H
KEEP_ADD_H              EQU     059H

SMOOTHING_END_ADD       EQU     05AH



;-------------------------------------------      
;标志位                    
;-------------------------------------------  
#define F_DELAY_MODE    FLAG.0
#define F_PROTECT_MODE  FLAG.1
#define F_NORMAL_MODE   FLAG.2
#define F_ADC_TIME      FLAG.3 
#define F_PROTECT_H      FLAG.4 
#define F_PROTECT_L      FLAG.5 
;#define WORK_OUT      FLAG.6 
#define  F_KEY_SCAN     FLAG.6


;***************************************************
;           常量定义 
;***************************************************         
;=============================================
;程序开始
;=============================================
.code
    ORG     000H      
    JMP     RESET
RESET:                
    NOP     
    JMP    INITIAL
;=============================================
;中断入口
;=============================================
    ORG     008H             ;中断入口      
    JMP     INT_PRO
;=============================================
;定时中断 
;=============================================
INT_PRO:
    PUSH
    SWAP  PFLAG        
    MOV   S_REG,A 
;=============================================
;中断函数  TC1中断程序  1.024MS
;=============================================
TC1_INT_JUDGE:
    BTS1    FTC1IRQ    
    JMP     INT_END
    BCLR    FTC1IRQ
    
    ;MOV	A,#0X08
    ;XOR	P0,A    
;----------------------------------------------------------
AD_TIME_JUDGE:                  ;AD采样基准 4MS      
	BSET	F_ADC_TIME
;--------------------------------------------------------
INT_END:
;-------中断结束------------------------------
INT_BACK: 
    SWAP    S_REG
    MOV     PFLAG,A 
    POP
    RETI

;=============================================
;初始化
;=============================================
INITIAL:
    MOV     A,#7FH          ;初始化堆栈       
	MOV		STKP,A	

    MOV     A,#0X5A  ;清看门狗
    B0MOV   WDTR,A
;-------初始化IO  P0M P2M P4M P5M------------------
;0为输入
;1为输出
    MOV     A,#08H               ;0000 1110
    B0MOV   P0,A
    MOV     A,#0FFH              ;1110 1110     I/O   
    B0MOV   P0M,A
    MOV     A,#00H               ;0001 0000     1开上拉  
    B0MOV   P0UR,A
    MOV     A,#08H               ;0001 0100
    B0MOV   P0,A

    MOV     A,#00H           ;0000 0010
    B0MOV   P2,A
    MOV     A,#0X3F          ;0001 0010                         
    B0MOV   P2M,A
    MOV     A,#00H           ;0000 0000  
    B0MOV   P2UR,A
    MOV     A,#00H           ;0000 0010
    B0MOV   P2,A
        
    MOV     A,#00H           ;0000 0010
    B0MOV   P4,A
    MOV     A,#0X00          ;0001 0010                         
    B0MOV   P4M,A
    MOV     A,#00H           ;0000 0000  
    B0MOV   P4UR,A
    MOV     A,#00H           ;0000 0010
    B0MOV   P4,A

    MOV     A,#00H     ;0000 1000
    B0MOV   P5,A
    MOV     A,#18H     ;0000 1000
    B0MOV   P5M,A
    MOV     A,#00H     ;0000 0000     
    B0MOV   P5UR,A
    MOV     A,#00H     ;0000 1000
    B0MOV   P5,A
    
    BTS0    FNT0               ;看门狗复位 回主函数
    JMP     INT_ROM_NOW
    BTS1    FNPD
    JMP     WDT_OVER 

;==================================================
;寄存器初始化                             
;==================================================
INT_ROM_NOW:
	B0MOV   Y,#00H
	B0MOV   Z,#3FH          ;64 RAM
CLR_YZ_BUF:
	CLR     @YZ
	DECMS   Z
	JMP     CLR_YZ_BUF
	CLR     @YZ

WDT_OVER:
    CLR     FLAG
    CLR     ADC_AVE_L       ;清平均值
    CLR     ADC_AVE_H      
;----------------------------------------------     
   	;BSET	TX_O 
;-----------------------------------------------
;初始化TC1寄存器
;16M4分频 预分频为Fosc/128   2.048MS进入一次中断
;-----------------------------------------------
TC0_INIT:
	CLR		INTEN   ;FORBIDDEN ALL INT
	MOV		A,#0X08  ;
	B0MOV	T0M,A   ;TC0 使用Fosc    
	
	MOV		A,#0X04  ;128 分频 开自动装载
	B0MOV	TC1M,A
	
	MOV		A,#0X00  ;
	B0MOV	TC1C,A
	B0MOV	TC1R,A    
;-----------------------------------------        
;开TC0  TC1
	B0BCLR	FTC0IRQ ;CLEAR TC0IRQ
	B0BCLR	FTC0IEN ;ENABLE TC0 INT
	B0BCLR	FTC0ENB ;ENABLE TC0
	B0BCLR	FTC1IRQ ;CLEAR TC1IRQ
	
	
	B0BSET	FTC1IEN ;ENABLE TC1 INT
	B0BSET	FTC1ENB ;ENABLE TC1
	
	B0BSET	FGIE    ;ENABLE GIE
;=============================================  TC1M
;主循环
;=============================================
MAIN: 
    MOV     A,#0X5A  ;清看门狗
    B0MOV   WDTR,A 
;--------------------------------------------	        
	B0BSET	FTC1IEN ;ENABLE TC0 INT
	B0BSET	FGIE
;刷新TC1配置
    MOV		A,#0X08;
    B0MOV	T0M,A   ;FORBIDDEN T0 WAKE UP CPU,Fcpu FREQUENCY     
    MOV		A,#0X94  ;0000 0100
    B0MOV	TC1M,A       
    MOV		A,#0X00   ;
    B0MOV	TC1R,A
;--------------------------------------------------
;ADC检测  P4.0 采样输入
;--------------------------------------------------
ADC_VDD_JUDGE:    
	BTS1	F_ADC_TIME           ;4MS时间基准   
	JMP		ADC_VDD_JUDGE_END
	BCLR	F_ADC_TIME   
	
	CLR     BUF0_TEMP
	CLR     BUF1_TEMP 
	
	CLR     ADM
	MOV		A,#00H     ;Fcpu/16,NORMAL MODE
	MOV		ADR,A 	     
;--------------------------------------------------
ADC_SCAN:        
	MOV		A,#02H      ;0000 0010  10 内部4V参考电压
	MOV		VREFH,A 
	
	MOV     A,#0X10         ;p4.4
	B0MOV   P4CON,A  
	
	MOV     A,#0X00          ;0001 0010                       
	B0MOV   P4M,A
	
	MOV     A,#00H           ;0000 0000
	B0MOV   P4UR,A
	
	B0BSET  FADENB          ;ENABLE ADENB
	CALL    DELAY_100US
	NOP
	NOP
	MOV     A,#0X04         ;P4.0
	OR      ADM,A	
	JMP		SET_END  

;=========================================================================
	;MOV	A,#02H      ;0000 0011 内部VDD参考电压  10 内部4V参考电压
	;MOV	VREFH,A       
	;MOV     A,#0X01         ;p4.0
	;B0MOV   P4CON,A    
	;MOV     A,#0X10          ;0001 0010                       
	;B0MOV   P4M,A
	;MOV     A,#00H           ;0000 0000
	;B0MOV   P4UR,A
	;B0BSET  FADENB          ;ENABLE ADENB
	;CALL    DELAY_100US
	;NOP
	;NOP
	;MOV     A,#0X00         ;P4.0
	;OR      ADM,A	
	;JMP	SET_END    
;--------------------------------------------------
SET_END:        
    B0BSET  FGCHS	      ;使能AIN通道
    B0BCLR	FADCIRQ		;清ADC中断请求
	B0BCLR	FADCIEN		;关闭中断使能
	BCLR    FEOC
	BSET	FADS           ;ADC启动位
WAIT_EOC:	
	BTS1	FEOC
	JMP		WAIT_EOC      ; wait ADC END
	
	MOV		A,ADB
	MOV		BUF1_TEMP,A 
	MOV		A,#0FH
	AND		A,ADR   
	MOV		BUF0_TEMP,A 
	BCLR	FEOC
	
	CLR     ADM           ; TURN OFF ADC
	
	MOV     A,#0FH
	AND     BUF0_TEMP,A     ;BUF0_TEMP=(0000,ADB3~ADB0)
	
	SWAP	BUF1_TEMP        ;A=(ADB7~ADB4,ADB12~ADB8)
	MOV		TEMP0,A          ;TEMP0=(ADB7~ADB4,ADB12~ADB8)
	
	MOV		A,#0FH
	AND		A,TEMP0          ;A=(0000,ADB12~ADB8)
	MOV     BUF1_TEMP,A     ;BUF1_TEMP=(0000,ADB12~ADB8)
	
	MOV     A,#0F0H
	AND     A,TEMP0         ;A=(ADB7~ADB4,0000)
	OR      BUF0_TEMP,A     ;BUF0_TEMP=(ADB7~ADB4,ADB3~ADB0)
;---------------------------------------------------------------    
;采样结束 比较采样值是否在最大最小值之间    
;------------------------------------------------------------------  
RESULT_SMOOTHING:       ;中值滤波 取9个数据排序 在取第5个值
	MOV		A,#3CH;3EH		;首地址 保存采样值从40H开始
	MOV		AD_SMOOTHING_ADD_L,A
	MOV		A,#3DH;3FH
	MOV		AD_SMOOTHING_ADD_H,A

	MOV     A,#0X02
	ADD     AD_SAMPLE_TIMES,A       ;加2得保存的地址基数
	
	B0MOV	Y,#00H
	
	MOV     A,AD_SAMPLE_TIMES
	ADD     A,AD_SMOOTHING_ADD_L
	MOV     Z,A                     ;得保存的最新地址
	MOV     A,BUF0_TEMP 
	MOV     @YZ,A                   ;保存采样值低八位
	
	MOV     A,AD_SAMPLE_TIMES
	ADD     A,AD_SMOOTHING_ADD_H
	MOV     Z,A 
	MOV     A,BUF1_TEMP 
	MOV     @YZ,A                   ;保存采样值高四位
	
	MOV     A,#18;16
	SUB     A,AD_SAMPLE_TIMES
	BTS0    FC 
	JMP     RESULT_JUDGE_END        ;保存9次采样数据 从40H-51H
	CLR     AD_SAMPLE_TIMES
;---------------------------------------------------------
;保存数据之后排序 并取第5个数据 
	MOV		A,#3EH;40H		        ;首地址 
	MOV		KEEP_ADD_L,A
	MOV		A,#3FH;41H
	MOV		KEEP_ADD_H,A
	MOV     A,#0X50                 ;结束地址 共18个寄存器排序
	MOV     SMOOTHING_END_ADD,A
	CALL    COMPARE_MAX_LOOP   

;------------------------------------------------------------------ 
;采样结果求平均
RESULT_AVE_JUDGE:           
      
;经过排序 最大值放在1CH 1DH里 最小值放在2EH 2FH里
;舍去最小值最大值 求平均值 
;此段程序只求和 平均值不在此计算 乘除法时多除8
	MOV		A,#40H		;首地址 保存采样值从40H开始
	MOV		AD_SMOOTHING_ADD_L,A
	MOV		A,#41H
	MOV		AD_SMOOTHING_ADD_H,A

    MOV     A,#0X08
    MOV     TEMP,A      
AVE_SUM_NEXT:
    B0MOV	Y,#00H
    MOV     A,#0X5A
    B0MOV   WDTR,A
    
    MOV     A,AD_SMOOTHING_ADD_L
    MOV     Z,A 
    MOV     A,@YZ
    MOV     AD_OLD_L,A 

    MOV     A,AD_SMOOTHING_ADD_H
    MOV     Z,A 
    MOV     A,@YZ
    MOV     AD_OLD_H,A 
    
    MOV		A,AD_OLD_L
	ADD 	ADC_AVE_L,A 
	MOV		A,AD_OLD_H
	ADC 	ADC_AVE_H,A 

	
    CLR     AD_OLD_L
    CLR     AD_OLD_H
    INCMS   AD_SMOOTHING_ADD_L
    INCMS   AD_SMOOTHING_ADD_L
    INCMS   AD_SMOOTHING_ADD_H 
    INCMS   AD_SMOOTHING_ADD_H

    DECMS   TEMP
    JMP     AVE_SUM_NEXT

    BCLR	FC              ;求平均值
	RRCM	ADC_AVE_H
	RRCM	ADC_AVE_L
	BCLR	FC              ;求平均值
	RRCM	ADC_AVE_H
	RRCM	ADC_AVE_L   
	BCLR	FC              ;求平均值
	RRCM	ADC_AVE_H
	RRCM	ADC_AVE_L    
;-----------------------------------------------
;两次采样差值在100之内 不更新显示值
ADC_DATA_CHUANGKOU:
    MOV		A,ADC_AVE_L
	MOV		ADC_SAMP_L,A	;上一次保留平均值低位
	MOV		A,ADC_AVE_H
	MOV		ADC_SAMP_H,A	;上一次保留平均值高位
 
	MOV		A,#0X26	
	ADD 	CHECK_DATA,A 

	MOV		A,#0X10	
	ADD 	CHECK_DATA,A 

	MOV		A,#0X40	
	ADD 	CHECK_DATA,A 

	MOV		A,ADC_SAMP_L
	ADD 	CHECK_DATA,A 

	MOV		A,ADC_SAMP_H
	ADD 	CHECK_DATA,A 


	MOV		A,#0X26	
	CALL	SEND_DATA_TO_COMPUTER
	MOV		A,#0X10	
	CALL	SEND_DATA_TO_COMPUTER
	
	MOV		A,#0X40	
	CALL	SEND_DATA_TO_COMPUTER

	MOV		A,ADC_SAMP_L
	CALL	SEND_DATA_TO_COMPUTER
	MOV		A,ADC_SAMP_H
	CALL	SEND_DATA_TO_COMPUTER

	MOV		A,CHECK_DATA
	CALL	SEND_DATA_TO_COMPUTER



	CLR		CHECK_DATA
	CLR		ADC_AVE_L
	CLR		ADC_AVE_H
	CLR		ADC_SAMP_L
	CLR		ADC_SAMP_H

RESULT_JUDGE_END:
ADC_VDD_JUDGE_END:
	JMP     MAIN
;-----------------------------------------------------------   

;=====================================================
;从大到小排序
;=====================================================
COMPARE_NEXT_GROUP:
	INCMS   KEEP_ADD_L
	INCMS   KEEP_ADD_L
	INCMS   KEEP_ADD_H 
	INCMS   KEEP_ADD_H
	
	MOV     A,KEEP_ADD_L
	SUB     A,SMOOTHING_END_ADD
	BTS0    FC 
	RET     
        
COMPARE_MAX_LOOP:	
	MOV		A,KEEP_ADD_L		        ;首地址 保存采样值从40H开始
	MOV		AD_SMOOTHING_ADD_L,A
	MOV		A,KEEP_ADD_H
	MOV		AD_SMOOTHING_ADD_H,A

	B0MOV	Y,#00H
	MOV     A,AD_SMOOTHING_ADD_L 
	MOV     Z,A 
	MOV     A,@YZ 
	MOV     SMOOTHING_TEMP1_L,A
	
	MOV     A,AD_SMOOTHING_ADD_H 
	MOV     Z,A 
	MOV     A,@YZ 
	MOV     SMOOTHING_TEMP1_H,A    ;对应地址取数据
        
COMPARE_NEXT:
	MOV     A,#0X5A  ;清看门狗
	B0MOV   WDTR,A
	INCMS   AD_SMOOTHING_ADD_L
	INCMS   AD_SMOOTHING_ADD_L
	INCMS   AD_SMOOTHING_ADD_H 
	INCMS   AD_SMOOTHING_ADD_H
	
	MOV     A,SMOOTHING_END_ADD     ;#0X50
	SUB     A,AD_SMOOTHING_ADD_L
	BTS1    FC 
	JMP     COMPARE_NEXT_GROUP
        
	MOV     A,AD_SMOOTHING_ADD_L 
	MOV     Z,A 
	MOV     A,@YZ 
	MOV     SMOOTHING_TEMP2_L,A
	
	MOV     A,AD_SMOOTHING_ADD_H 
	MOV     Z,A 
	MOV     A,@YZ 
	MOV     SMOOTHING_TEMP2_H,A
	
	MOV     A,SMOOTHING_TEMP1_L
	SUB     A,SMOOTHING_TEMP2_L
	MOV     A,SMOOTHING_TEMP1_H
	SBC     A,SMOOTHING_TEMP2_H
	BTS0    FC 
	JMP     COMPARE_NEXT    ;前面的数据大于后面的数据
	MOV     A,KEEP_ADD_L    ;前面的数据不大于后面的数据     ；后面的大
	MOV     Z,A 
	MOV     A,SMOOTHING_TEMP2_L         
	MOV     @YZ,A                         ;后面的数据放到前面的地址里

	MOV     A,KEEP_ADD_H
	MOV     Z,A 
	MOV     A,SMOOTHING_TEMP2_H
	MOV     @YZ,A
	
	MOV     A,AD_SMOOTHING_ADD_L
	MOV     Z,A 
	MOV     A,SMOOTHING_TEMP1_L
	MOV     @YZ,A
	
	MOV     A,AD_SMOOTHING_ADD_H
	MOV     Z,A 
	MOV     A,SMOOTHING_TEMP1_H
	MOV     @YZ,A                        ;;前面的数放在后面的地址
	
	MOV     A,SMOOTHING_TEMP2_L
	MOV     SMOOTHING_TEMP1_L,A
	MOV     A,SMOOTHING_TEMP2_H
	MOV     SMOOTHING_TEMP1_H,A          ;后面的数据放到前面的位置
	JMP     COMPARE_NEXT

;/*'
;--------------------------------------------  
;串口数据传送   ;调试时使用  
;--------------------------------------------          
;定义:
;TX_O = IO口
;TXCNT = 寄存器
;TXCLOCK = 寄存器
;TXDATA = 寄存器
;
SEND_DATA_TO_COMPUTER:
	B0BCLR	FGIE 
	B0BCLR	FGIE
   
    MOV		TXDATA,A
    BCLR	TX_O
    MOV		A,#0X08
    MOV		TXCNT,A
    MOV		A,#136;#100;88        ;0X21
    MOV		TXCLOCK,A
TX_DELAY1:
    DECMS	TXCLOCK
    JMP		TX_DELAY1
TX_LOOP:
    RRCM	TXDATA
    BTS0	FC
    BSET	TX_O
    BTS1	FC
    BCLR	TX_O

    MOV		A,#136;#100;88        ;0X21
    MOV		TXCLOCK,A
TX_DELAY2:
    DECMS	TXCLOCK
    JMP		TX_DELAY2

    DECMS	TXCNT
    JMP		TX_LOOP

    BSET	TX_O
    MOV		A,#136;40
    MOV		TXCLOCK,A
TX_DELAY3:
    DECMS	TXCLOCK
    JMP		TX_DELAY3

    B0BSET	FGIE
    RET

;'*/
;---------------------------------
; 10us延时  40*0.25US
;---------------------------------
DELAY_MS:
    MOV		A,#10
    MOV		DELAY_TIME,A 
DELAY_MS_LOOP:
    MOV		A,#80
    MOV		DELAY_INSIDE,A
DELAY_LOOP:  
    MOV		A,#0X5A  
    B0MOV	WDTR,A
    NOP
    JMP		$+1
    JMP		$+1
    DECMS	DELAY_INSIDE
    JMP		DELAY_LOOP
    
    DECMS	DELAY_TIME
    JMP		DELAY_MS_LOOP
    RET
        
;---------------------------------
;---------------------------------
DELAY_100US:
    MOV		A,#80
    MOV		DELAY_INSIDE,A
DELAY_10US_LOOP:  
    MOV     A,#0X5A  
    B0MOV   WDTR,A
    NOP
    JMP		$+1
    JMP		$+1
    DECMS	DELAY_INSIDE
    JMP		DELAY_10US_LOOP
  
    RET



	