Pic16f508 stepper motor program

Single chip microcomputer STM32L151CCU6
Mobile phone crystal 3.2*2.5mm 3225 26M (26.000MHZ) 7.5PF 10PPM 20PPM 30PPM
MOSFET imported original FET
Factory direct sales - SMD aluminum electrolytic capacitor - straight plug solid capacitors, the products are imported from Japan, aluminum foil,
>

;FileSTEP508.ASM
;...forPIC12C508Amicrocontroller
;ProgramtousePICasastepanddirectioncontrollerforaunipolar
;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

Pic16f508 stepper motor program

ADC Advertisement Display

commercial charging station

Shenzhen Hongjiali New Energy Co., Ltd. , https://www.hjlcharger.com

Posted on