⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 steptest.asm

📁 pic得电机控制程序
💻 ASM
字号:
;	Curtain control test program
;
;	This program tests the limit opto switches and direction inputs.
;	Test with LEDS instead of motor coils.
;
;	PORTA 	bit 0 - OPEN input
;		bit 1 - CLOSE input
;		bit 3 - Limit input 1
;		bit 4 - Limit input 2
;
;	PORTB	bit 4 - Coil 1
;		bit 5 - Coil 2
;		bit 6 - Coil 3
;		bit 7 - Coil 4
;
;	Pull cord:
;
;
;		\Limit 2/	\Limit 1/
;
;	--------*************************------------------------------	Curtains Open -->
;	|
;	| Pulley
;	| Here
;	|
;	------------------------------------------------********-------	Curtains Close -->
;
;
;	Shown in fully closed position.
;
;	Limit 2 only = Fully open
;	Limit 1 & 2 = Fully closed


#include P16C84.INC

        list    p=PIC16c84
count   equ     0x0C		;Position in STEPTAB Step table
instat  equ     0x0D		;Rotation demand status
        
	org     0x00		;Program start address
        goto    START


START   movlw   B'00000000'     ;PORTB all outputs
        tris    PORTB
        movlw   B'00011011'     ;PORTA bit 0,1,3,4 inputs
        tris    PORTA           
        movlw   B'00000111'     ;Set maximum timer prescalar value
        option
        movlw   1               ;Set initial step position
        movwf   count		;

        movlw   0		;Reset rotation demand to NONE
        movwf   instat		;
        
	goto    STEP


LOOP    btfss   PORTA,0         ;Is OPEN input active?
        goto    NXT1		;If not, check next input
        clrf    instat		;If so, clear current motor direction
        bsf     instat,0	;	and request forward direction

NXT1    btfss   PORTA,1         ;Is CLOSE input active?
        goto    NXT2		;If not, check next input
        clrf    instat		;If so, clear current motor direction
        bsf     instat,1	;	and request reverse direction

NXT2    btfss   PORTA,4         ;Is OPEN limit hit? (Check bit 4 set first) 
        goto    NXT3		;If not, check next input
        btfss   PORTA,3		;If so, is bit 3 clear?
        bcf     instat,0        ;If this is so, stop forward rotation (OPEN limit hit)

NXT3    btfsc   PORTA,3         ;Is CLOSED limit hit? (Check bit 3 set first)
        btfss   PORTA,4         ;If so, is bit 4 also set?
        goto 	CONT		;If not, nevermind
        bcf     instat,1	;Otherwise, stop reverse rotation (CLOSED limit hit)



CONT    btfsc   instat,0        ;Did we request forward direction?
        goto    FWD
        btfsc   instat,1        ;Did we request reverse direction?
        goto    REV
        goto    LOOP            ;Keep checking inputs...



FWD     movlw   4               ;
        subwf   count,w         ;
        btfss   STATUS,Z        ;Check if maximum count (end of step table)
        goto    INCCNT          ;If not, increment then output
        movlw   1               ;Otherwise reset back to minimum
        movwf   count
        goto    STEP


REV     movlw   1               ;
        subwf   count,w         ;
        btfss   STATUS,Z        ;Check if minimum count (start of step table)
        goto    DECCNT          ;If not, decrement then output
        movlw   4               ;Otherwise set back to maximum
        movwf   count
        goto    STEP

INCCNT  incf     count
        goto    STEP

DECCNT  decf    count
        goto    STEP


STEP    movf    count,w
        call    STEPTAB
        movwf   PORTB
        call    DELAY		;Not nice, but gives us....
        call 	DELAY		;a big delay so we can see...
        call 	DELAY		;everything happening.
        call 	DELAY		;
        call 	DELAY		;
        call 	DELAY		;
        call 	DELAY		;
        call 	DELAY		;
        call 	DELAY		;
        call 	DELAY		;
        call 	DELAY		;
        call 	DELAY		;
        call 	DELAY		;
        goto    LOOP


STEPTAB addwf  PCL,f            ;Coil output table. 1=coil energised
        retlw  b'11110000'      ;Position 0 not normally used
        retlw  b'10000000'	;This is just a test pattern...
        retlw  b'01000000'	;which lights 4 LEDs...
        retlw  b'00100000'	;sequentially so we can see...
        retlw  b'00010000'	;what direction we're doing!

DELAY   movlw   D'00'		
        movwf   TMR0
AGAIN   btfss   TMR0,5
        goto    AGAIN
        return


        end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -