Small 3-wheel ROBOT with PIC16F84 brain & InfraRed
eyes, By: TJACO. Page: 1-2-3-4-Home
The PIC16F84 brain
The PIC 16F84 that is used is a very basic& cheap
FLASH µController from MICROCHIP. It has 13 digital I/O's of which
just 5 are used here. The PIC16F84 has no analog inputs or outputs.
The controller is ideal for experimenting because it can be erased and
re-programmed 1000 times! In the software RB5 and RB6 are programmed
to be inputs; thet check if the IR sensors detect any objects. RB0,
RB1, RB2 and RB3 are outputs which drive the motors forward and backward
to avoid objects.
The µController uses an RC oscillator as clock (R5 C3).
The software is written in the original MICROCHIP assemby language.
The prgram can be assembled with MPASM which is part of MPLAB.
(MPLAB is free and can be downloaded at www.microchip.com)
Software description
The functionality of the software can be described
in a few lines:
1-Start moving forward (both motors forward)
2-If the LEFT sensor is triggered, reverse both motors shortly , then
reverse the RIGHT motor shortly:
(the robot will move backward shortly and then turns right)
3-If the RIGHT sensor is triggered, reverse both motors shortly, then
reverse the LEFT motor shortly:
(the robot will move backward shortly and then turns left)
4-Go back to moving forward.
Does not look very smart, but it is incredibly effective!
The program "V105.asm" is written in the
MICROCHIP assembly language, with the comments it will explain itself.
Download the program HERE.
If you want to learn more about the MICROCHIP assembly
language:
You can find the instruction set in the PIC16F84 specification
(see Component specs page) The code (.asm file) can be assembled with
MPASM which is part of MPLAB, more information available on my main
page.
;TJACO'S DESIGN GRAVEYARD: WWW.GEOCITIES.COM/TJACODESIGN ;
;22 JULY 2002 ;
;CERBERES : MINI ROBOT WITH IR EYES ;
;USES PIC16F84 µCONTROLLER ;
;WRITTEN IN MICROCHIP ASSEMBLY USE MPASM ASSEMBLER FROM MPLAB ;
;MPLAB CAN BE DOWNLOADED FROM WWW.MICROCHIP.COM ;
;***SET UP THE CONTANTS & VARIABLES****
LIST P=16C84
ERRORLEVEL -302 ;SUPPRESS BANK SELECTION MESSAGES
STATUS EQU H'03' ;STATUS REGISTER
TRISB EQU H'86' ;TRISB REGISTER FOR SETUP OF PORTB
PORTB EQU H'06' ;PORTB REGISTER TO DRIVE PORT B
COUNT1 EQU H'0C' ;COUNT VARIABLE 1 IS IN GENERAL PURPOSE REG 08H
COUNT2 EQU H'0D' ;COUNT VARIABLE 2 IS IN GENERAL PURPOSE REG 09H
;***SET UP PORT B IN & OUTPUT****
BSF STATUS,5 ;SWITCH TO BANK0 TO SET UP PORT B
MOVLW B'11110000' ;RB7,6,5,4 IS INPUT
MOVWF TRISB ;RB3,2,1,0 IS OUTPUT
BCF STATUS,5 ;SWITCH BACK TO BANK0 TO USE PORT B
;***MAIN PROGRAM****
START MOVLW B'00000101' ;MAKE RB0&2 HIGH: MOVE FORWARD
MOVWF PORTB ;
MOVLW H'FE' ;RESET COUNT1 TO 254
MOVWF COUNT1 ;
MOVLW H'FE' ;RESET COUNT2 TO 254
MOVWF COUNT2 ;
BTFSS PORTB,5 ;CHECK RB5 (INPUT); IF IT IS LOW
CALL BACKL ;THEN EXECUTE BACKLEFT ROUTINE
BTFSS PORTB,6 ;CHECK RB6 (INPUT); IF IT IS LOW
CALL BACKR ;EXECUTE BACKRIGHT ROUTINE
GOTO START ;RETURN TO LABEL START
;***BACKLEFT ROUTINE****
BACKL MOVLW B'00001010' ;MAKE RB1&3 HIGH: MOVE BACKWARD
MOVWF PORTB ;
CALL DELAY ;
MOVLW B'00001001' ;MAKE RB2&3 HIGH: ROTATE LEFT
MOVWF PORTB ;
CALL DELAY ;
RETURN
;***BACKRIGHT ROUTINE****
BACKR MOVLW B'00001010' ;MAKE RB1&3 HIGH: MOVE BACKWARD
MOVWF PORTB ;
CALL DELAY ;
MOVLW B'00000110' ;MAKE RB2&3 HIGH: ROTATE RIGHT
MOVWF PORTB ;
CALL DELAY ;
RETURN
DELAY MOVLW H'EE' ;RESET ALL COUNTER VARIABLES
MOVWF COUNT1
MOVLW H'99'
MOVWF COUNT2
LOOP1 CLRWDT ;RESET THE WATCHDOG TIMER
DECFSZ COUNT1,1 ;this is a delay loop
GOTO LOOP1 ;tuned to make Cerberes
DECFSZ COUNT2,1 ;turn about 90 degrees
GOTO LOOP1
RETURN
END;
|