;Magnet Actuator Driver for PIC16F84A Ver. 0.9
;MAGDRV09.ASM
;INPUT: RA4 Right logic pulse input
;4MHz clock
;Neutral:1550usec@50usec steps
LIST P=PIC16F84A
INCLUDE "P16F84A.INC"
__CONFIG _HS_OSC & _PWRTE_ON & _CP_OFF & _WDT_OFF
CNT020 EQU 0CH ;20usec wait timer
CNT050 EQU 0DH ;50usec wait timer
CNT100 EQU 0EH ;100usec wait timer
CNT200 EQU 0FH ;200usec wait timer
CNT400 EQU 10H ;400usec wait timer
CNT600 EQU 11H ;600usec wait timer
CNT800 EQU 12H ;800usec wait timer
CNT1000 EQU 13H ;1000usec wait timer
CNT1200 EQU 14H ;1200usec wait timer
CNT1600 EQU 15H ;1600usec wait timer
CNT2000 EQU 16H ;2000usec wait timer
ORG 0
MAIN
BSF STATUS,RP0 ;set to bank 1
CLRF TRISB ;PORT B is set to output
BCF STATUS,RP0 ;set to bank 0
MOVLW B'00000000'
MOVWF PORTB ;RB0-7 Low
LOOP ;main loop
TP1 BTFSC PORTA,4 ;RA4 Low(nonactive) then next skip
GOTO TP1
TP2 BTFSS PORTA,4 ;RA4 Hign(active) then next skip
GOTO TP2
TP3 CALL WAIT100 ;100usec
CALL WAIT100 ;200
CALL WAIT100 ;300
CALL WAIT100 ;400
CALL WAIT100 ;500
CALL WAIT100 ;600
CALL WAIT100 ;700
CALL WAIT100 ;800
BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO WRONG
CALL WAIT100 ;900usec
CALL WAIT100 ;1000usec
CALL WAIT100 ;1100usec
CALL WAIT100 ;1200usec
CALL WAIT050 ;1250usec
;1250usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1250
CALL WAIT050 ;1300usec
;1300usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1300
CALL WAIT050 ;1350usec
;1350usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1350
CALL WAIT050 ;1400usec
;1400sec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1400
CALL WAIT050 ;1450usec
;1450sec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1450
CALL WAIT050 ;1500usec
;1500usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1500
CALL WAIT050 ;1550usec
;1550usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1550
CALL WAIT050 ;1600usec
;1600usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1600
CALL WAIT050 ;1650usec
;1650usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1650
CALL WAIT050 ;1700usec
;1700usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1700
CALL WAIT050 ;1750usec
;1750usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1750
CALL WAIT050 ;1800usec
;1800usec BTFSS PORTA,4 ;RA4 High(active) then next skip
GOTO OUT1800
;1800usecȏ GOTO OUT1850
WRONG MOVLW B'00000000'
MOVWF PORTB ;RB0-7 Low
GOTO LOOP
;1250usec
OUT1250 MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
GOTO LOOP
;1300usec
OUT1300 MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT400
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT400
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT400
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT400
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT400
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT400
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT400
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT400
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
GOTO LOOP
;1350usec
OUT1350 MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT800
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT800
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT800
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT800
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT800
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT800
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT800
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT800
MOVLW B'11110000' ;RB0-3 High, RB4-7 Low
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
GOTO LOOP
;1400usec
OUT1400 MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
GOTO LOOP
;1450usec
OUT1450 MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
GOTO LOOP
;1500usec
OUT1500 MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT2000
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT2000
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT2000
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT2000
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT2000
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT2000
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT2000
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT2000
MOVLW B'11110000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000'
MOVWF PORTB
GOTO LOOP
;1550usec
OUT1550 MOVLW B'00000000'
MOVWF PORTB
GOTO LOOP
;1600usec
OUT1600 MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
CALL WAIT2000
MOVLW B'00001111' ;RB0-3 High, RB4-7 High
MOVWF PORTB
CALL WAIT400
MOVLW B'00000000' ;RB0-7 Low
MOVWF PORTB
GOTO LOOP
;1650usec
OUT1650 MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT800
MOVLW B'00000000'
MOVWF PORTB
GOTO LOOP
;1700usec
OUT1700 MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1200
MOVLW B'00000000'
MOVWF PORTB
GOTO LOOP
;1750usec
OUT1750 MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT800
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1600
MOVLW B'00000000'
MOVWF PORTB
GOTO LOOP
;1800usec
OUT1800 MOVLW B'00001111'
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT2000
MOVLW B'00000000'
MOVWF PORTB
CALL WAIT400
MOVLW B'00001111'
MOVWF PORTB
CALL WAIT1000
MOVLW B'00000000'
MOVWF PORTB
GOTO LOOP
;1850usec
OUT1850 MOVLW B'00001111'
MOVWF PORTB
GOTO LOOP
;20usec wait timer
WAIT020 MOVLW 05H
MOVWF CNT020
TIMLP1 DECFSZ CNT020,F
GOTO TIMLP1
NOP
NOP
RETURN
;50usec wait timer
WAIT050 MOVLW 0CH
MOVWF CNT050
TIMLP2 NOP
DECFSZ CNT050,F
GOTO TIMLP2
RETURN
;100usec wait timer
WAIT100 MOVLW 17H
MOVWF CNT100
TIMLP3 NOP
DECFSZ CNT100,F
GOTO TIMLP3
NOP
NOP
NOP
RETURN
;200usec wait timer
WAIT200 MOVLW 2EH
MOVWF CNT200
TIMLP4 NOP
DECFSZ CNT200,F
GOTO TIMLP4
NOP
NOP
NOP
RETURN
;400usec wait timer
WAIT400 MOVLW 5CH
MOVWF CNT400
TIMLP5 NOP
DECFSZ CNT400,F
GOTO TIMLP5
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RETURN
;600usec wait timer
WAIT600 MOVLW 8BH
MOVWF CNT600
TIMLP6 DECFSZ CNT600,F
GOTO TIMLP6
NOP
NOP
NOP
RETURN
;800usec wait timer
WAIT800 MOVLW 07H
MOVWF CNT800
TIMLP7 NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
CALL WAIT100
DECFSZ CNT800,F
GOTO TIMLP7
NOP
NOP
NOP
RETURN
;1000usec wait timer
WAIT1000 MOVLW 09H
MOVWF CNT1000
TIMLP8 NOP
NOP
NOP
NOP
NOP
NOP
NOP
CALL WAIT100
DECFSZ CNT1000,F
GOTO TIMLP8
NOP
NOP
NOP
NOP
NOP
RETURN
;1200usec wait timer
WAIT1200 MOVLW 0BH
MOVWF CNT1200
TIMLP9 NOP
NOP
NOP
NOP
NOP
CALL WAIT100
DECFSZ CNT1200,F
GOTO TIMLP9
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RETURN
;1600usec wait timer
WAIT1600 MOVLW 0FH
MOVWF CNT1600
TIMLP10 NOP
NOP
NOP
CALL WAIT100
DECFSZ CNT1600,F
GOTO TIMLP10
NOP
NOP
NOP
NOP
NOP
RETURN
;2000usec wait timer
WAIT2000 MOVLW 13H
MOVWF CNT2000
TIMLP11 NOP
NOP
CALL WAIT100
DECFSZ CNT2000,F
GOTO TIMLP11
RETURN
END