Yup, that will work.
Yup, that will work.
Dave
Always wear safety glasses while programming.
Cheers mackrackit.
My project, here's the master plan:
I'm going to use the 12F683 to output 4 bit words to drive a BCD to 7-segment decoder driver: Count up from 0-9 in a continual loop IF the push button is pressed THEN GOTO countdown from 9-0 in a continual loop, IF pressed again count down from 5-0 then stop.
This project covers a lot of the ground we've been over in the last week or two and would give me some much needed practical practice.
Another question: Is this program statement viable / do-able to provide input words into the decoder driver?
i VAR WORD
Main:
For i = 0 to 3 etc
LOOKUP i, [0, 1,2,3], GPIO
NEXT i
Sorry but the code tags didn't work tonight.
This would output from the PIC (I hope):
0000 making the driver display '0'
0001 " " '1'
0010 " " '2'
0011 " " '3'
1000 " " '4'
Also from the output side of the PIC ('words') to the input side of the display driver, I'd like to bleed off a little current to the base of four transistors with LED's in the collector leg to visually see the binary count, just for fun.
So what do we think then guys? Have I learned my lessons well, or am I heading for the books...!
David
Hi David,
That will work for exercise purposes but in the above case there's really no need for the LOOKUP table. You can just as well write i directly to GPIO, you'd also want a PAUSE in there or it will count really fast, and don't forget to set the TRIS-register to make the pins in question outputs:Code:i VAR WORD Main: For i = 0 to 3 etc LOOKUP i, [0, 1,2,3], GPIO NEXT iCode:Main: For i = 0 to 3 GPIO = i Pause 500 NEXT iNot quite, it will count (and display) 0, 1, 2 and 3 since 3 is what you have in your FOR statement. Actually i will get incremented one more time, to 4, but when that happens the code will jump to after the NEXT statement so the "4" will never make it to GPIO. (If that last thing didn't make sense never mind, the important thing is that it counts from 0 to 3.)0000 making the driver display '0'
0001 " " '1'
0010 " " '2'
0011 " " '3'
1000 " " '4'
/Henrik.
Hi Henrik
So to get the program to count down from 9-0 would this do it:
FOR i = 9 to 0 STEP -1
GPIO = i
Pause 500
NEXT i
*I don't know why but I my code tags still aren't working tonight, sorry*
If GPIO = 9 then out would go 1001 to the driver etc...
Yes, without the pause it would have counted to 3 lightning fast I guess.
The LOOKUP table is excellent for outputting stored values though, really glad we touched on it.
Last edited by LEDave; - 1st March 2010 at 22:14.
Hi,
Yes, that is correct - all of it. Good job!
All BBTags uses square brackets, ie. [...] and [/...] to turn the option ON and OFF respectively. Seems to work from here. There's a box at the bottom of the page showing if BBCode is ON or OFF, make sure it's ON.
/Henrik.
Henrik thanks for that.
I'm trying to use the COUNT command that mackrackit put me onto to jump from one loop to the next after a button is pressed. There are three loops (count up to nine when button pressed once - Jump to second loop and count down from nine if button pressed a second time and to a final third loop, count down from five after button is pressed a third time).
Is this code anywhere near to where I need to be? If I'm close but not quite there please let me carry on thinking. If I'm miles off course then a pointer would be much appreciated.
My code tags are working today, I didn't touch anything.Code:COUNT PIN.n, 10000, VAR B_P_C WORD 'Set GPIO.n as input, define Button Push Count as VAR WORD B_P_C, with a loop count time of 10 secs. Let i = B_P_C IF B_P_C = i GOTO FIRSTLOOP ' Button pressed once IF B_p_c = i+i GOTO SECONDLOOP ' Button pressed twice IF B_P_C = i+i+i Goto THIRDLOOP ' Button pressed a third time
David
Last edited by LEDave; - 2nd March 2010 at 14:58.
Hi,
Not quite sure I understand. Are you saying that you want it to execute one of the three loops depending on how many times the butten is pressed within a certain amount of time? Or are you saying that you want to execute the three loops, one after the other, but to wait for a button press between the loops?
In any case, I'm afraid what you have there ain't gonna work....
The above will define a 16 bit variable called B_P_C and then immediatley start counting how many times the button connected to GPIO.5 is pushed. It will keep counting for 10 seconds (10000mS) after which it continues in the program.Code:B_P_C VAR WORD COUNT GPIO.5, 10000, P_B_C
What this does is to say that i should be assigned whatever value B_P_C is. So, after this is exectued i has the same value as B_P_C, provided i is declared the same size as B_P_C - a WORD in this case.Code:Let i = B_P_C
Now, since i is the same as B_P_C (it is because you told it to be) the only condition that can ever be true is the first one.Code:IF B_P_C = i GOTO FIRSTLOOP ' Button pressed once IF B_p_c = i+i GOTO SECONDLOOP ' Button pressed twice IF B_P_C = i+i+i Goto THIRDLOOP ' Button pressed a third time
/Henrik.
PS. Pushbuttons are quite "bouncy", the COUNT command may register several counts even though you only push the button once.
Last edited by HenrikOlsson; - 2nd March 2010 at 17:32.
Bookmarks