炭化炉厂家
免费服务热线

Free service

hotline

010-00000000
炭化炉厂家
热门搜索:
技术资讯
当前位置:首页 > 技术资讯

用PIC12C508509单片机控制一个步进电机源程序

发布时间:2020-07-01 01:58:35 阅读: 来源:炭化炉厂家

; STEP_M (12C508 / 12C509) ;; Controls a stepping motor driver on GPIO bits 4, 2, 1 and 0.;; The direction is controlled by a switch on GPIO bit 3. Bit 5 is notused.;; (Typical drivers might include a ULN2803 Octal Driver, 2N2222 or TIP122; transistors or power FETs. See Parallel Port Manual - Vol 1).;; Outputs patterns 0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x09, 0x01,; .. in sequence to advance stepping motor in one direction. This is; achieved by causing INDEX to advance from 0 to 7, to 0, etc and; mapping the INDEX into a pattern which is then output on bits 4, 2, 1; and 0 of GPIO.;; Note that GPIO bit 3 is not used. Thus, prior to outputting, bit 3; of PATT is copied to the bit 4 position.;; Motor is advanced in the other direction by causing INDEX to move in; the opposite direction; 7 to 0 to 7, etc.;; Switch on GPIO, Bit 3 is read between each output to the stepping; motor to determine whether INDEX is to be incremented (0-7, 0) or; decremented.;; The delay in between steps determines the speed of the stepper. In; this program it is 25 msecs. LIST P=PIC12C509__CONFIG 0EH ; MCLR - dis, CP - dis, WDT - dis, FOSC - int#include c:\mplab\C>

CONSTANT BASE_VAR=07H

INDEX EQU BASE_VAR+0PATT EQU BASE_VAR+1

LOOP1 EQU BASE_VAR+2 ; for timing loopLOOP2 EQU BASE_VAR+3

ORG 000H

MOVLW 080H ; GPWU disabled, GPPU enabled, other bits not usedOPTION

MOVLW B'101000'TRIS GPIO ; Bit 3 input, Bits 4, 2, 1 and 0 ouputsCLRF INDEX ; start INDEX at zeroREAD_SW:BTFSC GPIO, 3 ; read direction switchGOTO FORWARDGOTO REVERSE

FORWARD:INCF INDEX, F ; increment the indexMOVLW .8SUBWF INDEX, W ; and test if equal to 8BTFSC STATUS, ZCLRF INDEX ; if at 8, set to 0GOTO ONE_STEP

REVERSE:DECF INDEX, F ; decrement the indexMOVLW 0FFHSUBWF INDEX, W ; test if at 0xFFBTFSC STATUS, ZGOTO REVERSE_1 ; if at FF, then reset to 7GOTO ONE_STEP

REVERSE_1:

MOVLW .7MOVWF INDEXGOTO ONE_STEP

ONE_STEP:MOVF INDEX, W ; copy count into wCALL GEN_PATT ; returns the correct pattern in wMOVWF PATT ; save itBTFSS PATT, 3 ; move bit 3 to bit 4BCF PATT, 4BTFSC PATT, 3BSF PATT, 4MOVF PATT, WMOVWF GPIOCALL DELAY ; 25 msecsGOTO READ_SW;;;;;;

GEN_PATT ; maps INDEX into appropriate stepping motor patternMOVF INDEX, WADDWF PCL, F ; add w to the program counterRETLW 01H ; stepping motor patternsRETLW 03HRETLW 02HRETLW 06HRETLW 04HRETLW 0CHRETLW 08HDELAY: ; provides nominal 25 msec delayMOVLW .25MOVWF LOOP1OUTTER:MOVLW .110MOVWF LOOP2INNER:CLRWDTNOPNOPNOPNOPNOPDECFSZ LOOP2, FGOTO INNERDECFSZ LOOP1, FGOTO OUTTERRETURNEND

51单片机相关文章:51单片机教程

单片机相关文章:单片机教程

单片机相关文章:单片机视频教程

单片机相关文章:单片机工作原理

滨州定做劳保工服

山东订做职业装

沈阳西服制作

吉林定做工作服