張明峰書例子5-5
代碼
#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
*博客內(nèi)容為網(wǎng)友個人發(fā)布,僅代表博主個人觀點,如有侵權(quán)請聯(lián)系工作人員刪除。