Searching \ for '[PIC] noob needs more help' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'noob needs more help'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] noob needs more help'
2007\02\15@150353 by picnoob

flavicon
face

srry to bother u ppl again with wot is probably a trivial question, but im
not sure i quite understand the decfsz function.

here is a delay routine i found on the www, that counts to 255, 255 times:


Delay
Loop1          decfsz               COUNT1,1 ;reduces COUNT1 by 1
                    goto                  Loop1 ;if COUNT1 isnt 0, reduce
it again(im understandin so far)
                    decfsz             COUNT2,1 ;reduce COUNT2 by 1
                    goto                 Loop1 ;HUH, WHA?? why are we going
back to loop1, and how has COUNT1 magically                    ;been brought
back to its initial value?
return

why does the count1 variable not remain 0 once it has been decfsz-ed to 0?
and what does the ",1" do at the end of the decfsz?

this is quite confusing.
--
View this message in context: www.nabble.com/noob-needs-more-help-tf3235793.html#a8992671
Sent from the PIC - [PIC] mailing list archive at Nabble.com.

2007\02\15@150513 by picnoob

flavicon
face

srry to bother u ppl again with wot is probably a trivial question, but im
not sure i quite understand the decfsz function.

here is a delay routine i found on the www, that counts to 255, 255 times:

(count1 and count2 both contain the value 255)

Delay
Loop1          decfsz               COUNT1,1 ;reduces COUNT1 by 1
                    goto                  Loop1 ;if COUNT1 isnt 0, reduce
it again(im understandin so far)
                    decfsz             COUNT2,1 ;reduce COUNT2 by 1
                    goto                 Loop1 ;HUH, WHA?? why are we going
back to loop1, and how has COUNT1 magically                    ;been brought
back to its initial value?
return

why does the count1 variable not remain 0 once it has been decfsz-ed to 0?
and what does the ",1" do at the end of the decfsz?

this is quite confusing.
--
View this message in context: www.nabble.com/noob-needs-more-help-tf3235793.html#a8992671
Sent from the PIC - [PIC] mailing list archive at Nabble.com.

2007\02\15@151838 by Marcel Birthelmer

picon face
Hi,
first of all, the second argument to decfsz does not indicate how much
to reduce by. It indicates where to store the result (either in the
register that you're working on, or W).
Secondly, after COUNT1 is 0 and you fall through to the second case,
you jump back to Loop1. Now, decrementing COUNT1 brings the value back
to 0xFF (with the STATUS, CARRY bit set). Since the check is done
after the decrement (when the value is 0xFF), it just keeps counting
down until it hits 0 again, and proceeds to fall through to the second
case, and so on.
- Marcel

On 2/15/07, picnoob <spam_OUTleeguy92TakeThisOuTspamgooglemail.com> wrote:
{Quote hidden}

> -

2007\02\15@152011 by PAUL James

picon face

Noob,

An 8 bit register can count from 0 to 255, or in this case from 255 to
0.  So, if you start at 255,
And decrement by 1, you get 254.  Do this again and you get 253.  Do
this 253 more times and you get zero.
Decrement one more time, and you get 255 again, because 255 is the limit
for 8 bits.  You can visualize the
Concept of what is happening by thinking of the idea of borrowing a 1
from the next higher byte.  

The one at the end of the decfsz instruction states to save the result
back into the register that was decremented.   If it was a zero, it
would save the result in the 'w' register.



                                                       Hope this helps,



Regards,

       
Jim




{Original Message removed}

2007\02\15@152446 by Timothy Weber

face picon face
picnoob wrote:
{Quote hidden}

The ",1" is equivalent to ",F" notation, which stores the value back in
memory after decrementing.  The opposite is ",W", which just leaves it
in the W register.

Re: your main question - when you decrement a one-byte value from 0, it
rolls over to 255.  If that seems magical, research binary arithmetic.
--
Timothy J. Weber
http://timothyweber.org

2007\02\15@152446 by Maarten Hofman

face picon face
Redwood Shores, 15 februari 2007.

decfsz first decrements, then checks. So if the value is 0, it first
decrements it, making it 255, and then checks if it is 0, which it isn't. So
it doesn't get its original value, it gets the value 255. The ",1" indicates
that the result of the decrement should be stored in COUNT1 (if you use ,0,
it is instead stored in W).

You should generally avoid using ,1 and ,0 though, instead you should use ,W
(for writing to W) and ,F (for writing to the value itself). The definitions
for W and F can be found in the standard include files, which should be
available in your development environment (if they are not, I recommend
using a different environment).

Greetings,
Maarten Hofman.

2007\02\15@152540 by Vitaliy

flavicon
face
picnoob wrote:

> srry to bother u ppl again with wot is probably a trivial question, but im
> not sure i quite understand the decfsz function.

It's not advisable to use "chat slang", it may get you in trouble here. :)

{Quote hidden}

If COUNT1 is zero (0x00), and you subtract 1 from it, it becomes 255 (0xFF).
Think of the tape recorder counter: which number comes after 000 if you go
backwards?

Vitaliy

2007\02\15@152630 by Herbert Graf

flavicon
face
On Thu, 2007-02-15 at 12:03 -0800, picnoob wrote:
{Quote hidden}

It's always best to "spell out" what the letters stand for: decfsz =
decrement f, skip if z.

So, this opcode does multiple things. First, it will get the value in
the file register you're pointing to (i.e. COUNT1 is a file register).
It will decrement that number by one. Where the result is put depends on
the "1". If that 1 were a zero the result would be put into the "w"
register. However, since it's a one, the result is put back into the
file register (i.e. COUNT1).

Now, aside from decrementing, it also checks if the decrement resulted
in a zero, if it did, it will cause the PIC to skip the next
instruction.

So the way this code works is: initially, COUNT1 and COUNT2 have 255

the "decfsz COUNT1, 1" will decrement COUNT1, and put the result back
into COUNT1.

if the decrement result is not zero, then the "goto Loop1" line is run,
causing another decrement to happen. If the decrement result IS zero,
the "goto Loop1" will be skipped, causing the "decfsz COUNT2,1" line to
be run.

As with the first "decfsz", when the decrement of COUNT2 hits zero, the
goto Loop1 line will be skipped, and you're done.

Lastly, assuming you are referencing code for one of the 8 bit PICs
(i.e. the 16F or 12F parts), remember that each register is only 8 bits.
Therefore, when you decrement something with zero in it, it underflows
and attains the value 255 again.

Hope this helped. TTYL

2007\02\15@153212 by alan smith

picon face
decrement register F, skip the next instruction if the value in F is zero.  Unless you specifically load a new value into the register, it will automagically have 0xFF in it if you decrement it once more (rolls over).  The '1' means the new value will be placed back into the register, putting a '0' places the value into the Wreg.  Might review the instruction set, it talks about how those values affect where the value is loaded, and also issues with bank selects.

picnoob <.....leeguy92KILLspamspam@spam@googlemail.com> wrote:  
srry to bother u ppl again with wot is probably a trivial question, but im
not sure i quite understand the decfsz function.

here is a delay routine i found on the www, that counts to 255, 255 times:


Delay
Loop1 decfsz COUNT1,1 ;reduces COUNT1 by 1
goto Loop1 ;if COUNT1 isnt 0, reduce
it again(im understandin so far)
decfsz COUNT2,1 ;reduce COUNT2 by 1
goto Loop1 ;HUH, WHA?? why are we going
back to loop1, and how has COUNT1 magically ;been brought
back to its initial value?
return

why does the count1 variable not remain 0 once it has been decfsz-ed to 0?
and what does the ",1" do at the end of the decfsz?

this is quite confusing.
--
View this message in context: www.nabble.com/noob-needs-more-help-tf3235793.html#a8992671
Sent from the PIC - [PIC] mailing list archive at Nabble.com.

2007\02\15@153610 by Cris Wilson

flavicon
face
part 1 1050 bytes content-type:text/plain; charset="us-ascii"; format=flowedAt 03:03 PM 2/15/2007, you wrote:

{Quote hidden}

I'm attaching a simple little program that uses pauses and IMHO makes
a little bit
more sense when you try to understand it.



part 2 2897 bytes content-type:text/plain; charset="us-ascii"
; Test program for a PIC 16f628 controlling a 74HC154 multiplexer
; that drives darlington arrays to sink 30V to drive LEDs
; Should be ported to drive HP ink cartridges instead of LEDS
; Pause time routine based on 4MHz crystal
; Program will light up 12 LEDs, one at a time for 10 seconds
; and then cut them off for 10 seconds
;
       list        p=16f628
       radix        hex
;
;CPU equates
;
portb        equ        0x06
ncount        equ        0x20
mcount        equ        0x21
pcount        equ        0x22
;
;Main
;
       org        0x000
       movlw        0x00
       tris        portb                ;set portb as an output
       movlw        b'00010000'        ;cut off 154 enable line
       movwf        portb
       call        pause10                ;ALL LEDs off for 10 seconds
start        movlw        b'00000000'        
       movwf        portb                ;Turn on LED 1
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00000001'
       movwf        portb                ;Turn on LED 2
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00000010'        
       movwf        portb                ;Turn on LED 3
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00000011'
       movwf        portb                ;Turn on LED 4
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00000100'
       movwf        portb                ;Turn on LED 5
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00000101'
       movwf        portb                ;Turn on LED 6
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00000110'
       movwf        portb                ;Turn on LED 7
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00000111'
       movwf        portb                ;Turn on LED 8
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00001000'
       movwf        portb                ;Turn on LED 9
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00001001'
       movwf        portb                ;Turn on LED 10
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00001010'
       movwf        portb                ;Turn on LED 11
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       movlw        b'00001011'
       movwf        portb                ;Turn on LED 12
       call        pause10                ;Keep LED on for 10 seconds
       call        pause10                ;Turn LED off for 10 seconds
       goto        start                ;repeat
;
; 30 second pause procedure based on 4MHz
;
pause30        movlw        0x96
       movwf        pcount
decp30        call        pause
       decfsz        pcount,f
       goto        decp30
       return                        ;End of procedure pause30
;
; 10 second pause procedure based on 4MHz
;
pause10        movlw        0x32
       movwf        pcount
decp10        call        pause
       decfsz        pcount,f
       goto        decp10
       movlw        b'00010000'        ;Turn off the LED
       movwf        portb        
       return                        ;End of procedure pause10
;
; Pause routine takes up about 0.2 seconds with 4MHz
;
pause        movlw        0x00                ;0x00 takes longer than 0xff - weird
       movwf        mcount
loadn        movlw        0x00
       movwf        ncount
decn        decfsz        ncount,f
       goto        decn
       decfsz        mcount,f
       goto        loadn
       return                        ;End of procedure pause
;
       end

part 3 277 bytes content-type:text/plain; charset="us-ascii"; format=flowed
_____________________________________________________________
Cris Wilson
Information Resource Consultant
College of Architecture, Arts, and Humanities
Clemson University
crisspamKILLspamclemson.edu
To report problems email: .....aah_computersKILLspamspam.....clemson.edu




                               

part 4 35 bytes content-type:text/plain; charset="us-ascii"
(decoded 7bit)

2007\02\15@165553 by Jinx

face picon face
noob, do you use MPLAB or something with a Watch window ? If
you don't, you should, or you're going to have problems forever

MPLAB is a free download from Microchip. There are other editors
and simulators that users can tell you about

Single-stepping code and seeing changes in various registers, whilst
referring to the datasheet, is a very practical way to learn

2007\02\15@170405 by PAUL James

picon face
Noob,

One thrid party simulator I can recommend is called "Virtual Breadboard"
It allosw such things as LCD's,
LED's, Logic chips, etc., etc., to be simulated in a graphic format.  It
is almost like looking at a common
Breadboard that you have a circuit setup on.  It's very good, it's
relatively inexpensive (about $50.00 IIRC)
And it's easy to use.   You won't regret getting it if you do.

Regards,   Jim

{Original Message removed}

2007\02\15@180210 by Byron A Jeff

face picon face
On Thu, Feb 15, 2007 at 12:03:43PM -0800, picnoob wrote:
>
> srry to bother u ppl again with wot is probably a trivial question, but im
> not sure i quite understand the decfsz function.

No problem. I would politely ask if you could please spell out your
sentences. It makes it easier to read.

>
> here is a delay routine i found on the www, that counts to 255, 255 times:
>
>
> Delay
> Loop1          decfsz               COUNT1,1 ;reduces COUNT1 by 1

The ,1 is bad karma. The target of the result is either the W register or
the original file register (COUNT1 in this case). While the numbers (0=W,
1=file) work, it makes it quite unreadable. Most code would rewrite as

Loop1   decfsz   COUNT1,F

>                      goto                  Loop1 ;if COUNT1 isnt 0, reduce
> it again(im understandin so far)

That's correct.

>                      decfsz             COUNT2,1 ;reduce COUNT2 by 1

Yes.

>                      goto                 Loop1 ;HUH, WHA?? why are we going
> back to loop1, and how has COUNT1 magically                    ;been brought
> back to its initial value?

Not it's initial value, but down to zero. Note that the loop doesn't make it
past the first goto until COUNT1 decrements to zero. Also note that the
decfsz instruction does the decrement first, then checks for the result being
zero. So this second goto heads back to Loop1 with COUNT1 having a value of
zero. The decfsz decrements the zero back to 255, and the top loop cycles
around for another spin.

> return
>
> why does the count1 variable not remain 0 once it has been decfsz-ed to 0?

Because the decrement is done first. If you decrement zero it wraps around
back to 255. In fact you could start both COUNT1 and COUNT2 with a value of
zero and the loop would loop 256 time for each COUNT1 and 256 times for
COUNT2 (0->255, 255->254..., 1->0, then out).

> and what does the ",1" do at the end of the decfsz?

Explained above. again it's bad Karma.

Hope this helps,

BAJ

2007\02\16@093736 by Alan B. Pearce

face picon face
>srry to bother u ppl again with wot

Umm, we use email here, not text phones ...

>and what does the ",1" do at the end of the decfsz?

Check the data sheet. Note that the assembler will also allow "f" and "w"
instead of "0" and "1".

More... (looser matching)
- Last day of these posts
- In 2007 , 2008 only
- Today
- New search...