Already been there. Had a lot of fun too!!!!I hope I'm not driving you all to mad?
Already been there. Had a lot of fun too!!!!I hope I'm not driving you all to mad?
Dave
Always wear safety glasses while programming.
Hi,
Just in case this isn't clear already....This is NOT how you you determine if an input is high or low. HIGH and LOW are commands that both sets the pin in question to "output mode" and then drives it either high or low. To check if a pin (or any bit in any register) is set you do either:Code:IF GPIO.0 = HIGH THEN UNLOCK
OrCode:If GPIO.1 = 1 THEN GOTO Unlock
OrCode:If GPIO.1 THEN GOTO Unlock
Right, back to HIGH and LOW... as have been said already the HIGH and LOW commands first sets the pin to "output mode" and then drives the pin high or low. It's nothing wrong with that except that it sets the pin to "output mode" each and every time either command is used. It doesn't matter if the pin already IS in "output mode" - it still writes to the TRIS register - every time and this wastes both time and codes space. It's much better to set the TRIS register manually and only change it if needed and then simply write to the Port or GPIO register directly.Code:If GPIO.1 = 0 THEN GPIO.2 = 1 Goto DoThis ELSE Goto Unlock ENDIF
/Henrik.
Hi Henrik, thanks for that. Being new to programming it's easy to get confused especially when many of the terms are so similar.
I'm a relatively slow learner too which doesn't help I guess. When I finally get it though, it does stick.
You've got to marvel the complexity contained within an eight pin microchip, staggering.
I can't wait to actually build something either.
Have a nice evening.
David
Hi everyone.
I'm working on my first circuit using the12F683 and I'd like to add a push button as an input. Would I be right in assuming that:
A pull-up resistor say 10k from the +5v line onto the chosen input GPIO.n and a push button connected from GPIO.n to ground should do the job?
This to my mind would leave GPIO.n at +5v until pressed, momentarily dropping to 0v.
David
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.
Bookmarks