|
本人写了一段程序,要求6.7脚作为输入[0-5V],3.5脚作为输出,但工作时,3.5脚始终是低电压,请问各位高手是不是软件问题,非常感谢.程序如下:
#define TMR0 01H
#define PCL 02H
#define STATUS 03H
#define FSR 04H
#define GPIO 05H
#define PCLATH 0AH
#define INTCON 0BH
#define ADRES 1EH
#define PIR1 0CH
#define ADCON0 1FH
#define OPTION 81H
#define PIE1 8CH
#define ADCON1 9FH
#define TRIS 85H
#DEFINE CMCON 19H
#define TEMP_WIMAGE 20H
#define WIMAGE 21H
#define TEMP_PCLATH 22H
#define TEMP_FSR 23H
#define TEMP_STATUS 24H
#define TEMP_WREG 25H
#define UPLIMT 26H
#define TWOH 27H
#define THREEH 28H
#define FOURH 29H
#define SIXH 2AH
#define EIGHTH 2BH
#define DSHI1 2CH
#define DSHI2 2DH
#define DSHI3 2EH
#define DFLAG 2FH
#define QUED 30H
#define DELAYTEMP 31H
#DEFINE FLAG 32H
#define ADREH 1EH
#define ADBUF 33H
#define DELAYTEMP1 34H
ORG 000H
CLRF PCLATH
GOTO INITSYS
INITSYS:
BSF STATUS, 5 ;选择寄存器体1
MOVLW B'11000111' ;设置选项寄存器
MOVWF OPTION
MOVLW B'00100011'
MOVWF ADCON1 ; 设置7脚和6脚为A/D信号
movlw 03H ;
movwf TRIS ;设置6、7为输入引脚
BCF STATUS, 5 ;选择寄存器体0
movlw 0ffH ;初始化输出寄存器
MOVWf GPIO
CALL WAIT_AD
MOVLW B'00000000'
MOVWF FLAG
LOOP:
CALL WAIT
BCF GPIO,2
MOVLW B'00000000' ;选择模拟信号输入通道为第7脚
MOVWF ADCON0
CALL WAIT
BSF ADCON0,1 ;启动A/D
WAIT11:
BTFSC ADCON0,1
GOTO WAIT11
;BCF PIR1,6
MOVF ADREH,0H ;取高位比较(舍去低位),比较结果控制第5脚电平,观察二极管的熄灭察看转换结果。
suBLW 040H
BTFSS STATUS,0
GOTO SHURU
BCF GPIO,4
CALL WAIT
CALL WAIT
GOTO OK
SHURU:
BSF GPIO,4
CALL WAIT
CALL WAIT
OK:
BSF GPIO,2
CALL WAIT
CALL WAIT
GOTO LOOP
WAIT_AD: ;延时子程序
BCF STATUS,5
MOVLW 0
MOVWF DELAYTEMP
WAITAD:
DECFSZ DELAYTEMP,1
GOTO WAITAD
RETURN
WAIT: ;延时子程序
BCF STATUS,5
MOVLW 0
MOVWF DELAYTEMP1
WAIT1:
CALL WAIT_AD
DECFSZ DELAYTEMP1,1
GOTO WAIT1
RETURN
END |
|