I have a lot of code to go but it is coming to me pretty quickly now. To give you an idea of what it looks like... Yeah, this is what I do for fun.
list p=16f887 ; list directive to define processor
#include ; processor specific variable definitions
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
SERVOCOUNT EQU D'2'
MINTIMER EQU D'1000' ;smallest pulse for one end of servo positioning
MAXTIMER EQU D'2000' ;largest pulse for other end of servo positioning
TOTALTIMER EQU D'40000' ;max 40ms
; declare servo arrary
VARIABLES UDATA_SHR
servo_start res 0
servo1_cycle res 1
servo1_duration_high res 1
servo1_duration_low res 1
servo2_cycle res 1
servo2_duration_high res 1
servo2_duration_low res 1
loop_count res 1
;**********************************************************************
RESET_VECTOR CODE 0x0000 ; processor reset vector
nop
goto start ; go to beginning of program
MAIN_PROG CODE
start
movlw SERVOCOUNT
movwf loop_count ; init each servo...
movlw servo_start ; start of the array of servo variables.
movwf FSR ; move the address into FSR
INIT_SERVO
; if cycle is 0, means that we are done at this position and must generate new position and cycle count
decfsz INDF
goto SAME_SERVO_POSITION ;cycle isn't 0 yet, stay at same place.
NEW_SERVO_POSITION
;new cycle count
movlw d'32' ;stay here for 32 cycles of 40ms ~1.2Seconds total. TODO replace this with randomizer
movwf INDF
;new servo position
incf FSR
movlw 0x05 ;move to center position of servo high byte TODO: replace this with randomizer
movwf INDF
incf FSR
movlw 0xDC ;move to center position of servo low byte
movwf INDF
incf FSR
decfsz loop_count, 1 ; are we done?
goto INIT_SERVO
goto INIT_SERVO_END
SAME_SERVO_POSITION ;this servo does not need to be moved yet.
incf FSR ;move to next servo
incf FSR
incf FSR
decfsz loop_count, 1 ;are we done?
goto INIT_SERVO
INIT_SERVO_END
goto $
end
No comments:
Post a Comment