PDA

View Full Version : How to compare strings/array? RFID Project



dan-tron
- 25th August 2007, 00:17
I am trying to make an RFID reader using Parallax's RFID Reader Module and a PIC 16F628A.
I am using PBP and am having troubles figuring out how to convert over the sample code found at Parallax to work in PBP.
Sample code: http://www.parallax.com/dl/src/prod/RFID1.BS2

The main trouble I am having is getting the comparison to work. I'm not sure what the best way would be to compare the scanned RFID 10 byte string array against a set of known tags.
Below is the part of the code I believe is not working right.
Does anybody have any idea on what I can do to fix this or perhaps someone has a better way of doing it? Thanks in advance!
-Dan

' -----[ EEPROM Data ]-----------------------------------------------------
Tag1 DATA "100050D77C" ' valid tags
Tag2 DATA "1000504B02"
Tag3 DATA "1000502DC9"
Tag4 DATA "100050803A"
Tag5 DATA "100050C472"

' -----[ Program Code ]----------------------------------------------------
Main:
LOW portb.3 ' activate the reader
SERIN2 portb.2, T2400, [WAIT($0A), STR buf\10] ' wait for hdr + ID
HIGH portb.3 ' deactivate reader

Check_List:
FOR tagNum = 1 TO LastTag ' 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

Darrel Taylor
- 25th August 2007, 02:46
Try using 396 instead of T2400 in the SERIN2 statement.

Constants like T2400 are only for SERIN (without the 2).
<br>

dan-tron
- 25th August 2007, 11:25
No luck. I replaced the T2400 with 396 and it made no difference. I don't believe that the serial input is the problem because I can debug with a serial LCD and I can get it to print the actual RFID tag numbers on the LCD. The problem seems to lie under Check_List:. Specifically the line...
READ (tagNum - 1 * 10 + idx), char ' get tag data from table

I've never saved anything to EEPROM before. Maybe its not reading it correctly? Or saving it?

Robson
- 25th August 2007, 12:35
Can you post your complete code?
I have to understand what are you´re trying to do.

regards Rob

dhouston
- 25th August 2007, 14:12
You might try using WRITE to store the data. That might isolate the problem to your DATA or READ statements.

Robson
- 25th August 2007, 14:41
Maybe this one will help you.
I don´t try before working with SERIN2 but give it a try. You can change this part with storing data to eeprom too. It´s only to see how to realize that, if i´m not wrong.
To store data on eeprom use
DATA @$00,$D7,$7C,$4B,$02,$2D,$C9,$80,$3A,$C4,$72



Loop VAR BYTE
ReadTag VAR BYTE[2]
ConvTag VAR WORD
Tag VAR WORD[5]

Tag(1) = $D77C
Tag(2) = $4B02
Tag(3) = $2DC9
Tag(4) = $803A
Tag(5) = $C472

' -----[ Program Code ]----------------------------------------------------
Main:

LOW PORTB.3 ' activate the reader
SERIN2 PORTB.2, T2400, [WAIT($0A,"100050"), STR ReadTag\2]
HIGH PORTB.3 ' deactivate reader

Check_List:
ConvTag = ReadTag(0)*$100 + ReadTag(1)
FOR Loop = 1 to 5
IF ConvTag = Tag(Loop) THEN Tag_found
NEXT Loop
GOTO Bad_Char

Bad_Char: ' try next tag
'....
'....
GOTO main

Tag_Found:

Bruce
- 25th August 2007, 15:15
Are you sure you're programming your tag numbers in EEPROM at burn time? You should be
able to read back the .hex after programming to check.

Robson
- 25th August 2007, 16:49
Are you sure you're programming your tag numbers in EEPROM at burn time? You should be
able to read back the .hex after programming to check.

I don´t wrote the code before for storing on eeprom.

But maybe this could work


DATA @$00, $D7, $7C, $4B, $02, $2D, $C9, $80, $3A, $C4, $72

Loop VAR BYTE
ReadTag VAR BYTE[2]
Tag VAR WORD[5]
TmpTag VAR BYTE[10]
ConvTag VAR WORD

' -----[ Program Code ]----------------------------------------------------

FOR Loop= 0 TO 9 ' Reading Data from EEprom Adr: $00 -$09
READ Loop,TmpTag(Loop)
NEXT Loop

Main:

LOW PORTB.3 ' activate the reader
SERIN2 PORTB.2, T2400, [WAIT($0A,"100050"), STR ReadTag\2]
HIGH PORTB.3 ' deactivate reader

Check_List:

FOR Loop = 0 TO 8 STEP 2 ' Calculate Word from HighByte + LowByte
Tag(Loop/2) = TmpTag(Loop)*$100+TmpTag(Loop+1)
NEXT Loop

ConvTag = ReadTag(0)*$100+ReadTag(1) ' Conversion of ReadTag to WORD

FOR Loop = 0 TO 4 ' Compare if ReadTag compares to Database in Eeprom
IF ConvTag = Tag(Loop) THEN Tag_found
NEXT Loop
GOTO Bad_Char

Bad_Char: ' try next tag
'....
'....
GOTO main

Tag_Found:


Error corrected... Sorry

dan-tron
- 25th August 2007, 20:51
I have simplified my program to isolate the issue. I believe it lies with the READ command. This is my simplified code.



CMCON = 7
DEFINE OSC 20

char VAR Byte ' character from table

' - LCD Stuff -
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

Tag1 DATA @$00,$10,$2A,$54,$FF,$7C

Main:

READ $02, 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]
serout2 portb.7,n96n,[i,ddram+6]
serout2 portb.7,n96n,[DEC char]
pause 1000

end


At this point I am just trying to read a byte form the EEPROM and display it on the LCD just to prove it is being read. I see the EEPROM data in the EEPROM data window on my EPICWin programming software. So I guess it is writing the EEPROM data at burn time. However all I can debug on the LCD so far is just 0. This leads me to think that the problem is with the READ command. With the above example I would think that the LCD would display 2A or at least something other than just 0's.

Darrel Taylor
- 25th August 2007, 21:55
"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=1188075182">
<br>

dan-tron
- 26th August 2007, 00:11
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.

dan-tron
- 26th August 2007, 00:34
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.



'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

Bruce
- 26th August 2007, 02:01
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?

dan-tron
- 26th August 2007, 09:07
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.



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

Bruce
- 26th August 2007, 12:46
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 -


12 + 3 * 2 / 5

...the BASIC Stamp goes through a sequence like this:

12 + 3 = 15
15 * 2 = 30
30 / 5 = 6
Unlike the BASIC Stamp, the PBP Compiler performs all math operations in full hierarchal
order. This means that there is precedence to the operators.

Multiplies and divides are performed before adds and subtracts, for example:


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
Forcing the addition first with parenthesis like: (12 + 3) * 2 / 5 would return the correct
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}

CSU_2010
- 20th November 2008, 18:31
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.




'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]

mister_e
- 20th November 2008, 18:36
try with SEROUT2 and use the STR modifier.

CSU_2010
- 20th November 2008, 19:20
Thanks, I tried SERIN2 and SEROUT 2, the LCD is still displaying weird symbols. It displays eveything else ok. Here's the code:




'RFID and LCD test

'Author Joshua Reynolds
'November 20th, 2008
'Rev. 1

'Configuring the 16F88 chip

DEFINE OSC 8 'Internal Oscillator set to 8mhz
OSCCON.4=1
OSCCON.5=1
OSCCON.6=1

ANSEL=0 'Turns off A/D converter

'------Define I/O pin names
rx VAR PORTB.1 'Serial input from RFID reader
rfid VAR PORTB.2 'Enable rfid low= on
led Var PORTB.3
lcd Var PORTB.5

buf VAR BYTE(10) 'Tag code stored as word

'------Declare Variables

key_value Var BYTE 'code byte from the keypad


High led
Pause 1000
Low led

'------Wait .5 sec for everything to power up
Pause 500

loop:

SEROUT lcd,0,[$FE,1]
SEROUT lcd,0,[$FE,1,"Read tag"]

low rfid
serin2 rx,396,[str buf\10]
high rfid

High led
Pause 500
low led
Pause 500
High led
Pause 500
low led

SEROUT lcd,0,[$FE,1,"One"]
Pause 4000

SEROUT lcd,0,[$FE,1,"Tag Number"]

Pause 2000

SEROUT2 lcd,396,[$FE,$C0,STR buf\10]

Pause 5000

Goto loop

End 'End of main program

mister_e
- 20th November 2008, 19:25
Try something, start a new code, fill the buf Array with some data (ASCII character), then send it to your LCD.

Any link for your RFID reader?

mister_e
- 20th November 2008, 19:30
Maybe not a bad idea to connect the RFID to your PC to see what happen... you'll need a MAX232 or any other level converter to do that.

mister_e
- 20th November 2008, 19:48
Just curious to know if the following line work with your LCD

SEROUT2 lcd,396,[$FE,$C0,"2nd Line???"]

CSU_2010
- 21st November 2008, 01:39
Thanks for the replies, I'll try it out in lab tomorrow. Here's a link to the RFID Parallax RFID (http://www.parallax.com/Store/Sensors/CustomKits/tabid/134/txtSearch/RFID/List/1/ProductID/114/Default.aspx?SortField=ProductName%2cProductName)
I'll have to look up the stuff on attaching it to a computer, I've never done anything like that.

CSU_2010
- 25th November 2008, 01:28
I'm trying to find out the RFID tag ID by reading the tag and displaying it on an LCD and I can't seem to figure it out. Has anyone else been able to display the tag ID on an LCD?

ScaleRobotics
- 21st April 2010, 17:27
I was at Radio Shack yesterday, trying to buy a breadboard. (No of course they didn't have it, why would my store have it in stock?)

Anyway, I was searching their bins and I saw a Parallax RFID READER WITH TAGS part number 276-0032, or this part: http://www.parallax.com/Store/Sensors/CustomKits/tabid/134/txtSearch/RFID/List/1/ProductID/114/Default.aspx?SortField=ProductName%2cProductName

It didn't have a price marked, so I had the lady scan it, and she told me it was $19.97. It's on my receipt as the correct part number, and correct product description. That's half off of Parallax's price, so if you are interested in RFID, you might want to check it out at Radio Shack.

Ioannis
- 22nd April 2010, 11:34
At their site they do not list it though...

Ioannis

RFEFX
- 9th December 2010, 09:26
i thought id post it here.. since this thread helped in the trick math operation.

My Board runs a PIC16F877A @ 20Mhz

Video Here (http://www.gmdii.com/Videos/RFEFX_RFID.mp4)



define OSC 20
ADCON1=7
CMCON=7


LastTag CON 3
X VAR byte
tagNum VAR byte ' from EEPROM table
idx VAR Byte ' tag byte index
char VAR Byte ' character from table
buf var byte(10)

'************************************************* ****************

SYMBOL PWRLED = PORTB.2 'Software controlled power LED
SYMBOL RFID = PORTC.5 'RFID /ENABLE


'************************************************* ****************


Tag1 DATA "0415146D53" ' 2 cards registered...
Tag3 DATA "30700D48A5"


'************************************************* ****************


HIGH PWRLED
HIGH RFID
PAUSE 1000

serout2 PORTC.0,84,[$55] ' uOLED Initialize

'************************************************* ****************

Reset:
gosub cls
PAUSE 1000

'************************************************* ****************

Main:

LOW rfid ' activate the reader
SERIN2 PORTC.4,396,[WAIT(10),str BUF\10] ' wait for hdr + ID
HIGH rfid ' deactivate reader

Check_List:
FOR tagNum = 1 TO lasttag
FOR idx = 0 TO 9
READ (((tagNum - 1) * 10) + idx), char 'The Tricky Order of Operation
IF (char <> buf(idx)) THEN Bad_Char
NEXT
GOTO Tag_found
Bad_Char:
NEXT

Bad_tag:
FOR x = 1 TO 2
serout2 PORTC.0,84,[$73,$6,$4,$0,$F0," ACCESS",$00] 'cmd,column,row,font,Color(msb:lsb),“string”,$00
serout2 PORTC.0,84,[$73,$6,$8,$0,$F0," DENIED",$00]
NEXT
PAUSE 4000
GOTO reset

Tag_Found:
for x = 0 to 2
serout2 PORTC.0,84,[$73,$6,$4,$0,$1F," ACCESS",$00] 'cmd,column,row,font,Color(msb:lsb),“string”,$00
serout2 PORTC.0,84,[$73,$6,$8,$0,$1F," GRANTED",$00]
next
pause 4000
GOTO reset


CLS:
FOR X = 0 TO 2
serout2 PORTC.0,84,[$45]
next
return

Ioannis
- 9th December 2010, 10:08
I wonder why you send the uOLED data 2 or 3 times in a loop.

Ioannis

RFEFX
- 9th December 2010, 17:57
In another post someone stated about lag issues with this particular uOLED from 4Dsystems They introduced Pauses, but i found out (through trial and error) that just sending the data a couple times in a loop (refreshing) rather than putting pauses in the the display code resolved any Lag issues. As you can see in the video it displays what im sending
to the display quite nicely and even before the RFID LED can change color.. I also dont read any ACK from the display, as it is not necessary and just slows down the process.

Cheers!

Ioannis
- 10th December 2010, 09:38
I see. OK, thanks.

What is you opinion about the display? (colors, brightness, sharpness).

Ioannis

RFEFX
- 10th December 2010, 16:03
Overall the display is great. you have full control over any text you send to the display: positioning (x,y), Color(msb:lsb), and even font size. you can even make custom bit mapped color characters and store them on a uSD card. Or even tell the uSD to run a script.

cmd,column,row,font,Color(msb:lsb),“string”,Termin ator ($00)

My next goal is to have the PIC play a video from the uSD card. the only obsticle i see is you have to know a lot of information about memory structure, like sectors and such, to address the uSD card. here is the video command info:

Command ext_cmd, cmd, x,y,width, height, colourMode, delay, frames(msb:lsb), SectorAdd(hi:mid:lo)

- ext_cmd 40(hex) or @(ascii) : Extended Command header byte
- cmd 56(hex) or V(ascii) : Command header byte
- x : Video horizontal start position (top left corner).
- y : Video vertical start position (top left corner).
- Width: Horizontal size of the video-animation.
- Height: Vertical size of the video-animation.
- ColourMode 08(hex) : 256 colour mode, 8bits/1byte per pixel. 10(hex) : 65K colour mode, 16b/2B per pixel .
- Delay : 1 byte inter-frame delay in milliseconds.
- Frames: 2 bytes (big endian) total frame count in the video-animation clip.
- SectorAdd : 3 bytes (big endian) sector address of a previously stored videoclip that is about to be displayed.

Ioannis
- 11th December 2010, 14:36
From the pdf that are available, I could not find the specs for the video files.

What files the LCD can play?

Ioannis

RFEFX
- 11th December 2010, 22:46
Hey Ioannis,

I got video to play on the display from the PIC..

once i get the project up and complete ill write a tutorial on the process.

Ioannis
- 12th December 2010, 21:10
Okie, looking forward...

Ioannis

RFEFX
- 14th December 2010, 08:03
Ioannis,

The video Tutorial On the 4Dsystems OLED is located in the Code Example section. link below.

Displaying Videos and Images on 4Dsystems uOLED Serially (http://www.picbasic.co.uk/forum/showthread.php?t=14113)

astanapane
- 28th March 2011, 10:42
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.



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



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

RFEFX
- 29th March 2011, 09:23
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


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:



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


Hope this helps... Cheers

astanapane
- 29th March 2011, 11:45
thank you very much for the help....

i ordered the reader and the ID-12 from SPARKFUN, and i wait for them next week. Once i get them i will start to built my project.

I will make schematics and PCBs and i will post them here.

A lot of thanks for the code. I only need a little bit help of the code you made corresponding to the schematic.

If you dont have time i will read the code and identify the Pins for the pic16f628.

thank you very much again for your help.

I dont see the time to have the reader and the rfid chips with me.

Kind Regards,

astanapane
- 29th March 2011, 14:54
i have also one more question please.

I need to use the ID-12 with a display also. Can i use the pic16f628a to run both?

thank you very much.

Archangel
- 29th March 2011, 17:06
i have also one more question please.

I need to use the ID-12 with a display also. Can i use the pic16f628a to run both?

thank you very much.
Go read your manual about LCDOUT, it explains in a thorough treatise exactly how to do that. I am perceiving this to be a school project, and it would be rather easy to hand you the code, I think that would do you more harm than good.
What you learn here you can then teach to someone else, that is how this forum works, a great many of the members ARE engineers, others are just interested hobbyist, and IF you are a student, as I believe, I do not want to enable you to fail and NO I do not mean fail the class. Write your code, Make the mistakes, Show us the mistakes, and receive help.

astanapane
- 29th March 2011, 18:36
sorry Joe.

i dont want to start that with student or not. If you think that i'm a student you might be right.

A student that is graduated from E.E.E. and i didnt like it then gradueated with MSc DATA COMS with Distinction and i only know to do CISCO. If someone will ask me about cisco i will help him with all my stength and examples.

Sorry i didnt like a lot my first degree thats why i dont know how to use programming very well.

Right now i;m working for a reseller company of Stratasys which makes the FORTUS RP systems.

I only want to make a small project for my father's home.

I'm not a programmer or student sorry....i just do not have enouph time to spend on this.

I will try by my self and i will ask for your help.

thanks.

Archangel
- 30th March 2011, 08:48
Not to be sorry . . . I just do not want to trip you up in your pursuit of life
all that said make sense of this



' Define LCD registers and bits as 4 bit
Define LCD_DREG PORTB ' port b handling the data
Define LCD_DBIT 4 ' Data bits begin on PortB.4 generally must use consecutive ports starting with 0 or 4
Define LCD_RSREG PORTA ' R/S bit on portA
Define LCD_RSBIT 0 ' Defined as PortA.0
Define LCD_EREG PORTA ' E Bit defined as PortA
Define LCD_EBIT 1 ' Ebit set to PortA.1

DEFINE LCD_LINES 4 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.
DEFINE OSC 20


lcdout $FE,1 ' Clear LCD
lcdout $FE,2, " Copyright 2006 " '
lcdout $fe,$C0,"This is my text" '


This is a cut/paste from a project Darrel really helped a lot on,(DID MOST OF) a serial backpack lcd controller.
The defines tell the pic which pins are working the LCD
$FE1 clears the LCD
$FE2 moves cursor to #1 position
$FE,$C0 moves the cursor to another line, my book is not handy right now
Keep in mind a 4X20 LCD is electrically in reality a 2X40 that is chopped in half and stacked so the beginning of line 2 is post 41? and the beginning of line 3 is 21, or something to that effect.
Check out the project at http://www.picbasic.co.uk/forum/content.php?r=171-LCD-serial-backpacks

Oh and BTW , NOBODY hates school more than Me. I totally get it. I still on occasion have to go back and take classes
just because I want to learn what they are teaching, and I still hate it!

astanapane
- 30th March 2011, 10:58
Dear All,

first of all i would like to thank all of you for any help on my next week try.

As i told you i'm waiting next week to receive the ID-12 RFID module and the RFID chips.

I have a display and a pic16f628a here with me. I would like before i start to make first some steps in order everyone in the future to have it as a guidance.

The project is based on the RFID. So this will be the INCOMING information from an RFID chip.

The componets are going to be used are as follows. (sorry that i provide you the sparkfun but i ordered all mine from there exept the pic)

1) PIC16f628a
2) ID-12 RFID module http://www.sparkfun.com/products/8419
3) RFID reader, you need this to read the IDs from the tags in order to use them on the programm (http://www.sparkfun.com/products/8852)
4) tag (http://www.sparkfun.com/products/9417) you can use any at 125khz
5) 16x2 Character LCD - White on Black 5V http://www.sparkfun.com/products/709

these are the core components we need. Once i make the schematic and the program i will provide all the info you might need.

So now what is the thought.

1) to be able to open the door using an RFID tag.
2) the rfid tag might be unique and stored in an eeprom
3) once we pass the tag from the ID-12 module the pic will recognise the ID of the tag and display on the 16x2 the Name of the carrier.
4) after the Displayed name (0,5 seconds) the door will open.
5) there we need to clear everything and be ready to use an other tag.

Now We need to think to use the 16x2 display and the RFID module with the same pic.

1) From my point of view i need for the display 6 ports reserved from the PIC. (see attached file)

we also need to give the above code at the beggining of our program in order to specify the parameter of the display.

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

2) then we also need for the ID-12 to reserved some pins from the pic ports but i dont know which ones. ( here i need some help) According to the attached file i would like to tell me how which pins from the ID-12 i need to connect to pic.

Once we know how many reserved pins we have then we share and seperate those pins to input from the ID-12 and output for the 16x2 lcd.

i will keep you updated with the code that i will try to write next week. Please let me know if anyone is able to help on this. I will be fololwing the code is already written here from all of you.

Best Regards,

astanapane.

astanapane
- 30th March 2011, 11:09
Joe,

thank you a lot, hehehe i think we did post the same time.

Hope you'll be here and help me out next week. I will start very simple and then we can improve everything accordinally.

Best Regards

astanapane
- 31st March 2011, 14:56
some more questions.

I guess that with the following format for the LCD


DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

i can only use the LCDOUT command and not the SEROUT2.

In case that i use for the pic16f628a the RB0 for the RFID READER then for the LCD can i use PORTA?

Then i would need also some help in the command to transfer it from the following

Serout2 porta.0,84

to the LCDOUT.

Archangel
- 1st April 2011, 01:50
The LCDs are parallel LCD. I have seen some circuits using shift registers to adapt then to accept, or use the serial backpack you will find in the article section and serout / serout2 / hserout as you choose. It is in the final code, set to accept several baud rates. It does all the LCDOut overhead in it's PIC, freeing you projects PIC of the burden. I listed it before, but here it is again.
http://www.picbasic.co.uk/forum/cont...rial-backpacks (http://www.picbasic.co.uk/forum/content.php?r=171-LCD-serial-backpacks)

astanapane
- 1st April 2011, 09:07
Hi Joe,

thank you, i will try to fix the code before i get the componets, but it a bit difficult without them.

I havent recieve the ID-12 modules yet. So i expect them next week possible on Wednesday.

astanapane
- 1st April 2011, 13:40
The attached file shown what i need to do with the ID-12 and the pic16f628a.

I will seperate those in two circuits.

The first circuit will read and identify the RFID cards and the second circuits will be based on the 3x4 keypad.

Once you pass the rfid card from the ID-12 the circuit will check if the card is valid or not.

If it is valid then will proceed and display your name. If not then you will need to go back and check card again.

Once you are accepted from the system then you only have 5 seconds to open the door. You will need to type your 4 digit code in order to open the door.

astanapane
- 9th April 2011, 15:15
hello all again,

i just received the RFID module 12 from sparkfun.

I test the serial usb device with Secure CRT and works fine.

Now i'm building the circuit and the code.

As i told you i would like to make a code that can display the name of the holder according to the ID of the RFID tag.

I havent connect the ID-12 yet because the dimensions of the pins are not much to the standard ones. I will make a pcb this afternoon and then i will try to make a schematic.

Now i have attached the code i have done so far, copied most of it from the people here in forum.


CMCON = 7
DEFINE OSC 4 'Set oscillator in MHz

DEFINE LCD_DREG PORTB 'define port to LCD
DEFINE LCD_DBIT 4 'RB4 RB5 RB6 RB7 display
DEFINE LCD_RSREG PORTA 'RS on porta
DEFINE LCD_RSBIT 0 'RS on porta.0
DEFINE LCD_EREG PORTA 'Enable on porta
DEFINE LCD_EBIT 1 'Numero Enable porta.1
DEFINE LCD_BITS 4 '
DEFINE LCD_LINES 2 'lines 2
PAUSE 200 ' Stop 200ms
LCDOUT $FE,1 'clear
Lcdout $FE,1,4
' -----[ Variables ]-------------------------------------------------------

buf VAR Byte(12)' 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 "450052B6BC1A"
Tag2 DATA "450052F2EB0A"


' -----[ Initialization ]--------------------------------------------------

HIGH portb.1 ' turn off RFID reader portb.1 is the reciever port
LOW portb.2 ' lock the door!
Low portb.3 ' Turn off LED
' -----[ Program Code ]----------------------------------------------------

Main:

LOW portb.1 ' activate the reader
SERIN2 portb.1, 396, [WAIT($0A)] ' STR buf\12] ' wait for hdr + ID
HIGH portb.1 ' deactivate reader

Check_List:
FOR tagNum = 1 to 2 ' scan through known tags
FOR idx = 0 TO 11 ' scan bytes in tag
READ (((tagNum-1) * 12) + 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 porta.3, 1000 */ $100, 115 */ $100 ' groan
PAUSE 1000
GOTO Main

Tag_Found:

IF tagNum = 1 then displayName1

IF tagNum = 2 then displayName2

GOTO Main

displayName1:
lcdout $FE, 1,"NAME for tag 1" 'assuming your display is on porta.0 @ 9600 baud
pause 500 'Pause ,5 sec then clear display
goto open_door

displayName2:
lcdout $FE, 1,"Name for tag 2" 'assuming your display is on porta.0 @ 9600 baud
pause 500 'Pause ,5 sec then clear display
goto open_door

open_door:
HIGH portb.2 ' remove latch
High portb.3 ' Light LED
FREQOUT porta.2, 2000 */ $100, 880 */$100 ' beep
LOW portb.2 ' restore latch
Low portb.3 ' LED OFF
GOTO Main


i would like to know if i can use the command serin2 on the pin portb.1 on the pic16f628a in order to read the data.

I know that the code may have a lot of mistakes but as i told you i'm not a programmer and i try to make it as good as i can.

I only need a little bit of your help in certain points that you sure know better than me.

thank you all for your help in advance.

astanapane
- 10th April 2011, 08:37
hi all,

i did some small changes and read data on 9600.

But i cannot make it work yet.

When i pass the TAG from the reader does not display the name.

It displays 'Bad Dag' only. And the tag is the valid one i pass from the reader.

Could you please help me with my program?

I have tags from Sparkfun that i believe are with 12 digits so i think we need to make some changes there.

here is the code:


@ DEVICE PIC16F628A

CMCON = 7
DEFINE OSC 4 'Set oscillator in MHz

DEFINE LCD_DREG PORTB 'define port to LCD
DEFINE LCD_DBIT 4 'RB4 RB5 RB6 RB7 to D4 D5 D6 D7 display
DEFINE LCD_RSREG PORTA 'RS on porta
DEFINE LCD_RSBIT 0 'RS on porta.0
DEFINE LCD_EREG PORTA 'Enable on porta
DEFINE LCD_EBIT 1 'Numero Enable porta.1
DEFINE LCD_BITS 4 '
DEFINE LCD_LINES 2 'lines 2
PAUSE 200 ' Stop 200ms
LCDOUT $FE,1 ' Åíåñãïðïßçóå ôï LCD
Lcdout $FE,1,4
lcdout $FE, 1," Leonardo"
pause 500
' -----[ Variables ]-------------------------------------------------------

buf VAR Byte(12)' 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 "450052B6BC1D"
Tag2 DATA "450052F2EB0E"


' -----[ Initialization ]--------------------------------------------------

high portb.1 ' turn off RFID reader portb.1 is the reciever port
LOW portb.2 ' lock the door!
Low portb.3 ' Turn off LED

' -----[ Program Code ]----------------------------------------------------

Main:
high portb.3
low portb.1 ' activate the reader
SERIN2 portb.1, 84, [WAIT($0A)] ' STR buf\12] ' wait for hdr + ID
high portb.1 ' deactivate reader
pause 500

Check_List:
FOR tagNum = 1 to 2 ' scan through known tags
FOR idx = 0 TO 11 ' scan bytes in tag
READ (((tagNum-1) * 12) + 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
high porta.3
pause 200
low porta.3
pause 200
lcdout $FE, 1," bad tag"
pause 500
FREQOUT porta.3, 1000 */ $100, 115 */ $100 ' groan
PAUSE 1000
lcdout $FE,1
GOTO Main

Tag_Found:

IF tagNum = 1 then displayName1

IF tagNum = 2 then displayName2

GOTO Main

displayName1:
lcdout $FE, 1,"ASTANAPANE" 'assuming your display is on porta.0 @ 9600 baud
pause 500 'Pause ,5 sec then clear display
goto open_door

displayName2:
lcdout $FE, 1,"TIGRI" 'assuming your display is on porta.0 @ 9600 baud
pause 500 'Pause ,5 sec then clear display
goto open_door

open_door:
HIGH portb.2 ' remove latch
High portb.3 ' Light LED
FREQOUT portb.3, 2000 */ $100, 880 */$100 ' beep
LOW portb.2 ' restore latch
Low portb.3 ' LED OFF
GOTO Main

astanapane
- 10th April 2011, 11:12
hi all again,

i try to see what the problem is.

I think there might be a problem on storing data to EEPROM of the pic16f628a...

and there also be a problem somewhere on the code...


Main:
high portb.3
low portb.1 ' activate the reader
SERIN2 portb.1, 84, [WAIT($0A)] ' STR buf\12] ' wait for hdr + ID
high portb.1 ' deactivate reader
pause 500

Check_List:
FOR tagNum = 1 to 2 ' scan through known tags
FOR idx = 0 TO 11 ' scan bytes in tag
READ (((tagNum-1) * 12) + 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!


when i try to pass the card from the reader it light the led of the reader but nothing happens to my LCD.

then i pass second time the card from the reader the led on the porta.3 light up and i get on my lcd the Error tag.

I dont understand what is happening on the first time that i pass the card. It doesnt do anything.

Why when i pass it two times i have bad tag on the display.

On other thing is that i cannot make it work to show me the name on the display on the right cards.

If you have any solutions please help me.

regards

Archangel
- 11th April 2011, 00:28
Just countin beans here:


buf VAR Byte(12)' RFID bytes buffer
I think should read


buf VAR Byte[12]' RFID bytes buffer
I am looking for other issues

astanapane
- 11th April 2011, 07:16
Thank you Joe,

i will make the change in the afternoon, then i will check and let you know.

Your help is much apreaciated.

Best Regards,

astanapane
- 11th April 2011, 16:24
i have changed the () with this [] but didnt work.

something else is the mistake and i cannot understand.

When i pass the tag from the reader doesnt do anything, but i pass it twice then i get the bad tag on the display.

It seems that doesnt recongise the tags i gave to the program.

somthing has to do with this line

SERIN2 portb.1, 84, [WAIT($0A), STR buf\10] 'the number 10 here is the 9600???

i cannot understand this line could you help?

FOR idx = 0 TO 11 ' here is it ok this line if my RFID tags have 12 digits?
READ (((tagNum-1) * 10) + idx), char ' this line is chineese to me. what is the number 10 in there? What number should i put if my RFID tags have 12 digits?

Archangel
- 11th April 2011, 21:38
i have changed the () with this [] but didnt work.

something else is the mistake and i cannot understand.

When i pass the tag from the reader doesnt do anything, but i pass it twice then i get the bad tag on the display.

It seems that doesnt recongise the tags i gave to the program.

somthing has to do with this line

SERIN2 portb.1, 84, [WAIT($0A), STR buf\10] 'the number 10 here is the 9600???

i cannot understand this line could you help?

FOR idx = 0 TO 11 ' here is it ok this line if my RFID tags have 12 digits?
READ (((tagNum-1) * 10) + idx), char ' this line is chineese to me. what is the number 10 in there? What number should i put if my RFID tags have 12 digits?
Working from memory here, my book is outside, and I am not dressed to go get it . . .
As I remember the 84 is the Mode setting the baud rate, the buff\10 sets the string state to 10 characters - 0 to 11 would equal 12 characters in your index, so I am thinking your buf\10 should be buf\12 . . .

astanapane
- 12th April 2011, 07:15
Hi Joe,

i would also like to specify that the tags i have there are manchester encoding. Do i have to decode it through the program in order to work?

I dont know how to decode it. As from the page here http://www.sparkfun.com/products/10169 these are the features
Features:

EM4001 ISO based RFID IC
125kHz Carrier
2kbps ASK
Manchester encoding
32-bit unique ID
64-bit data stream [Header+ID+Data+Parity]

From what you are saying now:

i have already change the buf/10 to 12 but nothing happens.

If you see the site in here http://melabs.com/resources/ser2modes.htm , there is a 4Mhz which i use at them moment.

There are several numbers in there included the 84. The number 84 seems to read the data at 9600.

Here is an other example of the code http://melabs.com/samples/PBP-mixed/ser2mod.htm


Serin2 pinin,396,[WAIT("F"), STR test8\8]

Serout2 pinout,396,["14: ",STR test8\8,13,10] ' 15: 7ZZ-0001

' Waits for the string "F", then collects the next 8 characters. These are

' stored as ascii in 8 locations of the array variable test8. The SerOut2

' statement uses the same modifier to send all 8 locations of the array

' variable as an ascii string.

Serin2 pinin,396,[WAIT("Z",45), STR test8\8\"0"]

Serout2 pinout,396,["15: ",STR test8\8,13,10] ' 16: F7ZZ-

' This example demonstrates how you can put multiple characters in the

' WAIT. It waits for the string "Z-", since the ascii code for "-" is

' 45. The STR item is the same as above except we have added the stop

' character "0". When it encounters "0" at the sixth character, it

' replaces it and fills the rest of the test8 array with null characters.

Pause 2000

Goto mainloop

End

Archangel
- 12th April 2011, 07:59
I know little to nothing about manchester encoding, I defer to the More Experienced members here, Right now I am still recovering from a hard drive crash, having "unearthed" my computer, I cannot see my bench for the scattered "stuff" ;(, at least the computer is up, except all my PDFs are corrupted.

astanapane
- 12th April 2011, 08:09
No problem Joe,

thanks for you help. IF there is anyone else can check the code and give me his advice.

Kind Regards,

Ioannis
- 12th April 2011, 13:08
There is a ' symbol after the wait that I think should go away. Buffer never gets filled.



SERIN2 portb.1, 84, [WAIT($0A)] ' STR buf\12] ' wait for hdr + ID


Ioannis

astanapane
- 12th April 2011, 14:44
Hi Ioannis

i will check that out later today and let you know.

I think i have correct that error but i will check it.

SERIN2 portb.1, 84, [WAIT($0A), STR buf\12]

An other thing that i have in mind is he WAIT($0A),what is that $0A doing?

what is waiting for? is that the first digit of the ID?

(ευχαριστω πολυ)

astanapane
- 12th April 2011, 16:45
hi all,

this is my code for your reference....there is somewhere a mistake that cannot find.


@ DEVICE PIC16F628A
INCLUDE "modedefs.bas"
CMCON = 7
DEFINE OSC 4 'Set oscillator in MHz

DEFINE LCD_DREG PORTB 'define port to LCD
DEFINE LCD_DBIT 4 'RB4 RB5 RB6 RB7 to D4 D5 D6 D7 display
DEFINE LCD_RSREG PORTA 'RS on porta
DEFINE LCD_RSBIT 0 'RS on porta.0
DEFINE LCD_EREG PORTA 'Enable on porta
DEFINE LCD_EBIT 1 'Numero Enable porta.1
DEFINE LCD_BITS 4 '
DEFINE LCD_LINES 2 'lines 2
PAUSE 200 ' Stop 200ms
LCDOUT $FE,1 ' power lcd
Lcdout $FE,1,4
lcdout $FE, 1," Copyright 2011"
lcdout $FE, $C0,"***********"
pause 2000
lcdout $FE,1
' -----[ Variables ]-------------------------------------------------------

buf VAR byte [12]' 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 "450052B6BC1D"
Tag2 DATA "450052F2EB0E"

' -----[ Initialization ]--------------------------------------------------

high portb.1 ' turn off RFID reader portb.1 is the reciever port
LOW portb.2 ' lock the door!
Low portb.3 ' Turn off LED

' -----[ Program Code ]----------------------------------------------------

Main:
lcdout $FE,1," Please use your"
lcdout $FE, $C0," TAG"
pause 500
high portb.3
low portb.1 ' activate the reader
pause 500
SERIN2 portb.1, 84, [WAIT($34),STR buf\12]
pause 500
high portb.1 ' deactivate reader

Check_List:
FOR tagNum = 1 to 2 ' scan through known tags
FOR idx = 0 TO 11 ' scan bytes in tag
READ (((tagNum-1)*12 ) + 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 porta.3, 1000 */ $100, 115 */ $100 ' groan
lcdout $FE, 1," invalid TAG"
lcdout $FE, $C0," try again"
pause 1000
lcdout $FE,1
GOTO Main

Tag_Found:

IF tagNum = 1 then displayName1

IF tagNum = 2 then displayName2

GOTO Main

displayName1:
lcdout $FE, 1," name_1"
lcdout $FE, $C0, "ACCESS GRANDED"
pause 1000 'Pause ,5 sec then clear display
goto open_door

displayName2:
lcdout $FE, 1," name_2"
LCDout $FE, $C0," ACCESS GRANDED"
pause 1000 'Pause ,5 sec then clear display
goto open_door

open_door:
HIGH portb.2 ' remove latch
pause 500
LOW portb.2 ' restore latch
Low portb.3 ' LED OFF
GOTO Main

astanapane
- 13th April 2011, 08:23
as i mentioned before, there might be a problem on the following lines.

SERIN2 portb.1, 84, [WAIT($0A),STR buf\12]

what is this value doing in here $0A is that the first digit of the tag?

pause 500
high portb.1 ' deactivate reader

Check_List:
FOR tagNum = 1 to 2 ' scan through known tags
FOR idx = 0 TO 11 ' scan bytes in tag
READ (((tagNum-1)*12 ) + idx), char ' get tag data from table

what is this value after tagnum -1 is doing? is this the number of the digits of the tag?

IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table

Ioannis
- 13th April 2011, 11:16
I do not know what the 0A is there for.

It for sure NOT for the ID-12.

In ASCII Hex mode,the ID-12 sends a STX (Start Sentinel) of 02 as the data sheet state.

So no WAIT(0Ah). It will give Bad Tag message.

On the e-mail I sent to you there was an error as I did not read correctly the Data Sheet.

Correct one is the



serin2 port_pin1,baud_rate1,[wait($02),str buf\10]

serout2 port_pin2,baud_rate2,[str buf\10,13,10]


just to test if the reading data are correct.

Ioannis

astanapane
- 13th April 2011, 11:41
for all our knowledge,

i would also like to know if the 12 digits i get from the usb reader, as sparkfun's video on their page...http://www.sparkfun.com/products/8419 is ASCII code.

It is needed first to understand what is this 12 digit number?

Thank you very much for your help. I need also to help you by understanding the basics. then might be easier for you to give me the right instructions.

astanapane
- 13th April 2011, 12:47
I do not know what the 0A is there for.

It for sure NOT for the ID-12.

In ASCII Hex mode,the ID-12 sends a STX (Start Sentinel) of 02 as the data sheet state.

So no WAIT(0Ah). It will give Bad Tag message.

On the e-mail I sent to you there was an error as I did not read correctly the Data Sheet.

Correct one is the



serin2 port_pin1,baud_rate1,[wait($02),str buf\10]

serout2 port_pin2,baud_rate2,[str buf\10,13,10]


just to test if the reading data are correct.

Ioannis


I will make the change to $02 this might solve the problem.

If not then i will try to figure out how to connect it to the computer thought the serial port to see what i get.

Can i do anything with the existing one i have (i mean the usb reader (http://www.sparkfun.com/products/9963))?

Can i find out from there what the Module is generating?

Because i got consfused. With this reader i get a number throught the Secure CRT program with 12 digits.

Gevo
- 13th April 2011, 22:15
Hi,

I have a lot of applications done with RFID. See my web http://www.picshop.nl/rfid.html
Here connected to a AmiPIC18 board with the PIC18F25K20. The firmware is in PICBASIC Pro.

After reading a Tag, the reader give a Hex02. So, you have to wait for that character and store the next 10-byte in a string. Thats the Tag ID. If the first byte = 0, than you have a read only tag. (1 means read/write)
The OEM reader what I use, has a CP signal, this will be high after reading a Tag, then 210ms later, the reader wil send out (9600 baud) the TAG ID. I use in the firmware the CP signal to poll of a Tag is reading or not. The micro is run on 8 Mhz or faster to read 9600baud.

I will post tomorrow some firmware to show hows iets work if you want.

Regards,

astanapane
- 14th April 2011, 07:19
Dear Mr. Gevo,

thanks a lot for that. Mr. Ioannis gave me some information in order to start from, read and learn. So i need to read all these info and then i will come back with all my questions.

I think i'm close to fix the problem and make the circuit to work.

At the moment i have use 4Mhz resonator for 9600. Do you think that this might be a problem? I will change it to 8Mhz crystal then.

Ioannis
- 14th April 2011, 10:31
If the PIC send without any poblem to a PC then its OK for the 4MHz.

I have many times used 9600 on 628 with 4MHz resonator (not crystal) and went smooth.

Ioannis

Bruce
- 14th April 2011, 15:46
Why not just use DEBUG for transmit & DEBUGIN for receive?

These commands work 100% with a 4MHz oscillator up to 19200 bps, offer the same modifiers as SERIN2/SEROUT2, and produce much smaller code!

Ioannis
- 15th April 2011, 07:59
Bruce just cought me. These two commands would be the next step to suggest.

astanapane is struggling with the basics so I did not put him to code changes. Debug need DEFINES declared on top of the code.

Ioannis

astanapane
- 15th April 2011, 08:58
Yes that's true,

i will focus at the moment to the basics and then i will try to your suggestions. In first place it is needed to understand the code itself. Then to get the datasheet from the RFID module and check everything in there step by step.

For your info the module ID-12 can be run at 9600 as from the datasheet. The boundrate code for that it seems to work on SERIN2 portb.1, 84. I tried to use the 16468 but didnt do anything.

Regards,

Ioannis
- 15th April 2011, 09:24
For the Serin2 the 84 is for True RS232 signal. The 16468 is for inverted signal as is the case with the ID-12.

I could not find in the manual where is the speed of the serial port.

Does it clearly state 9600? I found the part that says the signal is inverted and no driver is required.

Ioannis

Gevo
- 15th April 2011, 10:34
ok,

I use the OEM 125Khz reader See http://www.picshop.nl/rfid.html

This Reader has a CP signal, Before the 10-byte is serial out, the CP signal will be High. Then I have 210ms time to readout the reader. The PIC in the application is a 16F887.

buf var byte (10) ' RFID bytes from tag

Main:

If PORTA.7 = 0 then Read_Tag ' CP signal of the OEM reader, read within 210 mS

' Here other program lines

Goto Main


' ----- [ GOSUB ] -----------------------------------------------------------

Read_Tag:
' Wait for Hex 02 . . .
serin2 PORTB.0, 84, [WAIT($02), str buf\10] ' Read 10 byte from ECO-125

return

astanapane
- 20th April 2011, 18:24
Dear All,

thank you very much for your help. Ioannis helped me out to identify my mistakes on the code and he also gave me the right instructions in order to solve the problem.

i would like also to thanks, Joe, Bruce and Gevo for their support.

Please find attached pictures of my circuit.

astanapane
- 3rd May 2011, 09:54
now the next and most difficult part is to configure the code for GLCD use.

But i havent seen any library for GLCD. Some users in here have been working for many hours to built a standard code for GLCDs.

the problem is that there would be much better if a library were available from PIC BASIC.

i know and understand that will take place on the pic chip but in nowadays we all using more powerfull pic's.

Regards,

Leonardo

pedja089
- 3rd May 2011, 12:06
You might find something interesting here
http://www.picbasic.co.uk/forum/showthread.php?t=2078&p=102009#post102009

astanapane
- 7th May 2011, 15:57
here you can see a demo of the RFID circuit.

http://www.youtube.com/watch?v=0cp1Y1U_XGk

I need now to improve it with GLCd and Keypad.

i would like to say thanks to Mr. Ioannis for his patient and help.

regards,

rmteo
- 7th May 2011, 16:18
I need now to improve it with GLCd and Keypad.


If this is a one-off (which it appears to be) and price is not an overwhelming obstacle, then look at a serial Graphic LCD such as this one http://www.sparkfun.com/products/9351
Besides writing text, this serial graphic LCD allows the user to draw lines, circles and boxes, set or reset individual pixels, erase specific blocks of the display, control the backlight and adjust the baud rate. It costs $35 and you won't need a GLCD library.

Better yet, this full color TFT has a built-in touch screen so you won't need a keyboard http://www.sparkfun.com/products/10089 - it costs more at $85 and is fully programmable OR can can be controlled with a serial port.


http://www.youtube.com/watch?v=vWKWQcfNd3Y&feature=player_embedded

astanapane
- 7th May 2011, 19:23
hello rmteo,

thanks for your advice.

I dont know about the serial lcd. Can i drive it form a pic18f4550 for example?

Could you give me some instructions? a sample code? I will first use the serial lcd and then i will try the color.

How is the serial GLCD working, and why i dont need a GLCD library? As i see on the serial there is an ATEML chip. I dont know how to programm ATMEL. Sorry for my questions.

Thank you very much for any help in advance.

Kind regards,

astanapane.

rmteo
- 7th May 2011, 19:35
The serial GLCD can be used with any MCU (including the PIC184550) that can output serial data. You do not need a GLCD library as it is an intelligent display that has an AtmelAVR MCU on board - you could say that the library lives in the AVR.

I do not provide sample code. You send simple ASCII codes using SEROUT (or HSEROUT) at up to 115,200 baud. Take a look at the datasheet here http://www.sparkfun.com/datasheets/LCD/Monochrome/Corrected-SFE-0016-DataSheet-08884-SerialGraphicLCD-v2.pdf and (http://www.sparkfun.com/datasheets/LCD/Monochrome/Corrected-SFE-0016-DataSheet-08884-SerialGraphicLCD-v2.pdf) and the tutorial here http://www.sparkfun.com/tutorials/120

astanapane
- 7th May 2011, 19:42
so using picbasic, can i include a file on my code with a picture?

thanks a lot. Sorry for missanderstanding about a sample code. I didnt ask for an actual code but an example.

Thanks anyway for give me the information.

Kind regards,

rmteo
- 7th May 2011, 20:08
Going by the datasheet of the serial GLCD, it is obvious that the code in the AtmelAVR is pretty limited in capabilities. It can do text, pixels, lines, boxes, circles and not much else.

If you want to do pictures, then look into the COLOR LCD. It is a far more capable product that can even do full motion video (in color) as shown in the video. I have one and would highly recommend it. Full info here http://www.4dsystems.com.au/prod.php?id=114

In fact, since I no longer have a need for it, I may consider running a contest to give it away. :p:p

astanapane
- 7th May 2011, 20:35
thanks i will look for an LCD that is capable for my needs.

cncmachineguy
- 7th May 2011, 20:44
In fact, since I no longer have a need for it, I may consider running a contest to give it away.


Can I compete? or is there a limit?

kaganayanoglu
- 16th June 2014, 10:43
Dear All,

thank you very much for your help. Ioannis helped me out to identify my mistakes on the code and he also gave me the right instructions in order to solve the problem.

i would like also to thanks, Joe, Bruce and Gevo for their support.

Please find attached pictures of my circuit.


Dear astanapane,

Publications of the source code of the forum. Çok güzel proje. Ben de yapmak isterim. Thanks.

kaganayanoglu
- 16th June 2014, 21:17
Publications of the source code of the forum. Very nice project. I'd like to. Thanks

astanapane
- 28th March 2017, 09:00
apologize for my absent so many years.

I was working in Dubai for 4 years and really didnt have a time to login. I have more than a flight per day, so you understand that i wasnt able at all to handle many things at a time.

Now im back to real life, and i will upload the code and the circuits as well tonight.

Imagine that for so long time, the circuit remains the same in my lab, and i havent done anything to it yet apart from adding a second circuit, beside it with a keypad.

None of the core of the codes are mine, i just did some configurations and changes to fit my needs. (im not proud of this, as i would like ones to write completely my own code from the scratch)

The following image shows the circuit and the connection of one circuit to an other.

8389

I know that it is difficult to understand the schematic, as it is not corresponds at the moment to a circuit, but i have it on a TEST Board and i can do a small video of it.

As i have mentioned, there are two circuits, separated, the RFID circuit (with the uLCD) and the CODELOCK with keyboard.

What the circuit does:

1) once you place the Tag to the RFID reader, the uLCD, displays the picture of the person carries the RFID tag
2) at the same time, a BEEP on the buzzer is activated and sends a command to activate the second circuit.
3) You have 5 seconds until you add the code on the keypad otherwise the circuit lose its power and is not activated any more.

astanapane
- 28th March 2017, 20:08
the code for the RFID PIC16F88 chip


'* Author : LEONARDO BILALIS *
'* Notice : Copyright (c) 2017 [LEONARDOS BILALIS] *
'* : All Rights Reserved *
'* Date : 19/3/2017 *
'* Version : 1.3 *
'* Notes : This is an RFID ACCESS control with ulcd *
'* : and an interrupt LED on portb.3 *
'************************************************* ***************
@ ERRORLEVEL -306 ; this command prevents the compiler to give you a notice of
; crossing page boundary - make sure bits are set
Include "MODEDEFS.BAS"
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
DEFINE OSC 8
OSCCON=%01111000 '8 Mhz
CMCON = 7 'turn comparators off
ANSEL = 0 'All digital

;wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
wsave VAR BYTE $70 SYSTEM ' alternate save location for W
' if using $70, comment wsave1-3

' --- IF any of these three lines cause an error ?? ------------------------
' Comment them out to fix the problem ----
' -- Which variables are needed, depends on the Chip you are using --
wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3

;-----------------------------------------------------------------
LED VAR PORTb.3 ; this is the operation led

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

T1CON = $31 ; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
;-----------------------------------------------------------------
' -----[ 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
x var byte
Symbol PWRLED = PORTB.1 ; this shows that the initialization is finished and is ready for the RFID tag
symbol LCD = PORTB.5 ; to LCD operation
Symbol rfidin = PORTB.2 ; from RFID
Symbol GROAN = PORTB.7 ; goes to groan when the rfid is denied
Symbol TXRXIN = PORTB.0 ; this is the RX input signal from the other circuit
pause 2000

serout2 LCD,32,[$55] ' uOLED Initialize
pause 2000
serout2 lcd,32,[$56,$01]
pause 1000
serout2 lcd,32,[$45]
pause 500
serout2 lcd,32,[$55]
pause 500
serout2 lcd,32,[$45]
pause 500
serout2 lcd,32,[$73,$00,$03,$11,$ff,$ff," Leonardo Bilalis",$00]
pause 200
serout2 lcd,32,[$73,$02,$06,$10,$ff," Copyright 2017",$00]
pause 3000
serout2 lcd,32,[$45]
pause 1000
high pwrled 'Software controlled Power LED (if this LED is not on at load check your code)
' -----[ EEPROM Data ]-----------------------------------------------------

Tag1 DATA "xxxxxxxxxx"
Tag2 DATA "xxxxxxxxxx"
Tag3 data "xxxxxxxxxx"
Tag4 data "xxxxxxxxxx"
Tag5 data "xxxxxxxxxx"
Tag6 Data "xxxxxxxxxx"
Tag7 data "xxxxxxxxxx"
Tag8 data "xxxxxxxxxx"
Tag9 data "xxxxxxxxxx"
Tag10 data "xxxxxxxxxx"

' -----[ Initialization ]--------------------------------------------------
LOW portb.4 ' lock the door!

'----- [ LOGO ] ---------------------------------------------------------------
logo:
serout2 LCD,32,[$55] ' uOLED Initialize
pause 500
gosub Logo_png

' -----[ Program Code ]----------------------------------------------------

Main:
serin2 portb.2,84,[WAIT($02),str BUF\10]
pause 500

Check_List:
FOR tagNum = 1 to 10 ' 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
serout2 lcd,32,[$59,$03,$01]
pause 1000
serout2 lcd,32,[$40, $49, $00, $00, $80, $80, $10, $00, $00, $C0]
pause 500
FREQOUT groan, 1000 */ $100, 115 */ $100 ' groan
pause 500
serout2 lcd,32,[$45]
pause 500
serout2 lcd,32,[$59,$03,$00]
pause 200
goto main

Tag_Found:
IF tagNum = 1 then Leonardo

IF tagNum = 2 then ELENI

if tagnum = 3 then MAMAANNA

if tagnum = 4 then THEIAMARIA

if tagnum = 5 then MARIA

if tagnum = 6 then displayName6

if tagnum = 7 then displayName7

if tagnum = 8 then displayName8

if tagnum = 9 then displayname9

if tagnum = 10 then displayname10

GOTO main

Leonardo:
serout2 lcd,32,[$59,$03,$01]
pause 1000
serout2 lcd,32,[$40, $49, $00, $00, $80, $80, $10, $00, $00, $40]
pause 500 'Pause ,5 sec then clear display
goto open_door

ELENI:
serout2 lcd,32,[$59,$03,$01]
pause 1000
serout2 lcd,32,[$40, $49, $00, $00, $80, $80, $10, $00, $00, $00]
pause 500 'Pause ,5 sec then clear display
goto open_door

MAMAANNA:
serout2 lcd,32,[$59,$03,$01]
pause 1000
serout2 lcd,32,[$73,$00,$03,$11,$ff,$ff," Thank you ANNA",$00]
pause 200
serout2 lcd,32,[$73,$02,$06,$10,$ff," Please enter code",$00]
pause 500
goto open_door

THEIAMARIA:
serout2 lcd,32,[$59,$03,$01]
pause 1000
serout2 lcd,32,[$73,$00,$03,$11,$ff,$ff," Thank you MARIA",$00]
pause 200
serout2 lcd,32,[$73,$02,$06,$10,$ff," Please enter code",$00]
pause 500
goto open_door

MARIA:
serout2 lcd,32,[$59,$03,$01]
pause 1000
serout2 lcd,32,[$73,$00,$03,$11,$ff,$ff," Thank you MARIA",$00]
pause 200
serout2 lcd,32,[$73,$02,$06,$10,$ff," Please enter code",$00]
pause 500
goto open_door


displayName6:


displayName7:


displayName8:


displayName9:

displayName10:
'----------------------OPEN THE DOOR------------------------------
open_door:
HIGH portb.4 ' remove latch
pause 5000
if TXRXIN = 1 then
pause 8000
endif
LOW portb.4 ' restore latch
serout2 lcd,32,[$45]
pause 500
serout2 lcd,32,[$59,$03,$00]
goto main

;DOOR:
; serout2 lcd,32,[$45]
; serout2 lcd,32,[$73,$00,$03,$11,$ff,$ff,"DOOR is OPENED",$00]
; return
'----------------- [ LOGO Routine ] ------------------------------

Logo_png:
serout2 lcd,32,[$40, $49, $00, $00, $80, $80, $10, $00, $00, $00]
pause 3000
serout2 lcd,32,[$59,$03,$00]
pause 200
return
'-------------------- [ CLEAR ] ----------------------------------
Clearlcd:
serout2 lcd,32,[$45]
pause 500
goto logo

'---[TMR1 - interrupt handler]--------------------------------------------------
ToggleLED1:
TOGGLE led
@ INT_RETURN

and the code for the PIC16F84A


'************************************************* ***************
'* Name : CodeLock.bas *
'* Author : xxxxxx *
'* Date : xxxxxxxxxx *
'* Version : 1.0 *
'* Notes : Programable Code Lock with the PIC-16F84 *
'************************************************* ***************
; Change the code from 1234 by typing the code 1234 then * 1961#1961#

Include "MODEDEFS.BAS"
'************************************************* *
RL1_ON_time con 1000 * 5 'sec. Relay ON time
'************************************************* *

TrisA = 0 ' PORTA, all outputs
PortA = 16 ' turn off Buzer
OPTION_REG.7 = 0 ' PORTB Pullups.
TrisB = %11110000 ' PORTB.0-3 outputs, 4-7 inputs
PortB = 0

LD1 var PortA.2
RL1 var PortA.3
BUZ var portA.4

cnt var byte

key var byte
col var byte
row var byte
keycnt var byte
pwOK var bit

keybuf var byte[15]
pwbuf var byte[4]

EEPROM 0,[1,2,3,4] 'Default password 1,2,3,4 programmed at EEprom location 0..3
Read 0, pwbuf[0] 'Copy password from EEprom address 0..3 in to pwbuf[0..3]
Read 1, pwbuf[1]
Read 2, pwbuf[2]
Read 3, pwbuf[3]

pwOK = 0
keycnt = 0

Main:
high ld1
pause 200
gosub Chk_KEYPAD
pause 100

goto Main

Chk_KEYPAD:
for row = 0 to 3
PORTB = (dcd row) ^ $f
pause 1
col = PORTB >> 4
if (col <> $f) then 'key pressed
key = (row * 3) + (ncd (col ^ $f))
gosub Got_KEY
key = 255
endif
next
return

Beep:
low ld1
low buz
pause 40
high buz
return

Got_KEY:
gosub Beep
while (PORTB >> 4) <> $f
pause 1
wend
if key = 11 then key = 0
keybuf[keycnt] = key
gosub Chk_keycnt
return

Chk_PwOK:
PwOK = 0
if (keybuf[0] = pwbuf[0]) and (keybuf[1] = pwbuf[1]) and (keybuf[2] = pwbuf[2]) and (keybuf[3] = pwbuf[3]) then pwok = 1
return

Chk_NewPwOK:
PwOK = 0
if (keybuf[5] = keybuf[10]) and (keybuf[6] = keybuf[11]) and (keybuf[7] = keybuf[12]) and (keybuf[8] = keybuf[13]) then pwok = 1
return

Pw_Change:
pwbuf[0] = keybuf[5]
pwbuf[1] = keybuf[6]
pwbuf[2] = keybuf[7]
pwbuf[3] = keybuf[8]
Write 0, pwbuf[0] 'Store new password to EEprom location 0..3
Write 1, pwbuf[1]
Write 2, pwbuf[2]
Write 3, pwbuf[3]
return

Chk_keycnt:
select case keycnt
case 4
gosub Chk_PwOK
if pwOK then
if keybuf[keycnt] = 12 then Access_OK
if keybuf[keycnt] <> 10 then Clr_keybuf
gosub Beep
else
goto Clr_keybuf
endif
case 9
if keybuf[keycnt] <> 12 then Clr_keybuf
gosub Beep
case 14
if keybuf[keycnt] <> 12 then Clr_keybuf
gosub Beep
gosub Chk_NewPwOK
if pwOK then
gosub Beep
gosub Pw_Change
gosub Beep
goto Clr_keybuf
else
goto Clr_keybuf
endif
case else
if keybuf[keycnt] = 12 then Clr_keybuf
end select
keycnt = keycnt + 1
return

Access_OK:
High RL1
pause RL1_ON_time
low RL1

Clr_keybuf:
for cnt = 0 to 14
keybuf[cnt] = cnt
next
keycnt = 0
goto Main

end

astanapane
- 28th March 2017, 20:11
Tomorrow afternoon the video of what the circuit and the code are all about.

Ioannis
- 29th March 2017, 13:30
Welcome back Leonardo!

After this long time, your uLCD I guess is ... obsolete now!

Ioannis

astanapane
- 29th March 2017, 20:10
Hi Ioanni, the ulcd is not obsolete but upgraded as for as i checked with a newer version. I think the only difference is the change of the pins position. Instead of the pins are place in one line now they are in 2 lines

astanapane
- 30th March 2017, 07:51
Not very good quality of video and explanation but hope you can understand.

Im not a programmer so, it is the best i could up to now.

Next step is to add a RFID KEY MASTER in order to record more RFID tags in to the epprom without having to reprogram the chip.


http://www.youtube.com/watch?v=o0cPDSc_G_Q

astanapane
- 2nd April 2017, 13:38
Dear all,

the project for my home up to now works OK!.

Here is also a 3D printed case i have designed in order to place nice and clean all the components and electronics.

http://i67.tinypic.com/aujhh5.jpg

astanapane
- 3rd April 2017, 09:14
Dear all,

i have a small problem with my code and circuit.

After 3 or 4 tries, maybe less maybe after 2 or 3 minutes.....(it is strange) when i pass the RFID from the reader, the first circuit, works perfect, but the second circuit, looks like does not listen to any command from the keypad.

It looks like that it gets power from the first circuit, but when i try to press any button from the Keypad, does not respond.

here is the code of the circuit that is related to the keypad.

If you notice, i havent add any commands for the fuses....because when i did that i was getting errors

;@ DEVICE pic16F84A, HS_OSC, WDT_OFF, PWRT_ON, PROTECT_OFF --> this is not working.

;@ __config _HS_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF --> this was passing the first error the counldnt find the PIC16F84A but i was getting an error (2007)

The problem is: If i load the code without fuses, the program and circuit works fine on the test board.
When i transfer it to the PCB after 2-3 minutes when i try to pass the TAG from the reader, the Keypad looks like that is not responding.


'************************************************* ***************
'* Name : CodeLock.bas *
'* Author : xxxxxx *
'* Date : xxxxxxxxxx *
'* Version : 1.0 *
'* Notes : Programable Code Lock with the PIC-16F84 *
'************************************************* ***************
; Change the code from 1234 by typing the code 1234 then * 1961#1961#

Include "MODEDEFS.BAS"
'************************************************* *
RL1_ON_time con 1000 * 5 'sec. Relay ON time
'************************************************* *

TrisA = 0 ' PORTA, all outputs
PortA = 16 ' turn off Buzer
OPTION_REG.7 = 0 ' PORTB Pullups.
TrisB = %11110000 ' PORTB.0-3 outputs, 4-7 inputs
PortB = 0

LD1 var PortA.2
RL1 var PortA.3
BUZ var portA.4

cnt var byte

key var byte
col var byte
row var byte
keycnt var byte
pwOK var bit

keybuf var byte[15]
pwbuf var byte[4]

EEPROM 0,[1,2,3,4] 'Default password 1,2,3,4 programmed at EEprom location 0..3
Read 0, pwbuf[0] 'Copy password from EEprom address 0..3 in to pwbuf[0..3]
Read 1, pwbuf[1]
Read 2, pwbuf[2]
Read 3, pwbuf[3]

pwOK = 0
keycnt = 0

Main:
high ld1
pause 1
gosub Chk_KEYPAD


goto Main

Chk_KEYPAD:
for row = 0 to 3
PORTB = (dcd row) ^ $f
pause 1
col = PORTB >> 4
if (col <> $f) then 'key pressed
key = (row * 3) + (ncd (col ^ $f))
gosub Got_KEY
key = 255
endif
next
return

Beep:
low ld1
low buz
pause 40
high buz
return

Got_KEY:
gosub Beep
while (PORTB >> 4) <> $f
pause 1
wend
if key = 11 then key = 0
keybuf[keycnt] = key
gosub Chk_keycnt
return

Chk_PwOK:
PwOK = 0
if (keybuf[0] = pwbuf[0]) and (keybuf[1] = pwbuf[1]) and (keybuf[2] = pwbuf[2]) and (keybuf[3] = pwbuf[3]) then pwok = 1
return

Chk_NewPwOK:
PwOK = 0
if (keybuf[5] = keybuf[10]) and (keybuf[6] = keybuf[11]) and (keybuf[7] = keybuf[12]) and (keybuf[8] = keybuf[13]) then pwok = 1
return

Pw_Change:
pwbuf[0] = keybuf[5]
pwbuf[1] = keybuf[6]
pwbuf[2] = keybuf[7]
pwbuf[3] = keybuf[8]
Write 0, pwbuf[0] 'Store new password to EEprom location 0..3
Write 1, pwbuf[1]
Write 2, pwbuf[2]
Write 3, pwbuf[3]
return

Chk_keycnt:
select case keycnt
case 4
gosub Chk_PwOK
if pwOK then
if keybuf[keycnt] = 12 then Access_OK
if keybuf[keycnt] <> 10 then Clr_keybuf
gosub Beep
else
goto Clr_keybuf
endif
case 9
if keybuf[keycnt] <> 12 then Clr_keybuf
gosub Beep
case 14
if keybuf[keycnt] <> 12 then Clr_keybuf
gosub Beep
gosub Chk_NewPwOK
if pwOK then
gosub Beep
gosub Pw_Change
gosub Beep
goto Clr_keybuf
else
goto Clr_keybuf
endif
case else
if keybuf[keycnt] = 12 then Clr_keybuf
end select
keycnt = keycnt + 1
return

Access_OK:
High RL1
pause RL1_ON_time
low RL1

Clr_keybuf:
for cnt = 0 to 14
keybuf[cnt] = cnt
next
keycnt = 0
goto Main

end
Quick reply to this message Reply Reply With Quote Reply With Quote Multi-Quote This Message

astanapane
- 3rd April 2017, 10:11
Ok,

first thing first. I will edit the ,inc file and commend it in order to avoid the error 2007

overwritting previous address contents (2007)

then i will see if that works. I will post results tomorrow afternoon.

Ioannis
- 3rd April 2017, 10:20
Which compiler you use now?

Ioannis

astanapane
- 3rd April 2017, 12:24
an old one, as far as i remember is the 2.6b

Ioannis
- 3rd April 2017, 13:44
Then yes, you should edit the *.inc file first the way you stated.

Ioannis

astanapane
- 3rd April 2017, 13:48
Thanks Ioanni.

In case of the newer version, should i have to edit again the .inc files?

Let me first fix the code and then will discuss further.

Ioannis
- 3rd April 2017, 15:10
PBP 3 does not need messing with the inc files. But has different fuses setup. More easy.

Ioannis

astanapane
- 5th April 2017, 11:27
it took me a while to find the proper configuration of the fuses, but code works fine.

At the moment it works on a TEST BOARD, but not on the pcb board. Maybe i have done a mistake on the drawing and i create an overflow or a bad EMF that causes a problem to the resonator.

What im thinking of is to use the internal OSC of the PIC16F84A, 4Mhz, instead of the external 4Mhz resonator. In that way i will also eliminate a component and i will check whether that was the problem.

astanapane
- 10th April 2017, 07:21
Finally i did a second circuit, which both of the PICs are not related to once each other, but they are a separate operational circuits. Each of then drives the same relay.

As i have told you this a circuits that will be outside on a main door in a small Village, so people that would like to come in, they need to know either the PASSCODE on the Keypad, or to have with them an RFID key.

After a small discussion we had, old people didnt like to carry an RFID key, so they requested if it is possible to have only the keypad.

On the other side, the younger of the family, liked the idea of the rfid, which the only downside it is to take care not to loose it. Ofcourse both will know the main password on the keypad so, for those will have an rfid key, if once does not work, will have the option to use the keypad to access the door.

To be honest, in nowadays, especially in the village, you do not need a super extreme security system. In addition to that, the simplest the better!!!

I understand that to carry an RFID key is the same as to have the real key to open the door. In my next experiment i will try to include a fingerprint sensor, but im waiting to see a good one, because at the moment none is so reliable.

8390