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
ty arrati for help
Last edited by Mus.me; - 29th October 2009 at 01:50.
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.
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 .......
IT DOES COMPARE 33 AND 33 BUT NOT OTHER 7 BYTE WHY ?Code:DATA @0,$14,$21,$47,$56,$02,$11,$22,$33 EXTERNAL EEPROM = $14,$21,$47,$56,$02,$11,$22,$33
Last edited by Mus.me; - 29th October 2009 at 05:45.
Simply because you have still left out of the FOR/NEXT loop the compare instruction!IT DOES COMPARE 33 AND 33 BUT NOT OTHER 7 BYTE WHY ?
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.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
Al.
Last edited by aratti; - 29th October 2009 at 08:05.
All progress began with an idea
Sorry for the late reply but we had our national holiday.
Well, what type of EEPROM are you using?
Ioannis
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
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 SLEEPEEPROM 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 HELPCode: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
Bookmarks