pIC12C508 DTMF拔號(hào)程序
;|Name:MAIN.ASM|
;|Description:DTMF-》RS232converter(forusewithPCNummerViser)|
;|DetectsDTMFandringing,andtransmitstoastd.|
;|RS232port,at2400baud.|
;|||
;+--------------------------------------------------------------------+
;|Platform:PIC12C508(A)(usinginternal4MHzRC-oscillator)|
;|Uses:90-342W/512Wprogram-mem(all’switches’setto0/1)|
;|6B/25Bdata-mem|
;|Assembler:MPASM2.20(MPLAB4.00.00)|
;|Comments:-|
;+====================================================================+
TITLE’DTMFtoRS232converter’
PROCESSOR12C508
__CONFIG_CP_OFF&_MCLRE_OFF&_IntRC_OSC&_WDT_ON
INCLUDE
RADIXDEC
__IDLOCSh’0104’
OTPSET1;Usefactory-storedcal.-value(onOneTimeProgrammable)
TMR0CLKSET1;UseTMR0externalclockat3,579545MHz(insteadofIntRC)。
PARITYSET1;Useevenparity-bitwhentransmittingtotheserialport.
CLIONLYSET1;TransmitsCLI(A-numbers)only.
RINGSET1;Transmitsringing.
IDENTTXSET1;Transmits’ident’whenpressing’***’(DTMF)。
PWRUPIDSET1;Transmitsshort’ident’atpowerup.
ASCIISET1;TransmitsASCII-charsinsteadofbinary:
;DigitASCIIBinaryDigitASCIIBinary
;00(48d)0000000099(57d)00001001
;11(49d)00000001AA(65d)00001010
;22(50d)00000010BB(66d)00001011
;33(51d)00000011CC(67d)00001100
;44(52d)00000100DD(68d)00001101
;55(53d)00000101**(42d)00001110
;66(54d)00000110##(35d)00001111
;77(55d)00000111RingR(82d)00010000
;88(56d)00001000
;---+++***Constants***+++---
IFTMR0CLK==0;Internaloscillator
OPTION_REGequb’10000001’;’Default’timer/prescalersetup
ENDIF
IFTMR0CLK==1;ExternalTMR0source(3,579545MHz)
OPTION_REGequb’10100011’;’Default’timer/prescalersetup
ENDIF
#defineDTMF0GPIO,0;Bit0(LSB)fromMT8870
#defineDTMF1GPIO,1;Bit1fromMT8870
#defineDTMF2GPIO,3;Bit2fromMT8870/_Ring-detector
#defineDTMF3GPIO,4;Bit3fromMT8870/TxD-output(high=sPACe)
#defineDTMFOKGPIO,5;DTMFdetected,andreadyatDTMF0-3
;---+++***Variabledeclaration***+++---
cblock0Ch
DTMFval
identval
misc
temp1,temp2,teMP3;Temp-variables
endc
#defineCLIPmisc,0;SetwhenCLIPdetected
#defineCLIPendmisc,1;SetbyCLIPdetwhen#received
#defineIdentOKmisc,2;Setwhen’ident’detected(***)
;---+++***Resetvector***+++---
ORG0h
rst_vector:
MOVwfOSCCAL;Setoscillatorcalibration.
callinit
IFPWRUPID==1
gotopwrupident
pwrupidentreturn:
ENDIF
gotomain
;---+++***Identity(located’low’becauseofnoCP《64b)***+++---
identtable:
IFIDENTTX==1
addwfPCL,F(xiàn)
dt“+++PCNummerViser+++”,13
dt“Firmwarev1.04”,13,13
dt“JaCOBBlichfELDt’98”,13,13,13,0
ENDIF
pwrupidenttable:
IFPWRUPID==1
addwfPCL,F(xiàn)
dt“DTMFTORS232”,60,“0104”,62,0
ENDIF
;---+++***Initialization***+++---
init:
;SetupI/O-direction(GP0-3,5=input,GP4=output)
MOVlwb’11101111’
trisGPIO
;TxD=Space(GP4=low)
MOVlwb’00000000’
MOVwfGPIO
;EnableportBpull-up,dISAblewake-uponPINchange
;SetupT0=inc.oneitherOSC.orTMR0,prescaler=4/16(dependsonTMR0CLK)
clrwdt
MOVlwOPTION_REG
option
clrfmisc
clrfidentval
retlw0
;---+++***Power-upidentitytransmission***+++---
IFPWRUPID==1
pwrupident:
MOVlw4;waitapprox.1second
MOVwftemp3
pwrup11:clrftemp2
pwrup12clrftemp1
pwrup13:clrwdt
decfsztemp1,F(xiàn)
gotopwrup13
decfsztemp2,F(xiàn)
gotopwrup12
decfsztemp3,F(xiàn)
gotopwrup11
MOVlwh’0FF’
MOVwftemp3
pwrup2:clrwdt
incftemp3,F(xiàn)
MOVftemp3,W
callpwrupidenttable;Fetchtext
clrftemp2
subwftemp2,F(xiàn)
btfscSTATUS,Z;Endoftable?
gotopwrupend
calltxser
gotopwrup2
pwrupend:
gotopwrupidentreturn
ENDIF
;---+++***Main***+++---
main:gotoDTMFdet
DTMFdetreturn:
gotoringdet
ringdetreturn:
gotomain;Repeatmain
;ReadDTMF-bitsfrom8870,convertstonibble,andreturnsinW.
readDTMF:
MOVfGPIO,W
andlwb’00000011’;Getbit0-1
MOVwfDTMFval
bsfDTMFval,2;Getbit2
btfssDTMF2
bcfDTMFval,2
MOVlwb’11111111’;Getbit3(DTMF3=input)
bcfDTMFval,3
trisGPIO
MOVlwb’11101111’
btfscDTMF3
bsfDTMFval,3
trisGPIO;DTMF3=Output
bcfDTMF3
MOVfDTMFval,W;Convertfrom8870-》’normal’
andlwb’00001111’
callDTMFtable
MOVwfDTMFval
retlw0
DTMFtable:
addwfPCL,F(xiàn)
retlwb’00001101’;DTMF’D’
retlwb’00000001’;DTMF’1’
retlwb’00000010’;DTMF’2’
retlwb’00000011’;DTMF’3’
retlwb’00000100’;DTMF’4’
retlwb’00000101’;DTMF’5’
retlwb’00000110’;DTMF’6’
retlwb’00000111’;DTMF’7’
retlwb’00001000’;DTMF’8’
retlwb’00001001’;DTMF’9’
retlwb’00000000’;DTMF’0’
retlwb’00001110’;DTMF’*’
retlwb’00001111’;DTMF’#’
retlwb’00001010’;DTMF’A’
retlwb’00001011’;DTMF’B’
retlwb’00001100’;DTMF’C’
;ConvertsreceivedDTMFtoASCII(returnsinW)
conASCII:
IFASCII==1
addwfPCL,F(xiàn)
retlwA’0’
retlwA’1’
retlwA’2’
retlwA’3’
retlwA’4’
retlwA’5’
retlwA’6’
retlwA’7’
retlwA’8’
retlwA’9’
retlwA’A’
retlwA’B’
retlwA’C’
retlwA’D’
retlwA’*’
retlwA’#’
ENDIF
;Testsfor3subsequent’*’。
ident:
IFIDENTTX==1
bcfIdentOK
MOVlwb’00001110’;DTMF’*’
subwfDTMFval,W
btfssSTATUS,Z
gotoident1
incfidentval,F(xiàn)
MOVlwd’3’
subwfidentval,W
btfssSTATUS,Z
gotoidentend
bsfIdentOK
ident1:clrfidentval
identend:
retlw0
ENDIF
;TransmitsWat2400bps/std.RS232.Calculatesparity-bit.Returnswhendone.
txser:
MOVwftemp1
bcfSTATUS,C;Transmitstart-bit
calltxcarry
MOVlwd’8’;Transmit8databits
MOVwftemp2
txbits:clrwdt
rrftemp1,F(xiàn)
calltxcarry
decfsztemp2,F(xiàn)
gototxbits
IFPARITY==1
rrftemp1,F(xiàn);calculateparity(even)
swapftemp1,W
xorwftemp1,W
MOVwftemp1
rrftemp1,F(xiàn)
rrftemp1,F(xiàn)
xorwftemp1,F(xiàn)
rrftemp1,W
xorwftemp1,F(xiàn)
bcfSTATUS,C
btfsctemp1,0
bsfSTATUS,C
calltxcarry
ENDIF
bsfSTATUS,C;Transmit2*stop-bit
calltxcarry
bsfSTATUS,C
calltxcarry
retlw0
;transmitcarry-flag
IFTMR0CLK==0
txcarry:MOVlw(256-104);2400=416,666us=1666,666c/16=104,17
ENDIF
IFTMR0CLK==1
txcarry:MOVlw(256-93);2400=416,666us=1491,477c/16=93,22
ENDIF
txndone:btfscTMR0,7;Lastbittransmitted(TMR0ovfl.)?
gototxndone
bsfDTMF3;Space
btfscSTATUS,C;Settomark(-12V)ifCarry=1
;(RS232invertsoutput)
bcfDTMF3;Mark
MOVwfTMR0
retlw0
;RecognizesCLIP(DTMFreceivedinA),andsets/clearsCLIP.
IFCLIONLY==1
CLIPdet:
MOVwftemp1
MOVlwb’00001010’;DTMF’A’
subwftemp1,W
btfssSTATUS,Z
gotoCLIPdet2
bsfCLIP
gotoCLIPdetend
CLIPdet2:MOVlwb’00001101’;DTMF’D’
subwftemp1,W
btfssSTATUS,Z
gotoCLIPdet3
bsfCLIP
gotoCLIPdetend
CLIPdet3:btfssCLIP
gotoCLIPdetend
MOVlwb’00001111’;DTMF’#’
subwftemp1,W
btfssSTATUS,Z
gotoCLIPdetend
bcfCLIP
bsfCLIPend
CLIPdetend:
retlw0
ENDIF
;DTMF-detection-CallsreadDTMF,CLIPdet,conASCIIandtxserifDTMFispresent.
;ReturnswhenDTMFisreMOVed.
DTMFdet:clrwdt
btfssDTMFOK
gotoDTMFdetreturn
goto$+1;Doublenop
btfssDTMFOK
gotoDTMFdetreturn
callreadDTMF;DTMFpresent,read!
IFIDENTTX==1;Transmitidentif’***’received
callident
btfssIdentOK
gotoDTMFdet2
MOVlwh’0FF’
MOVwftemp3
DTMFdet1:clrwdt
incftemp3,F(xiàn)
MOVftemp3,W
callidenttable;Fetchtext
clrftemp2
subwftemp2,F(xiàn)
btfscSTATUS,Z;Endoftable?
gotoDTMFdet2
calltxser
gotoDTMFdet1
ENDIF
DTMFdet2:
MOVfDTMFval,W
IFCLIONLY==1;TransmitonlyCLI
callCLIPdet
btfssCLIPend;LastdigitinCLI(#)?
gotoDTMFdet21
bcfCLIPend
gotoDTMFdet22
DTMFdet21:
btfssCLIP
gotoDTMFoff
DTMFdet22:
MOVfDTMFval,W
ENDIF
IFASCII==1;ConverttoASCII
MOVfDTMFval,W
callconASCII
ENDIF
calltxser;Transmittoserialport
DTMFoff:clrwdt;WaitforDTMFtostop
btfscDTMFOK
gotoDTMFoff
DTMFend:gotoDTMFdetreturn
;Ring-detection-Ifringingispresent,callstxserwithW=(ascii)’R’。
;ReturnswhenringingendsorDTMFispresent.
ringdet:clrwdt
IFRING==1
btfscDTMF2
gotoringend
ringdet2:;Waitforringing-pulseto
clrwdt;stop(orDTMFpresent)。
btfscDTMFOK
gotoringend
btfssDTMF2
gotoringdet2
MOVlwb’10000111’;Setuptimer:50msbeforeoverflow.
option
MOVlwd’50’
MOVwfTMR0
ringdet3:clrwdt;Waitfornewringing-pulse
MOVlw0
subwfTMR0,W
btfscSTATUS,Z
gotoringend
btfscDTMF2
gotoringdet3
;Newpulsepresent.
MOVlwOPTION_REG;Restoreoldprescaler
option
MOVlwA’R’;Transmit’R’
calltxser
bcfCLIP;TerminateCLIP-sequence(ringdet.)
MOVlwb’10000111’;Setuptimer:50msbeforeoverflow.
option
ringdet4:MOVlwd’50’
MOVwfTMR0
ringdet5:clrwdt;Waitforringingtoend
btfssDTMF2
gotoringdet4
MOVlw0
subwfTMR0,W
btfscSTATUS,Z
gotoringend
btfssDTMFOK
gotoringdet5
ringend:MOVlwOPTION_REG;Restoreoldprescaler
option
ENDIF
gotoringdetreturn
IFOTP==0
ORGh’1FF’;(old12C508calibration-val.)
MOVlwh’0A0’
ENDIF
END
+---------------------------------------------------------------------+
|History|
+---------------------------------------------------------------------+
Rev.ChangeReasonDate
--------------------------------------------------------------------------------
0.0aSource-filecreated.-24.03.98
0.5aHierarchischdiagramfinished.-25.03.98
1.0aEverythingimplemented,readyfortest.-26.03.98
1.0bTestedin’reallife’。。.Everythingok,-27.03.98
(minorbugsreMOVed)。
1.0Firstversion,’inuse’。-27.03.98
1.01Fixed’#’nottransmittedwhenCLIP=1.-29.03.98
Fixed’D’-sequencesnotrecognizedas
CLIP(nottransmittedwhenCLIP=1)。
ImplementedPwrUpIdent.Givespossibilityof
auto-detection,and
FW-versiondetection.
1.02Implementedpossibilityofusingext.Moreprecisethan09.04.98
TMR0source,astimebaseforRS232-internalRC-oscillator.
communication.
BugfixedCLIPdet.ASCII-tablelocatedin
upperpagewhenall
switches=1.
1.03r+++First’public’release.+++IncasetheCLI-02.05.98
BreakCLIP-sequenceifringdetected.sequenceisnottermi-
natedprobably(because
oflinenoiseetc.)
1.04rMinorchanges/bugfixes:18.03.99
ChangedTX-timing.Transmittedat~2325bps.
Changedformatfrom8E1to8E2Enablesreceivertore-
(2stopbits).syncronizebetweeneach
byte,therebysupressing
framing-errors.
Minimized’read-DTMF’timing.ReMOVesunwanted10us
glitchonTXjustbefore
transmittingadigit.
Ideas/futurechanges:
-------------------------------------------------------------------------------
AddEEPROMandchangepower-supply,toenablereception/storingofDTMF,when
thePCisturnedoff.
Addoffhookdetector,toenable’lengthofconversation’,and’answered/not
answeredcall’logging.
評(píng)論
查看更多