pic12C508 DTMF dialing program

EL-C1600N100013-B
>

pIC12C508 DTMF dialing program
;|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
Dt"+++PCNummerViser+++",13
Dt"Firmwarev1.04", 13,13
Dt"JaCOBBlichfELDt'98",13,13,13,0
ENDIF

Pwrupidenttable:
IFPWRUPID==1
addwfPCL,F
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)
Crrwdt
MOVlwOPTION_REG
Option

Clrfmisc
Clrfidentval

Retlw0


;---+++***Power-upidentitytransmission***+++---
IFPWRUPID==1
Pwrupident:

MOVlw4;waitapprox.1second
MOVwftemp3
Pwrup11:clrftemp2
Pwrup12clrftemp1
Pwrup13:clrwdt
Decfsztemp1,F
Gotopwrup13
Decfsztemp2,F
Gotopwrup12
Decfsztemp3,F
Gotopwrup11

MOVlwh'0FF'
MOVwftemp3
Pwrup2:clrwdt
Incftemp3,F
MOVftemp3, W

Callpwrupidenttable;Fetchtext

Clrftemp2
Subwftemp2,F
btfscSTATUS,Z;Endoftable?
Gotopwrupend
Calltxser
Gotopwrup2

Pwrupend:
Gotopwrupidentreturn
ENDIF


;---+++***Main***+++---
Main:gotoDTMFdet
DTMFdetreturn:
Gotoringdet
Ringdetreturn:
Gotomain;Repatmain


;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
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
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

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
Calltxcarry
Decfsztemp2,F
Gototxbits

IFPARITY==1
Rrftemp1,F;calculateparity(even)
Swapftemp1,W
Xorwftemp1,W
MOVwftemp1
Rrftemp1,F
Rrftemp1,F
Xorwftemp1,F
Rrftemp1,W
Xorwftemp1,F
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
MOVftemp3, W

Callidenttable;Fetchtext

Clrftemp2
Subwftemp2,F
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:;Wayforforringing-pulseto
Crlwdt;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,thebybysupressing
Framing-errors.
Minimized'read-DTMF'timing.ReMOVesunwanted10us
glitchonTXjustbefore
Transmittingadigit.


Ideas/futurechanges:
-------------------------------------------------- -----------------------------
AddEEPROMandchangepower-supply, toenablereception/storingofDTMF, when
thePCisturnedoff.

Addoffhookdetector,toenable'lengthofconversation',and'answered/not
Answercall'logging.


Wind Power Substation

Pad Mounted Transformer,Wind Power Substation,Step-Up Wind Power Sustation,Step Up Transformer

Hangzhou Qiantang River Electric Group Co., Ltd.(QRE) , https://www.qretransformer.com

Posted on