Searching \ for '[PIC]: Problem with first 16F877 test program' 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=16F
Search entire site for: 'Problem with first 16F877 test program'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Problem with first 16F877 test program'
2003\02\01@125019 by Joe Farr

flavicon
face
Hi All, I'm new to PICs and am trying to "port" my Z80 assembler skills to
something that belongs in this century but am having problems with my
test program.
Here it is:
           LIST p=16f877,c=140
       include "p16f877.inc"
 org        0
clrf        STATUS
goto      BootStart
org        4
ISR     goto        5                      ; Setup Interupt Address
org        5
BootStart  clrf        PORTB
            bsf        STATUS,RP0    ; set Page 1 for TRIS registers
           movlw   b'00000000'
           movwf   TRISB           ; set PORTB for all outputs
            bcf        STATUS,RP0    ; back to page 0
LoopAgain
       ;movlw   0x00
       ;movwf   PORTB           ; All PORTB bits off
       ;movlw   0xFF
       ;movwf   PORTB           ; All PORTB bits on
        incf    W, 0                  ; W = W + 1
       movwf   PORTB           ; PORTB = W
       goto    LoopAgain
        end
 Now I thought that 'incf W, 0' would perform a W=W+1 operation, and that
when it reached 255, it would simply start from 0 (since it's an 8-bit
register), but this doesn't seem to be the case.
If I use the 4 commented lines instead of the 3 lower ones, then I get a
nice square wave on all 8 I/O pins, so I know the PIC is working and
that my programmer is ok etc.
All I expect the above test program to do is count in binary flashing 8
LEDs....
So what stupid thing am I doing wrong...
Any help much appreciated,
Joe

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@131230 by Olin Lathrop

face picon face
> I'm new to PICs and am trying to "port" my Z80 assembler skills to
> ...
> So what stupid thing am I doing wrong...

Using quoted printable encoding, which makes it a hassle to reply to your
message.  I read your message and was going to point out several things,
but the reply window came up without the "> " in front of your lines so I
gave up.  Resend using PLAIN TEXT and I'll show you a few problems I saw,
including one major misconception on your part.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@133323 by John De Villiers

flavicon
face
On Sat, 2003-02-01 at 19:39, Joe Farr wrote:
> Hi All,
>         incf    W, 0                  ; W = W + 1

incf increments an F register, not W, unless W on the 16F877 is an F
register. Dunno, havent had the need for those chips yet.

--
John De Villiers <spam_OUTbbjTakeThisOuTspamplz.co.za>

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@135403 by Tan Chun Chiek

flavicon
face
and you could use

       addlw B'1'

in place of

       incf    W, 0

regards,
Tan CC
----- Original Message -----
From: "John De Villiers" <.....bbjKILLspamspam@spam@PLZ.CO.ZA>
To: <PICLISTspamKILLspamMITVMA.MIT.EDU>
Sent: Sunday, February 02, 2003 2:31 AM
Subject: Re: [PIC]: Problem with first 16F877 test program


{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@170732 by Joe Farr

flavicon
face
Thanks Tan,
that did the trick.

What I don't understand is why the assembler didn't throw an error if incf W,0 isn't allowed.

Oh well..


-----Original Message-----
From: Tan Chun Chiek [EraseMEcodespam_OUTspamTakeThisOuTMXHUB.NET] Sent: 01 February 2003 18:52
To: PICLISTspamspam_OUTMITVMA.MIT.EDU
Subject: Re: [PIC]: Problem with first 16F877 test program

and you could use

       addlw B'1'

in place of

       incf    W, 0

regards,
Tan CC

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@170743 by Jinx

face picon face
>         INCF    PORTB, F        ; Race the PORT B.

Manipulating the port directly "could" cause read-modify-write
problems. Better to use a shadow register

           incf   shadow,f
           movf shadow,w
           movwf  portb

The reason is that the instruction reads the register, modifies it,
then writes the result back to the register. Port pins are a special
case for r-m-w because the read looks at the level on the pin, but
the write addresses the output latch. That's why it's recommended
to have an intervening instruction between bit-setting instructions to
the same port to give the pin time to follow the level in the latch.
Factors such as pin load and clock speed come into it, but it's
reasonably safe to use just one intervening instruction

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@171351 by Wouter van Ooijen

face picon face
> What I don't understand is why the assembler didn't throw an error if
> incf W,0 isn't allowed.

Because W is just #define W 0, so you just specified incf 0,0 which is
perfectly valid. One more reason to use a propper HLL, even when it is
only to write asm: in Jal inline assembly incf w,0 would not be allowed,
unless of course w was defined as a variable. Guess the same holds for
asm in other compilers?

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@171811 by Herbert Graf

flavicon
face
> What I don't understand is why the assembler didn't throw an error if
> incf W,0 isn't allowed.

       Where does it say it ISN'T allowed? It is certainly allowed, it just
doesn't do what you expect. incf W, 0 will assemble without issue. The
reason is 'W' is simply a constant while assembling, the preprocessor simply
replaces 'W' with it's numerical value (0 IIRC), so the assembler actually
sees: incf 0, 0, a perfectly valid opcode. Now, you could say that Microchip
could have added something in the assembler to catch these sorts of things.
The problem is that is a slippery slope for them, where does the "babying"
end? TTYL

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@172701 by Dwayne Reid

flavicon
face
At 05:39 PM 2/1/03 +0000, Joe Farr wrote:
>
>         incf    W, 0                  ; W = W + 1

Use addlw 1 instead of the above.

I have macros called 'incw' and 'decw' that do this for the 14 bit
PICs.  They do not work on the 12 bit core PICs.

dwayne

--
Dwayne Reid   <@spam@dwaynerKILLspamspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 18 years of Engineering Innovation (1984 - 2002)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@183721 by cdb

flavicon
face
On Sat, 1 Feb 2003 13:08:55 -0500, Olin Lathrop wrote:
> I'm new to PICs and am trying to "port" my Z80 assembler skills to
> ...
> So what stupid thing am I doing wrong...

Using quoted printable encoding, which makes it a hassle to reply to
your
message.  I read your message and was going to point out several
things,
but the reply window came up without the "> " in front of your lines
so I
gave up.  Resend using PLAIN TEXT and I'll show you a few problems I
saw,
including one major misconception on your part.

This is how Mr Lathrops message arrived.
Note Mr L that your email client automatically put "> " in front of your quote. Note also that mine does not and if when you receive it it has then it is your client that is inserting them.
CDB
-- cdb, KILLspambodgy1KILLspamspamoptusnet.com.au on 02/02/2003

I have always been a few Dendrites short of an Axon and believe me it shows.

Light travels faster than sound. That's why some people appear bright until they speak!

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\02@114842 by Olin Lathrop

face picon face
> Note Mr L that your email client automatically put "> " in
> front of your quote.

Actually it didn't.  I had to put them there manually, like the two lines
above.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\03@045311 by Alan B. Pearce

face picon face
>         incf    W, 0                  ; W = W + 1

The other thing that I have not yet seen explained to you, and would have
helped you catch this error. Use W and F as the destinations of these
mnemonics, instead of using 0 and 1. This is the purpose for which W and F
are defined.

Your code would then have looked like this

        incf    W, W                  ; W = W + 1

which should have flagged an error in your mind, as you have used the W in
two places in the same instruction.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

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