Searching \ for '[PIC]: How to test multiply bits ?' 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/math/index.htm?key=multiply
Search entire site for: 'How to test multiply bits ?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: How to test multiply bits ?'
2001\10\15@164004 by Lasse Madsen

flavicon
face
Hey all

I would like to test 4 bits on Portb (which are set to input) and compare them with preset values for instance

i would like to test RB0,1,2,3 agains 0000 and if its 0000 then goto xxxx if not check if RBxxx is 0001 then goto zzz

In short .. i would like to check these bits almost simultaniously where for example and the 4 bits are RB0,1,2,3
0000 = goto a 0001 = goto b
0010 = goto c ....

can this be done ?
best regards
lasse madsen

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


2001\10\15@174732 by Joris van den Heuvel

flavicon
face
Hi,

You could set up a table, like this:

   movlw   high tb       ;set page
   movwf   PCLATH
   movf    PORTB,W       ;get port B input
   andlw   15
tb  addwf   PCL,F         ;jump table
   goto    target0000
   goto    target0001
   goto    target0010
   .......
   goto    target1110
   goto    target1111

Is this what you had in mind?

Regards,
Joris.


{Original Message removed}

2001\10\15@175402 by Herbert Graf

flavicon
face
One way I can think of is to mask off the upper four bits (with an AND) and
then do multiple sublw's and btfsc's on the Z bit of the status register.
Not perhaps the most elegant or efficient way of doing it, but it works.
TTYL

> {Original Message removed}

2001\10\16@172507 by Lasse Madsen

flavicon
face
Hi again !

Thanks for the reply and sample code !

I would like to start out by telling about my assembler experience - i have
read and understood Easy PIC'n by david benson and played alot around (so
far sucessfully) thats all

I cant seem to find some of the instructions you use in my list:

These are: PCL , PCLATH

As far as i understand from the PIC memory map the PCLATH is some kind of
address table which (please correct me if im wrong - which i probertly am)
is a better way of writing Tris right ?

PCL now thats more tricky because i cant seem to find any reference to this
command anywhere


Im most sorry that i didnt specify that the Target PIC is a 12C509A this is
ofcause a vital information.
but how ever if the code cant be executed on the target please let me know
as the 16C54 would be fine also.

Im not totally sure about your code, lets assume again that the target is
the 12C509A and i initialize it as is:

portb equ 0x06
org 0x000
start  movlw b'111100'
tris portb

As we can see the we have the 4 input ports assigned and 2 output ports.

As im not totally aware of the functions of your code i "allow" my self to
ask these stupid questions:

movlw   high tb       ; doesnt "high" or "tb" need to be assigned as an
equate some where or is this some kind of special assembler command ?

movwf   PCLATH
movf    PORTB,W       ; Will this work when theres output ports assigned on
portb also ?

andlw   15    ; this i understand :)
tb  addwf   PCL,F         ; But ! which bits are MSB and LSB ???  - sorry
for asking stupid !

goto    target0000 ; this i understand :)
...

I thank you alot for the code you wrote and hope that you will help me get
on with assembler.

Best regards
Lasse Madsen

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


2001\10\17@040212 by Vasile Surducan

flavicon
face
On Tue, 16 Oct 2001, Lasse Madsen wrote:

>
> I cant seem to find some of the instructions you use in my list:
>
> These are: PCL , PCLATH
>
> As far as i understand from the PIC memory map the PCLATH is some kind of
> address table which (please correct me if im wrong - which i probertly am)
> is a better way of writing Tris right ?
>
> PCL now thats more tricky because i cant seem to find any reference to this
> command anywhere

Lasse, PCL is not a command, is a register which address is 02h in bank0
or 81h in bank1 and so on, it have various addresses in four banks
microcontrollers. You may see it in any "Memory organisation" chapter for
any PIC microcontroller.
About what is PCL and PCLATH you may read in any PIC data sheet at chapter
"PCL and PCLATH"


{Quote hidden}

 The code above is the standard way of reading table read by adding
offsets. It's the same used in Jal in pragma_jump_table.
Take a look. Take a look also at piclist at table read section.
( better: do a copy of all intersting stuff you will find here and search
in before asking something, you'll find almost anything you need, don't
forget to say thanks to James Newton )

Vasile

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


2001\10\17@090853 by 742-9014

face picon face
> I cant seem to find some of the instructions you use in my list:
>
> These are: PCL , PCLATH

These are registers not instruction.  They are well described in the data
sheet.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

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


2001\10\18@175215 by Lasse Madsen

flavicon
face
part 1 653 bytes content-type:text/plain; (decoded 7bit)

Hi all

Im still experimenting with the PCLATH register but i cant seem to get it to
work :o(
What im trying to do is take input on portb and put it on porta. (just to
try something)

Im not sure if i wrote everything right and if i have choosen the right
registers.
anyway the code doesnt work and its driving me nuts.

What i want to do first is Take input from 3 buttons connected to RB0,1,2
and display this on RA1,2,3

RB0 ... RB3 ,  = , RA0 ... RA2
000 = 000
001 = 001
010 = 010
011 = 011
100 = 100
101 = 101
110 = 110
111 = 111

The code is attached.

Many thanks for supporting !

Best regards
Lasse Madsen




part 2 1721 bytes content-type:application/octet-stream; (decode)

part 3 105 bytes
--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2001\10\18@181714 by Andrew Warren

flavicon
face
Lasse Madsen <EraseMEPICLISTspam_OUTspamTakeThisOuTmitvma.mit.edu> wrote:

> Im still experimenting with the PCLATH register but i cant seem to
> get it to work :o( What im trying to do is take input on portb and
> put it on porta. (just to try something)
>
> Im not sure if i wrote everything right and if i have choosen the
> right registers. anyway the code doesnt work and its driving me
> nuts.

Lasse:

It doesn't work because you're ANDing W with 15 just before the ADDWF
PCL; you SHOULD be ANDing it with 7.

-Andrew


=== 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 hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\10\18@183801 by Joris van den Heuvel

flavicon
face
Lasse,

I think you want too much. First of all, you should use the .INC file
Microchip supplies with their MPASM. This file includes all register names
and their addresses so you don't have to use memory locations but instead
you can just type in the name of the register. In order to use PCLATH and
PCL you have to EQU these first. the P16F84A.INC file that comes with MPASM
does this for you. Take a look at an assembler listing from a more
experienced programmer (like myself) and learn from it. See how you can
include files into the listing and how to use the registers.

Second, you pasted the code I posted a few days ago right into your program
(don't get me wrong, you can of course use it) but the alignment is off so
the instructions are not 8 spaces from the sideline. This should have
generated a large list of errors (not shure though!).

See further comments below.

Joris.



{Original Message removed}

2001\10\18@183809 by Byron A Jeff

face picon face
On Thu, Oct 18, 2001 at 11:50:11PM +0200, Lasse Madsen wrote:
> Hi all
>
> Im still experimenting with the PCLATH register but i cant seem to get it to
> work :o(

Tell us what's going on with it.

> What im trying to do is take input on portb and put it on porta. (just to
> try something)

This is not a good design problem for what you are trying to learn. PCLATH
has very little to do with the problem you're trying to solve.

So let me throw out a real world problem that is directly impacted by it:

For your LCD display you would like to be able to write one of several dozen
fixed messages, represented as NULL terminated strings. Because the total
length of all the messages is more than 256 bytes, the message address is
represented by two bytes, strhi and strlo. Write a routine that will transfer
successive bytes of a message to PORTB until a NULL is reached. Note that
the messages must be stored in the program memory of the PIC and you cannot
assume that you can read the program memory directly so that you can run this
routine on parts like the 16F628.

Now this problem cannot be solved without understanding how PCLATH works.
Go take a stab at it. Once you solve it, you'll have a very useful routine
and a clearer understanding of how PCLATH works. Just remember the rule of
thumb:

PCLATH is transferred to PCH whenever PCL is directly written.

Hope this helps,

P.S. On your original code, you could have problems with successive bit sets
or clears on an I/O port. Because of the way that ports are set up, a write
immediately followed by a read may not transfer all of the bits correctly.
Conventional wisdom is to put at least one instruction, possible even a NOP,
between successive bit operations on the same port.

BAJ

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


2001\10\18@185508 by Bob Barr

picon face
Andrew Warren wrote:
>
>It doesn't work because you're ANDing W with 15 just before the ADDWF
>PCL; you SHOULD be ANDing it with 7.
>

Andrew:

True, the (presumably unconnected) RB3 would be adding a value 8 locations
farther than expected. Voila, instant 'goto garbage' instruction. Grounding
RB3 should 'fix' it though. :=)

Lasse:

Assuming that you're using MPLAB, you might want to take a look at file
'p16f84.inc'. It has all of the register definitions and will save you a bit
of typing. Just add the line "include 'p16f84.inc'" near the beginning of
your file. Using it will also force a consistency in style since all of the
registers in your code will need to be in upper case. (It uses 'PORTA' vs.
your 'porta')

This short program will leave PCLATH set at 0 (its reset value). PCLATH only
needs to be set when the code is above location 0xFF. I believe that the
label 'tb' needs to be on the first location in the table, not on the addwf
PCL instruction. [Flame away if I've gotten this wrong, folks.]

It's not generally a good practice to do successive bcf/bsf on port pins
without allowing some time between them. The first bcf/bsf changes the state
of the bit during the last clock cycle of its operation. The following
bcf/bsf reads that pin during its first clock cycle. Writing and reading
back that quickly can cause the pin to be read back incorrectly. (You can
check the archives for 'read-modify-write' for further information. I'm sure
that everybody's been bitten by this one.)

Regards, Bob

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

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


2001\10\18@232120 by Paul15583396818

picon face

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


2001\10\19@104802 by Lasse Madsen

flavicon
face
> I think you want too much. First of all, you should use the .INC file
> Microchip supplies with their MPASM. This file includes all register names
> and their addresses so you don't have to use memory locations but instead
> you can just type in the name of the register. In order to use PCLATH and
> PCL you have to EQU these first. the P16F84A.INC file that comes with
MPASM
> does this for you.

Thanks for pointing this out ! - I wasnt aware of this include file.

> Take a look at an assembler listing from a more
> experienced programmer (like myself) and learn from it. See how you can
> include files into the listing and how to use the registers.

I'll pay more attention to code being written exept that you guys operate on
a hole different level than me. So its a bit difficult to understand the
code that you write please cope with me as i have only read the Easy Pic'N
which i thourght was pretty good - unfortunetly i cant afford the next book
in the series so im kind of stuck on this "knowleadge level"

> Second, you pasted the code I posted a few days ago right into your
program
> (don't get me wrong, you can of course use it) but the alignment is off so
> the instructions are not 8 spaces from the sideline. This should have
> generated a large list of errors (not shure though!).

I used the code you posted because im not as experienced as you. And before
i started to rewrite (modifiy) something i would like to make sure that the
code works first and your code posting seemed like the "sure thing".

> What im trying to do is take input on portb and put it on porta. (just to
> try something)
>This is not a good design problem for what you are trying to learn. PCLATH
>has very little to do with the problem you're trying to solve.

I suggested this example because this i could "easily" show in the means of
code

What i want to do when the code is working is to take parallel inputs and
according to the input select a specific subroutine which pulses a led or
something ...

Thanks for the good advices !

Best Regards
Lasse Madsen

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


2001\10\19@130551 by Lasse Madsen

flavicon
face
Hi Guys

I would like to thank you all for helping me with this !

The code works wonderful - thanks to you :o)

Just a last question and i will leave you all alone for now.

How did you come to the conclution that the value 7 had to be AND with W ?
Is there a formular for this or is this some- mega advanced "you dont wanna
know" outrageous procedure which requires a degree in hardware archetecture
to understand because if it is
i think i will satisfy my self with the answer that: 7 was a "good number"
:o)

Thanks for helping me !
I really appriciate the afford that you guys put in to it, I hope that i
will be able to help someone else at another ocation.

Best Regards
Lasse Madsen

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


2001\10\19@134731 by Ned Konz

flavicon
face
On Friday 19 October 2001 09:58 am, Lasse Madsen wrote:

> How did you come to the conclution that the value 7 had to be AND with W ?

If you're reading the three lowest bits of a port, you need to AND with
binary 00000111 which is 7.

By ANDing with 15, you're looking at the lowest 4 bits of the port.

--
Ned Konz
currently: Stanwood, WA
email:     TakeThisOuTnedEraseMEspamspam_OUTbike-nomad.com
homepage:  http://bike-nomad.com

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


2001\10\19@135807 by Bob Barr

picon face
Lasse Madsen wrote:
>
>How did you come to the conclution that the value 7 had to be AND with W ?
>Is there a formular for this or is this some- mega advanced "you dont wanna
>know" outrageous procedure which requires a degree in hardware archetecture
>to understand because if it is
>i think i will satisfy my self with the answer that: 7 was a "good number"
>:o)

If you look at 7 in binary, it's 00000111. By ANDing with it, you keep only
the bits that you care about. Masking with 7 keeps your value within the
bounds of your table.

If you had, for example, 5 bits to look at (with 32 cases possible), you
would mask with 0x1f to get just the bits that you are interested in.

In your case, by masking with 15 (0x0f), you had one extra bit that was
giving you a result too big for your jump table. When it went 'off the end',
you lost control of your program.

Regards, Bob


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

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


2001\10\19@174120 by Lasse Madsen

flavicon
face
> > How did you come to the conclution that the value 7 had to be AND with W
?
>
> If you're reading the three lowest bits of a port, you need to AND with
> binary 00000111 which is 7.
>
> By ANDing with 15, you're looking at the lowest 4 bits of the port.

Thanks for the easy description !

Thanks to all who replied and helped me get this far in my asm. adventure
:o)

regards
Lasse M.

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


2001\10\20@171119 by Dwayne Reid

flavicon
face
At 06:58 PM 10/19/01 +0200, Lasse Madsen wrote:

>How did you come to the conclution that the value 7 had to be AND with W ?
>Is there a formular for this or is this some- mega advanced "you dont wanna
>know" outrageous procedure which requires a degree in hardware archetecture
>to understand because if it is
>i think i will satisfy my self with the answer that: 7 was a "good number"

You wanted to look at the lowest 3 bits which is 00000111 which is 7

The better way to express a bit mask like this is to actually do it in
binary as follows: b'00000111' instead of just saying '7'.  Then you can
more easily see the bits you want to keep and which bits you want to
discard.  Let the compiler take care of the effort of converting the number
to hex.

dwayne



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

Celebrating 17 years of Engineering Innovation (1984 - 2001)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


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