当前位置:首页 > 单片机 > 单片机
[导读] ;|http://www.pICavr.com-------------------------------------------------;|2000;|------------------------------------------------------------------------|;|7LED频率计共计35MHz.Thedecimal小

;|http://www.pICavr.com-------------------------------------------------
;|2000
;|------------------------------------------------------------------------|
;|7LED频率计共计35MHz.Thedecimal小数点|

;|pointisafterMHzdigit,butCANbesetatanyposition.Twodotscan|
;|besettoo(timingformulawillchange!).|
;||
;|功耗:2.5V/9mA,3V/13mA,5V/35mA.|
;||
;|硬件:|
;|:PIC16F84|
;|4051(BCD->1of8decoder)|
;|8个NPN三极管,|
;|7LED(共阴),|
;|someresistors,caPACitorsand2switchingdiodes|
;||
;|Note:|
;|"Calculatordisplay"means(say)7digitLEDmultiplexeddisplay.|
;|Bothcommoncathodeandcommonanodecanbeused.SOFtwareiswritten|
;|forbothcommoncathodeandcommonanodedisplay.Forcommonanode|
;|displaysitrequiresveryslightsoftware(uncommentwhatiscommented|
;|andcommentwhatisn’t...;-)andhardwaremodification(switching|
;|transistorsarePNPinsteadNPN,therEMItersareconnectedwith+5V|
;|andalsoPINNo.3of4051shouldbegrounded).|
;||
;|PICisusedas3bytecounter.Ifitcounts0.1smaximummeasured|
;|FrequencyisFFFFFF,e.g.167.77215MHz(theoretically).|
;||
;|Inrealitythemaximummeasuredfrequencywillnotexceed50MHz|
;|whatismaximuminputfrequencyofPICprecounter.Butrealoneis|
;|around27MHzandwith1/6of74HC14(Schmitttrigger)upto38MHz.|
;||||
;|+-++-+|
;||||||
;||470||470|||
;|||||||
;||+-++---+-+|
;|RA4|+------+|||||
;|RA3|--|470|-+--|+0-+-|
;|RA2|+------+|||___|
;|------++---//||
;|V|
;|||
;|---|
;|------------------------------------------------------------------------|
;||
;|ThescaleusesinternalprescalerofPICaslowbyteofcounter,|
;|TMR0asmiddlebyteandsomeregisterashighbyteofcounter.The|
;|softwareDOESN’Treadanythingfromanyinputport.RA4isusedas|
;|prescalerinput.|
;||
;|------------------------------------------------------------------------|
;||
;|Measuringperiodis100000us.|
;|ProcesorcycleisT=4/Fxus[MHz],fxisXtalfrequency|
;||
;|Numberofprocesorcyclespermeasuringperiod:|
;||
;|N=100000/Tprocesorcycles|
;|N=Fx*100000/4=25000*Fx|
;||
;|Themainstepsofmeasuringperiod:|
;||
;|1.startmeasurement,|
;|2.precodedecimalvalueofdigittosegments,|
;|3.ifit’s5thdigitsetdecimalpoint,|
;|4.outputtoPortB,|
;|5.outputdigitnumbertoPortA|
;|(numbersfromlefttorightare6543210),|
;|6.testTMR0overflowbite,ifYESincreaseTimerH,|
;|7.leavedigittolight,|
;|8.increasedigitnumber,|
;|9.if<7goto2,|
;|10.elsezerodigitnumber,decreasecounterandgoto2,|
;|11.stopmeasurement,|
;|12.shiftoutprecountercontent,|
;|13.incaseofdigitalscaleadd/substractRF,|
;|14.precode3-bytevalueinto7decimalnumbers,|
;|15.goto1|
;||
;|------------------------------------------------------------------------|
;||
;|Totaltimingformula:|
;||
;|N=25000*Fx=60*[7*(36+3*T1)+6+3*T2]+12+3*T3+Z|
;||
;|whereT1,T2,T3areinitialvaluesoftimingloops,|
;|ZareadditionaltunigNOPs,|
;|FxXtalfrequencyinMHz.|
;||
;|------------------------------------------------------------------------|
;|Someideasweretakenfrom"Simplelow-costdigitalfrequencymeter|
;|usingaPIC16C54"(frqmeter.asm)|
;|writtenbyJamesHutchby,MadLabLtd.1996|
;|------------------------------------------------------------------------|
;||
;|Thissoftwareisfreeforprivateusage.ItwascreatedforHAMradio|
;|communitymembers.Commercialexploatationisallowedonlywith|
;|permissionofauthors.|
;||
;|------------------------------------------------------------------------|

;include
include

;--------------------------------------------------------------------------

Indexequ0Ch;dummyregister
Countequ0Dh;inkrementalregister
Helpequ0Eh;dummyregister

LED0equ0Fh
LED1equ010h
LED2equ011h
LED3equ012h
LED4equ013h
LED5equ014h
LED6equ015h
LED7equ016h

TimerHequ017h;higherbyteofSWcounter

LowBequ018h;lowbyteofresuLTEdfrequency
MidBequ019h;middlebyteofresultedfrequency
HigBequ01Ah;highbyteofresultedfrequency

Tempequ01Bh;temporaryregister
HIndexequ01Ch;indexregister
LEDIndexequ01Dh;LEDpointer

;--------------------------------------------------------------------------

include;timingloopvalues

;--------------------------------------------------------------------------

org0

StartclrfIndex
clrfLEDIndex

clrfLED0
clrfLED1
clrfLED2
clrfLED3
clrfLED4
clrfLED5
clrfLED6
clrfLED7

clrfLowB
clrfMidB
clrfHigB

bsfSTATUS,RP0

MOVlwb’00010000’;RA0..RA3outputs
MOVwfTRISA;RA4input

MOVlwb’00000000’;RB0..RB7outputs
MOVwfTRISB

clrwdt;
MOVlwb’00100111’;Prescaler->TMR0,
MOVwfOPTION_REG;1:256,risingedge

bcfSTATUS,RP0;

gotoGo;line370

;+-------------------------------------------------------------------------+
;|ThebLOCkofsubroutinesandconstantstables|
;+-------------------------------------------------------------------------+

;+-------------------------------------------------------------------------+
;|3bytesubstractionoftheconstantfromthetable,itsetscarry|
;|ifresultisnegative|
;+-------------------------------------------------------------------------+

Subc24clrfTemp;itwilltemporarysaveCF
MOVfIndex,W;pointertolowbyteofconstant
MOVwfHIndex;W->HIndex
callDecTable;Wreturnedwithlowbyteofconstant
bsfSTATUS,C;setCF
subwfLowB,F;LowB-W->LowB
;ifunderflow->C=0
btfscSTATUS,C
gotoStep1
bsfSTATUS,C
MOVlw1
subwfMidB,F;decrementMidB
;ifunderflow->C=0
btfscSTATUS,C
gotoStep1

bsfSTATUS,C
MOVlw1
subwfHigB,F;decrementHigB
btfscSTATUS,C;ifunderflow->C=0
gotoStep1
bsfTemp,C;setC

Step1decfHIndex,F
MOVfHIndex,W;pointertomiddlebyteofconst
callDecTable
bsfSTATUS,C
subwfMidB,F;MidB-W->MidB
btfscSTATUS,C;ifunderflow->C=0
gotoStep2
bsfSTATUS,C
MOVlw1
subwfHigB,1;decrementHigB
btfscSTATUS,C;ifunderflow->C=0
gotoStep2
bsfTemp,C;setC

Step2decfHIndex,F
MOVfHIndex,W;pointertomiddlebyteofconstatnt
callDecTable
bsfSTATUS,C
subwfHigB,F;HigB-W->HigB
btfscSTATUS,C;ifunderflow->C=0
gotoClearCF
bsfSTATUS,C
gotoSubEnd
ClearCFrrfTemp,C;C->STATUS
SubEndretlw0

;+-------------------------------------------------------------------------+
;|3byteadditionoftheconstantfromthetable,itsetscarryif|
;|resultoverflows|
;+-------------------------------------------------------------------------+

Addc24clrfTemp;registerfortemporarystorageofCF
MOVfIndex,W;pointertolowerbyteofconstintoW
MOVwfHIndex;saveitintoHIndex
callDecTable;Wcontainslowbyteofconst
bcfSTATUS,C;clearC
addwfLowB,1;W+LowB->LowB
btfssSTATUS,C;testoverflow
gotoAdd2
bcfSTATUS,C;clearC
MOVlw1
addwfMidB,F;incrementMidB
btfssSTATUS,C
gotoAdd2
bcfSTATUS,C
MOVlw1
addwfHigB,F;incrementHigB
btfssSTATUS,C;testoverflow
gotoAdd2
bsfTemp,C;storeC

Add2decfHIndex,F;pointertomiddlebyteintoW
MOVfHIndex,W
callDecTable
bcfSTATUS,C
addwfMidB,1;W+MidB->MidB
btfssSTATUS,C
gotoAdd3
bcfSTATUS,C;clearC
MOVlw1
addwfHigB,1;incrementHigB
btfssSTATUS,C
gotoAdd3
bsfTemp,C

Add3decfHIndex,F;pointertohigherbyteintoW
MOVfHIndex,W
callDecTable
bsfSTATUS,C
addwfHigB,F;W+HigB->HigB,
btfssSTATUS,C
gotoClarCF
bsfSTATUS,C
gotoAddEnd
ClarCFrrfTemp,C;C->STATUS

AddEndretlw0

;+------------------------------------------------------------------------+
;|Tablesof3-byteconstants|
;+------------------------------------------------------------------------+
;|Tableofdecades|
;+------------------------------------------------------------------------+

DecTableaddwfPCL,F;W+PCL->PCL
retlw0;10
retlw0;
retlw0Ah;

retlw0;100
retlw0;
retlw064h;

retlw0;1000
retlw03h;
retlw0E8h;

retlw0;10000
retlw027h;
retlw010h;

retlw01h;100000
retlw086h;
retlw0A0h;

retlw0Fh;1000000
retlw042h;
retlw040h;

;+-----------------------------------------------------------------------+
;|TableforconversionBCD->7segments|
;+-----------------------------------------------------------------------+

LEDTableaddwfPCL,F;W+PCL->PCL
retlwb’00111111’;..FEDCBA=’0’
retlwb’00000110’;.....CB.=’1’
retlwb’01011011’;.G.ED.BA=’2’
retlwb’01001111’;.G..DCBA=’3’
retlwb’01100110’;.GF..CB.=’4’
retlwb’01101101’;.GF.DC.A=’5’
retlwb’01111101’;.GFEDC.A=’6’
retlwb’00000111’;.....CBA=’7’
retlwb’01111111’;.GFEDCBA=’8’
retlwb’01100111’;.GF..CBA=’9’
retlwb’10000000’;H.......=’.’

;ItfollowsCOMMONANODEdatatable

;LEDTableaddwfPCL,F;W+PCL->PCL
;retlwb’11000000’;..FEDCBA=’0’
;retlwb’11111001’;.....CB.=’1’
;retlwb’10100100’;.G.ED.BA=’2’
;retlwb’10110000’;.G..DCBA=’3’
;retlwb’10011001’;.GF..CB.=’4’
;retlwb’10010010’;.GF.DC.A=’5’
;retlwb’10000010’;.GFEDC.A=’6’
;retlwb’11111000’;.....CBA=’7’
;retlwb’10000000’;.GFEDCBA=’8’
;retlwb’10011000’;.GF..CBA=’9’
;retlwb’01111111’;H.......=’.’

;+------------------------------------------------------------------------+
;|Themaincycleentrypoint|
;+------------------------------------------------------------------------+
;|Routineforconversionof3-bytenumberinto7digits|
;+------------------------------------------------------------------------+

GobsfSTATUS,RP0
MOVlwb’00000000’
MOVwfTRISB
bcfSTATUS,RP0

MOVlw6*3-1;pointertodec.table
MOVwfIndex;6*3-1->Index

MOVlw9;maximumofsubstractions
MOVwfCount;9->Count

clrfHelp

MOVlw6
MOVwfLEDIndex

DividecallSubc24;substractuntillresultisnegative,
btfscSTATUS,C;addlastsubstractednumber
gotoAdd24;nextdigit
incfHelp,F
decfCount,F
btfssSTATUS,Z
gotoDivide
MOVlw3
subwfIndex,F
gotoNext

Add24callAddc24
MOVlw3
subwfIndex,F

NextMOVlw9
MOVwfCount
MOVlwLED1;LED1->W
addwfLEDIndex,W;LED1+LEDIndex->W
MOVwfTemp
decfTemp,F;LEDIndex+LED1-1->TEMP
MOVfTemp,W

MOVwfFSR;W->FSR
MOVfHelp,W;Help->W
clrfHelp;saveresultatLEDx
MOVwfINDF;W->LED(6..1)
decfLEDIndex,F

MOVlw1
addwfIndex,W
btfssSTATUS,Z
gotoDivide

MOVfLowB,W
MOVwfLED0;therest->LED0

;+-----------------------------------------------------------------------+
;|RegistersLED0..LED6arefilledwithvalues|
;+-----------------------------------------------------------------------+

clrfTimerH

clrfTMR0
nop
nop

clrfLEDIndex

MOVlw.60;setinitialcountervalue
MOVwfIndex;60->Index

clrfINTCON;globalINTdisable,TMR0INTdisable
;clearTMR0overflowbite

;+---------------------------------------------------------------------+
;|Startofthemeasurement:RA3+RA4setinput|
;+---------------------------------------------------------------------+

MOVlwb’00010000’;allportssetL,RA4setH
MOVwfPORTA

bsfSTATUS,RP0
MOVlwb’00011000’;RA0..RA2output,RA3,RA4input
MOVwfTRISA
bcfSTATUS,RP0

;+-----------------------------------------------------------------------+
;|7-stepcycleofdigits|
;+-----------------------------------------------------------------------+

LEDCycleMOVlwLED0
addwfLEDIndex,W;LED1+LEDIndex->W

MOVwfFSR;W->FSR
MOVfINDF,W;LED(0..6)->W
callLEDTable;Wcontainssegments

MOVwfTemp;testfordecimalpoint
MOVlw5

bsfSTATUS,Z
subwfLEDIndex,W
btfssSTATUS,Z
gotoNoDot
bsfTemp,7;commoncathode....
;bcfTemp,7;commonanode....

NoDotMOVfTemp,W
MOVwfPORTB;segments->PORTB

MOVfLEDIndex,W;LEDIndex->W
nop
MOVwfPORTA;digitnumber->PORTA

;+------------------------------------------------------------------------
;TestforTMR0overflow
;+------------------------------------------------------------------------

btfssINTCON,2;TestforTMR0overflow
gotoDoNothing
incfTimerH,F;YES!IncrementSWcounter
bcfINTCON,2;clearoverflowbite
gotoO_K

DoNothingnop
nop
nop

;+-----------------------------------------------------------------------+
;|Thefirsttimingloop2+3*T1procesorcycles|
;+-----------------------------------------------------------------------+

O_KMOVlwT1
MOVwfTemp

PausedecfszTemp,F
gotoPause
nop

;+-----------------------------------------------------------------------+
;|Theendofonedigitprocessing|
;+-----------------------------------------------------------------------+

incfLEDIndex,F
MOVlw7;is7th?
bcfSTATUS,Z
subwfLEDIndex,W
btfssSTATUS,Z
gotoLEDCycle;nextdigit
nop

;+-----------------------------------------------------------------------+
;|Thesecondtimingloop2+3*T2procesorcycles|
;+-----------------------------------------------------------------------+

MOVlwT2
MOVwfTemp

AgaindecfszTemp,F
gotoAgain
nop

;+-----------------------------------------------------------------------+
;|Theendofone7-digitsprocessing|
;+-----------------------------------------------------------------------+

clrfLEDIndex
decfszIndex,F
gotoLEDCycle;next7*LED
nop

;+-----------------------------------------------------------------------+
;|Thethirdtimingloop2+9*T3+Zprocesorcycles|
;+-----------------------------------------------------------------------+

MOVlwT3
MOVwfTemp

EndPausedecfszTemp,F
gotoEndPause
nop

include
;nop;ZtimesNOP
;nop;60*(6+7*(36+3*T1)+3*T2)+2+3*T3+Z

;===========最后测试TMR0溢出位============
btfssINTCON,2;1
gotoNothing2Do;3
incfTimerH,F;3
bcfINTCON,2;4
gotoNx;6

Nothing2Donop;4
nop;5
nop;660*(6+7*(36+3*T1)+3*T2)+8+3*T3+Z

;===========停止测量:RA3out;RA4in================
Nxclrw;Forcommoncathode
;NxMOVlwb’11111111’;Forcommonanode

MOVwfPORTB
MOVlwb’00010000’;RA0..RA3=0
MOVwfPORTA;W->PORTA

bsfSTATUS,RP0
MOVlwb’00010000’;RA0..RA3output
MOVwfTRISA;RA4input
bcfSTATUS,RP0

btfscINTCON,2;reallyfinalcheck
incfTimerH,F
bcfINTCON,2

;==========分晰存储计数值==========|
MOVfTMR0,W
MOVwfMidB;TMR0->MidB
MOVfTimerH,W
MOVwfHigB;TimerH->HigB
clrfTemp
CountItincfTemp,F
bsfPORTA,3;伪信号
bcfPORTA,3;
;
bcfINTCON,2
MOVfTMR0,W;TMR0->W
bcfSTATUS,Z
subwfMidB,W
btfscSTATUS,Z
gotoCountIt
incfTemp,F
comfTemp,F
incfTemp,F
incfTemp,W

MOVwfLowB
;==========================
gotoGo

;==============================
end

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

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 信息技术
关闭
关闭