In SX Microcontrollers, SX/B Compiler and SX-Key Tool, stef wrote: Hi I'm trieing to read wiegand protocol to interface an acces controle reader to my sx and send the data then out true a serial line to a computer. I have struggeld so far now that it is working but I always get diffrend data when presenting the same badge. Thier is something wrong in the program but I can't find what it is. Is somebody willing to take a look and point me to the bug or give me a clue what i'm doing wrong. I listed the program below. Thanks Stef [1] [code] DEVICE SX28,TURBO,STACKX_OPTIONX '-------------------------------------------------------------------------------- ' wiegand reader interface '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- ' Pins '-------------------------------------------------------------------------------- DIMBIT pulseled=RA.3 DIMBIT data0=RA.0 DIMBIT data1=RA.1 DIMBIT greenled=RC.7 DIMBIT TX=RB.0 '-------------------------------------------------------------------------------- ' Variables '-------------------------------------------------------------------------------- DIM N DIM databit DIM bitcnt DIM bytecnt DIM rfid(3) DIM siteid DIM cardid(2) outdir greenled indir data0,data1,pulseled watch siteid,cardid,data0,data1 level RA=$ff pullup RA=$00 LEVEL RB=$00 SCHMITT RB=$FF '-------------------------------------------------------------------------------- 'Programma '-------------------------------------------------------------------------------- start: bitcnt=0 bytecnt=0 databit=0 main: ' controle if both lines are high IF data0 = TRUE then if data1 = TRUE then greenled = false GOTO main ENDIF ENDIF greenled = true ' controle if one line is low IF data1 = FALSE THEN SHIFTINL databit,data0 'wait untile data1 line is back high WHILE DATA1=FALSE WEND ELSE SHIFTINL databit,data0 'wait untile data0 line is back high WHILE data0=FALSE WEND ENDIF ' add bit count INCR bitcnt IF bitcnt = 8 THEN bitcnt = 0 rfid(bytecnt) = databit INCR bytecnt ENDIF 'controle 3 bytes if bytecnt < 3 THEN GOTO main ' send data to serial port out SEROUTA TX,rfid(0),3 'seroutA tx,rfid(1),3 'seroutA tx,rfid(2),3 goto start END [/code] [/1] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=154102 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)