; PHONE2PIC program
; This program interfaces a cellphone to a pic by means of cellphone
; audio output: upon detecting any signal present on the pin
; connected to the cellphone headset audio output, a led is lit.
;
;
; Just a proof-of-concept: use this source to write a program which allow
; driving an high current relais to be able to drive any equipment by SMS
; (you'll need a proper program running on the cellphone).
;
; ****** Comparatore settings ******
; Comparator pins RA3 to RA0 (4 pins)
; Set comparators mode by settings bits CM2:CM0 in CMCON register:
; CM2:CM0 = 010 : pin RA0 is input, bit C1OUT (bit 6) in CMCON is output,
; internal Vref is reference voltage.
; Voltage Reference module must be set up by setting VRCON register:
; VRCON = 1010.0110
; |||| |||'-- VR0 \
; |||| ||'--- VR1 \
; |||| |'---- VR2 / Vref = VR*Vdd/24 if Vrr = 1
; |||| '----- VR3 / Vref = Vdd/4 + VR*Vdd/32 if Vrr = 0
; |||'------- n/a
; ||'-------- Vrr Set divisions
; |'--------- VRoe Send output to RA2 if enabled
; '---------- VRen Enable Vref circuit.
PROCESSOR 16F628A
RADIX DEC
INCLUDE "P16F628A.INC"
;__CONFIG 11110100010000B
; Configuration is:
; Master Clear pin is disabled (used as input)
; Code Protection is OFF
; Watchdog Timer is ON
; Oscillator is Internal RC
__config _MCLRE_OFF & _CP_OFF & _WDT_ON & _INTRC_OSC_NOCLKOUT
cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
C1OUTMASK Equ b'01000000' ;Comparator1 output bit
ORG 0x0000
GOTO START
ORG 0x0004
GOTO START
START
bcf STATUS,RP0 ; You must be in Bank 0 to access CMCON.
movlw b'00000010' ; enable comparators by setting CM2:CM0 == 010 (internal reference)
; |||||||'-- \ Set comparator mode:
; ||||||'--- '010' means "use internal voltage reference
; |||||'---- /
; ||||'----- CIS = 0 => Comp1 input is from RA0
; |||'------ C1INV: invert Comp1 result (DISABLED)
; ||'------- C2INV: invert Comp2 result(DISABLED)
; |'-------- ****** C1OUT: output of Comp1 ******* <<<=====----
; '--------- C2OUT: output of Comp2 (NOT USED)
movwf CMCON ; Comparator input is RA0. See 16F628A datasheet section 10.0
bsf STATUS,RP0 ; You must be in Bank 1 to access VRCON.
; ********** Set reference value ********* <<<====----
movlw b'10100001' ; Enable Vref module and set Vref ======== 0110 = 6 => 1/4 Vdd = 0.125 V
; |||||||'-- VR0 \
; ||||||'--- VR1 \
; |||||'---- VR2 / if Vrr = 1: Vref = VR*Vdd/24
; ||||'----- VR3 / if Vrr = 0: Vref = Vdd/4 + VR*Vdd/32
; |||'------ n/a
; ||'------- Vrr Set divisions scale
; |'-------- VRoe Send output to RA2 if enabled
; '--------- VRen Enable Vref circuit.
movwf VRCON ; See 16F628A datasheet section 11.0
call DELAY ;Time to settle down VREF
BSF STATUS,RP0 ; Bank 1
CLRF TRISB ; PORT B is output
BCF STATUS,RP0 ; Bank 0
bcf STATUS,RP0 ; Must be on Bank 0 to access CMCON (comparator results)
L_CHECK
CLRWDT
movf CMCON,w
andlw C1OUTMASK ; check C1OUT bit
btfsc STATUS,Z
goto L_ACK ; Comparator = 1 => Light led
goto L_NOTH ; Comparator = 0 => loop
L_ACK
MOVLW 11100000B
MOVWF PORTB
goto L_CHECK
L_NOTH
MOVLW 00000000B
MOVWF PORTB
goto L_CHECK
DELAY movlw d'250' ;delay 250 ms (4 MHz clock) to make run faster or slower change the d'250' setting
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
return
END