"Program/Verify Data" must be checked for it to write EEPROM data when programming.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1940&stc=1&d=118807518 2">
<br>
"Program/Verify Data" must be checked for it to write EEPROM data when programming.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1940&stc=1&d=118807518 2">
<br>
DT
I already have the "Program/Verify Data" option checked. Also if I Read the chip after Programming it, I do see the EEPROM data present in the Data EEPROM window. So it's definitely writing to the EEPROM. It's just not reading it for some reason.
Also some other things I tried just now was switching to the internal 4MHz resonator and trying a second chip in case it was a bad chip. Neither made any difference.
Ok, get this! I just tried using a 16F84A instead of the 16F628A using nearly the exact same code and it works! I just removed the CMCON = 7 and DEFINE OSC 20 and stuck a 4MHz resonator on the board. With the 84A the LCD reads out the proper values one after the other, 10,2A,54,FF,7C. So now it looks like there is either something weird happening when I compile or the 628A does not like this code. Any ideas? I'd rather not have to step down my chip for this and have to order more old 16F84A's.
Code:'CMCON = 7 'DEFINE OSC 20 char VAR Byte ' character from table loop var byte i con 254 clrlcd con 1 cgram con 64 ddram con 128 n96n con $4054 pause 1000 serout2 portb.7,n96n,[i,clrlcd] pause 1 DATA @$00,$10,$2A,$54,$FF,$7C Main: for loop = 0 to 4 READ loop, char ' get tag data from table 'Debug to LCD serout2 portb.7,n96n,[i,clrlcd] pause 500 serout2 portb.7,n96n,[i,ddram+0] serout2 portb.7,n96n,[HEX char] pause 1000 next end
Change this: READ (tagNum - 1 * 10 + idx), char ' get tag data from table
to this: (((tagNum - 1) * 10) + idx), char ' get tag data from table
Does it work now?
EUREKA!
Thanks guys! You have been a huge help. I have finally figured it out.
My problem was more like 3 problems...
1. I have never done EEPROM stuff before so I was lost to begin with.
2. As Bruce pointed out, the mathematical order of operations in one line was not correct. I guess the BS2 thinks a little differently from PBP in that respect.
3. My PicBasic Pro compiler was Version 2.30 form 2000. It seems that v2.30 supports the PIC 16F628 but the PIC 16F628A was implemented in a later version. I have upgraded my PBP to version 2.47 and now the EEPROM features work correctly on the 16F628A. When I successfully tested a 16F84A using the same code, that lead me to question the compiler.
So for future generations and the benefit of other people like me, here's my WORKING code that is tested successfully on a PIC 16F628A with a 20MHz resonator compiled using PBP v2.47. It reads data from the Parallax RFID Reader Module, compares it against known values stored in EEPROM and allows or denies access accordingly. Enjoy.
Code:CMCON = 7 DEFINE OSC 20 'Set oscillator in MHz ' -----[ Variables ]------------------------------------------------------- buf VAR Byte(10) ' RFID bytes buffer tagNum VAR Byte ' from EEPROM table idx VAR Byte ' tag byte index char VAR Byte ' character from table ' -----[ EEPROM Data ]----------------------------------------------------- Tag1 DATA "100050A4B7" Tag2 DATA "1000508E0A" Tag3 DATA "10005091DC" Tag4 DATA "100050203A" Tag5 DATA "100050DA36" ' -----[ Initialization ]-------------------------------------------------- HIGH portb.3 ' turn off RFID reader LOW portb.6 ' lock the door! Low portb.4 'Turn off LED ' -----[ Program Code ]---------------------------------------------------- Main: LOW portb.3 ' activate the reader SERIN2 portb.2, 396, [WAIT($0A), STR buf\10] ' wait for hdr + ID HIGH portb.3 ' deactivate reader Check_List: FOR tagNum = 1 to 5 ' scan through known tags FOR idx = 0 TO 9 ' scan bytes in tag READ (((tagNum-1) * 10) + idx), char ' get tag data from table IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table NEXT GOTO Tag_Found ' all bytes match! Bad_Char: ' try next tag NEXT Bad_Tag: tagNum = 0 FREQOUT portb.5, 1000 */ $100, 115 */ $100 ' groan PAUSE 1000 GOTO Main Tag_Found: HIGH portb.6 ' remove latch High portb.4 ' Light LED FREQOUT portb.5, 2000 */ $100, 880 */$100 ' beep LOW portb.6 ' restore latch Low portb.4 ' LED OFF GOTO Main
The BASIC Stamp solves math problems in the order they are written; from left to right. The
result of each operation is fed into the next operation. So to compute -
Unlike the BASIC Stamp, the PBP Compiler performs all math operations in full hierarchalCode:12 + 3 * 2 / 5 ...the BASIC Stamp goes through a sequence like this: 12 + 3 = 15 15 * 2 = 30 30 / 5 = 6
order. This means that there is precedence to the operators.
Multiplies and divides are performed before adds and subtracts, for example:
Forcing the addition first with parenthesis like: (12 + 3) * 2 / 5 would return the correctCode:12 + 3 * 2 / 5 ...PBP goes through a sequence like this: 3 * 2 = 6 multiply first 6 / 5 = 1.2 divide second (the .2 is lost) 12 + 1 = 13 add last
result. Good stuff to remember when porting BASIC Stamp code over to PBP.
I haven't played with a BASIC Stamp in years, but once I looked in the Stamp editor help
file under PBASIC Operators, it was obvious. I'm glad you got it working. Looks like a
fun project.
Maybe you could post your final version in the code examples section? Could save someone
else using the Parallax RFID components with PBP a lot of head-scratching...;o}
I know I'm resurrecting a dead thread here but I've searched and can't quite find what i'm looking for. I'm using a Parallax RFID reader and a PIC 16F88, with a 4 line LCD. Right now I'm just trying to get the tag ID's to display on the LCD. So far I can get the RFID to turn on and read a tag, but the information sent to the display is cryptic. I would appreciate any help you might be able to give. Thanks!
Here's the code I have so far.
Code:'RFID and LCD test DEFINE OSC8 OSCCON=%01110000 ANSEL=0 led VAR PORTB.3 'led rx VAR PORTB.0 'Serial input from RFID reader lcd VAR PORTB.5 'Serial Output to LCD rfid VAR PORTB.1 'Enable rfid low= on buf VAR BYTE(10) 'Tag code stored as word Pause 1000 High rfid High led Pause 1000 Low led SEROUT lcd,0,[$FE,1] SEROUT lcd,0,[$FE,1,"Test"] Pause 4000 High led Pause 3000 Low led low rfid SERIN2 rx,396,[Wait($0A ),STR buf\10] High rfid High led Pause 2000 Low led Pause 500 SEROUT lcd,0,[$FE,1] SEROUT lcd,0,[$FE,1,"Tag number"] SEROUT lcd,0,[$FE,$C0,buf]
Last edited by CSU_2010; - 20th November 2008 at 19:09.
hello all,
i would like to see the schematic of the above code if it is possible.
One more thing that i would like to incude at the code is to identify the name of the target id.
For example, once you pass the RFID chip from the reader, on the display to give you the name of the carrier.
if i have a chip with a target id : 123456789012 then i would like once i pass it from the reader to give a name like ASTANAPANE.
I guess that on the code i have to corespond the name to the target id.
How can we do that.
I have bought the modules from SPARKFUN and the RFID chips also from them.
I would like to make a small project for my room.
thanks for any suggestions.
Best Regards
Last edited by astanapane; - 28th March 2011 at 10:45.
whenever the PIC identifies a tag stored in the EEPROM it still holds onto the "tagNum" variable. from there you can have your program branch off with the "tagNum" variable to display whatever you want. for argument sake lets say your third RFID badge is yours then:Check_List:
FOR tagNum = 1 to 5 ' scan through known tags
FOR idx = 0 TO 9 ' scan bytes in tag
READ (((tagNum-1) * 10) + idx), char ' get tag data from table
IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table
NEXT
GOTO Tag_Found ' all bytes match!
Bad_Char: ' try next tag
NEXT
Hope this helps... CheersCode:Tag_Found: IF tagNum = 3 then displayName GOTO Main displayName: Serout2 portc.0,84,["ASTANAPANE"] 'assuming your display is on portc.0 @ 9600 baud pause 5000 'Pause 5 sec then clear display gosub CLRLCD Goto main
Bookmarks