乐动体育热门赛事

电子元器件原材料
采购信息平台

扫码下载
手机洽洽

  • 乐动体育热门赛事 公众号

    电子元器件原材料

    采购信息平台

  • 乐动体育热门赛事 移动端

    生意随身带

    随时随地找货

  • 华强微电子公众号

    专注电子产业链

    坚持深度原创

  • 华强商城公众号

    一站式电子元器件

    采购平台

  • 芯八哥公众号

    半导体行业小灵通

pic16f84 LED频率计

来源:乐动体育热门赛事 作者:华仔 浏览:479

标签:

摘要: >;|http://www、pICavr、com------------------------------------------------- ;|2000 ;|------------------------------------------------------------------------| ;|7LED频率计共计35MHz。Thedecimal小数点| ;|pointisaf

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

型号 厂商 价格
EPCOS 爱普科斯 /
STM32F103RCT6 ST ¥461.23
STM32F103C8T6 ST ¥84
STM32F103VET6 ST ¥426.57
STM32F103RET6 ST ¥780.82
STM8S003F3P6 ST ¥10.62
STM32F103VCT6 ST ¥275.84
STM32F103CBT6 ST ¥130.66
STM32F030C8T6 ST ¥18.11
N76E003AT20 NUVOTON ¥9.67
型号/产品名 平均报价 涨跌幅
STM8S003F3P6 1.72 1.12%
74HC573D 0.64 2.86%
2N7002 3.66 400.00%
STM32F103C8T6 7.47 27.87%
1N4007 1.58 0.00%
ADM2483BRWZ 8.90 3.21%
SHT10 16.21 5.88%
STM32F103RCT6 12.56 24.44%
LM358 118206.75 16.67%
发布求购