Program description
What does it do?
This program runs the CHRP robot as a line follower.
CHRP Robot program
Short description.
What you should know before starting
Make sure that the floor LED (LED10) and the phototransistor have been tested and are working.
Create the program
The entire OUTPUT.ASM program is shown below. Start a new project in MPLAB, copy all of the OUTPUT.ASM code into the project, and build the program.
;CHRP20bot.ASM v2.0 Last modified on January 7, 2010 ;=============================================================================== ;Description: Runs the CHRP robot in digital line following mode. ;Start of MPLAB and processor configuration. include "p16f886.inc" ;Include processor definitions __config _CONFIG1, _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTOSCIO __config _CONFIG2, _WRT_OFF & _BOR40V ;End of MPLAB and processor configuration. ;Start of hardware equates Q1 equ 0 ;Port A position of phototransistor Q1 Q2 equ 1 ;Port A position of phototransistor Q2 ;End of hardware equates org 00h ;Start of program memory clrf PORTA ;Turn off all port outputs clrf PORTB clrf PORTC goto initPorts ;Jump to initialize subroutine org 05h initPorts ;Set Ports B and C to support CHRP digital circuitry. banksel ANSEL ;Switch register banks movlw 01010111b ;Enable Port B pull-ups, TMR0 internal movwf OPTION_REG ;clock, and 256 prescaler clrf ANSEL ;Set all PORTA pins to digital I/O clrf ANSELH ;Set all PORTB pins to digital I/O and banksel TRISA ;Switch register banks movlw 01101111b ;Setup LED and beeper outputs, and movwf TRISA ;make all other PORTA pins inputs clrf TRISB ;Make all PORTB pins outputs movlw 10110000b ;Setup serial input and output pins, movwf TRISC ;and set motor outputs banksel PORTB ;Return to PORTB register bank bsf PORTA,7 ;Turn on floor LED checkRight btfss PORTA,Q1 ;Check if the right sensor sees the line goto checkLeft ;If not, check the left sensor btfss PORTA,Q2 ;Check if the left sensor sees the line too goto turnRight ;If not, turn right goto straight ;Go straight if both see line checkLeft btfss PORTA,Q2 ;Check if the left sensor sees the line goto reverse ;If not, back up goto turnLeft ;If so, turn toward the line straight movlw 00000110b ;Move forward movwf PORTC goto checkRight ;Check the sensors again turnLeft movlw 00000100b ;Turn the right motor on movwf PORTC goto checkRight ;Check the sensors again turnRight movlw 00000010b ;Turn the left motor on movwf PORTC goto checkRight ;Check the sensors again reverse movlw 00001001b ;Move backward movwf PORTC goto checkRight ;Check the sensors again org 1F00h ;Start of bootloader code area res 256 ;Reserve memory for bootloader end

