當前位置:首頁 > 單片機 > 單片機
[導讀] 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.

本站聲明: 本文章由作者或相關機構(gòu)授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫毥谦F公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關鍵字: 汽車 人工智能 智能驅(qū)動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務中斷的風險,如企業(yè)系統(tǒng)復雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務連續(xù)性,提升韌性,成...

關鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會上,華為常務董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權最終是由生態(tài)的繁榮決定的。

關鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務引領增長 以科技創(chuàng)新為引領,提升企業(yè)核心競爭力 堅持高質(zhì)量發(fā)展策略,塑強核心競爭優(yōu)勢...

關鍵字: 通信 BSP 電信運營商 數(shù)字經(jīng)濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術學會聯(lián)合牽頭組建的NVI技術創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術創(chuàng)新聯(lián)...

關鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關鍵字: BSP 信息技術
關閉
關閉