PDA

View Full Version : how to compare data



Mus.me
- 27th October 2009, 01:47
hello everyones i need help plz . im readin i2c eeprom and i wrote the same data in my code so im trying to write a code to compare the data of the ext eeeprom and the code data ex:


Include "modedefs.bas"
define osc 4


PORTA = 1
PORTB = 0
KEY VAR BYTE
KEY1 VAR BYTE
ADR VAR BYTE

SCAN:
FOR ADR = 0 TO 7
I2CREAD SDAT,SCLK,$A0,ADR,[KEY]
PAUSE 10
READ ADR,KEY1

PAUSE 10


IF (KEY = KEY1) THEN
HIGH RELY
PAUSE 1000
LOW RELY

ENDIF
RETURN

END
DATA @0,14,21,47,56,02,11,22,33

SO ID DID THIS CODE BUT IT WONT COMPARE ME THE SAME DATA FROM THE EXT EEPROM WITH THIS DATA IN THE CODE AND I WANT IT NOT TO TOGGLE LED1 WHEN ITS NOT THE SAME DATA FROM EXTERNAL EPPROM

Ioannis
- 27th October 2009, 08:30
Can you post all the code? I suppose you cut and paste a part of it, right?

Ioannis

Mus.me
- 27th October 2009, 18:55
PORTA = 1
PORTB = 0
KEY VAR BYTE
KEY1 VAR BYTE
ADR VAR BYTE
SYMBOL SCLK = PORTB.0
SYMBOL SDAT = PORTB.1
SYMBOL RELY = PORTB.3
SYMBOL STRT = PORTA.0

START:

IF STRT = 0 THEN GOSUB SCAN
ENDIF
GOTO START

SCAN:
FOR ADR = 0 TO 7
I2CREAD SDAT,SCLK,$A0,ADR,[KEY]
PAUSE 10
READ ADR,KEY1
PAUSE 10
NEXT ADR
IF UNLCK = 0 THEN
I2CWRITE SDAT,SCLK,$A0,ADR,[KEY1]
PAUSE 1000
IF (KEY = KEY1) THEN
HIGH RELY
PAUSE 1000
LOW RELY
ENDIF
RETURN
END
DATA @0,14,21,47,56,02,11,22,33
this is wat i have in the external eeprom 24c02 "14,21,47,56,02,11,22,33 the same data i want my code to compare it.when it similare with the internal data it toggle relay or led if not similare it dont please help this wat i want to do but im sure there another way bcz this isnt working it does compare sometimes even the data not similare it toggle the led IF (KEY = KEY1) THEN

Mus.me
- 28th October 2009, 22:05
PORTA = 1
PORTB = 0
KEY VAR BYTE
KEY1 VAR BYTE
ADR VAR BYTE
SYMBOL SCLK = PORTB.0
SYMBOL SDAT = PORTB.1
SYMBOL RELY = PORTB.3
SYMBOL STRT = PORTA.0

START:

IF STRT = 0 THEN GOSUB SCAN
ENDIF
GOTO START

SCAN:
FOR ADR = 0 TO 7
I2CREAD SDAT,SCLK,$A0,ADR,[KEY]
PAUSE 10
READ ADR,KEY1
PAUSE 10
NEXT ADR
IF (KEY = KEY1) THEN
HIGH RELY
PAUSE 1000
LOW RELY
ENDIF
RETURN
END
DATA @0,14,21,47,56,02,11,22,33
this is wat i have in the external eeprom 24c02 "14,21,47,56,02,11,22,33 the same data i want my code to compare it.when it similare with the internal data it toggle relay or led if not similare it dont please help this wat i want to do but im sure there another way bcz this isnt working it does compare sometimes even the data not similare it toggle the led IF (KEY = KEY1) THEN

i hope someone will hel me

aratti
- 28th October 2009, 22:42
You simply put the IF/THEN in the wrong place. It must be within the FOR/NEXT loop.
I don't see the setting for the TRIS registers.

Al.



PORTA = 0
PORTB = 0
TrisA = %00000001 ' ????????????????
TrisB = %00000000 ' ???????????????
KEY VAR BYTE
KEY1 VAR BYTE
ADR VAR BYTE
SYMBOL SCLK = PORTB.0
SYMBOL SDAT = PORTB.1
SYMBOL RELY = PORTB.3
SYMBOL STRT = PORTA.0

START:
PAUSE 10
IF STRT = 0 THEN GOSUB SCAN
ENDIF
GOTO START

SCAN:
FOR ADR = 0 TO 7
I2CREAD SDAT,SCLK,$A0,ADR,[KEY]
PAUSE 10
READ ADR,KEY1
PAUSE 10

IF KEY = KEY1 THEN
HIGH RELY
PAUSE 1000
LOW RELY
Pause 1000
ENDIF

NEXT ADR

RETURN
END
DATA @0,14,21,47,56,02,11,22,33

Mus.me
- 29th October 2009, 01:47
ty arrati for help

Mus.me
- 29th October 2009, 01:48
ty for reply still the problem it toggle the rely even i change the data in ext epprom or in pic eeprom it still doing error im sure there other way to compare variables .plz need more help how to compare variables i want to do this project for doorlock so i will have 24c02 in my keys ty aratti


SCAN:
FOR ADR = 0 TO 7
NEXT ADR
I2CREAD SDAT,SCLK,$A0,ADR,[KEY] 'same data as data eeprom
PAUSE 10
READ ADR,KEY1 ' same data as external eeprom 24c02
PAUSE 100
IF (KEY = KEY1) THEN , here is the problem it does hight rely even i put diffirent data in key and key1
HIGH RELY
PAUSE 1000
LOW RELY
ENDIF

Mus.me
- 29th October 2009, 05:42
It works i cahnged somethings but the problem i have is it compare just the 7th byte when u change other bytes from 0 to 6 it doesnt detect them but when i change the 7th byte it say error that means it compares it with the 7th byte in the external eeprom NEDD help please .......

DATA @0,$14,$21,$47,$56,$02,$11,$22,$33 EXTERNAL EEPROM = $14,$21,$47,$56,$02,$11,$22,$33 IT DOES COMPARE 33 AND 33 BUT NOT OTHER 7 BYTE WHY ?

aratti
- 29th October 2009, 08:02
IT DOES COMPARE 33 AND 33 BUT NOT OTHER 7 BYTE WHY ?

Simply because you have still left out of the FOR/NEXT loop the compare instruction!



SCAN:
FOR ADR = 0 TO 7

I2CREAD SDAT,SCLK,$A0,ADR,[KEY] 'same data as data eeprom
PAUSE 10
READ ADR,KEY1 ' same data as external eeprom 24c02
PAUSE 100
IF (KEY = KEY1) THEN , here is the problem it does hight rely even i put diffirent data in key and key1
HIGH RELY
PAUSE 1000
LOW RELY
ENDIF
NEXT ADR


See my correction to your last code posted or just copy and paste the code in post #5 (the one with my correction in read) and try it.

Al.

Ioannis
- 29th October 2009, 08:04
Sorry for the late reply but we had our national holiday.

Well, what type of EEPROM are you using?

Ioannis

Ioannis
- 29th October 2009, 08:56
Al is absolutely correct. You read the whole data at once and the lase read is left in your variable.

So your program performs exactly as you wished! Although you might want something else...

So make the correction and please tell us what EEPROM you have.

If you scan more than 255 elements, then you may need to use Word variable instead of byte, in the future, that is.

Ioannis

Mus.me
- 29th October 2009, 14:53
HELLO AND THANK U EVERYONES IS HELPING ME I DID IT LAST NIGHT AND I TRYED SO IT WORKS GREAT NOW IM USING F84 AND 24C02 SO I WILL DP IT FOR THE DOORLOCK AND THE EEPROM WILL BE IN THE KEY HERE IS MY CODE I IDDED SOME SLEEP AND BUZ SO MAYBE SOMEONE WILL NEED THIS CODE IT WORKS GOOD FOR LOCKS ALL WAT IM LOOKIN FOR NOW IS HOW TO WAKE UP PIC WHEN IT GOES SLEEP
Include "modedefs.bas"
define osc 4
PORTA = 1
PORTB = 0

KEY VAR BIT [7]
KEY1 VAR BIT [7]
ADR VAR BYTE
COD VAR BYTE
SYMBOL SCLK = PORTB.0
SYMBOL SDAT = PORTB.1
SYMBOL BUZ = PORTB.2
SYMBOL LED1 = PORTB.4
SYMBOL RELY = PORTB.3
SYMBOL STRT = PORTA.0
SYMBOL UNLCK = PORTA.1
SYMBOL BLCK = PORTA.2

START:
IF STRT = 0 THEN GOSUB SCAN
IF BLCK = 0 THEN GOTO ANGRY
IF STRT = 1 THEN
HIGH LED1
PAUSE 100
LOW LED1
IF STRT = 0 THEN GOSUB SCAN
IF BLCK = 0 THEN GOTO ANGRY
PAUSE 100
ENDIF
GOTO START

SCAN:
FOR ADR = 0 TO 7
I2CREAD SDAT,SCLK,$A0,ADR,[KEY]
READ ADR,KEY1
IF KEY != KEY1 THEN GOSUB ERROR
IF (KEY == KEY1) THEN COD = 1
IF RELY = 1 THEN SEROUT LED1,N2400,["ITS UNLOCKED HERO"]
NEXT ADR
PAUSE 10
RELY = COD
PAUSE 2000
LOW RELY
RETURN

ANGRY:
SOUND BUZ,[102,75]
HIGH LED1
PAUSE 1000
SLEEP 30
NOP
SOUND BUZ,[102,75]
PAUSE 1000
GOTO START

ERROR:
LOW RELY
SOUND BUZ,[102,75]
PAUSE 1000
HIGH LED1
PAUSE 1000
LOW LED1
PAUSE 1000
SOUND BUZ,[102,75]
HIGH LED1
SOUND BUZ,[102,75]
SLEEP 10
GOTO START

END
DATA @0,$14,$21,$47,$56,$02,$11,$22,$33

EEPROM 24C02 SHOULD BE THE SAME ADDRESS AND DATA STORED THIS $14,$21,$47,$56,$02,$11,$22,$33 SO U CAN CHANGE THEM BOTH OR CHANGE THE ADRESS OR WATEVER IMNEW IN PBP . THANK U EVERYONES FOR HELP

aratti
- 29th October 2009, 15:29
I am glad that finaly your program works as you wanted. Make sure to add the two corrections in red, to your code, otherwise you could experiment some wierd behaviour.

Al.




Include "modedefs.bas"
define osc 4
PORTA = 1
PORTB = 0

KEY VAR BIT [7]
KEY1 VAR BIT [7]
ADR VAR BYTE
COD VAR BYTE
SYMBOL SCLK = PORTB.0
SYMBOL SDAT = PORTB.1
SYMBOL BUZ = PORTB.2
SYMBOL LED1 = PORTB.4
SYMBOL RELY = PORTB.3
SYMBOL STRT = PORTA.0
SYMBOL UNLCK = PORTA.1
SYMBOL BLCK = PORTA.2

START:
IF STRT = 0 THEN GOSUB SCAN
IF BLCK = 0 THEN GOTO ANGRY
IF STRT = 1 THEN
HIGH LED1
PAUSE 100
LOW LED1
IF STRT = 0 THEN GOSUB SCAN
IF BLCK = 0 THEN GOTO ANGRY
PAUSE 100
ENDIF
GOTO START

SCAN:
FOR ADR = 0 TO 7
I2CREAD SDAT,SCLK,$A0,ADR,[KEY]
READ ADR,KEY1
IF KEY != KEY1 THEN ERROR ' Not GOSUB ERROR
IF (KEY == KEY1) THEN COD = 1
IF RELY = 1 THEN SEROUT LED1,N2400,["ITS UNLOCKED HERO"]
NEXT ADR
PAUSE 10
RELY = COD
PAUSE 2000
LOW RELY
RETURN

ANGRY:
SOUND BUZ,[102,75]
HIGH LED1
PAUSE 1000
SLEEP 30
NOP
SOUND BUZ,[102,75]
PAUSE 1000
GOTO START

ERROR:
LOW RELY
SOUND BUZ,[102,75]
PAUSE 1000
HIGH LED1
PAUSE 1000
LOW LED1
PAUSE 1000
SOUND BUZ,[102,75]
HIGH LED1
SOUND BUZ,[102,75]
SLEEP 10
RETURN ' Not GOTO START

END
DATA @0,$14,$21,$47,$56,$02,$11,$22,$33
'

Mus.me
- 29th October 2009, 20:54
i am glad that finaly your program works as you wanted. Make sure to add the two corrections in red, to your code, otherwise you could experiment some wierd behaviour.

Al.




include "modedefs.bas"
define osc 4
porta = 1
portb = 0

key var bit [7]
key1 var bit [7]
adr var byte
cod var byte
symbol sclk = portb.0
symbol sdat = portb.1
symbol buz = portb.2
symbol led1 = portb.4
symbol rely = portb.3
symbol strt = porta.0
symbol unlck = porta.1
symbol blck = porta.2

start:
If strt = 0 then gosub scan
if blck = 0 then goto angry
if strt = 1 then
high led1
pause 100
low led1
if strt = 0 then gosub scan
if blck = 0 then goto angry
pause 100
endif
goto start

scan:
For adr = 0 to 7
i2cread sdat,sclk,$a0,adr,[key]
read adr,key1
if key != key1 then error ' not gosub error
if (key == key1) then cod = 1
if rely = 1 then serout led1,n2400,["its unlocked hero"]
next adr
pause 10
rely = cod
pause 2000
low rely
return

angry:
Sound buz,[102,75]
high led1
pause 1000
sleep 30
nop
sound buz,[102,75]
pause 1000
goto start

error:
Low rely
sound buz,[102,75]
pause 1000
high led1
pause 1000
low led1
pause 1000
sound buz,[102,75]
high led1
sound buz,[102,75]
sleep 10
return ' not goto start

end
data @0,$14,$21,$47,$56,$02,$11,$22,$33
'

thank u aratti for help i jsut want to make pic goes sleep and wake it when i push abottom or some im new in pbp help me if u can thnk u again

aratti
- 30th October 2009, 08:27
want to make pic goes sleep and wake it when i push abottom

To do that you need to re-wire your circuit and use portB.0 as your push-button detector. (now you are using portB.0 for I2C communication)

Once you have done that, you will need to learn how to use and activate the interrupt on portB.0, because this will wakeup your sleeping MCU.

I strongly suggest you to look at Darrel Taylor instant interrupt and experiment a while with it and then use it to improve your program.

Have a look @ http://darreltaylor.com/DT_INTS-14/hello.html

Al.

Mus.me
- 1st November 2009, 00:49
To do that you need to re-wire your circuit and use portB.0 as your push-button detector. (now you are using portB.0 for I2C communication)

Once you have done that, you will need to learn how to use and activate the interrupt on portB.0, because this will wakeup your sleeping MCU.

I strongly suggest you to look at Darrel Taylor instant interrupt and experiment a while with it and then use it to improve your program.

Have a look @ http://darreltaylor.com/DT_INTS-14/hello.html

Al. i found out. and it works great pic goes to sleep when u dont press bottoms after 1 mnt.using PB.0 for int and some beeps when wake up, so it works ok thank you aratti for helping me.im new in pbp i still donno about timers adc many things and no assembler at all lol

Mus.me
- 1st November 2009, 00:57
im trying to read and write gold card,i know it has pic16f877 and 24c16, useing pic 16f628 ,anyone has any ideas or datasheet or how to adress it or it need to be slave or wat ?and which 1 i use shiftout & shiftin or i2c, plz help

Ioannis
- 1st November 2009, 19:08
Gold card? Does this have to do with Sat TV?

Watch out. Jail is waiting for new roomers....

Ioannis

Mus.me
- 1st November 2009, 22:17
gold card? Does this have to do with sat tv?

Watch out. Jail is waiting for new roomers....

Ioannis

i know THEY were using them to watch tps france and digital plus spainISH before 2005 .but now they use abracadabra moresate team DSR SAT COMPANY IN EUROPE selling them i havnt got 1 ITS CHEAPER HERE 18£ TO WATCH ALL SCREMBEL CHANNELS BUT WE DONT USE THEM BCZ U HAVE TO FLASH UR DSR EVERY 3 DAYS NOW NONE HACKIN CHANNELS HERE BCZ THEY CHANGED TO OTHER SYSTEMS AND THE OTHER PROBLEM IS NOT ALOWED . Well im programing gold card but i donno how to adress it from pic.i want to use IT for my own project instead 24c02 scroll up , so just want help how to transfer data between pic and goldcard or piccard they call it just adress how can i access its eeprom is 24c16 thank u anyway for ur ideas

Ioannis
- 1st November 2009, 22:30
I have not used this cards, but I recall reading somewhere that you have to write some piece of software to have access in the EEPROM.

It is not directly accessible from the pins of the cards.

Check here: http://ucables.com/ref/SILVERCARD

If you know the internmal EEPROM connection you can do the rest...

Ioannis