Searching \ for ' Beginners 16C84 programming question' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/begin.htm?key=programming
Search entire site for: 'Beginners 16C84 programming question'.

No exact or substring matches. trying for part
PICList Thread
'[PICLIST] Beginners 16C84 programming question'
2002\01\14@190145 by Daryl Sayers

flavicon
face
I had a play with a 16C84 several years ago and I now need to make it do
something. I am a real PIC beginner. My simple programming question is how do
I represent a byte out to the RB port. It seems my restriction is using a
variable in the bsf op code. I manually did it by doing each bit but I am
sure there is a more elegant way of doing it through a loop.
I am using gpasm-0.9.14 alpha to assemble code.

  movlw 0x01
  subwf TmpByte,w
  btfsc STATUS, Z
  bsf   PORTB,0

  movlw 0x02
  subwf TmpByte,w
  btfsc STATUS, Z
  bsf   PORTB,1

......

  movlw 0x80
  subwf TmpByte,w
  btfsc STATUS, Z
  bsf   PORTB,7


--
Daryl Sayers
Corinthian Engineering                         Ph: (02) 9906 7866
Suite 19, 401 Pacific Hwy                     Fax: (02) 9906 1556
Artarmon, NSW, 2064                         email: spam_OUTdarylTakeThisOuTspamci.com.au
Australia                                     www: http://www.cordoors.com.au

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


2002\01\15@163507 by Al Williams

flavicon
face
Do you mean:
  movf TmpByte,w
  movwf PORTB

Al Williams
AWC
* Floating point math for the Stamp, PIC, SX, or any microcontroller
http://www.al-williams.com/awce/pak1.htm



> {Original Message removed}

2002\01\15@163814 by Martin Peach

flavicon
face
----- Original Message -----
From: "Daryl Sayers" <.....darylKILLspamspam@spam@CI.COM.AU>
To: <PICLISTspamKILLspamMITVMA.MIT.EDU>
Sent: Monday, January 14, 2002 6:49 PM
Subject: Beginners 16C84 programming question


> I had a play with a 16C84 several years ago and I now need to make it do
> something. I am a real PIC beginner. My simple programming question is how
do
{Quote hidden}

You sure are taking the long way around! Why not just:
   movf    TmpByte,W
   movwf   PORTB
?
In your code you also fail to reset the port pin if STATUS,Z is 0...
/\/\/\/*=Martin

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2002\01\15@164447 by Andrew Warren

flavicon
face
Daryl Sayers <EraseMEPICLISTspam_OUTspamTakeThisOuTmitvma.mit.edu> wrote:

{Quote hidden}

   Daryl:

       movf  TmpByte,w
       movwf PORTB

   -Andy

=== Andrew Warren -- aiwspamspam_OUTcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2002\01\15@171958 by Daryl Sayers

flavicon
face
I had a play with a 16C84 several years ago and I now need to make it do
something. I am a real PIC beginner. My simple programming question is how do
I represent a byte out to the PORTB of the 84. It seems my restriction is
using a variable in the bsf op code. I manually did it by doing each bit but
I am sure there is a more elegant way of doing it through a loop. I am using
gpasm-0.9.14 alpha (Linux) to assemble my code.

  movlw 0x01
  subwf TmpByte,w
  btfsc STATUS, Z
  bsf   PORTB,0

  movlw 0x02
  subwf TmpByte,w
  btfsc STATUS, Z
  bsf   PORTB,1

......

  movlw 0x80
  subwf TmpByte,w
  btfsc STATUS, Z
  bsf   PORTB,7


--
Daryl Sayers
Corinthian Engineering                         Ph: (02) 9906 7866
Suite 19, 401 Pacific Hwy                     Fax: (02) 9906 1556
Artarmon, NSW, 2064                         email: KILLspamdarylKILLspamspamci.com.au
Australia                                     www: http://www.cordoors.com.au

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2002\01\15@184427 by Byron A Jeff

face picon face
On Tue, Jan 15, 2002 at 10:49:46AM +1100, Daryl Sayers wrote:
> I had a play with a 16C84 several years ago and I now need to make it do
> something. I am a real PIC beginner.

Let me offer a suggestion before you get too involved. Since you've last
taken a look, Microchip has come out with several feature packed inexpensive
parts that are superior to the 16F84. These parts are the 16F628 and the
16F87X family, specifically the 16F872. They have more program memory, more
data memory, more data EEPROM, more periperals including a true hardware USART,
more timers. And the best part is that they are cheaper than the 16F84 or
16F84A. I just Digikey priced singles of the 16F872 for $4.63 and 16F628
singles at $3.88 as compared to $7.38 for the 16F84 and $6.00 for the 16F84A.

I'm sure that you have 16F84 in hand and I'm not necessarily suggesting that
you switch immediately. However these parts are so superior to the 16F84
that once you've started using them, you'll never look back.

Now on to your question....

{Quote hidden}

OK. I've very confused. Your text ask a really simple question. So let's answer
that first. You can send a byte directly to a port, just like any other
register. So unless I completely misunderstand your question the following
code should work just fine:

   movf    TmpByte,W
   movwf   PORTB

The above will transfer the contents of TmpByte to PORTB, which seems to
satisfy the question you asked.

Now on to your code. It's not doing what I think you want to do. It seems
you want to check TmpByte one bit at a time and set the corresponding bit
of PORTB. There are a few problems with your approach:

1) subwf takes account all of the bits of W and TmpByte. So for each section
the 'btfsc STATUS,Z' will be taken unless TmpByte is exactly equal to W. It
seems that a 'andwf  TmpByte,W' will do a better job of isolating the single
bit of interest.

2) You have no code to clear the bit in PORTB when the corresponding bit in
TmpByte is 0.

3) Finally unless TmpByte has exactly one bit set, the code won't do anything
at all. It only has the potential to affect one and exactly one bit of PORTB
and that's only if TmpByte is exactly a power of 2.

If it isn't too much trouble can you come back and explain in more detail
what it is that you need to get accomplished? My feeling is that you are
taking a very convoluted route to do something simple.

Let us know,

BAJ

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2002\01\15@224806 by David Duffy

flavicon
face
At 09:17 AM 16/01/2002 +1100, you wrote:
{Quote hidden}

What is the intended result? I don't quite get what you're trying to do.
Where does TmpByte come into it?
Regards...

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2002\01\16@072441 by Peter Onion

flavicon
face
On 15-Jan-02 Daryl Sayers wrote:
> I had a play with a 16C84 several years ago and I now need to make it do
> something. I am a real PIC beginner. My simple programming question is how do
> I represent a byte out to the PORTB of the 84. It seems my restriction is
> using a variable in the bsf op code. I manually did it by doing each bit but
> I am sure there is a more elegant way of doing it through a loop. I am using
> gpasm-0.9.14 alpha (Linux) to assemble my code.


I think you want

movf    TmpByte,W
movwf   PORTB

But your code only sets bits in PORTB when the matching bit in TmpByte is a 1,
so you code actually does the same as this...

movwf   TmpByte,W
iorwf   PORTB

which I don't think is what you want.

Can I suggest you spend some time reading some of the tutorials listed on
http://www.piclist.com/techref/piclist/begin.htm

Peter

{Quote hidden}

----------------------------------
E-Mail: Peter Onion <EraseMEponionspamsrd.bt.co.uk>
Date: 16-Jan-02
Time: 12:15:23

This message was sent by XFMail
----------------------------------

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestEraseMEspamEraseMEmitvma.mit.edu


2002\01\16@075013 by Fabio Pereira

flavicon
face
----- Original Message -----
From: "Daryl Sayers" <RemoveMEdarylspam_OUTspamKILLspamCI.COM.AU>
To: <RemoveMEPICLISTTakeThisOuTspamspamMITVMA.MIT.EDU>
Sent: Monday, January 14, 2002 8:49 PM
Subject: Beginners 16C84 programming question


> I had a play with a 16C84 several years ago and I now need to make it do
> something. I am a real PIC beginner. My simple programming question is how
do
> I represent a byte out to the RB port. It seems my restriction is using a
> variable in the bsf op code. I manually did it by doing each bit but I am
> sure there is a more elegant way of doing it through a loop.
> I am using gpasm-0.9.14 alpha to assemble code.
>
What about a MOVWF PORTB instruction ???

Fabio

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspamspamspamBeGonemitvma.mit.edu


2002\01\16@161919 by Daryl Sayers

flavicon
face
Sorry for not explaining my question correctly. What I REALLY wanted was
to express the data between 0-7 as bit location to turn on.

eg: if the data was 0x03 then I would turn on bit 3 of port B.

The code snippet I gave showed this but my question was incorrect. I have
since tried a few ideas and have come up with the following. I hope its not
too repulsive.

       ...
       CALL    Setport
       RETURN

Setport
       BCF     STATUS, C
       RLF     DataByte, w
       ANDLW   0fh
       addwf   PCL,f
       bsf     PORTB,0
       RETURN
       bsf     PORTB,1
       RETURN
       bsf     PORTB,2
       RETURN
       bsf     PORTB,3
       RETURN
       bsf     PORTB,4
       RETURN
       bsf     PORTB,5
       RETURN
       bsf     PORTB,6
       RETURN
       bsf     PORTB,7
       RETURN


{Quote hidden}

>> {Original Message removed}

2002\01\16@163718 by Al Williams

flavicon
face
One thing you could do is use the RETLW instruction:

 Call SetPortLookup
 Iorwf portimage,f
 Movf portimage,w
 Movwf portb
. . .

SetPortLookup:
 Andlw 7    ; bit #s from 0 to 7 only
 Addwf PCL,F
 Retlw 1
 Retlw 2
 Retlw 4
 Retlw 8
 Retlw .16
 Retlw .32
 Retlw .64
 Retlw .128

A few notes:

.64 is decimal no matter what radix you are using by default.

I modified a variable rather than the port directly because of possible
problems with using read modify write instructions with a port. I try to
always write to a fake port register and then output the register
directly. Otherwise you could have said:

Iorwf portb,f

You can read more about this problem in the data sheet.

Also, you might enjoy http://www.al-williams.com/pictutor

Good luck!

Al Williams
AWC
* Easy RS-232 Prototyping
http://www.al-williams.com/awce/rs1.htm

> {Original Message removed}

2002\01\16@165916 by Bob Ammerman

picon face
Your code isn't too bad.

You could eliminate the BCF STATUS,C instruction and change the ANDLW to
ANDLW 0Eh.

This is a bit shorter:

; Call this with the bit number in W

set_bit_in_portb:
   call    getmask
   iorwf portb,f
   return

getmask:
   andlw   7            ; extract bit number
   addwf    pcl,f        ; assumes page bits/pclath set properly and table
fits in page
   retlw    1
   retlw    2
   retlw    4
   retlw    8
   retlw    16
   retlw    32
   retlw    64
   retlw    128

What is real cool is you can also create:

clr_bit_in_port_b:
   call    getmask
   xorlw    0FFh
   andwf    portb,f
   return

and:

toggle_bit_in_port_b:
   call    getmask
   xorwf    portb,f
   return

Bob Ammerman
RAm Systems


----- Original Message -----
From: "Daryl Sayers" <RemoveMEdarylKILLspamspamCI.COM.AU>
To: <PICLISTSTOPspamspamspam_OUTMITVMA.MIT.EDU>
Sent: Wednesday, January 16, 2002 1:16 PM
Subject: Re: Beginners 16C84 programming question


> Sorry for not explaining my question correctly. What I REALLY wanted was
> to express the data between 0-7 as bit location to turn on.
>
> eg: if the data was 0x03 then I would turn on bit 3 of port B.
>
> The code snippet I gave showed this but my question was incorrect. I have
> since tried a few ideas and have come up with the following. I hope its
not
{Quote hidden}

> >> {Original Message removed}

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