do the debounce in software. (short pause) or if it's off to do something else once triggered, you may not even need debounce..
you can search for debounce examples from here http://www.picbasic.co.uk/forum/showthread.php?t=4751
do the debounce in software. (short pause) or if it's off to do something else once triggered, you may not even need debounce..
you can search for debounce examples from here http://www.picbasic.co.uk/forum/showthread.php?t=4751
Ok, a bit more reading .... it seems the button command will be perfect for needs.
My initial problem is that it only acts on PORTB pins (& the Pickit 2 board has its switch wired to RA3). therefore I've rigged up a pull up resistor onto pin RB7 & a small switch which goes to ground (therefore puts 0V onto RB7 when this new switch pressed). However RB7 is being held low all the time.
I'm figuring this must be something to do with the .inc file again (I've rechecked my wiring - it's fine ...10k resistor between RB7 & the 5V rail....and a normally open switch going from RB7 to ground). I chose RB7 for my new switch as it seemed to have the least happening! On the datasheet it's listed as RB7/TX/CK ...how can I be sure it's being used as an input pin only (& not being overridden by one ithe pins other purposes)
Does anyone have any ideas why my RB7 might be permanently low.
Here's the small bit of code I'm using...
@MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON
@MyConfig = MyConfig & _MCLRE_OFF & _BOR_OFF
@ __config MyConfig
DEFINE OSC 4
ANSEL=0 ' all digital
ANSELH=0 ' analog module disabled
CM1CON0=0 ' dunno what this line does!
CM2CON0=0 ' nor this one!
TRISA=%11111111 ; set all Port A pins as inputs
TRISB=%11111111 ; set all Port B pins as inputs
TRISC=%00000000 ; set all Port C pins as outputs
B0 VAR BYTE ;creates a variable as needed for the button command below
B0 = 0 ; give it a value of zero (as per the command's reference)
LED1 var PortC.0 ' ; assign a more usable name to the first LED port
start:
LOW LED1 ; turn the first LED off
BUTTON 7, 0, 255, 0, B0, 1, Loop ; monitor the switch on RB7 for 0V,
;if this condition is net, then go to next
next:
high LED1 ; turn the first LED on
PAUSE 1000 ; wait one second
goto start ;start over
End
Last edited by HankMcSpank; - 16th March 2009 at 00:39.
BUTTON 7, 0, 255, 0, B0, 1, Loop
???????
Try
BUTTON PORTB.7, 0, 255, 0, B0, 1, Loop
Or better yet
OOPS!!!!!!Code:IF PORTB.7 = 0 THEN GOTO NEXT
That will not work...NEXT is a reserved word. Will have to think of something else to call that label.. FRED??
Dave
Always wear safety glasses while programming.
HankMcSpank,
I think the 'F690 is going to be my next favorite PIC. It has SO MUCH STUFF on it!
In other words, not a beginner PIC ( like the 16F628, F648, F87, F84(old and gray) )
There are ALOT of registers to learn how to use on this chip.
NOTE: something that used to trip me up when reading data sheets:
when you "SET" a value you change it to "1"
when you "CLEAR" a value you change it to "0"
so that if someone says "set the flag", it means to ONE, (1), HIGH
I only bring this up because you are new. The M-chip data sheets use this nomenclature all the time.
Also NOTE: The 16F690 Datasheet is your new best friend. All 306 pages, WOW. You might want to print out the pages with
the register descriptions for each "feature" so you know what CM1CON0, etc means. Adobe pages 34-37 are best. Also,
under the feature headings are listed all relevant registers that need to be set/cleared, usually near the end.
You might need to set ( or CLEAR) the following registers as well (some required in other PICs):
'Registers:
ANSEL = %00000000 ' clears the individual bits that select analog inputs (low register)
ANSELH = %00000000 ' clears the individual bits that select analog inputs (high register)
VRCON = %00000000 ' turns the Vref Module OFF by CLEARING bit7, 6, 4
'I use the binary format so I can easily set them later. I know it seems redundant when they are all 0's, but later....
'Bits Only:
CM1CON0.7 = 0 ' turns Comparator1 OFF by CLEARING bit7
CM2CON0.7 = 0 ' turns Comparator2 OFF by CLEARING bit7
ADCON0.0 = 0 ' turns the AD Converter OFF by CLEARING bit0
INTCON.0 = 0 ' clears the RABIF Flag (to 0), COULD be 1 on reset (unique to F690)
RCSTA.7 = 0 ' clears the SPEN bit ( SETTING SPEN DISABLES RB7 AS GENERAL PURPOSE! )
'note that there is an Errata Datasheet that mentions issues with SPEN, but only when using the Serial Hardware
'you might HAVE TO do this after clearing ANSEL/ANSELH
PORTA = %00000000 ' Clear the port register latches
PORTB = %00000000
PORTC = %00000000
TRISA = %11111111 ' Set or Clear the data direction registers
TRISB = %11111111
TRISC = %00000000
'FOR EXAMPLE: On the F628 and friends, you only need:
'CM1CON = 7 ' turns the comparators OFF by SETTING bits 0,1,2
'and the Port/Tris settings
'OK, now on to your code...
'The Button Command:
BUTTON 7, 0, 255, 0, B0, 1, Loop
'"7" is not a pin name.
'For buttons and LEDs, I use names like btnStart or btnUp, LEDFault, LEDStatus.
'But sometime I use PHYSICAL pin numbers on new chips that I'm learning. So try :
RB7pin10 VAR PortB.7
'I wouldn't use the term B0 as a variable, it is used so many other places (mainly STAMP) to denote PortB.0. Try:
Temp VAR BYTE
'Also, for the Jump To label you use "Loop", but I don't see it in your listing. Maybe you meant "Next", but you can't use that name.
'So Now:
Start:
LED1 = 0
Button RB7pin10, 0, 255, 0, Temp, 1, Blink
GOTO Start
Blink:
LED1 = 1
Pause 1000
GOTO Start
End
'I'm not at work so I can't test this until tomorrow.![]()
Well, the command & it's example syntax it was lifted from here (page 104)....
http://books.google.co.uk/books?id=X...sult#PPA104,M1
I figured that since the button command *only* wokds on PortB, that nominating ust the number 7 (as opposed to RB7) would be ok. certainly the example that link gives justiuses the number 7 too!
Greg...many thanks for the lengthy reply - i'll give that a shot tonight (I'm at work right now too!)
I'm not sure that the Button Command "only works on PortB". Every other command works on any pin except the hardware modules (HPWM, HSERIN, etc).
Besides you can always use:
If btnTest = 0 then Blink 'did I change the button name? oops
Of course there is no debounce, but this is good for testing. Actually, your 1sec delay for the LED is a great debounce! nothing else is going to happen during that interval, nothing. You could also do this to BLINK as long as you hold the button down:
Start:
WHILE btnTest = 0
LED1 = 1
Pause 500
LED1 = 0
Pause 250
WEND
GOTO Start
Greg,
Just had a chance to try out your suggestions - it works! (iepin 10 is now high...at this stage, I can't be sure which one of those tips you gave was the one that nailed it, becuase I used them all!)
Some excellent ideas you've given there too about my main program ...in fact, I reckon I've enough sufficient info get this little program sorted now.
Many thanks to all who took the time to help me out....the internet working at its finest.
mackrackit...it was very late, & I'd just quickly googled my problem (as I always do when I have a problem & as a beginner, a search engine often serves me better as I can phrase a question when I'm not totally sure of what I'm asking!)...Google led me to that online PICbasic book & I took it at face value!
Lesson learned.
Last edited by HankMcSpank; - 16th March 2009 at 18:30.
Bookmarks