RF_ID Reader project
Rod_NSCC
Posts: 5
I'm trying to create a time clock on a Professional Development Board with a BS2 that will use an RF-ID reader (#28140),4 * 20 LCD display (#27979), and a clock circuit . I have created both circuits so that they work separately however once I combined the code together. The program freezes and will not re-display the clock on the LCD.
The clock is always displayed on the first two lines of the LCD. When a RF-ID is passed by the reader a Tag# will be displayed on the third line of the LCD. Then it should reset only displaying the clock on the LCD. But as I mentioned above the program freezes. Looking for assistance. I think that it is simply my placement of the clock code within the RF-ID program, however I've tried moving the clock code to several different places, and it is still will not work properly.
Regards,
Rod
The clock is always displayed on the first two lines of the LCD. When a RF-ID is passed by the reader a Tag# will be displayed on the third line of the LCD. Then it should reset only displaying the clock on the LCD. But as I mentioned above the program freezes. Looking for assistance. I think that it is simply my placement of the clock code within the RF-ID program, however I've tried moving the clock code to several different places, and it is still will not work properly.
Regards,
Rod
BS2
13K
Comments
But I would probably rewrite the entire main loop to use a series of GOSUBS and a single loop. Something like this:
Basically, it appears that you are trying to use some of the more esoteric allowances of PBASIC, and that makes your code very difficult to debug. I would get rid completely of the label scheme in the "Program Code" section, and put all the important code blocks as subroutines. Once you've done that it will make it much easier to add functionality and debug. Don't forget to always post the most recent code that you have.
Changes made to code below:
Main:
GOSUB Clock
LOW Enable ' activate the reader
IF (RX = 0) THEN
GOSUB Tag
ENDIF
GOSUB Check_List
GOTO Main
'
[ Subroutines ]
Tag:
SERIN RX, T2400, [WAIT($0A), STR buf\10] ' wait for hdr + ID
HIGH Enable ' deactivate reader
RETURN
Check_List:
FOR tagNum = 1 TO LastTag ' scan through known tags
FOR idx = 8 TO 9 ' scan bytes in tag
READ (tagNum - 1 * 10 + idx), char ' get tag data from table
IF (char <> buf(idx)) THEN GOSUB Bad_Tag ' compare tag to table
NEXT
NEXT
RETURN
Bad_Char:
RETURN
Bad_Tag:
tagNum = 0
FREQOUT Spkr, 1000, 215 ' groan
GOSUB LCDDisplay
PAUSE 500
GOTO Main
Tag_Found:
FREQOUT Spkr, 1000, 880 ' beep
GOSUB LCDDisplay
PAUSE 500
GOTO Main
Your updated code (post #5) will never get to tag_found... There was a recent discussion on the forum about GOTO, and it's a bit up in the air, but I think your code would be better if you minimized their use. Right now it appears that you're trying many small changes and seeing if that works, then trying something else without correcting the previous changes.
When I'm debugging and I can't find the problem I find it very helpful to go through and format the code really nicely, and to follow the flow of the program. I start at the beginning and work my way through the entire program, visualizing precisely what the code will do for any particular input. It will help you find small inconsistencies in the code that, by themselves, may not be significant (for example, you GOSUB into Bad_Tag but never return from it...) but never the less make the code harder to understand.
To maximize the answers that you get here on the forum, please remember these simple rules:
1. Attach your full code every time.
2. Explain precisely what the problem is with the code and what you want to do.
3. Answer any questions that are asked
With these, it makes our job easier of helping to get the code working.