#include ;#include "banks.inc" ; This header file defines configurations, registers, and other useful ; bits of information for the PIC18F4550 microcontroller. These names ; are taken to match the data sheets as closely as possible. CONFIG WDT = OFF; Disable watchdog timer CONFIG MCLRE = ON; MCLEAR Pin on CONFIG DEBUG = OFF; disable Debug Mode CONFIG LVP = OFF; Low-Voltage programming disabled CONFIG FOSC = HSPLL_HS; HS oscillator, PLL enabled, HS used by USB CONFIG PBADEN = OFF; PORTB<4:0> pins are configured as digital I/O on Reset CONFIG VREGEN = ON ; USB voltage regulator enabled CONFIG PLLDIV = 5 ; PLL prescaler Divide by 5 (20 MHz oscillator input) CONFIG USBDIV = 2 ; USB clock source comes from the 96 MHz PLL divided by 2 CONFIG CP0 = ON ; Code Protect CONFIG CP1 = ON CONFIG CP2 = ON CONFIG CPB = ON ; Boot Sect Code Protect CONFIG CPD = OFF ; EEPROM Data Protect CONFIG WRT0 = OFF ; Table Write Protect CONFIG WRT1 = OFF CONFIG WRT2 = OFF CONFIG WRTB = ON ; Boot Table Write Protest ;------sensa1c.ASM--------------------------------------- ; robot test - checks function of forward, back, left and right movement ;for the pic18f4550 20Mhz -> 4Mhz -> 100Mhz processor ; 5/09/10 (efa) //works for my robot ;------------------------------------------------------ list p=18f4550 ;------------------------------------------------------- ; setup equates for ram memory -- Pic16f648: 0x20 to 0x7F (in bank 0), 0xA0 to 0xEF (in bank 1), ; 0x120 to 0x16F (in bank 2). 256 total ram count equ 0x20 ocount equ 0x21 ncount equ 0x22 ncount1 equ 0x23 ncount2 equ 0x24 ncount3 equ 0x25 seconds equ 0x26 tenths equ 0x27 sens equ 0x28 ;sensor status flag bumper, rt_sens, etc. LCD_tmp1 equ 0x29 Temp equ 0x2a ;--------------------- special registers and flags ------------------ porta equ PORTA portb equ PORTB portc equ PORTC portd equ PORTD w equ 0 f equ 1 ;------------------------------------------------------- ; org 0x800 ;reset starting address 00 goto begin org 0x804 ; define the interrupt, starts at 0x804 goto begin ; not currently used, just goto begin begin ; Initialize and setup processor to do work ; movlw 0x10 ; load w with 0001 0000 - controls input/output MOVWF TRISD ; ; movlw 0x02 ; load w with 0000 0010 MOVWF TRISC ; ; bcf INTCON, GIE ;disable interrupts MOVLW 0x07 ; turn comparators off and MOVWF CMCON ; enable pins for I/O functions ;**************** Clear Variables ********************* clrf porta clrf portb clrf sens ; clear sensors status flags call m_off ; turn motors off ; wait for a time --- give it a second to stablize movlw 0x04 ; load a 4 second wait in w movwf seconds ; load w value to seconds call wait ; wait for alotted seconds loop1 ;------------------------------------------------------- ;------------------------------------------------------- ; First check sensor status ;------------------------------------------------------- chk_sens ; call look_rt ; check right sensor for an object ; call look_lft ; check left sensor for an object call f_bump ; check front bumper ;------------------------------------------------------- ;****** Check the front bumper ******* btfsc sens,3 ; if(f_bump == TRUE) goto if2 goto endif2 if2 call back_turn_left call m_forward goto chk_sens endif2 ;------------------------------------------------------- call m_forward ; wait for a time --- best value ??? movlw 0x01 ; load 1/10 seconds to wait in w movwf tenths ; load w value to seconds call wait10th ; wait for alotted 1/10 seconds goto loop1 ; infinite loop ;******************************************************* ;------------------------------------------------------- ; m_forward:: subroutine to turn the motors on (turning forward) ; 3/10/09 (efa) // might differ from board to board... ;------------------------------------------------------- m_forward bcf portc,2 ;disable motors (c2) bcf portd,0 ;m1 (off) (d0) left side motor bsf portd,2 ;m2 (on) (d2) bcf portd,1 ;m3 (off) (d1) right side motor bsf portd,3 ;m4 (on) (d3) bsf portc,2 ;enable motors (c2) return ;------------------------------------------------------- ; m_off:: subroutine to turn the motors off (full-stop) ; 3/23/09 (efa) ;------------------------------------------------------- m_off bcf portc,2 ;disable motors (c2) bcf portd,0 ;m1 (off) (d0) left side motor bcf portd,2 ;m2 (off) (d2) bcf portd,1 ;m3 (off) (d1) right side motor bcf portd,3 ;m4 (off) (d3) return ;------------------------------------------------------- ; m_back:: subroutine to turn the motors on (turning backwards) ; 3//09 () your_initials ;------------------------------------------------------- m_back bcf portc,2 ;disable motors (c2) bsf portd,0 ;m1 (on) (d0) left side motor bcf portd,2 ;m2 (off) (d2) bsf portd,1 ;m3 (on) (d1) right side motor bcf portd,3 ;m4 (off) (d3) bsf portc,2 ;enable motors (c2) return ;------------------------------------------------------- ; m_left:: subroutine to turn the motors on (turning left) ; 3/23/09 (efa) your_initials ;------------------------------------------------------- m_left bcf portc,2 ;disable motors (c2) bcf portd,0 ;m1 (off) (d0) left side motor bsf portd,2 ;m2 (on) (d2) bsf portd,1 ;m3 (on) (d1) right side motor bcf portd,3 ;m4 (off) (d3) bsf portc,2 ;enable motors (c2) return ;------------------------------------------------------- ; m_right:: subroutine to turn the motors on (turning right) ; 3/23/09 (efa) your_initials ;------------------------------------------------------- m_right bcf portc,2 ;disable motors (c2) bsf portd,0 ;m1 (on) (d0) left side motor bcf portd,2 ;m2 (off) (d2) bcf portd,1 ;m3 (off) (d1) right side motor bsf portd,3 ;m4 (on) (d3) bsf portc,2 ;enable motors (c2) return ;------------------------------------------------------- ; back_turn_left:: subroutine to backup turn left ; 9/10/00 (efa) ;------------------------------------------------------- back_turn_left call m_back ; backup ; wait for a time ---- time backing up // best value ??? movlw 0x0a ; load 1/10 seconds to wait in w movwf tenths ; load w value to seconds call wait10th ; wait for alotted seconds call m_left ; motors on (turning left) ; wait for a time ---- time turning left //best value ??? movlw 0x0a ; load 1/10 seconds to wait in w movwf tenths ; load w value to seconds call wait10th ; wait for alotted seconds return ;------------------------------------------------------- ; f_bump:: subroutine to Check front bumper ; 3/12/09 (efa) ;------------------------------------------------------- f_bump btfss portd,4 ; skip if bit4 is +5volts goto f_bump_if1 goto f_bump_else1 f_bump_if1 ; bsf sens,3 ; front bumper was bumped goto f_bump_endif1 f_bump_else1 bcf sens,3 ; front bumper not bumped f_bump_endif1 return ;------------------------------------------------------- ; wait:: subroutine to "wait" for up to 255 seconds. ; Wait routine uses "pause" and variable "seconds" ; 01/31/10 (efa) - calibrated (+/- .1%) ;------------------------------------------------------- wait movwf seconds ; wait for 1-255 seconds incf seconds,f ; start 1 second back... s_loop movlw 0x0a ;max value inner counter movwf ncount1 ;load value inner counter decfsz seconds,f ; --ncount goto start ; pause for a time return ; subroutine return start movlw 0x01 ; load 1/10 seconds to wait in w movwf tenths ; load w value to seconds call wait10th ; pause for .1 seconds decfsz ncount1,f ; --ncount1 goto start ; inner1 loop goto s_loop ; go back to s_loop ;------------------------------------------------------- ; wait10th:: subroutine to "wait" for up to 255 (1/10) seconds. ; Wait routine uses "pause" and variable "seconds" ; 02/04/10 (efa) - calibrated ;------------------------------------------------------- wait10th movwf tenths ; wait for 1-255 (1/10) seconds incf tenths,f ; start 1 second back... s_loop1 movlw 0x0a ;max value inner counter movwf ncount2 ;load value inner counter decfsz tenths,f ; --ncount goto start1 ; pause for a time return ; subroutine return start1 call wait100th ; pause for .01 seconds decfsz ncount2,f ; --ncount1 goto start1 ; inner1 loop goto s_loop1 ; go back to s_loop ;------------------------------------------------------- ; wait100th:: subroutine to pause for 1/100 second ; To decrease pause decrease max value in outer loop ; 02/04/10 (efa) - calibrated ;------------------------------------------------------- wait100th movlw 0x0a ;max value outer counter (10) movwf ncount3 ;load value outer counter outer1 call wait_ms ; no operation, just a delay decfsz ncount3,f ; --ocount goto outer1 ; outer loop return ; subroutine return ;------------------------------------------------------- ; wait_ms:: subroutine to wait for 1/1000 second ; To decrease pause decrease max value in outer loop ; 1/30/10 (efa) calibrated ;------------------------------------------------------- wait_ms movlw 0x18 ;max value outer counter () movwf ocount ;load value outer counter outer movlw 0x7b ;max value inner counter movwf ncount ;load value inner counter inner nop ; no operation, just a delay decfsz ncount,f ; --ncount goto inner ; inner loop decfsz ocount,f ; --ocount goto outer ; outer loop return ; subroutine return ;------------------------------------------------------- end