Searching \ for 'Help beginner programmer' 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/devprogs.htm?key=programmer
Search entire site for: 'Help beginner programmer'.

Truncated match.
PICList Thread
'Help beginner programmer'
1999\12\26@233612 by Brian Gracia

flavicon
face
Hello,

I just started to learn Pic programming.  Can someone comment on my coments
about this program?

org     0

clrf   PORTB                   ; Clear all the bits in PortB
This line clears PORTB to all 0's right?

bsf    STATUS, RP0             ; Goto bank 1 to set port direction
This switches to bank 1

bcf    TRISB & 0x07f, 0        ; Set bit 0 to output
Here is where I have trouble.  If I understand this correctly,  this should
take 00000000 and (and) it
with 01111111.  Am I right?

bcf    STATUS, RP0             ; Go back to bank 0
It then switches back to bank 0.
Finished
Goto   $

end

Another thing I want to know is how can you clear PortB if you don't switch
banks first?  I mean according to Mykes book,  which is where I copied this
program from, the above code says it is ok to clear PortB, but to set the
I/O direction, you need to switch banks first.

TIA,
Brian
********************************************
Better Produce through Better Control
********************************************

1999\12\27@000655 by quozl

flavicon
face
On Sun, Dec 26, 1999 at 10:26:33PM -0600, Brian Gracia wrote:
> I just started to learn Pic programming.  Can someone comment on my coments
> about this program?

Which processor are you writing for?  I'll assume a PIC 16F84.

> org     0

That's good.

>  clrf   PORTB                   ; Clear all the bits in PortB
>  This line clears PORTB to all 0's right?

It clears the port latch.  The effect so far will be nothing, since
the ports start out in input state.

>  bsf    STATUS, RP0             ; Goto bank 1 to set port direction
> This switches to bank 1

Yep, not really worth the effort though.

>  bcf    TRISB & 0x07f, 0        ; Set bit 0 to output
> Here is where I have trouble.  If I understand this correctly,  this should
> take 00000000 and (and) it
> with 01111111.  Am I right?

Yes.  But why are you doing this?  Why not just "TRIS PORTB", that way
you don't have to stuff around with bank switching or masking.  Anyway,
masking is probably not worth the effort either, unless you have an
assembler that complains.  Which assembler?

> Another thing I want to know is how can you clear PortB if you don't switch
> banks first?  I mean according to Mykes book,  which is where I copied this
> program from, the above code says it is ok to clear PortB, but to set the
> I/O direction, you need to switch banks first.

Use TRIS instruction if on 16F84.

Did you try this program?  Did it work?

--
James Cameron   spam_OUTquozlTakeThisOuTspamus.netrek.org   http://quozl.us.netrek.org/

1999\12\27@111151 by Ken Webster

flavicon
face
>Hello,
>
>I just started to learn Pic programming.  Can someone comment on my coments
>about this program?
>
>org     0
>
> clrf   PORTB                   ; Clear all the bits in PortB
> This line clears PORTB to all 0's right?

Correct.

> bsf    STATUS, RP0             ; Goto bank 1 to set port direction
>This switches to bank 1


Correct.

> bcf    TRISB & 0x07f, 0        ; Set bit 0 to output
>Here is where I have trouble.  If I understand this correctly,  this should
>take 00000000 and (and) it
>with 01111111.  Am I right?


There are 2 operands to the BCF instruction.  The first one (in this case
"TRISB & 0x07f") specifies the address of the register to operate on.  The
second one (in this case 0) specifies which bit to clear.  This instruction
therefore clears bit 0 of the TRISB register.

The "& 0x07f" part merely makes the address smaller than 0x80 by masking off
the highest bit.  This prevents warning messages from some assemblers (but
otherwise serves no purpose and has no effect on the code produced).  The
warning messages that would be produced merely remind you to be sure you
have the bank select bits correctly set because the address is in the high
(non-default) bank.


> bcf    STATUS, RP0             ; Go back to bank 0
>It then switches back to bank 0.

Correct.

>Finished
> Goto   $
>
> end
>
>Another thing I want to know is how can you clear PortB if you don't switch
>banks first?  I mean according to Mykes book,  which is where I copied this

The RP0 bit of the STATUS register is cleared upon reset.  Thus, when your
code first starts up, you can count on the RP0 bit being 0.


>program from, the above code says it is ok to clear PortB, but to set the
>I/O direction, you need to switch banks first.
>
>TIA,
>Brian
>********************************************
>Better Produce through Better Control
>********************************************


Hope this helps,

Ken

1999\12\27@161725 by Agnes en Henk Tobbe

flavicon
face
> bcf    TRISB & 0x07f, 0        ; Set bit 0 to output
>Here is where I have trouble.  If I understand this correctly,  this should
>take 00000000 and (and) it
>with 01111111.  Am I right?
>

Adding to the comments others make:
Unless there is a specific reason to use a more complex way I always use the
model:
   decide which ports to set for input and for output
   load the set of "0" ad "1" as a byte in the port-register
   for instance :  movlw    b'11111110'    ; set all ports of PORTB to
input except PORTB,0
                           movwf    TRISB

By using the binary notation you are able to see the state of the ports at a
glance.

The other suggestion by some of the others (have not seen your remarks Paul
B. ;-) is to use the TRIS instruction. That way you do NOT need to switch
banks by setting and clearing the STATUS register. However this generates a
warning by the compiler (using MPLAB) because Microchip - for no sensible
reasons - frowns on this practice. Let this not scare you off this space
saving practice.

VK2GWK - HENK
Home page: http://www.users.bigpond.com/tobbe/index.htm

1999\12\27@213228 by Brian Gracia

flavicon
face
Hello,

I just started to learn Pic programming.  Can someone comment on my coments
about this program?

org     0

clrf    PORTB                   ; Clear all the bits in PortB
This line clears PORTB to all 0's right?

bsf     STATUS, RP0             ; Goto bank 1 to set port direction
This switches to bank 1

bcf     TRISB & 0x07f, 0        ; Set bit 0 to output
Here is where I have trouble.  If I understand this correctly,  this should
take 00000000 and (and) it
with 01111111.  Am I right?

bcf     STATUS, RP0             ; Go back to bank 0
It then switches back to bank 0.
Finished
Goto    $

end

Another thing I want to know is how can you clear PortB if you don't switch
banks first?  I mean according to Mykes book,  which is where I copied this
program from, the above code says it is ok to clear PortB, but to set the
I/O direction, you need to switch banks first.

TIA,
Brian
********************************************
Better Produce through Better Control
********************************************

1999\12\28@011805 by paulb

flavicon
face
Henk Tobbe wrote:

> have not seen your remarks Paul B. ;-)

 I'm shocked!

> However this generates a warning by the compiler (using MPLAB) because
> Microchip - for no sensible reasons - frowns on this practice.

 That's a very concise way of putting it!

> Let this not scare you off this space saving practice.

 Easily fixed.  Just edit the line " ERRORLEVEL -224" into the .INC
files in MPASM for all 14-bit devices - 16C/F84, 16C6x, 16C6xx, 16C7x,
16C7xx, 16F87x and so on.  (Make sure they are still there after
upgrading).
--
 Cheers,
       Paul B.

1999\12\28@072609 by Jim Robertson

flavicon
face
At 20:30 27/12/99 -0600, you wrote:
>Hello,
>
>I just started to learn Pic programming.  Can someone comment on my coments
>about this program?
>
>org     0
>
>clrf    PORTB                   ; Clear all the bits in PortB
>This line clears PORTB to all 0's right?
>
>bsf     STATUS, RP0             ; Goto bank 1 to set port direction
>This switches to bank 1
>
>bcf     TRISB & 0x07f, 0        ; Set bit 0 to output
>Here is where I have trouble.  If I understand this correctly,  this should
>take 00000000 and (and) it
>with 01111111.  Am I right?

No, it takes the address of TRISB (86h) and ANDs this with 7Fh to give the
result of 06h. This is the address of the PORTB i/o register in fact. The
setting of RP0 in the status reg provides bit-7 of the TRISB address. The
,0 specifies the I/O bit and has nothing to do with the ANDing operation.

So:

bsf     STATUS, RP0             ; Goto bank 1 to set port direction
bcf     TRISB & 0x07f, 0        ; Set bit 0 to output
bcf     STATUS, RP0             ; Go back to bank 0

Is the same to the PIC assembler as:

bsf     STATUS, RP0             ; Goto bank 1 to set port direction
bcf     PORTB, 0              ; Set bit 0 to output
bcf     STATUS, RP0             ; Go back to bank 0

But which is easier for the poor old Human to read and tells YOU exactly what
the code is doing?

BTW, We are only making bit-0 an output in the above example. The other
Data direction Bits are not changed.

Jim


{Quote hidden}

Regards,

Jim Robertson
NEWFOUND ELECTRONICS
________________________________________
Email: .....newfoundKILLspamspam@spam@pipeline.com.au
http://www.new-elect.com
MPLAB compatible PIC programmers.
________________________________________

1999\12\28@212929 by Myke Predko

flavicon
face
Hi Brian,

Quick reply to your questions.

The application looks good, the only comment I have is on the statement:

> bcf     TRISB & 0x07f, 0        ; Set bit 0 to output
> Here is where I have trouble.  If I understand this correctly,  this
should
> take 00000000 and (and) it
> with 01111111.  Am I right?

Most people would consider this to be 11111110, with bit 0 being on the
right.

Other than that (and it's a nit), the code looks good.

> Another thing I want to know is how can you clear PortB if you don't
switch
> banks first?  I mean according to Mykes book,  which is where I copied
this
> program from, the above code says it is ok to clear PortB, but to set the
> I/O direction, you need to switch banks first.

If you write directly to the Port register, the new value will be saved even
though the port bits are in input mode.  Once the Port register bits are put
into output mode, then the values written to them will be driven out of the
pins.

Does this help explain it?

myke

1999\12\28@213951 by Jim Paul

flavicon
face
Myke,

How's the peepers coming along?   All is well I hope.
I also hope the Christmas season so far has been
good to you and your family.

                                                   Regards,

                                                       Jim
{Original Message removed}

1999\12\29@105357 by Jurva-Markus Vehasmaa

flavicon
face
At 20:30 27.12.1999 -0600, you wrote:
>Hello,
>
>I just started to learn Pic programming.  Can someone comment on my coments
>about this program?
>
>org     0
>
>clrf    PORTB
>bsf     STATUS, RP0

>bcf     TRISB & 0x07f, 0        ; Set bit 0 to output
>Here is where I have trouble.  If I understand this correctly,  this should
>take 00000000 and (and) it
>with 01111111.  Am I right?

What are you trying to do here? Set RB0 as output?
Why do need to and register address to $7f ? No need to my nolidge.
Simply would need only to do
       bcf TRISB,0     to set RB0 as output.

>
>bcf     STATUS, RP0
>Goto    $
>end

>Another thing I want to know is how can you clear PortB if you don't switch
>banks first?  I mean according to Mykes book,  which is where I copied this
>program from, the above code says it is ok to clear PortB, but to set the
>I/O direction, you need to switch banks first.

Thats true.

You can always clear portb and porta whitout changing bank. Direction
registers how ever are loccated in bank 1 and there fore need to change
bank when need to change directions.

J.M. Vehasmaa
Name: Jurva-Markus Vehasmaa
Email: vehasmaaspamKILLspamdlc.fi
Homepage: http://www.saunalahti.fi/vehasmaa/
--------------------------
Resist Microsoft monopoly,
install Linux challenger.

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