USB Humping Dog改造大作戦 ソースコード
LIST P=10F200 #INCLUDE <P10F200.INC>
;----------------------------------------
; コンフィギュレーション
;----------------------------------------
;外部リセットなし、WDTなし、メモリリードプロテクトなし __config _MCLRE_OFF & _WDT_OFF & _CP_OFF
;----------------------------------------
; 変数
;----------------------------------------
mfLoopCount equ 0x10 ; サブルーチン用汎用ループカウンタ
iWait_msec equ 0x11 ; Wait_msecサブルーチンのWait秒数
iDuty equ 0x12 ; Move_motorサブルーチンのDuty(0-255)
maLoopCount equ 0x15 ; アプリケーション用汎用ループカウンタ
mTimeCount equ 0x16 ; 1秒カウント用の変数
mGPIO3Bku equ 0x17 ; GPIOの前回の値
mMoveCount equ 0x1a ;
;****************************** ; プログラム開始 ;****************************** org 0x0000 movwf OSCCAL
;GP3:IN GP0-2:OUT(use GP1) movlw b'00001000' tris GPIO movlw b'11000100' ;ps 1/32 option
clrf GPIO goto STATE_Idle1Sec
;---------------------------------------------
;
;
STATE_Idle1Sec
;for (maLoopCount = 4) -> 0
movlw d'5' movwf maLoopCount
STATE_Idle1Sec_do
;{
movlw d'250' movwf iWait_msec call SUB_Wait_msec ;(iWait_msec = 250)
decfsz maLoopCount,f goto STATE_Idle1Sec_do
;}
STATE_Idle1Sec_exit
goto STATE_stay
;---------------------------------------------
;
;
STATE_stay
;do untile (GPIO3 == 1)
STATE_stay_do
;{
btfss GPIO,3 goto STATE_stay_do
;}
STATE_stay_exit
goto STATE_move
;---------------------------------------------
;
;
STATE_suspend
;do untile (GPIO3 == 0)
STATE_suspend_do
;{
btfsc GPIO,3 goto STATE_suspend_do
;}
STATE_suspend_exit
goto STATE_Idle1Sec
;---------------------------------------------
;
;
STATE_move
STATE_move_entry
;{
movlw d'250' movwf mTimeCount movfw GPIO movwf mGPIO3Bku
clrf mMoveCount
;do (gpio fix 1sec)
STATE_move_do
;{
movlw d'5' movwf iWait_msec movlw d'1' movwf iDuty ; duty 70% call SUB_Move_motor ;(iWait_msec = 1(4msec) , iDuty = 177)
;if ( gpio3 xor gpio3bku == 0 ) movfw mGPIO3Bku xorwf GPIO , w andlw 0x08 btfss STATUS , Z goto __STATE_move_gpio3chg ;{ decf mTimeCount , f goto __STATE_move_gpio3chg_endif ;} ;else
__STATE_move_gpio3chg
;{ movlw d'250' movwf mTimeCount movfw GPIO movwf mGPIO3Bku
incf mMoveCount,f ;}
__STATE_move_gpio3chg_endif
movf mTimeCount , f btfss STATUS , Z goto STATE_move_do
;}
movlw d'10' subwf mMoveCount , w ; btfss STATUS , C goto STATE_move_exit
movlw d'250' movwf iWait_msec bsf GPIO , 1 call SUB_Wait_msec ;(iWait_msec = 250) movlw d'250' movwf iWait_msec call SUB_Wait_msec ;(iWait_msec = 250) bcf GPIO , 1 movlw d'32' movwf iWait_msec call SUB_Wait_msec ;(iWait_msec = 250)
movlw d'32' movwf iWait_msec bsf GPIO , 1 call SUB_Wait_msec ;(iWait_msec = 250) bcf GPIO , 1 movlw d'64' movwf iWait_msec call SUB_Wait_msec ;(iWait_msec = 250)
movlw d'32' movwf iWait_msec bsf GPIO , 1 call SUB_Wait_msec ;(iWait_msec = 250) bcf GPIO , 1 movlw d'250' movwf iWait_msec call SUB_Wait_msec ;(iWait_msec = 250)
movlw d'32' movwf iWait_msec bsf GPIO , 1 call SUB_Wait_msec ;(iWait_msec = 250) bcf GPIO , 1 movlw d'32' movwf iWait_msec call SUB_Wait_msec ;(iWait_msec = 250)
movlw d'32' movwf iWait_msec bsf GPIO , 1 call SUB_Wait_msec ;(iWait_msec = 250) bcf GPIO , 1 movlw d'250' movwf iWait_msec call SUB_Wait_msec ;(iWait_msec = 250)
movlw d'32' movwf iWait_msec bsf GPIO , 1 call SUB_Wait_msec ;(iWait_msec = 250) bcf GPIO , 1
STATE_move_exit
;if (gpio3 == 0)
;{
btfss GPIO , 3 goto STATE_stay
;}
;else{
goto STATE_suspend
;}
;---------------------------------------------
;
;
SUB_Wait_msec
SUB_Wait_msec_do
;for (iWait_msec) -> 0
;{
clrf TMR0 ;do (1msec)
__SUB_Wait_msec_4msecloop
;{ movlw d'125' subwf TMR0,w ;4usec / inc btfss STATUS,C goto __SUB_Wait_msec_4msecloop ;}
decfsz iWait_msec,f goto SUB_Wait_msec_do
;}
SUB_Wait_msec_exit
retlw 0
;---------------------------------------------
;
;
SUB_Move_motor
SUB_Move_motor_do
;for (iWait_msec) -> 0
;{
clrf TMR0 ;do (1msec)
__SUB_Move_motor_PWM
;{
bsf GPIO , 1 ;for (mfLoopCount = iDuty) -> 0 movfw iDuty movwf mfLoopCount
__SUB_Move_motor_onloop
;{ decfsz mfLoopCount,f goto __SUB_Move_motor_onloop ;}
bcf GPIO , 1 ;for (mfLoopCount = 255 - iDuty) -> 0 movlw d'255' subwf iDuty , w movwf mfLoopCount
__SUB_Move_motor_offloop
;{ decfsz mfLoopCount , f goto __SUB_Move_motor_offloop ;}
movlw d'125' subwf TMR0 , w ;4usec / inc btfss STATUS , C goto __SUB_Move_motor_PWM ;}
decfsz iWait_msec , f goto SUB_Move_motor_do
;}
SUB_Move_motor_exit
retlw 0
END
- 最終更新:2008-12-12 08:35:21