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4KPiBkb2Vzbid0IHdvcmsgdG8gd2VsbCB3aXRoIGEgbG93IGltcGVkYW5jZSBzdXBw bHkuIDopCj4KPiAtLQo+IOKaguKagyAxMDAlIG5hdHVyYWwtIEhpZGUgcXVvdGVkIHRleHQgLQo+ Cj4gLSBTaG93IHF1b3RlZCB0ZXh0IC0KCk9vcHMsICBXaGF0IGhhdmUgSSBkb25lPyAgTXVzdCBi ZSB0b28gdGlyZWQgam9nZ2luZyBhbmQgbm90IGVub3VnaApjb2ZmZWUuLi4uLi4KCgpBbGxlbgo=
PIC12F629 beginner needs help
Nov 15, 2010
26 Replies
e
Might try this idea to get the button press time.The example returns a value in the variable TOTAL which represents the time the button was pressed (16 seconds max). Then you can test the bits in the variable TOTAL to see how long the button was pressed. Or subtract some threshold value from TOTAL and then check the status bits to determine if it's greater or less than the threshold. Just an idea.
Test_Button
clrf TOTAL ; clear the variable TOTAL btfsc GPIO,0 ; look to see if pin is low (clear =3D low if button pressed) return ; exit, button not pressed call Delay ; get 65 millisecond delay incf TOTAL ; Accumulate time in 65mS segments goto $ - 4 ; Jump back 4 lines return
Delay
movlw d'255' movwf TEMP ; load 255 or hex FF into TEMP goto $ +4 ; Jump 4 lines down decfsz TEMP,f ; decrement TEMP, skip if zero goto $ +2 ; Jump 2 lines down return movlw d'255' movwf COUNTER decfsz COUNTER,f goto $ -1 goto $ -7
-Bill
ave
1button
Yes, That's a great idea. This program will let me determine the duration I want to use for a long press. I thought you are only interested in hardware design and not uControllers. How long have you been into uC?
Allen
If you have any spare outputs? can you multiplex and use scan lines instead of the switches using a fixed source.
2/5
s and
ower
rnal
se
uld
ith
is
=A0Good
ois
ng
kDo you mean connecting the switches in matrix? I have thought about that as well. But a 2x2 or 3x1 matrix only yields 4 or 3 switches. I have also read an application Notes ANxxx from Microchip that I could double the use of LED and SPK outputs with the other 4 GPIO set as inputs to form a 2x4 matrix. But the software was quite complicated and I dont totally understand the logic behind.
At the moment, I think this is the best I can achieve with a small chip like 12F629. My next project is a bicycle computer using 16F628 which has 16 ports and I will plan to do more ambitious things on it. A LCD display and Odometer and RPM and temperature sensing and ........
I am sure to have more questions to ask then.
Allen
I discovered PICs about 8 years ago since all the support stuff was free, and flash memory was easy to update. MPLAB was good at debugging and I could step the programs one line at a time and watch the variables change in the "watch window". None of my programs worked without stepping them first to catch the bugs.
-Bill
u
Hi Bill,
I started PIC 6 years ago as my friend introduced it to me. He didn't like Assembly Language so he found PIC Basic Pro and wanted me to join venture with him playing with PIC. I lost interest soon as I was playing with the 89c51, 89S4051 and I just completed my programmer for the 2 MCU.
I became interested in PIC again due to the USB ICSP that was made locally and sold very cheaply here (Only RM 50 =3D USD 16.80) each. I still play with my 8031 EMC32 board from Canada, that I bought many years ago. It has 32k RAM and a RS232 serial port. The programming and debugging were mainly done through the serial port. It also included a nice monitor program in eprom.
Allen
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required