当前位置:首页 > 单片机 > 单片机
[导读] pIC12C508 DTMF拔号程序;|Name:MAIN.ASM|;|Description:DTMF->RS232converter(forusewithPCNummerViser)|;|DetectsDTMFandringing,andtransmitstoastd.|;|RS232port,at2400baud.|;|||;+---------------

pIC12C508 DTMF拔号程序
;|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)
clrwdt
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;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
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:;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.

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

9月2日消息,不造车的华为或将催生出更大的独角兽公司,随着阿维塔和赛力斯的入局,华为引望愈发显得引人瞩目。

关键字: 阿维塔 塞力斯 华为

加利福尼亚州圣克拉拉县2024年8月30日 /美通社/ -- 数字化转型技术解决方案公司Trianz今天宣布,该公司与Amazon Web Services (AWS)签订了...

关键字: AWS AN BSP 数字化

伦敦2024年8月29日 /美通社/ -- 英国汽车技术公司SODA.Auto推出其旗舰产品SODA V,这是全球首款涵盖汽车工程师从创意到认证的所有需求的工具,可用于创建软件定义汽车。 SODA V工具的开发耗时1.5...

关键字: 汽车 人工智能 智能驱动 BSP

北京2024年8月28日 /美通社/ -- 越来越多用户希望企业业务能7×24不间断运行,同时企业却面临越来越多业务中断的风险,如企业系统复杂性的增加,频繁的功能更新和发布等。如何确保业务连续性,提升韧性,成...

关键字: 亚马逊 解密 控制平面 BSP

8月30日消息,据媒体报道,腾讯和网易近期正在缩减他们对日本游戏市场的投资。

关键字: 腾讯 编码器 CPU

8月28日消息,今天上午,2024中国国际大数据产业博览会开幕式在贵阳举行,华为董事、质量流程IT总裁陶景文发表了演讲。

关键字: 华为 12nm EDA 半导体

8月28日消息,在2024中国国际大数据产业博览会上,华为常务董事、华为云CEO张平安发表演讲称,数字世界的话语权最终是由生态的繁荣决定的。

关键字: 华为 12nm 手机 卫星通信

要点: 有效应对环境变化,经营业绩稳中有升 落实提质增效举措,毛利润率延续升势 战略布局成效显著,战新业务引领增长 以科技创新为引领,提升企业核心竞争力 坚持高质量发展策略,塑强核心竞争优势...

关键字: 通信 BSP 电信运营商 数字经济

北京2024年8月27日 /美通社/ -- 8月21日,由中央广播电视总台与中国电影电视技术学会联合牵头组建的NVI技术创新联盟在BIRTV2024超高清全产业链发展研讨会上宣布正式成立。 活动现场 NVI技术创新联...

关键字: VI 传输协议 音频 BSP

北京2024年8月27日 /美通社/ -- 在8月23日举办的2024年长三角生态绿色一体化发展示范区联合招商会上,软通动力信息技术(集团)股份有限公司(以下简称"软通动力")与长三角投资(上海)有限...

关键字: BSP 信息技术
关闭
关闭