#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 ;------test1b.ASM--------------------------------------- ; robot test - checks function of forward 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 seconds equ 0x25 sens equ 0x26 ;sensor status flag rt_sens, etc. ;--------------------- 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 0x00 ; load w with 0000 0000 - controls input/output MOVWF TRISD ; ; movlw 0x32 ; load w with 0011 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 0x01 ; load 1 second to wait in w movwf seconds ; load w value to seconds call wait ; wait for alotted 1/10 seconds loop1 ;----------------- beginning of main program loop ------------------------- call m_forward ; wait for a time---- time turning left movlw 0x02 ; load seconds to wait in w movwf seconds ; load w value to seconds call wait ; wait for alotted seconds call m_off ; wait for a time---- time turning left movlw 0x02 ; load seconds to wait in w movwf seconds ; load w value to seconds call wait ; wait for alotted seconds goto loop1 ; infinite loop ;----------------- end of main program 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 (b2) bcf portd,0 ;m1 (off) (b4) left side motor bsf portd,2 ;m2 (on) (b0) bsf portd,1 ;m3 (on) (b3) right side motor bcf portd,3 ;m4 (off) (b1) bsf portc,2 ;enable motors (b2) return ;------------------------------------------------------- ; m_off:: subroutine to turn the motors off (full-stop) ; 3/10/09 (efa) ;------------------------------------------------------- m_off bcf portc,2 ;disable motors (b2) bcf portd,0 ;m1 (off) (b4) left side motor bcf portd,2 ;m2 (off) (b0) bcf portd,1 ;m3 (off) (b3) right side motor bcf portd,3 ;m4 (off) (b1) return ;------------------------------------------------------- ; wait:: subroutine to "wait" for up to 255 seconds. ; Wait routine uses "pause" and variable "seconds" ; 10/10/00 (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 call pause ; pause for .5 seconds call pause ; pause for .5 seconds decfsz ncount1,f ; --ncount1 goto start ; inner1 loop goto s_loop ; go back to s_loop ;------------------------------------------------------- ; wait1:: subroutine to "wait" for up to 255 (1/10 seconds). ; Wait routine uses "pause" and variable "seconds" ; 2/14/06 (efa) - calibrated (+/- 1%) ;------------------------------------------------------- wait1 movwf seconds ; wait for 1-255, 1/10 seconds incf seconds,f ; start 1/10 second back... s_loop1 movlw 0x01 ;max value inner counter movwf ncount1 ;load value inner counter decfsz seconds,f ; --ncount goto start1 ; pause for a time return ; subroutine return start1 call pause ; pause for .05 seconds call pause ; pause for .05 seconds decfsz ncount1,f ; --ncount1 goto start1 ; inner1 loop goto s_loop1 ; go back to s_loop ;------------------------------------------------------- ; pause:: subroutine to pause for 1/120 seconds ; To decrease pause decrease max value in outer loop ; 2/14/06 (efa) calibrated (+/- 1%) ;------------------------------------------------------- pause movlw 0xe6 ;max value outer counter (230) movwf ocount ;load value outer counter outer movlw 0xff ;max value inner counter movwf ncount ;load value inner counter inner nop ; no operation, just a delay 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