8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
nicholastyc
Thu Jun 19 2008, 01:49AM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
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...

Back to top


shyam
Thu Jun 19 2008, 02:58AM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 665
Thanked 93 times in 89 posts
please confirm the controller u want to use??

any way PSW flags can be compared for the above operations!

lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top


pdi33
Thu Jun 19 2008, 03:46AM

 User Offline
Registered Member #1329
Joined: Mon Jun 04 2007, 09:28AM

Posts: 394
Thanked 77 times in 76 posts
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'


* inspired to develop,developing to inspire *
Back to top


nicholastyc
Thu Jun 19 2008, 05:16AM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
hi i m using pic12f629 !

i m so confused about this 1...

can some1 explain it..thanks
Back to top


Arun Kumar V
Thu Jun 19 2008, 05:33AM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 291
Thanked 108 times in 91 posts
hello pdi33

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



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
Back to top


nicholastyc
Thu Jun 19 2008, 05:54AM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
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? ...
Back to top


pdi33
Thu Jun 19 2008, 10:42AM

 User Offline
Registered Member #1329
Joined: Mon Jun 04 2007, 09:28AM

Posts: 394
Thanked 77 times in 76 posts
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


* inspired to develop,developing to inspire *
Back to top


sashijoseph
Thu Jun 19 2008, 12:16PM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 471
Thanked 106 times in 101 posts
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....


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...


Countdown = 255 (assuming MyVa l= 0)

Strange..not even a compare instruction is available for the 12fxxx.

[ Edited Thu Jun 19 2008, 12:21PM ]

Let there be music........
Back to top


nicholastyc
Thu Jun 19 2008, 02:53PM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
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
Back to top


shyam
Thu Jun 19 2008, 11:08PM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 665
Thanked 93 times in 89 posts
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.


lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems