今天是: 创芯电子 | 发布供求信息 | 设为首页 | 加入收藏  

首页   解密专栏   设计应用    初学实战   解决方案   下载中心   厂商信息   供求信息   资讯快递   联系我们
热点推荐
揭开物联网产业链全局图:..
我国电子信息产业现状及面..
深圳IC设计"拨云见日" ..
绿色、安全和通讯是汽车电..
从香港电子展分析消费电子..
金融危机影响电子元器件市..
松翰单片机解密/FEELING单..
并行频域OCT图像预处理系统..
基于dSPACE的双绕组感应发..
基于RF技术的机械数码一体..

图片链接






 首页 >> 初学实战 >> 综合实战
PIC单片机控制步进电机源程序
时间: 2008-7-11
PIC 单片机控制步进电机源程序

; STEP_3.ASM (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 not used.
;
; (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\P12C509.INC>

CONSTANT BASE_VAR=07H

INDEX EQU BASE_VAR+0
PATT EQU BASE_VAR+1

LOOP1 EQU BASE_VAR+2 ; for timing loop
LOOP2 EQU BASE_VAR+3

ORG 000H

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

MOVLW B'101000'
TRIS GPIO ; Bit 3 input, Bits 4, 2, 1 and 0 ouputs

CLRF INDEX ; start INDEX at zero
READ_SW:
BTFSC GPIO, 3 ; read direction switch
GOTO FORWARD
GOTO REVERSE

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

REVERSE:
DECF INDEX, F ; decrement the index
MOVLW 0FFH
SUBWF INDEX, W ; test if at 0xFF
BTFSC STATUS, Z
GOTO REVERSE_1 ; if at FF, then reset to 7
GOTO ONE_STEP

REVERSE_1:

MOVLW .7
MOVWF INDEX
GOTO ONE_STEP

ONE_STEP:
MOVF INDEX, W ; copy count into w
CALL GEN_PATT ; returns the correct pattern in w
MOVWF PATT ; save it
BTFSS PATT, 3 ; move bit 3 to bit 4
BCF PATT, 4
BTFSC PATT, 3
BSF PATT, 4
MOVF PATT, W
MOVWF GPIO
CALL DELAY ; 25 msecs

GOTO READ_SW
;;;;;;

GEN_PATT ; maps INDEX into appropriate stepping motor pattern
MOVF INDEX, W
ADDWF PCL, F ; add w to the program counter
RETLW 01H ; stepping motor patterns
RETLW 03H
RETLW 02H
RETLW 06H
RETLW 04H
RETLW 0CH
RETLW 08H
DELAY: ; provides nominal 25 msec delay
MOVLW .25
MOVWF LOOP1
OUTTER:
MOVLW .110
MOVWF LOOP2
INNER:
CLRWDT
NOP
NOP
NOP
NOP
NOP
DECFSZ LOOP2, F
GOTO INNER
DECFSZ LOOP1, F
GOTO OUTTER
RETURN
END
 
上一篇: 单片机双机异步通信程序
下一篇: PIC单片机中BANK和PAGE的分析
打印】 【关闭

【资讯版权声明】
 1. 凡本网站注明“来源:单片机基地”的所有作品,版权均属于单片机基地,转载请注明“来源:单片机基地”。
 2. 本网转载自其它媒体的信息,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。
 3. 未经本站明确许可,任何网站不得非法盗链软件下载连接及抄袭本网站原创内容资源。
 4. 违反上述声明者,本网将追究其相关法律责任。谢谢!

网站地图  广告服务  版权声明  友情连接  关于我们 
Copyright©2005-2010 单片机基地,创芯电子技术 版权所有
技术支持:0755-82701553 21976338 E-mail:mcubase@163.com QQ:719659769
致力于单片机解密,IC解密,芯片解密加密技术研究,提供芯片解密服务,仅供合法研究学习用途
基地资源仅供学习参考,部分内容来源于网络,如侵犯您的版权,请通知本站即撤
ICP备案序号:粤ICP备06120039号