12f675 programming question
this program is used in a metal detector. An analog signal goes into pin 6 of the 12f675. the way the program should work is that if a button is being pressed a 5V signal will be sent to pin 4. After every a/d pin 4 is checked to see if there is a digital 1 or 5V. If so then the value stored in ADRESL from the a/d should be stored in temp (variable stored in memory). when the button is not pressed the program will take the new data from ADRESL and subtract the value stored in temp from it. after this subtraction if the carry bit in the status register is clear the pic will turn on pin 5 and then turn it off which makes a wave that can be heard throw a speaker.
here is my code
list p=12F675;
#include <p12F675.inc>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
#define boy D'255';
#define man 0x20;
temp EQU 0x21
bcf STATUS,RP0
clrf GPIO
movlw 07h
movwf CMCON
movlw 85h
movwf ADCON0
bsf STATUS,RP0
movlw 02h
movwf ANSEL ;sets pin 6 as analog input
movlw 0Ah
movwf TRISIO ;sets pin 4 and 5 as outputs 6 as input
bcf STATUS,RP0
ad
movlw 87h
movwf ADCON0
adfinish
btfsc ADCON0,1
goto adfinish
btfsc GPIO,GPIO3 ;tests if button is pressed
goto reference
movlw 0FFh
bsf STATUS,RP0
andwf ADRESL,1
bsf STATUS,C
bcf STATUS,RP0
movlw temp
bsf STATUS,RP0
subwf ADRESL,1
btfsc STATUS,C ;check if signal is greater than 0
goto ad ;no metal perform next A/D
on
;turn pin on
bcf STATUS,RP0
movlw 04h
movwf GPIO
call delay;
;turn pin off
movlw 00h
movwf GPIO
call delay
goto ad
reference
bsf STATUS,RP0
movf ADRESL,0
bcf STATUS,RP0
movwf temp
goto ad
delay;
movlw boy;
movwf man;
loop;
decfsz man,f;
goto loop;
return;
end