LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
count ;used in table read routine
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB'
LEDTRIS Equ TRISB ;set constant for TRIS register
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf LEDTRIS
bcf STATUS, RP0 ;select bank 0
clrf LEDPORT ;set all outputs low
Start1 clrf count ;set counter register to zero
Read1 movf count, w ;put counter value in W
call Table1
movwf LEDPORT
call Delay1
incf count, w
xorlw d'4' ;check for last (4th) entry
btfsc STATUS, Z
goto Start2 ;if start from start2 ( reverse )
incf count, f ;else do next
goto Read1
Table1 call Delay2
ADDWF PCL, f ;data table for bit pattern
retlw b'01100000'
retlw b'10100000'
retlw b'10010000'
retlw b'01010000'
Start2 clrf count ;set counter register to zero
Read2 movf count, w ;put counter value in W
call Table2
movwf LEDPORT
call Delay1
incf count, w
xorlw d'4' ;check for last (4th) entry
btfsc STATUS, Z
goto Start1 ;if start from start1 ( forward )
incf count, f ;else do next
goto Read2
Table2 call Delay2
ADDWF PCL,f ;data table for reverse bit pattern
retlw b'10010000'
retlw b'01010000'
retlw b'10100000'
retlw b'01100000'
Delay1 movlw d'2' ;delay ? ms (4 MHz clock)for motor speed
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_1
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_1
decfsz count1 ,f
goto d1
retlw 0x00
Delay2 movlw d'100' ;delay ? ms (4 MHz clock)for reversing delay
movwf count1
d2 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_2
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_2
decfsz count1 ,f
goto d2
retlw 0x00
end