大家好 ,请教个AD问题
详细请看以下,静态电流判断部分,当我AD采的值超过了2.0V的时候,没有反映,还是转跳到pASS这边,但是前部分的V0输出电压判断部分正常.
我用访真过,采样的值正确.
不知道那里问题啊! LIST P=16F877A #INCLUDE<P16F877a.INC> ;包含芯片头文件 __CONFIG _DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_OFF&_WDT_OFF&_HS_OSC ;芯片配置字,看门狗关,上电延时开,掉电检测关,低压编程关,加密,4M晶体HS振荡 ;280116001 测试程序 ;2008-12-26 ;******************************************* PORTA EQU 0X05 TRISA EQU 0X85 PORTB EQU 0X06 TRISB EQU 0X86 PORTC EQU 0X07 TRISC EQU 0X87 PORTD EQU 0X08 TRISD EQU 0X88 PORTE EQU 0X09 TRISE EQU 0X89 RP0 EQU 0X05 Z EQU 0X02 DC EQU 0X01 C EQU 0X00 ADCON1 EQU 0X9F ADCON0 EQU 0X1F INTCON EQU 0X0B TMR0 EQU 0X01 N1 EQU 0X21 N2 EQU 0X22 N3 EQU 0X28 N4 EQU 0X27 TEMP1 EQU 0X20 STATUS EQU 0X03 ADRESH EQU 0X1E INTCON EQU 0X0B PIR1 EQU 0X0C PIE1 EQU 0X8C TEMP0 EQU 0X23 ;***********程序开始************** ORG 0X00 NOP GOTO MAIN ORG 0X05 MAIN CALL RESTE CALL START GOTO CHECK ;************按键按下检查********** CHECK BSF STATUS,RP0 MOVLW 0X3F MOVWF TRISA MOVLW 0XBF MOVWF TRISB BSF TRISB,0 BCF STATUS,RP0 BTFSC PORTB,0; 按键判断 GOTO CHECK ; caLL DELAY_10MS; 延时10MS BTFSC PORTB,0; 继续判断 BSF STATUS,RP0;关闭FAIL.PASS指示灯 BCF TRISC,2 BCF TRISC,3 BCF STATUS,RP0 BCF PORTC,2 BCF PORTC,3 BSF STATUS,RP0;选择为1 BSF TRISB,0 CALL RESTE CALL START ;*************第1步************** CALL DELAY_1S BCF STATUS,RP0 CLRF ADRESH; MOVLW 0X30 ;显示1 MOVWF PORTD BSF STATUS,RP0 BCF TRISB,2;RB2为输出口 BCF STATUS,RP0;选择体0 BSF PORTB,2; OPEN S2 CALL DELAY_250MS CALL P0 ;************第2步*************** NEXT2 CALL DELAY_1S; 为1,到下一步 BCF STATUS,RP0 CLRF ADRESH; BSF STATUS,RP0 MOVLW 0X00 MOVWF TRISD BCF STATUS,RP0 MOVLW 0XDB ;显示2 MOVWF PORTD BSF STATUS,RP0 BCF TRISB,1; RB1为输出口 BCF STATUS,RP0;选择体0 BSF PORTB,1;OPEN S1 CALL DELAY_250MS CALL P1 ;***********第3步***************** NEXT3 CALL DELAY_1S ; 没有借位,下一步开始 BCF STATUS,RP0 CLRF ADRESH; BSF STATUS,RP0 MOVLW 0X00; MOVWF TRISD; BCF STATUS,RP0;选择体0 MOVLW 0X4F ;显示3 MOVWF PORTD BCF PORTB,1;CLOSE S1 BCF PORTB,2;CLOSE S2 CALL DELAY_250MS BSF STATUS,RP0 BCF TRISB,3 ;RB3.RB2 OUTPUT BCF TRISB,2 BCF STATUS,RP0 BSF PORTB,3; 打开S3 BSF PORTB,2;再打开S2 CALL DELAY_250MS CALL P3 ;***********第4步***************** NEXT4 CALL DELAY_1S ; 没有借位,下一步开始 BCF STATUS,RP0 CLRF ADRESH; BSF STATUS,RP0 MOVLW 0X00 MOVWF TRISD; BCF STATUS,RP0;选择体0 MOVLW 0XE6 ;显示4 MOVWF PORTD BCF PORTB,3;CLOSE S3 BCF PORTB, 2;CLOSE S2 CALL DELAY_250MS BSF STATUS,RP0;选择体1 BCF TRISB,2 BCF TRISB,4 BCF STATUS,RP0 BSF PORTB,2;OPEN S2 CALL DELAY_250MS BSF PORTB,4;OPEN S4 CALL DELAY_250MS CALL P4 ;**********第5步***************** NEXT5 CALL DELAY_1S ; 没有借位,下一步开始 BCF STATUS,RP0 CLRF ADRESH; BSF STATUS,RP0 MOVLW 0X00 MOVWF TRISD BCF STATUS,RP0; 选择体0 MOVLW 0X6D ;显示5 MOVWF PORTD BCF PORTB,4;CLOSE S4 BCF PORTB,2;CLOSE S2 CALL DELAY_250MS; BSF STATUS,RP0; BCF TRISB,1; BCF TRISB,5; BCF STATUS,RP0; BSF PORTB,1;OPEN S1 BSF PORTB,5;OPEN S5 CALL DELAY_1S CALL P2 ;*************PASS子程序**************** PASS BSF STATUS,RP0 BCF TRISC,3 BCF STATUS,RP0 BSF PORTC,3; 点亮PASS LED GOTO CHECK ;再看启动按键有没有按下,重新开始测试 RETURN ;**************FAIL子程序*************** FAIL BSF STATUS,RP0 BCF TRISC,2 BCF STATUS,RP0; BSF PORTC,2 ;点亮FAIL LED GOTO CHECK ;再看启动按键有没有按下,重新开始测试 RETURN ;********延时10MS子程序**************** DELAY_10MS MOVLW D'1' MOVWF N1 DELAY0 MOVLW D'2' MOVWF N2 DELAY1 DECFSZ N2,1 GOTO DELAY1 DECFSZ N1,1 GOTO DELAY0 RETURN ;********延时250MS子程序************** DELAY_250MS MOVLW D'39' MOVWF N1; DELAY2 MOVLW D'100'; MOVWF N2; DELAY3 MOVLW D'20'; MOVWF N4 DELAY4 DECFSZ N4,1 GOTO DELAY4 DECFSZ N2,1 GOTO DELAY3 DECFSZ N1,1 GOTO DELAY2 RETURN ;***********延时1S子程序**************** DELAY_1S MOVLW 0X30 MOVWF N2; LOOP3 MOVLW 0XC8 MOVWF N1; LOOP2 MOVLW 0X24 MOVWF N4; LOOP1 DECFSZ N4,1 GOTO LOOP1 DECFSZ N1,1 GOTO LOOP2; DECFSZ N2,1 GOTO LOOP3 RETURN ;**********初始化各寄存器************** RESTE BCF STATUS,RP0 CLRF N1; CLRF N2; CLRF N3; CLRF N4; CLRF TEMP1; CLRF PORTB CLRF PORTC; CLRF PORTE; CLRF ADRESH; CLRF PIR1; CLRF INTCON; CLRF ADCON0; BSF STATUS,RP0 CLRF ADCON1 CLRF PIE1 MOVLW 0XFF MOVWF OPTION_REG RETURN ;************************************* START BSF STATUS,RP0; MOVLW 0X00; TRISD.TRISB.TRISC为输出口 MOVWF TRISD; MOVLW 0X00 MOVWF TRISC; BSF TRISB,0;RB0为输入口 BCF STATUS,RP0 MOVLW 0X3F;显示0 MOVWF PORTD; RETURN ;*********V0输出电压判断子程序************ P0 BCF STATUS,5 MOVLW B'01001001'; MOVWF ADCON0 BSF STATUS,5 BSF STATUS,6 MOVLW B'10000111' MOVWF OPTION_REG BSF STATUS,5 BCF STATUS,6 MOVLW B'00001110' MOVWF ADCON1 BCF STATUS,5 S0 BTFSS INTCON,2 GOTO S0 BCF INTCON,2 BSF ADCON0,2 WAIT0 BTFSS PIR1,6 GOTO WAIT0 MOVF ADRESH,W SUBLW 0XB7;3.6V-A/D BTFSC STATUS,0 GOTO FAIL GOTO NEXT2 RETURN ;******过放保护判断测试子程序********** P1 BCF STATUS,5 BCF STATUS,6 MOVLW B'01001001'; MOVWF ADCON0 BSF STATUS,5 BSF STATUS,6 MOVLW B'10000111' MOVWF OPTION_REG BSF STATUS,5 BCF STATUS,6 MOVLW B'00001110' MOVWF ADCON1 BCF STATUS,5 S1 BTFSS INTCON,2 GOTO S1 BCF INTCON,2 BSF ADCON0,2 WAIT1 BTFSS PIR1,6 GOTO WAIT1 MOVF ADRESH,W SUBLW 0X19;0.5V-A/D BTFSC STATUS,0 GOTO NEXT3 GOTO FAIL RETURN ;*************静态电流判断<10UA********** P2 BCF STATUS,5 BCF STATUS,6 BCF STATUS,0 MOVLW B'01000001'; MOVWF ADCON0 BSF STATUS,5 BSF STATUS,6 MOVLW B'10000111' MOVWF OPTION_REG BSF STATUS,5 BCF STATUS,6 MOVLW B'00001110' MOVWF ADCON1 BCF STATUS,5 S2 BTFSS INTCON,2 GOTO S2 BCF INTCON,2 BSF ADCON0,2 WAIT2 BTFSS PIR1,6 GOTO WAIT2 MOVF ADRESH,W ;CALL DELAY_250MS SUBLW 0X5B;2V-A/D BCF STATUS,RP0 BCF STATUS,RP1 BTFSC STATUS,C GOTO PASS GOTO FAIL RETURN ;******NTC保护保测试子程序************ P3 BCF STATUS,5 MOVLW B'01001001'; MOVWF ADCON0 BSF STATUS,5 BSF STATUS,6 MOVLW B'10000111' MOVWF OPTION_REG BSF STATUS,5 BCF STATUS,6 MOVLW B'00001110' MOVWF ADCON1 BCF STATUS,5 S3 BTFSS INTCON,2 GOTO S3 BCF INTCON,2 BSF ADCON0,2 WAIT3 BTFSS PIR1,6 GOTO WAIT3 MOVF ADRESH,W SUBLW 0X19;0.5V-A/D BTFSC STATUS,0 GOTO NEXT4 GOTO FAIL RETURN ;****** RT保护测试子程序********** P4 BCF STATUS,5 MOVLW B'01001001'; MOVWF ADCON0 BSF STATUS,5 BSF STATUS,6 MOVLW B'10000111' MOVWF OPTION_REG BSF STATUS,5 BCF STATUS,6 MOVLW B'00001110' MOVWF ADCON1 BCF STATUS,5 S4 BTFSS INTCON,2 GOTO S4 BCF INTCON,2 BSF ADCON0,2 WAIT4 BTFSS PIR1,6 GOTO WAIT4 MOVF ADRESH,W SUBLW 0X19;0.5V-A/D BTFSC STATUS,0 GOTO NEXT5 GOTO FAIL RETURN ;***************************** END
|