; February-26-2002, PTB. ; ; Clock = 47K + 27K + 20K POT + 32pf cap. ; LIST p=16f84 include "P16F84.INC" ; include "d:\mplab\16f84_lc.inc" ; has lower case register names. include "c:\progra~1\mplab\16f84_lc.inc" __config _cp_off & _wdt_off & _pwrte_on & _rc_osc ; __idlocs 0xffff errorlevel -302 ; no pullups on Port-B: b'1xxxxxxx' ; _opt256 equ b'10000111' ; OK, timer 1:256, no PU _opt128 equ b'10000110' ; OK, timer 1:128, no PU _opt64 equ b'10000101' ; OK, timer 1:64, no PU _opt32 equ b'10000100' ; OK, timer 1:32, no PU _opt16 equ b'10000011' ; OK, timer 1:16, no PU _opt2 equ b'10000000' ; OK, timer 1:2, no PU _int equ b'00000000' ; OK ; 43210 a_pins equ b'11111' ; all tri-stated a_tris equ b'00000' ; all outputs, =0 ; |||||____ leg 1 enable ; ||||_____ leg 2 enable ; |||______ leg 3 enable ; ||_______ leg 4 enable ; |________ optional speed FET p-ch, 0= fast, 1= slow ; 76543210 b_pins equ b'00000000' ; 1= all high b_tris equ b'00000000' ; 0= output ; ||||||||____ leg 1a hip ; |||||||_____ leg 1b knee ; ||||||______ leg 2a hip ; |||||_______ leg 2b knee ; ||||________ leg 3a hip ; |||_________ leg 3b knee ; ||__________ leg 4a hip ; |___________ leg 4b knee bit0 equ 0 bit1 equ 1 bit2 equ 2 bit3 equ 3 bit4 equ 4 bit5 equ 5 bit6 equ 6 bit7 equ 7 #define bank0 status,rp0 #define bank1 status,rp0 #define z_flag status,z #define carry status,c #define _eeif eecon1,bit5 #define _wrerr eecon1,bit4 #define _wren eecon1,bit3 #define _wr eecon1,bit1 #define _rd eecon1,bit0 #define _gie intcon,gie #define _intf intcon,intf #define _inte intcon,inte #define _t0if intcon,t0if ; timer overflow flag #define _rbie intcon,rbie #define _rbif intcon,rbif ; portb (4..7) only pin change flag #define runtim1 .255-.128 ; time for motor steps #define runtim2 .255-.128 ; time for motor steps #define runtim3 .255-.128 ; time for motor steps #define runtim4 .255-.128 ; time for motor steps ; tied to 74HC139 enables: enables equ porta ena1 equ b'11110' ena2 equ b'11101' ena3 equ b'11011' ena4 equ b'10111' ea equ b'11110' eb equ b'11101' ec equ b'11011' ed equ b'10111' enaoff equ b'11111' #define speed porta,bit4 ; speed FET P-ch + 10K pullup. ; tied to 74HC139 AB inputs: legs equ portb a.c equ b'11111100' ; 0 h+ a.u equ b'11111101' ; 1 k+ a.w equ b'11111110' ; 2 h- a.d equ b'11111111' ; 3 k- b.c equ b'11110011' ; 0 h+ b.u equ b'11110111' ; 1 k+ b.w equ b'11111011' ; 2 h- b.d equ b'11111111' ; 3 k- c.c equ b'11001111' ; 0 h+ c.u equ b'11011111' ; 1 k+ c.w equ b'11101111' ; 2 h- c.d equ b'11111111' ; 3 k- d.c equ b'00111111' ; 0 h+ d.u equ b'01111111' ; 1 k+ d.w equ b'10111111' ; 2 h- d.d equ b'11111111' ; 3 k- ; RAM RAM RAM RAM RAM RAM RAM RAM RAM ; CBLOCK 0x0C ; to 0x4F inclusive _ena, _time ; port values _legs, _enables ; port copies _wtemp, _status _eeadr, _eedata, _eeloop ENDC ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@ ; @ .@ ; @ . @ ; @ . @ ; @. @ ; @@@@ ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; org 0 b Cold ; ;44444444444444444444444444444444 ; 4 ; 4 4 ; 4 4 ; 444444 ; 4 ; 4 ;44444444444444444444444444444444 ; org 4 ; movwf _wtemp ; save W ; swapf status,w ; move status to W (nibbles) ; movwf _status ; save status register ; ; do something here . . . ; ;Ixit swapf _status,w ; restore status register (nibbles) ; movwf status ; restores bank ; swapf _wtemp,f ; restore W (nibbles) ; swapf _wtemp,w ;_/ retfie ; ;-------------------------------- ; Cold clrf intcon ; no interrupts used at all clrf tmr0 ; start timer after 2 cycles movlw _legs ; want address of first movwf fsr ; start pointer to clrnxt clrf indf ; clear out local RAM incf fsr,f ; x1xx-xxxx btfss fsr,6 ; is it 0x40 ? b clrnxt ; ->to 0x3F inclusive bsf bank1 ; yup, continue movlw _opt128 ; setup prescaler amount movwf option_reg movlw a_tris ; setup external pin directions movwf trisa movlw b_tris movwf trisb bcf bank0 movlw a_pins ; all enables off movwf porta movlw b_pins ; all legs stopped movwf portb ; ;-------------------------------- ; ; Hips: W=ccW, C=Cw ; Knees: U=Up/out, D=Down ; ; Sequence: ; 1U&4W, 1U, 3D, 3D&4D, 1W&4D, ; 1W&2W, 2W, 4C, 4C&1D, 1D&2U, ; 2U&3W, 3W, 1C, 1C&2C, 2C&3U, ; 3U&4U, 4U, 2D, 2D&3C, 3C&4W. ; Repeat. ; ; Main movlw a.u&d.w ;1 - '139 A/B Selectors movwf portb ; set A/B movlw ea&ed ; '139 enables call OneMtr ; run motors, then disable enables. movlw a.u ;2 movwf portb movlw ea call OneMtr movlw c.d ;3 movwf portb movlw ec call OneMtr movlw c.d&d.d ;4 movwf portb movlw ec&ed call OneMtr movlw a.w&d.d ;5 movwf portb movlw ea&ed call OneMtr movlw a.w&b.w ;6 movwf portb movlw ea&eb call OneMtr movlw b.w ;7 movwf portb movlw eb call OneMtr movlw d.c ;8 movwf portb movlw ed call OneMtr movlw d.c&a.d ;9 movwf portb movlw ed&ea call OneMtr movlw a.d&b.u ;10 movwf portb movlw ea&eb call OneMtr movlw b.u&c.w ;11 movwf portb movlw eb&ec call OneMtr movlw c.w ;12 movwf portb movlw ec call OneMtr movlw a.c ;13 movwf portb movlw ea call OneMtr movlw a.c&b.c ;14 movwf portb movlw ea&eb call OneMtr movlw b.c&c.u ;15 movwf portb movlw eb&ec call OneMtr movlw c.u&d.u ;16 movwf portb movlw ec&ed call OneMtr movlw d.u ;17 movwf portb movlw ed call OneMtr movlw b.d ;18 movwf portb movlw eb call OneMtr movlw b.d&c.c ;19 movwf portb movlw eb&ec call OneMtr movlw c.c&d.w ;20 movwf portb movlw ec&ed call OneMtr b Main ; do this forever ; ;-------------------------------- ; run one leg-motor at a time: ; OneMtr movwf porta movlw runtim1 ; get running time movwf tmr0 ; start timer bcf _t0if ; make sure flag not set nop p1 btfss _t0if ; is tmr0 done ? b p1 ; no, continue checking movlw 0xff ; yes, turn all enables off movwf porta ;_/ return ; ;-------------------------------- ; END