您的位置 首页 报告

根据PIC12C508 DTMF拔号程序编写共享

基于PIC12C508 DTMF拔号程序编写分享-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.|

;|||

;+——————————————————————–+

根据P%&&&&&%12C508 DTMF拔号程序编写共享

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

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ceping/baogao/347019.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部