Help in lookup table
Sat Jul 11 2009, 11:47 am
Hi, i am currently doing a project using lookup table which i am not really familiar with.
The 8051 reads through Port 1 where higher nibbles stand for 1 sets of inputs and the lower nibbles stand for another set,which is total of 2 sets of inputs after every 60seconds.
The question now I am facing is how to use the lookup table to read the 2 different sets of input to compare them whether they are equal, smaller or greater to each other.
Thanks for helping:-)
The 8051 reads through Port 1 where higher nibbles stand for 1 sets of inputs and the lower nibbles stand for another set,which is total of 2 sets of inputs after every 60seconds.
The question now I am facing is how to use the lookup table to read the 2 different sets of input to compare them whether they are equal, smaller or greater to each other.
Thanks for helping:-)
Sat Jul 11 2009, 11:24 pm
well I understand what you need but i am not able to understand how lookup tables are involved in this.
you said u want to compare two nibbles of P1 so from where this lookup table comes?
or gimme better explanation with example
you said u want to compare two nibbles of P1 so from where this lookup table comes?
or gimme better explanation with example
Tue Jul 14 2009, 10:53 pm
Sorry for the late reply.
The lookup table is register like that store the inputs from P1 nibbles.
Example: first input is 0100 and the second is 0110 then the input data is move to the lookup table.
Then the data in the lookup table is being compare to determine whether they are bigger,equal or smaller.
Thanks :-)
The lookup table is register like that store the inputs from P1 nibbles.
Example: first input is 0100 and the second is 0110 then the input data is move to the lookup table.
Then the data in the lookup table is being compare to determine whether they are bigger,equal or smaller.
Thanks :-)
Tue Jul 14 2009, 11:49 pm
The question is why use a lookup table to compare values
You would use the micro's comparison instructions to do that.
A lookup table is normally fixed, pre-set data, used to swap one value
for a different one.
You would use the micro's comparison instructions to do that.
A lookup table is normally fixed, pre-set data, used to swap one value
for a different one.
[ Edited Wed Jul 15 2009, 12:00 am ]
Wed Jul 15 2009, 12:48 am
Ya, I know. But this is a question given by my lecturer, i have to do what he told me to do :-|
Wed Jul 15 2009, 01:24 am
i agree with ExperimenterUK
just
mask ---> swap ---> compare
that's it!!!
look up table may not be fixed, they can be set up inside ram location , for this case we don't need either
If this is a question given by your lecture and we are helping you ? then what's the point
without trying how you can learn something ? refer Mazidi for implementation of lookup tables :bye
just
mask ---> swap ---> compare
that's it!!!
look up table may not be fixed, they can be set up inside ram location , for this case we don't need either
If this is a question given by your lecture and we are helping you ? then what's the point
without trying how you can learn something ? refer Mazidi for implementation of lookup tables :bye
[ Edited Wed Jul 15 2009, 01:29 am ]
Wed Jul 15 2009, 01:38 am
Since this is a pointless exercise it is hard to know what
a good method is
However you could..
Fill an array (table) of 16 bytes with 0s
Get the first nibble, use it as an offset into the table,store 1 at that entry.
Fill all addresses that follow with 2s
To compare,
Use the second nibble as an offset into the table and get the byte at that entry.
If the byte is 0 the second nibble is lower, if 1, it is the same
and if it is 2, it is higher.
(and I get the marks )
Generally I agree with afilash's comment about doing this yourself, but I think
a small pointer is OK just this once.
a good method is
However you could..
Fill an array (table) of 16 bytes with 0s
Get the first nibble, use it as an offset into the table,store 1 at that entry.
Fill all addresses that follow with 2s
To compare,
Use the second nibble as an offset into the table and get the byte at that entry.
If the byte is 0 the second nibble is lower, if 1, it is the same
and if it is 2, it is higher.
(and I get the marks )
Generally I agree with afilash's comment about doing this yourself, but I think
a small pointer is OK just this once.
[ Edited Thu Jul 16 2009, 04:57 pm ]
Wed Jul 15 2009, 05:49 pm
are you using C or assembly?
in assembly lookup table is defined in CODE memory as follows:
i stored 03H and 05H in code memory using directive DB (define byte).
to use these values or to read them from lookup table we use MOVC instruction as shown below..
in assembly lookup table is defined in CODE memory as follows:
LookUp: ;this is a lable DB: 03H,05H
i stored 03H and 05H in code memory using directive DB (define byte).
to use these values or to read them from lookup table we use MOVC instruction as shown below..
CLR A ;clear A MOV DPTR,#LookUp ;load address from lable MOVC A,@A+DPTR ;load data from address pointed by A+DPTR ;remember its good to have A as 0 before reading from lookup table and increment DPTR for next value
Thu Jul 16 2009, 09:01 am
Thanks for all your help in this topic. :-)
I am using assembly language. (FX8031 kits). :-)
This is the code that I've tried to write. Is the method I am using correct ?:-)
I am using assembly language. (FX8031 kits). :-)
cseg Start: CLR P1.0 CLR P0.0 CLR A MOV TMOD,#11H MOV TCON,#01H MOV IE,#082H MOV DPTR,#LookUp MOVC A,@A+DPTR MOV R2,A INC DPTR MOVC A,@A+DPTR SUBB A,R2 JC BIGGER JNC SMALLER SJMP EQUAL CALL DELAY_20MS CLR P0.0 ENDS END
This is the code that I've tried to write. Is the method I am using correct ?:-)
[ Edited Thu Jul 16 2009, 10:11 am ]
Powered by e107 Forum System