用一pIC的A/D判断电压大小,当电压在3.1V和4.3V之间的时候,POTRB 7灯点亮,当电压高于4.3V和低于3.1V的时候,PORTB 3的灯点亮,但是实验中发现A/D采样过的的数值正确,但是不知道怎么判断不出来? 3.1V和4.3V的数字是这样得出来的 .X*5/255=4.3V X=0XDB X*5/255=3.1V X=0X9Ea,不知道是计算错误还是程序有问题? ;pic:16f877 ;2008-11-24 ;LED显示 LIST P=16F877A #INCLUDE<P16F877a.INC> ;包含芯片头文件 __CONFIG _DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC ;芯片配置字,看门狗关,上电延时开,掉电检测关,低压编程关,加密,4M晶体HS振荡 ;**************************
STATUS EQU 0X03 PORTC EQU 0X07 TRISC EQU 0X87 ADCON0 EQU 0X1F ADCON1 EQU 0X9F PIR1 EQU 0X0C PIE1 EQU 0X8C INTCON EQU 0X0B TRISC EQU 0X87 PORTC EQU 0X07 N1 EQU 0X20
;******************** ORG 0X00 NOP
GOTO START ORG 0X05 START BSF STATUS,5 MOVLW 0X3F MOVWF TRISC BCF STATUS,5 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 MAIN BTFSS INTCON,2 GOTO MAIN BCF INTCON,2 BSF ADCON0,2 WAIT BTFSS PIR1,6 GOTO WAIT MOVF ADRESH,W SUBLW 0X9E;3.1V-A/D BTFSC STATUS,0 GOTO FAIL SUBLW 0XDB;4.3V-A/D BTFSC STATUS,0 GOTO PASS GOTO FAIL ;*********************** FAIL BSF STATUS,5 MOVLW 0XBF MOVWF TRISC BSF PORTC,6 RETURN GOTO WAIT ;******************** PASS BSF STATUS,5 MOVLW 0X7F MOVWF TRISC BSF PORTC,7 RETURN GOTO WAIT ;********************** end 请指教! |