how to compare data


Closed Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    May 2009
    Posts
    66

    Default how to compare data

    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:

    Code:
    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
    Last edited by Mus.me; - 27th October 2009 at 01:50.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    Can you post all the code? I suppose you cut and paste a part of it, right?

    Ioannis

  3. #3
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

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

  4. #4
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mus.me View Post
    Code:
    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

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
    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
    Last edited by aratti; - 28th October 2009 at 23:04.
    All progress began with an idea

  6. #6
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    ty arrati for help
    Last edited by Mus.me; - 29th October 2009 at 01:50.

  7. #7
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Angry

    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

    Code:
    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
    Last edited by Mus.me; - 29th October 2009 at 01:54.

  8. #8
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    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 .......
    Code:
    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 ?
    Last edited by Mus.me; - 29th October 2009 at 05:45.

  9. #9
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    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!

    Code:
    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.
    Last edited by aratti; - 29th October 2009 at 08:05.
    All progress began with an idea

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    Sorry for the late reply but we had our national holiday.

    Well, what type of EEPROM are you using?

    Ioannis

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    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

  12. #12
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

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

  13. #13
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    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.


    Code:
    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
    '
    All progress began with an idea

  14. #14
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    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.


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

  15. #15
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by aratti; - 30th October 2009 at 08:32.
    All progress began with an idea

  16. #16
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    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

  17. #17
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default came bk again looking for some help ...?

    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
    Last edited by Mus.me; - 1st November 2009 at 01:01.

  18. #18
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    Gold card? Does this have to do with Sat TV?

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

    Ioannis

  19. #19
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ioannis View Post
    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
    Last edited by Mus.me; - 1st November 2009 at 22:24.

  20. #20
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by Ioannis; - 1st November 2009 at 22:34.

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 04:47
  2. Nokia 3310 display text
    By chai98a in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th August 2007, 03:39
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  4. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 14:50
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 28th November 2004, 23:56

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts