PDA

View Full Version : Efficient comparison on data (iButton)



enigma
- 22nd September 2008, 18:02
Hi All

Having completed the code for DS1990A reading (thanks Darrel) I have a working code section but I`m looking for a much more efficient way to compare the results. Code section included below for reference. The individual iButtons are used to identify room access by person.

The iButton id number is contained in these variables, 6 hex bytes:
id[0],id[1],id[2],id[3],id[4],id[5]

Assuming there is a button in the socket, whats the best way to do a compare to see if its the same button or a different one, without strings of comparsons against the last valid number?


Cheers Pete




Fam var byte
id var byte[6]
crc var byte

OWOUT portb.0,1,[$33], NotThere ' Issue Read ROM, jump to NotThere if no button

OWIN PORTA.1,0,[Fam,id[0],id[1],id[2],id[3],id[4],id[5],crc] 'Read the button

(code required)

goto main



NotThere:

id[0]=0:id[1]=0:id[2]=0:id[3]=0.id[4]=0:id[5]=0 'set all to zero if no iButton inserted

goto main

skimask
- 22nd September 2008, 19:13
Quick and dirty, add all 6 bytes together into a word and compare that number to the 'new' number. If they're not equal, you know you've got a different button. If they're the same, you MIGHT NOT have the same button and have to do further comparisons.
Any way you go, you're going to have to do some comparisons somewhere...

A bit less quick and not so dirty, put those 6 bytes into 3 words and compare those 3 words the same way as above.

I don't know why you're against comparisons. PBP supports them just fine.

Bruce
- 22nd September 2008, 19:39
I would for sure compare the whole number. Leave just a fraction of room for
Murphys' Law to creep in, and it does...;o}

enigma
- 24th September 2008, 09:17
Hi All

I`m not so much against comparisons just looking for the smallest way to implement this. I shall give this more thought and see what I can manage. Certainly adding the total is a good quick and dirty method, I`ll look at this first.

Cheers Pete




I would for sure compare the whole number. Leave just a fraction of room for
Murphys' Law to creep in, and it does...;o}

barcosta
- 24th August 2010, 15:48
can you please tell me how to compare 2 word in picbasic ?? :)

mackrackit
- 25th August 2010, 04:04
Look in the manual under sections
4.18 Comparison Operators
and
4.19 Logical Operators.

barcosta
- 27th August 2010, 02:12
i have finish a temperature regulator system with rs232 serial port
to finish the project i have to create a interface for real time mesurement of the temperature
,,,,,
Can somebody give a interface (GUI )maltab or other php with a code for reading from the port rs232 reading
the temperature >>>>>thank you

Dave
- 27th August 2010, 13:37
barcosta , Why don't we just do the project for you? It's one thing to ask for help, and another to ask for the code....
What are YOU learning?
Dave Purola,
N8NTA