The uln2803 is a npn... the stepper common must be high and I think you need to invert your output!!
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Define CONFIG = 0x000a
'__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
'; control a small stepper motor with a 12F509
'; There are two controls, run/stop And direction
'; The motor steps when the run button is depressed (zero)
'; If the direction button is pressed
'; the direction is reversed
Dim index As Byte
Dim mask As Byte 'Output bit pattern
'; GP3 controls run/stop
'; GP5 controls direction
ConfigPin GPIO = Output
ConfigPin GPIO.3 = Input
ConfigPin GPIO.5 = Input
Symbol run_btn = GPIO.3
Symbol dir_btn = GPIO.5
index = 0
loop:
'check For run/stop button
If run_btn <> 0 Then Goto loop 'Run if = zero
If dir_btn = 1 Then 'Button high
index = index - 1 'less than zero goes to 255 in Oshonsoft
If index > 7 Then index = 7
Goto sendit
Endif
If dir_btn = 0 Then 'Button low
index = index + 1
If index > 7 Then index = 0
Endif
sendit:
Call stepm()
GPIO = mask
WaitMs 10
Goto loop
End
'; routine To get Step value index
Proc stepm()
mask = LookUp(%00000001, %00000101, %00000100, %00000110, %00000010, %00010010, %00010000, %00010001), index
End Proc
list p=12f509
#include <p12f509.inc>
radix dec
; Compiled with: PIC10 Simulator IDE v2.51
; Microcontroller model: PIC12F509
; Clock frequency: 4.0MHz
;
R0L EQU 0x007
R0H EQU 0x008
R4L EQU 0x00F
R4H EQU 0x010
R0HL EQU 0x007
R4HL EQU 0x00F
RTRIS6 EQU 0x009
ROPTION EQU 0x00A
; The address of 'index' (byte) (global) is 0x00B
; The address of 'mask' (byte) (global) is 0x00C
; The address of 'run_btn' (bit) (global) is 0x006,3
; The address of 'dir_btn' (bit) (global) is 0x006,5
ORG 0x0000
MOVWF OSCCAL
CLRF FSR
MOVLW 0xFF
MOVWF RTRIS6
MOVWF ROPTION
BCF STATUS,6
BCF STATUS,5
GOTO L0004
_bootL0003:
GOTO L0003
_bootDL02:
GOTO DL02
_boot_lookup_lab_0001:
GOTO _lookup_lab_0001
; LookUp Table: (%00000001, %00000101, %00000100, %00000110, %00000010, %00010010, %00010000, %00010001)
_lookup_lab_0001:
ADDWF PCL,F
RETLW 0x01
RETLW 0x05
RETLW 0x04
RETLW 0x06
RETLW 0x02
RETLW 0x12
RETLW 0x10
RETLW 0x11
; User code start
L0004:
; 1: Define CONFIG = 0x000a
; 2: '__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
; 3:
; 4:
; 5: '; control a small stepper motor with a 12F509
; 6:
; 7:
; 8: '; There are two controls, run/stop And direction
; 9: '; The motor steps when the run button is depressed (zero)
; 10: '; If the direction button is pressed
; 11: '; the direction is reversed
; 12:
; 13: Dim index As Byte
; 14: Dim mask As Byte 'Output bit pattern
; 15: '; GP3 controls run/stop
; 16: '; GP5 controls direction
; 17:
; 18:
; 19: ConfigPin GPIO = Output
CLRW
MOVWF RTRIS6
TRIS 6
; 20: ConfigPin GPIO.3 = Input
BSF RTRIS6,3
MOVF RTRIS6,W
TRIS 6
; 21: ConfigPin GPIO.5 = Input
BSF RTRIS6,5
MOVF RTRIS6,W
TRIS 6
; 22:
; 23: Symbol run_btn = GPIO.3
; 24: Symbol dir_btn = GPIO.5
; 25:
; 26:
; 27: index = 0
CLRF 0x00B
; 28:
; 29: loop:
L0001:
; 30:
; 31: 'check For run/stop button
; 32: If run_btn <> 0 Then Goto loop 'Run if = zero
BTFSS 0x006,3
GOTO L0005
GOTO L0001
L0005:
; 33:
; 34:
; 35: If dir_btn = 1 Then 'Button high
BTFSS 0x006,5
GOTO L0006
; 36: index = index - 1 'less than zero goes to 255 in Oshonsoft
DECF 0x00B,F
; 37: If index > 7 Then index = 7
MOVLW 0x07
MOVWF R0L
MOVF 0x00B,W
SUBWF R0L,W
BTFSC STATUS,C
GOTO L0007
MOVLW 0x07
MOVWF 0x00B
L0007:
; 38: Goto sendit
GOTO L0002
; 39: Endif
L0006:
; 40:
; 41: If dir_btn = 0 Then 'Button low
BTFSC 0x006,5
GOTO L0008
; 42: index = index + 1
INCF 0x00B,F
; 43: If index > 7 Then index = 0
MOVLW 0x07
MOVWF R0L
MOVF 0x00B,W
SUBWF R0L,W
BTFSC STATUS,C
GOTO L0009
CLRF 0x00B
L0009:
; 44: Endif
L0008:
; 45:
; 46: sendit:
L0002:
; 47: Call stepm()
CALL _bootL0003
; 48:
; 49: GPIO = mask
MOVF 0x00C,W
MOVWF GPIO
; 50:
; 51: WaitMs 10
MOVLW 0xE6
MOVWF R4L
MOVLW 0x03
MOVWF R4H
CALL _bootDL02
; 52:
; 53: Goto loop
GOTO L0001
; 54: End
L0010: GOTO L0010
; 55: '; routine To get Step value index
; 56:
; 57: Proc stepm()
L0003:
; 58: mask = LookUp(%00000001, %00000101, %00000100, %00000110, %00000010, %00010010, %00010000, %00010001), index
MOVF 0x00B,W
CALL _boot_lookup_lab_0001
MOVWF 0x00C
; 59: End Proc
RETLW 0x00
; 60:
; 61:
; 62:
; 63:
; End of user code
L0011: GOTO L0011
;
;
; Delay Routine Byte
; minimal routine execution time: 10µs
; routine execution time step: 3µs
; maximal routine execution time: 772µs
DL01:
DECFSZ R4L,F
GOTO DL01
RETLW 0x00
; Delay Routine Word
; minimal routine execution time: 17µs
; routine execution time step: 10µs
; maximal routine execution time: 655367µs
DL02:
MOVLW 0x01
SUBWF R4L,F
CLRW
BTFSS STATUS,C
IORLW 0x01
SUBWF R4H,F
BTFSS STATUS,C
RETLW 0x00
GOTO DL02
; Waitms Routine
W001: MOVLW 0x01
SUBWF R0L,F
CLRW
BTFSS STATUS,C
IORLW 0x01
SUBWF R0H,F
BTFSS STATUS,C
RETLW 0x00
MOVLW 0x61
MOVWF R4L
MOVLW 0x00
MOVWF R4H
CALL _bootDL02
GOTO W001
;
;
; Oscillator calibration value
ORG 0x03FF
MOVLW 0xFE
; Configuration settings
ORG 0x0FFF
DW 0x000A
; End of listing
END