|
MOTOR TEST PROGRAM Motor Test Program for Mainboard (PIC16F876) The main part of the code at "Start" performs the following function: Set Motor Left Forward The program loops forever and has
the following effect:
The Code: list p=16f876 #include "P16F876.inc" ;Define ports so we can use them by name #define ML1 PORTB,5 ;OUTPUT #define ML2 PORTB,4 ;OUTPUT #define MR1 PORTB,3 ;OUTPUT #define MR2 PORTB,2 ;OUTPUT cblock 20h VLDelay, LDelay, MDelay, SDelay ;variables for delay routines endc org 0 goto init ;jump over interrupt vectors org 10 init bsf STATUS, RP0 bcf STATUS, RP1 ;select bank 1 movlw b'11000011' movwf TRISB ;RB2,RB3,RB4,RB5 set as outputs bcf STATUS, RP0 ;select bank 0 Start bsf ML1 bcf ML2 ;Motor Left Forward bsf MR1 bcf MR2 ;Motor Right Foward movlw .200 ;200*10mS=2S call LongDelay ;wait for 2 second bcf ML1 bcf ML2 ;Motor Left Stop bcf MR1 bcf MR2 ;Motor Right Stop movlw .100 ;100*10mS=1S call LongDelay ;wait for 1 second bcf ML1 bsf ML2 ;Motor Left Reverse bcf MR1 bsf MR2 ;Motor Right Reverse movlw .200 ;200*10mS=2S call LongDelay ;wait for 2 second bcf ML1 bcf ML2 ;Motor Left Stop bcf MR1 bcf MR2 ;Motor Right Stop movlw .100 ;100*10mS=1S call LongDelay ;wait for 1 second goto Start ;loop forever ;***** Delay Routines from 12 uS to 255 Sec ;***** Very Long Delay 1 Sec to 255 Sec, value in w on entry, 1 tick = 1 Sec VLongDelay movwf VLDelay waitvldelay movlw .100 call LongDelay decfsz VLDelay,F goto waitvldelay return ;***** Long Delay 10 mS to 2.55 Sec, value in w on entry, 1 tick = 10 mS LongDelay movwf LDelay waitldelay movlw .10 call MedDelay decfsz LDelay,F goto waitldelay return ;***** Medium Delay 1 mS to 255 mSec, value in w on entry, 1 tick = 1 mS MedDelay movwf MDelay waitmdelay movlw .83 call ShortDelay decfsz MDelay,F goto waitmdelay return ;***** Short Delay 12 uS to 3 mSec, value in w on entry, 1 tick = 12 uS ShortDelay movwf SDelay WaitSDF nop nop nop nop nop nop nop nop nop nop decfsz SDelay,F goto WaitSDF Return ;************************** ;*** Config word *** ;************************** __CONFIG h'3FFF' & _LVP_OFF & _BODEN_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF end
|