您现在的位置: 主页 > 嵌入式开发入门到精通 > 单片机技术进阶 > pic16f508步进电机程序 -
本文所属标签:
为本文创立个标签吧:

pic16f508步进电机程序 -

来源: 网络用户发布,如有版权联系网管删除 2018-09-07 

[导读]
;FileSTEP508.ASM;...forPIC12C508Amicrocontroller;ProgramtousePICasastepanddirectioncontrollerforaunipolar;stepmotor.StepanddirectionPINsareGPIO-5,GPIO-3;GPIO_0,GPIO_1,GPIO_2,GPIO_4,are;th

;FileSTEP508.ASM
;...forPIC12C508Amicrocontroller
;ProgramtousePICasastepanddirectioncontrollerforaunipolar

本文引用地址: http://www.21ic.com/app/mcu/201807/765575.htm

;stepmotor.StepanddirectionPINsareGPIO-5,GPIO-3;GPIO_0,GPIO_1,GPIO_2,GPIO_4,are;thewindings;inorder(drivenbyNPNsmallsigtransistorsorMOSFETS)
;Stepsonnegativegoingedgeofsteppulse.

;CPUconfiguration
;(It’sa12C508A,InternalRCoscillator,
;watchdogtimeroff,power-uptimeron)
LISTP=12C508A
processor12c508A
include
;__config_IntRC_OSC&_WDT_OFF&_PWRTE_ON&_MCLRE_OFF

;Declarevariables

pattAequH’0D’;Currentsteppatternnumber(0-7)foraxisA
lastAequH’0E’;LaststateofsteppinonaxisA(1ishigh,0islow)
inportequH’11’;ValueofportAwhenread(storedforlateraCCess)
tempequH’12’

#DEFINESTEPinport,5;Steppulseinput
#DEFINEDIRinport,3;DirectionInput

OPMASKEQUB’11000000’
IOMASKEQUB’00101000’;allbitsoutput(exceptGP3andGP5)
;GP0,GP1,GP2,GP4controlsThestepperCoils
;GP3controlsdirection
;GP5ControlsStepPulses



ORG0

;startofmaincode
;***************************************************
;
;STARTOFPIC12c508ACODEFORSTEP;
;
;***************************************************
;

;------------------------------------------
;****Poweronresetstartpoint
;------------------------------------------

;***Initializationofprogram
MOVWFOSCCAL

MOVLWOPMASK
OPTION

;SetGPIOforinput&output

MOVLWIOMASK
TRISGPIO




;Clearportandzeromotors


MOVlwB’00000001’
MOVwfGPIO
clrflastA
clrfpattA

;Looparoundforawhiletoleteverythingstabilize

MOVlwd’255’
MOVwfinport
loop:decfszinport,f
;gotoloop

;***Basicprogramloop

;Mainroutine-checkpinstatesandsteponnegativeedge
;Getportdataandstore,thencheckaxisA
;A10checksifoldis0,newis1(updateregister)
;A01checksifoldis1,newis0(stepandupdateregister)
;SimilarlyforaxisB

main:MOVfGPIO,w
MOVwfinport
CLRWDT
A10:btfsclastA,0
gotoA01
btfssSTEP
gotoA01
bsflastA,0
A01:btfsslastA,0
gotoB10
btfscSTEP
gotoB10
bcflastA,0
gotostepA

B10:gotomain

;------------------------------------------
;***stepA-subtocycleaxisAoneFullstep
;Dirof1isincrease,elsedecrease

stepA:btfssDIR
decfpattA,f
btfscDIR
incfpattA,f

;Checkforpatternoverflowandfix


MOVfpattA,w
XORLWD’255’
MOVlwD’07’
btfscSTATUS,Z
MOVwfpattA

MOVfpattA,w
XORLWD’08’
btfscSTATUS,Z
clrfpattA

;GetsteppatternandsendtoGPIOonbits0-1-2-4

MOVfpattA,w
calldcode
MOVwfGPIO

gotomain



;------------------------------------------
;***stepcode-subtogeneratebitpatternfornumberinw(!!MUSTBE0-7!!)
;patternisstoredinwregister

dcode:addwfPCL,f;UsebelowcolumnforthehalfStep
retlwB’00000001’;0retlwB’00000001’;0
retlwB’00000010’;1retlwB’00000011’;1
retlwB’00000100’;2retlwB’00000010’;2
retlwB’00010000’;3retlwB’00000110’;3
retlwB’00000001’;4retlwB’00000100’;4
retlwB’00000010’;5retlwB’00010100’;5
retlwB’00000100’;6retlwB’00010000’;6
retlwB’00010000’;7retlwB’00010001’;7


;Mandatoryendofprogramcommand

end




              查看评论 回复



 

网站地图

围观()