nicholastyc
Jun 19 2008, 1:49 AM
hi,
thanks for looking...
i wan to keep decrease a number till 0 in ASM mode...
how i know it is already 0 or it decreased more than 0 ...
how to stop it from substract more than 0 ...?
same question goes to....i have a number , i wan to increase it till 255 in ASM mode too..
how i know it is already 255 or it increased more than 255 ...
how to stop it from adding more than 255 ...?
thanks...
need some suggestion...please...either it will affect the Carry in STATUS REGISTER, or...
thanks...
thanks for looking...
i wan to keep decrease a number till 0 in ASM mode...
how i know it is already 0 or it decreased more than 0 ...
how to stop it from substract more than 0 ...?
same question goes to....i have a number , i wan to increase it till 255 in ASM mode too..
how i know it is already 255 or it increased more than 255 ...
how to stop it from adding more than 255 ...?
thanks...
need some suggestion...please...either it will affect the Carry in STATUS REGISTER, or...
thanks...
shyam
Jun 19 2008, 2:58 AM
please confirm the controller u want to use??
any way PSW flags can be compared for the above operations!
any way PSW flags can be compared for the above operations!
pdi33
Jun 19 2008, 3:46 AM
hi nic,
well, if u are using 8051
;
if the numberwhich is stored in say register r5 is decremented,then use the following code:
mov a,r5
jz label1
. ;here add the code for decrementing the variable
.
.
ret
label:
. ;here the counter has reached zero.
.
.
.
ret
the 'jz' instuction checks if the value in accumulator is zero and jumps accordingly.
For incremented variable use the JC instruction like below (here r5 is limited to 16):
mov a, r5
cjne a,#10,label1
. ;here r5 =10h
.
ret
label1:
. ;here r5 not equal to 5
.
ret
Note:
if the register has a value 0, then the instructions
subb r5,#01h and dec r5
will set the carry flag. u can then check the carry flag using the instruction 'jc label'
well, if u are using 8051
;
if the numberwhich is stored in say register r5 is decremented,then use the following code:
mov a,r5
jz label1
. ;here add the code for decrementing the variable
.
.
ret
label:
. ;here the counter has reached zero.
.
.
.
ret
the 'jz' instuction checks if the value in accumulator is zero and jumps accordingly.
For incremented variable use the JC instruction like below (here r5 is limited to 16):
mov a, r5
cjne a,#10,label1
. ;here r5 =10h
.
ret
label1:
. ;here r5 not equal to 5
.
ret
Note:
if the register has a value 0, then the instructions
subb r5,#01h and dec r5
will set the carry flag. u can then check the carry flag using the instruction 'jc label'
nicholastyc
Jun 19 2008, 5:16 AM
hi i m using pic12f629 !
i m so confused about this 1...
can some1 explain it..thanks
i m so confused about this 1...
can some1 explain it..thanks
Arun Kumar V
Jun 19 2008, 5:33 AM
hello pdi33
i am unable to see where you are using JC instr in the above example
nic you have used two different terms here :
Incrementing and adding, both look similar but differ in usage, you can increment in the multiples of 1 but you can add any two values
if you are starting from say 0 and incrementing then you can know if you have reached 255 by
simple CJNE A,#0FFH,xxxx instr, but when you are adding and the result is more than 255 then you have to subb 0FFH and check the Carry flag.
Arun
For incremented variable use the JC instruction like below (here r5 is limited to 16):
mov a, r5
cjne a,#10,label1
. ;here r5 =10h
.
ret
label1:
. ;here r5 not equal to 5
.
ret
mov a, r5
cjne a,#10,label1
. ;here r5 =10h
.
ret
label1:
. ;here r5 not equal to 5
.
ret
i am unable to see where you are using JC instr in the above example
nic you have used two different terms here :
Incrementing and adding, both look similar but differ in usage, you can increment in the multiples of 1 but you can add any two values
if you are starting from say 0 and incrementing then you can know if you have reached 255 by
simple CJNE A,#0FFH,xxxx instr, but when you are adding and the result is more than 255 then you have to subb 0FFH and check the Carry flag.
Arun
nicholastyc
Jun 19 2008, 5:54 AM
H Arun, Can u please explain it in PIc languague (ASM)
because i dunno about the language u used ...sorry
i wan to INCF a register to 255 or DECF to 0 but i donwan them to exceed the value...
thanks...
but how can i check for that? ...
because i dunno about the language u used ...sorry
i wan to INCF a register to 255 or DECF to 0 but i donwan them to exceed the value...
thanks...
but how can i check for that? ...
pdi33
Jun 19 2008, 10:42 AM
hi arun,
thanks for pointing out my errors
actually i noticed it too so i added the last statement. anyways nic needs it in PIC for which i am as newbee as him
thanks for pointing out my errors
actually i noticed it too so i added the last statement. anyways nic needs it in PIC for which i am as newbee as him
sashijoseph
Jun 19 2008, 12:16 PM
nicholastyc wrote ...
H Arun, Can u please explain it in PIc languague (ASM)
because i dunno about the language u used ...sorry
i wan to INCF a register to 255 or DECF to 0 but i donwan them to exceed the value...
thanks...
but how can i check for that? ...
You can use the instruction DECFSZ to decrement and check for zero.It has 2 parameters.. a register and a 0 or 1.The register contains the value to be deremented and the "1" puts the decremented result back in the register(a " 0 " puts the result in the W register).As long as the result is not 0,the very next instruction is executed.If the result is 0,the very next instruction is skipped and the one after that is executed.
So you employ the instruction in this way...
CODE:
Not_Zero decfsz MyVal,1
goto Not_Zero
other instructions....
goto Not_Zero
other instructions....
As long as MyVal is not zero ' goto Not_Zero' is executed,forming a loop.Once MyVal becomes 0,the goto instruction is skipped and execution starts from 'other instructions'.
For incrementing to 255 you can do it this way..
CODE:
Not_255 Incf MyVal,1
Decfsz Countdown,1
goto Not_255
other instructions...
Decfsz Countdown,1
goto Not_255
other instructions...
Countdown = 255 (assuming MyVa l= 0)
Strange..not even a compare instruction is available for the 12fxxx.
nicholastyc
Jun 19 2008, 2:53 PM
thanks for info...
i really having problem for the encoder part...
i try to use incf and decf and then btfss/btfsc STATUS,Z to check for the max 255 and min 0 !it works...but the encoder part really having big problem..its cant determine which direction correctly...Shyam can u provide me a code of encoder? thanks
i really having problem for the encoder part...
i try to use incf and decf and then btfss/btfsc STATUS,Z to check for the max 255 and min 0 !it works...but the encoder part really having big problem..its cant determine which direction correctly...Shyam can u provide me a code of encoder? thanks
shyam
Jun 19 2008, 11:08 PM
actually u people are working on assembly...
i didnt use assembly for years
so cant help on asm parts..
have interfaced encoder on lpc21xx controllers working fine but inc
the procedure is the same as i explained...
keep trying for a couple more days .. may be this weekend i'll make a code fr ya...
will do it fr the 51 uC in asm..
till then keep trying and have us informed.
i didnt use assembly for years
so cant help on asm parts..
have interfaced encoder on lpc21xx controllers working fine but inc
the procedure is the same as i explained...
keep trying for a couple more days .. may be this weekend i'll make a code fr ya...
will do it fr the 51 uC in asm..
till then keep trying and have us informed.