Discussion in "8051 Discussion Forum" started by    tran2000    Sep 17, 2010.
Mon Sep 20 2010, 12:09 am
#11
hi tran2000


org 00h
mov p1,#0ffh          ; here i make every pin as input every pin of port1 is high



if u want to create a routine then simply call them why u want to jump there
u edit ur code as

org 00h
setb p1.5 ; make P1.5 an input
back:
call Turnleft    ; call function not jump
again: jnb p1.5, again ; get out when P1.5 = 1
call continue
jmp back
end


nw by using this what u want to do i think ur not understanding hat how to create a flow in the program

 tran2000 like this.
Mon Sep 20 2010, 04:35 am
#12
So would the "turnleft" function be for used for if the input is high and the "continue" function would be used for the input when it is low? Could i use this code for monitoring three ports with the same functions
Mon Sep 20 2010, 10:50 am
#13
let say three pins are p.0,p1.1 and p1.2

org 00h
mov p1,#0ffh          ; here i make every pin as input every pin of port1 is high
back:
jnb p1.0,conti          ; jump to conti  if p1.0=0
call turnleft

back2:
jnb p1.1,conti1          ; jump to conti  if p1.1=0
call turnleft1

back1:
jnb p1.2,conti2          ; jump to conti  if p1.2=0
call turnleft2
jmp back

conti:
call continue
jmp back2

conti1:
call continue1
jmp back1

conti2:
call continue2
jmp back

continue:   // function
;
;
;
; write a code here for a continue function

ret

continue1:   // function
;
;
;
; write a code here for a continue function

ret

continue2:   // function
;
;
;
; write a code here for a continue function

ret


turnleft:
;
;
;
; write a code here for a continue function

ret

turnleft1:
;
;
;
; write a code here for a continue function

ret

turnleft2:
;
;
;
; write a code here for a continue function

ret

end
 tran2000 like this.
Tue Sep 21 2010, 06:18 am
#14
Hey, thanks Majoka, i will try and piece together the program tonight and try it out. I'll let you know how it turns out. Im sure it'll work. Thanks again. You have helped me out greatly.
Tue Sep 21 2010, 08:51 am
#15
ur wlcome gud luck
Wed Sep 22 2010, 06:54 am
#16
I am trying the code and its not working right. I seems like it just skips right to the next routine regardless. What should the checking pins be set on? analog or digital, and push/pull or open drain?
Wed Sep 22 2010, 08:13 am
#17
;$MOD330
org 00h

ANL PCA0MD, #NOT(040h) ; disable the WDT
MOV XBR1, #40h ; enable Crossbar
ORL P0MDOUT, #0ffh
ORL P1MDOUT, #0ffh ; make LED pin input mode digital
MOV TMOD, #00000001B ; This will select Mode 1

;========================================================================
; Main Routine - Program
;========================================================================
LeftForward equ P0.0 ;L293D Positive of Left Motor
LeftReverse equ P0.1 ;L293D Negative of Left Motor
RightForward equ P0.2 ;L293D Positive of Right Motor
RightReverse equ P0.3 ;L293D Negative of Right Motor



;========================================================================
; Movement Routines
;========================================================================

;mov P1, #0ffh

setb P1.0
BACK: jnb P1.0,BACK
call turnleft
call shortdelay
call stop
jmp back
Wed Sep 22 2010, 08:15 am
#18
That is my code just to test one sensor but everytime i start the program, it runs through setb p1.0, back: jnb p1.0, back, then it goes next to call turnleft. Call turnleft was suppose to be only if the bit is high.
How should i set my ports, analog or digital, push/pull or open drain? is there any other configurations i need to modify? i am using the C8051F342DC.
Wed Sep 22 2010, 09:40 am
#19
i not ever work on C8051F342DC
try to see its data sheet
in the main program unhigh the pin by urself then it check the line
BACK: jnb P1.0,BACK
if pin is low then it wait on the line to goes high and when it goes high it call turnleft,short delay and stop respectively


[ Edited Wed Sep 22 2010, 09:44 am ]
 tran2000 like this.
Thu Sep 23 2010, 12:46 am
#20
how you're testing your code? on simulator? or what?

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am