LIST P=16F877A
INCLUDE "P16F877a.inc"
__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON
CHK1 EQU 0X21
CNT1 EQU 0x22
CNT2 EQU 0x23
count EQU 0x20
org 0x000
nop
BSF STATUS,RP0
MOVLW H'FF'
MOVWF TRISA
movlw H'00';
movwf TRISB;
banksel PORTA
BCF STATUS,RP0
clrf PORTB
banksel ADCON1
movlw b'10000000'
movwf ADCON1
banksel ADCON0
movlw b'10000001'
movwf ADCON0
getAD movlw 007
movwf count
down decfsz count
goto down
bsf ADCON0,GO
wait btfsc ADCON0,GO
goto wait
return
delay MOVLW D'5'
MOVWF CNT2
CON1 MOVLW H'FF'
MOVWF CNT1
DECFSZ CNT1,1
GOTO $-1
DECFSZ CNT2,1
GOTO CON1
RETURN
start call getAD ; get adc result store at adresh
movlw 0xC8 ;
subwf ADRESH,1 ; adc result in adresh will minus....
btfsc ADRESH,0 ;...C8 and the answer store at adresh again..
goto start ; if answer in adresh is not 0....then the program will jump to start again...
btfsc ADRESH,1
goto start
btfsc ADRESH,2
goto start
btfsc ADRESH,3
goto start
btfsc ADRESH,4
goto start
btfsc ADRESH,5
goto start
btfsc ADRESH,6
goto start
btfsc ADRESH,7
goto start
bsf PORTB,1
call delay
END
LIST P=16F877A
INCLUDE "P16F877a.inc"
__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON
CHK1 EQU 0X21
CNT1 EQU 0x22
CNT2 EQU 0x23
count EQU 0x20
org 0x000
nop
BSF STATUS,RP0
MOVLW H'FF'
MOVWF TRISA
movlw H'00';
movwf TRISB;
banksel PORTA
BCF STATUS,RP0
clrf PORTB
banksel ADCON1
movlw b'10000000'
movwf ADCON1
banksel ADCON0
movlw b'10000001'
movwf ADCON0
;;; [COLOR="Blue"]THE PROGRAM WILL ENTER HERE AFTER THE INTIALISING[/COLOR]
getAD movlw 007
movwf count
down decfsz count
goto down
bsf ADCON0,GO
wait btfsc ADCON0,GO
goto wait
[COLOR="Blue"]return ;;;;;;;;; RETURN TO WHERE on 1st pass .???
[/COLOR]
delay MOVLW D'5'
MOVWF CNT2
CON1 MOVLW H'FF'
MOVWF CNT1
DECFSZ CNT1,1
GOTO $-1
DECFSZ CNT2,1
GOTO CON1
RETURN
start call getAD ; get adc result store at adresh
movlw 0xC8 ;
subwf ADRESH,1 ; adc result in adresh will minus....
btfsc ADRESH,0 ;...C8 and the answer store at adresh again..
goto start ; if answer in adresh is not 0....then the program will jump to start again...
btfsc ADRESH,1
goto start
btfsc ADRESH,2
goto start
btfsc ADRESH,3
goto start
btfsc ADRESH,4
goto start
btfsc ADRESH,5
goto start
btfsc ADRESH,6
goto start
btfsc ADRESH,7
goto start
bsf PORTB,1
call delay
END
LIST P=16F877A
INCLUDE "P16F877a.inc"
__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON
CHK1 EQU 0X21
CNT1 EQU 0CH
CNT2 EQU 0DH
count EQU 0x20
org 0x000
nop
BSF STATUS,RP0
MOVLW H'FF'
MOVWF TRISA
movlw H'00';
movwf TRISB;
banksel PORTA
BCF STATUS,RP0
clrf PORTB
banksel ADCON1
movlw b'10000000'
movwf ADCON1
banksel ADCON0
movlw b'10000001'
movwf ADCON0
goto start
getAD movlw 007
movwf count
down decfsz count
goto down
bsf ADCON0,GO
wait btfsc ADCON0,GO
goto wait
return
delay MOVLW D'5'
MOVWF CNT2
CON1 MOVLW H'FF'
MOVWF CNT1
DECFSZ CNT1,1
GOTO $-1
DECFSZ CNT2,1
GOTO CON1
RETURN
start call getAD ; get adc result store at adresh
movlw 0xC8 ;
subwf ADRESH,1 ; adc result in adresh will minus....
btfsc ADRESH,0 ;...C8 and the answer store at adresh again..
goto start ; if answer in adresh is not 0....then the program will jump to start again...
btfsc ADRESH,1
goto start
btfsc ADRESH,2
goto start
btfsc ADRESH,3
goto start
btfsc ADRESH,4
goto start
btfsc ADRESH,5
goto start
btfsc ADRESH,6
goto start
btfsc ADRESH,7
goto start
bsf PORTB,1
call delay
END
LIST P=16F877A
INCLUDE "P16F877a.inc"
__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON
CHK1 EQU 0X21
CNT1 EQU 0CH
CNT2 EQU 0DH
count EQU 0x20
org 0x000
nop
BSF STATUS,RP0
MOVLW H'FF'
MOVWF TRISA
movlw H'00';
movwf TRISB;
BCF STATUS,RP0
BANKSEL PORTA
clrf PORTB
BANKSEL ADCON1
movlw b'10000000'
movwf ADCON1
BANKSEL ADCON0
movlw b'10000001'
movwf ADCON0
goto start
getAD bsf ADCON0,GO
btfsc ADCON0,GO
goto $-1
movf ADRESH,W
return
delay MOVLW D'5'
MOVWF CNT2
CON1 MOVLW H'FF'
MOVWF CNT1
DECFSZ CNT1,1
GOTO $-1
DECFSZ CNT2,1
GOTO CON1
RETURN
start call getAD ; get adc result store at adresh
movlw 0x29 ;
subwf ADRESH,1 ; adc result in adresh will minus....
btfsc ADRESH,0 ;...C8 and the answer store at adresh again..
goto start ; if answer in adresh is not 0....then the program will jump to start again...
btfsc ADRESH,1
goto start
btfsc ADRESH,2
goto start
btfsc ADRESH,3
goto start
btfsc ADRESH,4
goto start
btfsc ADRESH,5
goto start
btfsc ADRESH,6
goto start
btfsc ADRESH,7
goto start
bsf PORTB,1
call delay
END
getAD bsf ADCON0,GO
btfsc ADCON0,GO
goto $-1
movf ADRESH,W [COLOR="Blue"];you are saving ADRESH in W, then RETURNING[/COLOR]
return
delay MOVLW D'5'
MOVWF CNT2
CON1 MOVLW H'FF'
MOVWF CNT1
DECFSZ CNT1,1
GOTO $-1
DECFSZ CNT2,1
GOTO CON1
RETURN
start call getAD ; get adc result store at adresh
movlw 0x29 ; [COLOR="Blue"]you are now replacing the ADRESH value with 29h...!!!!!![/COLOR]
subwf ADRESH,1 ; adc result in adresh will minus....
LIST P=16F877A
INCLUDE "P16F877a.inc"
status EQU 0x03
TRISA EQU 0X85
PORTA EQU 0X05
TRISB EQU 0X86
PORTB EQU 0X06
CHK1 EQU 0X21
CNT1 EQU 0CH
CNT2 EQU 0DH
count EQU 0x20h
NumH equ 0x22h
org 0x000
nop
BSF STATUS,RP0
MOVLW H'FF'
MOVWF TRISA
movlw H'00';
movwf TRISB;
banksel PORTA
BCF STATUS,RP0
clrf PORTB
banksel ADCON1
movlw b'10000000'
movwf ADCON1
banksel ADCON0
movlw b'10000001'
movwf ADCON0
goto start
getAD bsf ADCON0,GO
btfsc ADCON0,GO
goto $-1
banksel ADRESH
movf ADRESH,w
movwf NumH
return
delay MOVLW D'5'
MOVWF CNT2
CON1 MOVLW H'FF'
MOVWF CNT1
DECFSZ CNT1,1
GOTO $-1
DECFSZ CNT2,1
GOTO CON1
RETURN
start call getAD ; get adc result store at NumH
sublw 0x29 ;adc result in NumH will minus with 0x29....
btfss status,2 ;jump to bsf if after subwf is = zero
goto start ;if not = zero,start again
bsf PORTB,0
call delay
end
getAD bsf ADCON0,GO
[COLOR="Red"];wait 20uS or more for ADC internal work[/COLOR]
btfsc ADCON0,GO
goto $-1
;;;;
;;;;
call delay
[COLOR="Red"] still run, till the end of memory then start from 0 [/COLOR]
end
actually i want to send a 0.1V sine wave from frequency generator to PIC to convert from A to D. After convert ,i will subtract it with 0x29 (0x29 = 0.1V). If i get value equal to zero,it will show me the output.This is my code after modification, is that still got any error?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?