go away spammer

Author Topic: Programming buggy with assembly language please help..  (Read 1989 times)

0 Members and 1 Guest are viewing this topic.

Offline PeterpantsTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Programming buggy with assembly language please help..
« on: February 17, 2012, 12:25:31 AM »
Hi societyofrobots,

-16f876, L293D, 4infrared sensors and 2 dc motor.

i am rather new to what i am doing and would need some help.
i am trying to program my buggy to detect and avoid obstacle with 2 sensors infront and 1 at each sides.
Currently it is able to detect and avoid obstacle but i would like it stop moving after meeting the third obstacle. How can i do it?

Its is a school project and i am in charge of the electronics while my partner was with the software just the two of us. The project is due on the 1st of march and he dropped out of school just 1month before. Its affecting me right now, and currently im having my end semster exams and i cant find much time to commit to the assembly language from scratch. People out here please help me out, i would like to have 30mins or an hour of your time to check our the code and the schematics.
yours reponses will be much appreciated.


I have attached the relavant files(schematics) here please kindly take a look. Thank you.
Sincerely,
Peter.

; ************* HEADER **************************************************************
LIST p=16F876 ;PIC16F876 is the target processor
#include "P16F876.INC" ;Include header file
__config H'3F39' ;Osc=XT; WDT=Off;
;Power Up Timer=Off; Brown Out Detect=Off
;LVP=Disabled, Flash Program Write=Enabled,
;Data EE Read Protect=Off; Code Protect=Off
;
;************** File Register Variable use ******************************************
cblock H'20'; directive to assign address offset to many variables
NUMBER
d1 ;use for Delay subroutine
d2
d3
d4
Bottom
Top
SENSOR
SENSOR_M
endc ;
;
; ************* Reset Vector ********************************************************
org H'00'
clrf STATUS
movlw 0x00
movwf PCLATH
goto Initial
;
; ************* Port B and C I/O Initialisation *************************************
Initial bsf STATUS,RP0 ; Select BANK 1 R/w-0 another file adress
; banksel TRISB
movlw B'00000000' ; Set PortB to Output pins
movwf TRISB ;
movlw B'11111111' ; Set PortC to Input pins
movwf TRISC ;
movlw B'00000000' ; Set PortA to Output pins
movwf TRISA ;
movlw B'00000110' ;making all pins digital
movwf ADCON1 ;set to digital output

;PORTA MOTOR, PORTB LED, PORTC SENSOR

;
; ************* Main Program *******************************************************
banksel PORTA ;


Enable_BS170 movlw b'00110000' ;
movwf PORTA


RUN call SENSING
call SENSOR_MANIPULATE_TOP
call MOTOR
goto RUN


SENSING
movfw PORTC ;
movwf SENSOR ;
movwf PORTB  ; 
return





SENSOR_MANIPULATE_TOP ;
clrf SENSOR_M


chk_s4 btfss SENSOR,4
goto chk_s5
bsf SENSOR_M,0
chk_s5 btfss SENSOR,5
goto chk_s6
bsf SENSOR_M,1
chk_s6 btfss SENSOR,6
goto chk_s7
bsf SENSOR_M,2

chk_s7 btfss SENSOR,7
goto chk_sX
bsf SENSOR_M,3


chk_sX return


MOTOR
movfw SENSOR_M ;
andlw b'00001111';set upper 4bit to 0
call Get_Code_TOP
movwf PORTA
call Delay_100us
call Delay_100us
call Delay_100us
call Delay_100us
movlw b'00110000'
movwf PORTA
call Delay_100us
call Delay_100us
return




Get_Code_TOP

   addwf PCL
   retlw   b'00110000'   ;stop (0000)
   retlw   b'00111100'   ;right   (0001)
   retlw   b'00110001'   ;left   (0010)
   retlw   b'00111101'   ;forward (0011)
   retlw   b'00111100'   ;right(0100)
   retlw   b'00111100'   ;right (0101)
   retlw   b'00110001'   ;left (0110)
   retlw   b'00111100'   ;right(0111)
   retlw   b'00110001'   ;left(1000)
   retlw   b'00111100'   ;right(1001)
   retlw   b'00110001'   ;left (1010)
   retlw   b'00110001'   ;left (1011)
   retlw   b'00110000'   ;stop(1100)
   retlw   b'00111100'   ;right (1101)
   retlw   b'00110001'   ;left (1110)
   retlw   b'00111101'   ;forward(1111)










; *************** Delays ***********************************************************


Delay_100us movlw 0x1F
movwf d1


again2 decfsz d1,f
goto again2


goto $+1
return


Delay_50us movlw 0x0F
movwf d1


again3 decfsz d1,f
goto again3


return


;
; ************* End of the program ************************************************
END ;End of the program


Please help me out.
Thanks.

Sincerely,
Peter.



« Last Edit: February 22, 2012, 02:21:32 AM by Peterpants »

Offline lrmall01

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 2
Re: mini Buggy with 16f876, L293D and 4infrared sensors, please help..
« Reply #1 on: February 18, 2012, 04:14:18 PM »
It has been a long long time since I wrote anything in assembly so I can't provide an example or code modification.  I am assuming that you want it to stop, but not forever.  You didn't really mention what would trigger it to start moving again but if my assumption is wrong you could modify your goto RUN statement at the end of main to not return after 3 obstacles.  Add a variable that you increment or each obstacle and then put your goto RUN statement in a conditional test that will stop returning when you condition is met.

Similarly, you could create a variable for MOVE that you can set to 0 or 1 depending upon whatever conditions may occur.  In your example it would be after the third obstacle.

Another thought that occurs to me is that another quick and dirty way to do it is a long delay after the third obstacle.

Hope that helps give you some things to think about.  Good luck.

Offline PeterpantsTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: mini Buggy with 16f876, L293D and 4infrared sensors, please help..
« Reply #2 on: February 21, 2012, 08:32:21 AM »
It has been a long long time since I wrote anything in assembly so I can't provide an example or code modification.  I am assuming that you want it to stop, but not forever.  You didn't really mention what would trigger it to start moving again but if my assumption is wrong you could modify your goto RUN statement at the end of main to not return after 3 obstacles.  Add a variable that you increment or each obstacle and then put your goto RUN statement in a conditional test that will stop returning when you condition is met.

Similarly, you could create a variable for MOVE that you can set to 0 or 1 depending upon whatever conditions may occur.  In your example it would be after the third obstacle.

Another thought that occurs to me is that another quick and dirty way to do it is a long delay after the third obstacle.

Hope that helps give you some things to think about.  Good luck.



Hi irmall01,
 
             Thanks for the idea but i dont really know how to do it. The code wasnt done by me and im not good in assemblers. Could you show me a thing or two or you could edit my code. Thanks alot.

PEter.

 


Get Your Ad Here

data_list