keylog:
addressPointer = 0
mybyte = key
FOR addressPointer = 0 TO 10
WRITE addressPointer, myByte
NEXT
The only thing in your FOR/NEXT loop is the statement that writes the byte to the EEPROM. You need to collect data between writes. Take a look again at the code Terry posted on Apr 27.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ OS-X: because making Unix user-friendly was easier than debugging Windows
push:
IF db = 1 [color=green]THEN done[/color]' Already responded to this press, so done.
[color=red]db = 1: press = 1[/color] ' Set debounce and keypress flags.
key = (key-1)+(row*4) ' Add column (0-3) to row x 4 (0,4,8,12).
LOOKUP key,[noparse][[/noparse]13,15,0,14,12,9,8,7,11,6,5,4,10,3,2,1],key
done:
[color=green]INPUT row ' Disconnect output on row.
RETURN ' Return to program.[/color]
This· is wrong -- db = 1: press = 1.·· It needs to be two lines:
db = 1
press = 1
You are GOSUBing to "done" -- is that REALLY what you want to do?· Because it RETURNs, of course to "push", when what I think you want to do (??) is get out of "push" (??) and return to the top and get another key-press (??).
Maybe I'm being picky, but I think that you need to re-work this --
key = (key-1)+(row*4) ' Add column (0-3) to row x 4 (0,4,8,12) --
Yes, you must be very careful when using GOSUB's and RETURNS to insure that for each GOSUB there's a matching RETURN. Typically you do this by NOT using a 'GOTO' that leaves the subroutine entirely -- especially not a GOTO that goes to a 'caller' of the subroutine.
See the fixed file.
Oh, and "IF xxx THEN DoLabel" -- is an implied "GOTO DoLabel", not a gosub. P.J. Allen was mistaken about this.
Note I'm not sure if the attached file is completely fixed.· It just has the major GOSUB -- GOTO faults fixed.
· Well, this one had gone for a while and then the Originator re-posted -- so, I figured the best way to get loads of help/input would be for me to stick my neck out.· · But, honestly, I'm befuddled with/by the Originator's intentions,·hence my generous use of (??).· If others can say, then more power to them; it's not clear to me sometimes whether the difference between GOTO and GOSUB·is clear to others (no offense.) · So, roberto, SSteve and allanlane5 "got your back".· Adíos, hombrés.
again:
GOSUB writeByte
press= 0
writeByte:
press= 0
GOSUB keyscan
IF press = 0 THEN again
DEBUG HEX key
GOSUB keylog
RETURN
The above code won't work because you GOSUB to "writeByte", but it calls "again" with a GOTO ("IF press = 0 THEN again"). That's going to cause your GOSUB/RETURN stack to overflow. Try something like this instead:
press= 0
DO
again:
GOSUB keyscan
IF press = 0 THEN again
DEBUG HEX key
GOSUB keylog
press = 0
LOOP
Note that this requires the keyscan routine to set the variable "press" to a non-zero value when a key is pressed. Your current keyscan doesn't do that.
There are a few problems with this subroutine:
keylog:
addressPointer = 0
mybyte = key
FOR addressPointer = 0 TO 10
WRITE addressPointer, myByte
NEXT
First off, it doesn't end with RETURN, so the program flow will fall through to keyscan when it's through. The FOR/NEXT loop simply writes the value in "mybyte" to the first 11 locations in EEPROM because addressPointer is going from 0 to 10. The "mybyte" variable is superfluous. Try something like this:
The subroutines getAddressPointer/saveAddressPointer need to read/write the current addressPointer value to a fixed location in the EEPROM.
The trick to successful programming is to put yourself in the mindset of the processor and meticulously follow the effects of each line of code. Write down the name of each variable at the top of a column and write down its initial value. Every time that variable is changed, cross out the old value and write down the new value. Keep careful track of program flow (GOTO, GOSUB/RETURN, DO/LOOP etc.). When you're a beginner this is a slow and arduous process--there's no way around it. But it's a lot faster than just trying to cobble together bits of code from disparate sources and hoping it will work. Once you have a more intuitive grasp of how it works the process will be much faster and you'll be able to more easily incorporate 3rd-party code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ OS-X: because making Unix user-friendly was easier than debugging Windows
i keep getting the same eerors (logs key entry 11 times)
even if i play around with the code maybe i should get a keypad encoder instead off trying to log the keys from this program ?
i think its because the press is always = 0.
someone have any 4x4 matrix keypad scanner where it would be much easier from me to log keystoke to the eeprom ?
this is what i have has hardware bs2, bs2pe, 4x4 matrix keypad, all the resistors needed will buy.
in future thinking of logging the time (also have the ds1302) for specific key press thats why the bs2pe.
· Maybe you should start over and take a step-by-step approach.· Instead of a 4x4, you might consider a 2x2 (using 4 push-button switches), something more manageable,·and get your key concept straight.· When you consistently get the result with DEBUG (1 gets a "1", 2 gets a "2", etc.) then you can move on to expanding it to a 4x4, and then to writing/reading everything in the eeprom.· The one-felled-swoop approach isn't working.·
· Q:· How do you eat an elephant? · A:· One mouthful at a time.
Perhaps I am missing something elsewhere because I have seen several message reagrding the same key being logged several times, yet your routine seems to be setup to do this very thing.
keylog:
addressPointer = 0
mybyte = key
FOR addressPointer = 0 TO 10
WRITE addressPointer, myByte ' BAD -- you're writeing eeprom WAY too often
NEXT
I think this was already pointed out too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Tech Support csavage@parallax.com
I know i am getting ahead of myself but i saw your template for the ds1302
do you think i would be able to use that code to log time when a specific key if pressed? in the bspe2
Everytime it goes to "keylog", it is going to Reset addressPointer (to zero)· Is that desired?
Another matter: How many keylogs do you want to do/make?
I think you need to make addressPointer = 0 at the beginning, before joining the DO...LOOP and then increment it from there.
Let's say your limit is 16 keypresses (0 through 15), then:
addressPointer VAR Word
myByte VAR Byte
db VAR Bit ' Debounce bit for use by keyScan.
press VAR Bit ' Flag to indicate keypress.
key VAR Nib ' Key number 0-15.
row VAR Nib ' Counter used in scanning keys.
cols VAR INB ' Input states of pins P4-P7.
press= 0
addressPointer = 0
DO
again:
GOSUB keyscan
IF press = 0 THEN again
DEBUG HEX key
GOSUB keylog
press = 0
LOOP
keylog:
[color=red]IF addressPointer = 16 THEN pointerReset[/color]
mybyte = key
WRITE addressPointer, myByte
addressPointer = addressPointer + 1
Return
[color=red]pointerReset:[/color]
[color=red] addressPointer = 0[/color]
[color=red] GOTO keylog[/color]
It's possible to use that code with yours to log the time, but first you need to get the current code working before adding anything.· You need to run the code before asking for help.· In order to run your code I would need to build your circuits as well, so I am focusing on the obvious, as well as on program flow, which, at this point is not easy to follow because the code jumps around a lot.· You have a lot of sub routines calling other subroutines, and you had conditionals in there.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Tech Support csavage@parallax.com
roberto has deleted a number of his posts.· On the second page there was one with his whole program on· it --·and it is gone.· Why did you Delete your previous posts, roberto?· That is not cricket.
i think there is something wrong because the debug screen keeps repeating the time over and over i dont think that was intented. But the demo versions works fine. Has you know i am trying to log the time with the keylog when a specific key is pressed· do you have any hints to give me on that? i think i am starting to grasp the programming aspect of PBASIC gradually so is there· any links where it shows how to·link·two programs together ?
·· Well if you're going to learn PBASIC by writing a complex application then you will need to do a lot of imperical testing and experimenting.· Otherwise we would be basically writing the software for you over the course of the thread.· I'm not opposed to helping out as you can see from all the help I have given, but there is a point where you will have learn the necessary material to be able to accomplish this.
·· If I were in your shoes I would've learned how to use the DS1302 completely, making changes to the code and seeing how that affects the results.· Then I would've learned about storing data in the EEPROM and finally how to log data.· Once you have all of that then you can start merging the concepts together into a working program.
·· On the same token it's hard to offer help and examples if the recipient doesn't understand the material given.· We have a tutorial on the BASIC Stamp called, "What's A Microcontroller?" which is a free download in PDF format from our website.· By any chance have you read through this?· If not I would highly recommend downloading it and going through it.· A link is provided below (bottom of each page).· And remember, both the Editor Help File and the BASIC Stamp Syntax & Reference Manual are excellent references for the commands and examples of how they work.
In keylog.txt, I see that you have the addressPointer = 0, that I recommended, before you start your DO...LOOP.· Good -- but, as it stands: if you push buttons enough, eventually you will start over-writing (corrupting) the program area of the EEPROM.· Is there some way you're preventing this that I cannot see?· If not, you may want to add the pointerReset feature which I also suggested a couple of (my) posts ago.
Comments
The only thing in your FOR/NEXT loop is the statement that writes the byte to the EEPROM. You need to collect data between writes. Take a look again at the code Terry posted on Apr 27.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
This· is wrong -- db = 1: press = 1.·· It needs to be two lines:
You are GOSUBing to "done" -- is that REALLY what you want to do?· Because it RETURNs, of course to "push", when what I think you want to do (??) is get out of "push" (??) and return to the top and get another key-press (??).
Maybe I'm being picky, but I think that you need to re-work this --
to be:
·
It's generally avoided as bad coding practice, however. Two statements on one line are harder to read.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
See the fixed file.
Oh, and "IF xxx THEN DoLabel" -- is an implied "GOTO DoLabel", not a gosub. P.J. Allen was mistaken about this.
Note I'm not sure if the attached file is completely fixed.· It just has the major GOSUB -- GOTO faults fixed.
· But, honestly, I'm befuddled with/by the Originator's intentions,·hence my generous use of (??).· If others can say, then more power to them; it's not clear to me sometimes whether the difference between GOTO and GOSUB·is clear to others (no offense.)
· So, roberto, SSteve and allanlane5 "got your back".· Adíos, hombrés.
the file is still loggin 10 times the same last key presed
likr bfore
how do i go around that
this is what i get when i read after pressing 1234 on the keypad ( i am reading 0 to 20)
444444444440000000000
Post Edited (roberto) : 5/1/2006 8:24:13 PM GMT
The above code won't work because you GOSUB to "writeByte", but it calls "again" with a GOTO ("IF press = 0 THEN again"). That's going to cause your GOSUB/RETURN stack to overflow. Try something like this instead:
Note that this requires the keyscan routine to set the variable "press" to a non-zero value when a key is pressed. Your current keyscan doesn't do that.
There are a few problems with this subroutine:
First off, it doesn't end with RETURN, so the program flow will fall through to keyscan when it's through. The FOR/NEXT loop simply writes the value in "mybyte" to the first 11 locations in EEPROM because addressPointer is going from 0 to 10. The "mybyte" variable is superfluous. Try something like this:
The subroutines getAddressPointer/saveAddressPointer need to read/write the current addressPointer value to a fixed location in the EEPROM.
The trick to successful programming is to put yourself in the mindset of the processor and meticulously follow the effects of each line of code. Write down the name of each variable at the top of a column and write down its initial value. Every time that variable is changed, cross out the old value and write down the new value. Keep careful track of program flow (GOTO, GOSUB/RETURN, DO/LOOP etc.). When you're a beginner this is a slow and arduous process--there's no way around it. But it's a lot faster than just trying to cobble together bits of code from disparate sources and hoping it will work. Once you have a more intuitive grasp of how it works the process will be much faster and you'll be able to more easily incorporate 3rd-party code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
even if i play around with the code maybe i should get a keypad encoder instead off trying to log the keys from this program ?
i think its because the press is always = 0.
someone have any 4x4 matrix keypad scanner where it would be much easier from me to log keystoke to the eeprom ?
this is what i have has hardware bs2, bs2pe, 4x4 matrix keypad, all the resistors needed will buy.
in future thinking of logging the time (also have the ds1302) for specific key press thats why the bs2pe.
Post Edited (roberto) : 5/2/2006 2:31:49 PM GMT
· Q:· How do you eat an elephant?
· A:· One mouthful at a time.
I think this was already pointed out too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
keylog:
addressPointer = 0
mybyte = key
WRITE addressPointer, myByte
Return
where would i go about incrementing the addressPointer so it does not rewrite to the same location
i wanted this
for addressPointer = 0 to 10
because i wanted to try to log·fist ten keys
i guess thats not how i do that·either
Post Edited (roberto) : 5/2/2006 3:58:59 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
does this works better ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I know i am getting ahead of myself but i saw your template for the ds1302
do you think i would be able to use that code to log time when a specific key if pressed? in the bspe2
Given:
Everytime it goes to "keylog", it is going to Reset addressPointer (to zero)· Is that desired?
Another matter: How many keylogs do you want to do/make?
I think you need to make addressPointer = 0 at the beginning, before joining the DO...LOOP and then increment it from there.
Let's say your limit is 16 keypresses (0 through 15), then:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
and yes it works Chris
logs every key one after the other
thanks a bunch
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
i though i deleted the ones where i though i was repeating myself for no reason
sorry
there is noway to·put it back where it was?
The Ds1302 template that you posted here ·http://forums.parallax.com/showthread.php?p=531080
i think there is something wrong because the debug screen keeps repeating the time over and over i dont think that was intented. But the demo versions works fine. Has you know i am trying to log the time with the keylog when a specific key is pressed· do you have any hints to give me on that? i think i am starting to grasp the programming aspect of PBASIC gradually so is there· any links where it shows how to·link·two programs together ?
Post Edited (roberto) : 5/4/2006 5:18:06 PM GMT
·· Well if you're going to learn PBASIC by writing a complex application then you will need to do a lot of imperical testing and experimenting.· Otherwise we would be basically writing the software for you over the course of the thread.· I'm not opposed to helping out as you can see from all the help I have given, but there is a point where you will have learn the necessary material to be able to accomplish this.
·· If I were in your shoes I would've learned how to use the DS1302 completely, making changes to the code and seeing how that affects the results.· Then I would've learned about storing data in the EEPROM and finally how to log data.· Once you have all of that then you can start merging the concepts together into a working program.
·· On the same token it's hard to offer help and examples if the recipient doesn't understand the material given.· We have a tutorial on the BASIC Stamp called, "What's A Microcontroller?" which is a free download in PDF format from our website.· By any chance have you read through this?· If not I would highly recommend downloading it and going through it.· A link is provided below (bottom of each page).· And remember, both the Editor Help File and the BASIC Stamp Syntax & Reference Manual are excellent references for the commands and examples of how they work.
http://www.parallax.com/detail.asp?product_id=28123
http://www.parallax.com/detail.asp?product_id=27218
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com