"); //-->
代码
#include<p16f877.inc> __CONFIG(_CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF& _CPD_OFF); nCount equ 0x20 mCount equ 0x21 i equ 0x22 j equ 0x23 org 0x0000 goto main org 0x0020 main CALL IO_ADC call delay GOTO main IO_ADC BANKSEL TRISB movlw 0x00 movwf TRISD MOVLW TRISB MOVWF FSR MOVLW B'11101111' MOVWF INDF BANKSEL nCount clrf nCount movlw .255 movwf mCount btfsc PORTB,5 GOTO _VtChk0 bsf PORTB,4 BTFSS PORTB,5 GOTO $-1 GOTO _ioAD_Start _VtChk0 bcf PORTB,4 BTFSC PORTB,5 GOTO $-1 _ioAD_Start btfss PORTB,5 GOTO _ioAD_hi bcf PORTB,4 INCF nCount,f goto _ioAD_cnt _ioAD_hi bsf PORTB,4 GOTO _ioAD_cnt _ioAD_cnt decfsz mCount,f goto _ioAD_Start BANKSEL PORTD MOVF nCount,w movwf PORTD return delay clrf i clrf j decfsz j,f goto $-1 decfsz i,f goto $-3 return end
原理图
1.5V时,显示0x53,就是83,理论值77
1V时显示0x3f,就是63,理论值51
2V时显示0x6d,就是109,理论值102
2.5V时显示0x7f,就是127,理论值127
3V时显示0x9d,就是157,理论值153
3.5V时显示0xb6,就是182,理论值178.5
4V时显示0xcd,就是205,理论值204
4.5V时显示0xe8,就是232,理论值229.5
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。