PIC12F629 beginner needs help

On Nov 17, 7:33 am, Allen Bong <allenbsf6...@gmail.com> wrote:
On Nov 17, 1:27 pm, Randy Day <randy....@sasktel.netx> wrote:



In article <863dfac8-adbb-4ad5-89ff-
32ea6f859...@j9g2000vbr.googlegroups.com>,
allenbsf6...@gmail.com says...

[snip]

The long and short duration technique is nice and I wonder if you have
some codes for me to try out?

Just air code. I'm using timer SFR names
from micros I use, so they may not apply
to the '675:

Button_Loop
        btfsc GPIO, 0
        goto Button_Loop

        ; enable 1 second timer here

Short_Loop
        btfsc GPIO, 0
        goto  Short_Press

        ; loop until timer expires
        btfss   PIR1, TMR1IF
        goto Short_Loop

        ; if timer manages to expire, the
        ; button is still pressed,
        ; and is considered a 'long' (>1sec)
        ; press.

        ; turn off timer here

Long_Press      ; keep looping until button is released
        btfss GPIO, 0
        goto Long_Press

        ; run your 'long press' code
        goto Main_Program

Short_Press
        ; if gpio<0> went high before 1sec,
        ; the button was released as a 'short'
        ; (<1sec) press.

        ; turn off timer here
        ; run your 'short press' code
        goto    Main_Program

Let me see if I understand it right.

For a short press: It enters Botton_Loop, pass the first btfsc test.
Then enable 1 sec timer, past second btfsc test. Timer 1 not yet
expired, Loop back into the Short_Loop.  Release button before timer 1
expires and exit into Short_Press.

For a long press:  Enters at Button_Loop, pass the first btfsc test,
set up timer 1 for 1 sec, Goes through second btfsc test and on 3rd
btfss test, also dropped into the Short_Loop until > 1 second, timer1
expires, will drop onto Long_Press loop and exit btfss when the button
is released.

Very nice, but at first glance, a bit tough to understand how it
works.

Thank you Randy for teaching me this new trick!!  I'll put it into my
macro library file and include it on my next program.

Cheers,

Allen
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 = 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
 
On Nov 18, 9:26 am, Bill Bowden <bper...@bowdenshobbycircuits.info>
wrote:
On Nov 17, 7:33 am, Allen Bong <allenbsf6...@gmail.com> wrote:





On Nov 17, 1:27 pm, Randy Day <randy....@sasktel.netx> wrote:

In article <863dfac8-adbb-4ad5-89ff-
32ea6f859...@j9g2000vbr.googlegroups.com>,
allenbsf6...@gmail.com says...

[snip]

The long and short duration technique is nice and I wonder if you have
some codes for me to try out?

Just air code. I'm using timer SFR names
from micros I use, so they may not apply
to the '675:

Button_Loop
        btfsc GPIO, 0
        goto Button_Loop

        ; enable 1 second timer here

Short_Loop
        btfsc GPIO, 0
        goto  Short_Press

        ; loop until timer expires
        btfss   PIR1, TMR1IF
        goto Short_Loop

        ; if timer manages to expire, the
        ; button is still pressed,
        ; and is considered a 'long' (>1sec)
        ; press.

        ; turn off timer here

Long_Press      ; keep looping until button is released
        btfss GPIO, 0
        goto Long_Press

        ; run your 'long press' code
        goto Main_Program

Short_Press
        ; if gpio<0> went high before 1sec,
        ; the button was released as a 'short'
        ; (<1sec) press.

        ; turn off timer here
        ; run your 'short press' code
        goto    Main_Program

Let me see if I understand it right.

For a short press: It enters Botton_Loop, pass the first btfsc test.
Then enable 1 sec timer, past second btfsc test. Timer 1 not yet
expired, Loop back into the Short_Loop.  Release button before timer 1
expires and exit into Short_Press.

For a long press:  Enters at Button_Loop, pass the first btfsc test,
set up timer 1 for 1 sec, Goes through second btfsc test and on 3rd
btfss test, also dropped into the Short_Loop until > 1 second, timer1
expires, will drop onto Long_Press loop and exit btfss when the button
is released.

Very nice, but at first glance, a bit tough to understand how it
works.

Thank you Randy for teaching me this new trick!!  I'll put it into my
macro library file and include it on my next program.

Cheers,

Allen

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 = 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- Hide quoted text -

- Show quoted text -
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
 
Allen Bong wrote:

On Nov 17, 9:03 am, Varactor <morefl...@gmail.com> wrote:

On Nov 17, 1:17 pm, Allen Bong <allenbsf6...@gmail.com> wrote:






On Nov 17, 3:17 am, Varactor <morefl...@gmail.com> wrote:

On Nov 17, 6:46 am, Allen Bong <allenbsf6...@gmail.com> wrote:

On Nov 16, 6:03 pm, Varactor <morefl...@gmail.com> wrote:

On Nov 15, 3:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz. Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select. That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button. And how do I calibrate the internal
osc freq using OSCCAL bits? Can someone here help?

Thanks.

You really don't need all those pins for those functions. Why not use
one pin for start and stop -they are exclusive after all. You could
get away with 2 pins if you just use one switch for start and stop
functions and the analog in for the other functions. The key is to
realize that the switches can each add a different current to the
input so that by measuring the input voltage you can decide what
combinations of switches are set. You could even use just one pin with
this method ...

Hope this helps.

MC- Hide quoted text -

- Show quoted text -

Do you mean like the circuit below? My 12f675 does have 4 analog
inputs.

So AN0 will normally be 2.5V when A nor B is pressed. If Button A is
pressed then AN0=5V. If button B is pressed then AN0=0V, right? Good
idea !!!!

Allen

VCC VCC
| |
12F675 .-. o |
.------. | | |=| "A"
| | 4.7K | | o |
| | '-' |
| | | |
| | 2.5V | |
| AN0|--------+----+
| | | |
| | | |
| | .-. o |
| | | | |=| "B"
'------' 4.7K | | o |
'-' |
|
| |
=== ===
GND GND

Yes, that would be OK for 2 buttons. To get more you need to think
about binary coding and about each button being a part of a digital to
analog converter. The press of each button adds in a current which is
then measured. So, if each button is connected to the pin via a
resistor to Vcc and each resistor value goes as a power of 2 then the
voltage on that pin, measured by a resistor to ground will be binary
coded. The limit is the precision of the resistors and the A/D
converter. With a 10 bit converter you could easily code > 4 buttons
(the theoretical maximum is the bit resolution of the converter, but
with only 5% resistors the maximum is 4) ... Just make sure you use
the whole range of the converter.

With an A/D converter pin you can do a lot of tricks.

Cheers MC- Hide quoted text -

- Show quoted text -

The circuit below would detect 4 switches at 5v, 3.75, 2.5, 1.25v
idealling at 0V. Would
this setup work? How many switches can I connect to my 12F675 running
at 4 MHz, 4.5V Vcc
with 1% resistors if the setup works?

Regards,

Allen

VCC
+----+
T | |
--- | .-.
12F675 +---o o----+ | |
.-----. | | |1k
| | | T '-'
| | | --- |
| | +------+-o o----+
| | | |
| | | .-.
| | | | |
| | | | |1k
| | | T '-'
| | | --- |
| AN1|----+---+--+-o o----+
| | | | | |
'-----' .-. | | .-.
| | - | | |
10k| | ^ | | |1k
'-' | | T '-'
| | | --- |
+---+ +-o o----+
| |
| .-.
GND | |
| |1k
'-'
|
GND

(created by AACircuit v1.28.6 beta 04/19/05www.tech-chat.de)

Close, but not quite. Look at it, the top switch connects the pin to
Vcc regardless of the other switches so the pic will only see that
switch. There are a couple of ways of doing it. Try putting the
switches with their coding resistors in parallel to Vcc and all
connected to the input pin. Now, the resistor to ground from the pin
forms a voltage divider (you can also use the input resistance of the
pic alone) with the resistor to Vcc formed by variable numbers of //'d
resistors. The number of those resistors and their values determines
the voltage. So, provided each resistor value is unique, the overall
resistance from the pin to Vcc is uniquely coded by the switches.
The second way is to use each switch to short out a single resistor
from the chain (which may be simpler to think about). Again the value
of each resistor in the chain must be unique and ideally very
different (say powers of 2 (i.e. 1k, 2k, 4k, 8k). A few (fun :))
minutes with a soldering iron and a multimeter will let you see how it
works -by whatever method. Finally, if the switches are double pole
you can use a R2R ladder (you can google that). The R2R ladder is a
method used to make many D/A converters. You may also want to look up
'Gray coding' to further your knowledge of how to reliably encode
physical parameters for a computer.

Good luck!

MC- Hide quoted text -

- Show quoted text -


Thanks very much MC,

I would need more time to digest what you have said. Google is my
best friend anyway not forgetting wikidepia as well. I will post back
here if there's anything I dont understand.

I would like to thanks those answering my post including Bill Bowden
whose web site I frequently visit to get circuit ideas. I have
another 2 more projects I am going to do: poor man's o'scope using
12F675 and a bike computer using 16F628 for my newly bought bicycle.

Cheers,

Allen.


If you have any spare outputs? can you multiplex and use scan lines
instead of the switches using a fixed source.
 
On Nov 19, 4:48 am, Jamie
<jamie_ka1lpa_not_valid_after_ka1l...@charter.net> wrote:
Allen Bong wrote:
On Nov 17, 9:03 am, Varactor <morefl...@gmail.com> wrote:

On Nov 17, 1:17 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

On Nov 17, 3:17 am, Varactor <morefl...@gmail.com> wrote:

On Nov 17, 6:46 am, Allen Bong <allenbsf6...@gmail.com> wrote:

On Nov 16, 6:03 pm, Varactor <morefl...@gmail.com> wrote:

On Nov 15, 3:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz.  Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select.  That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button.  And how do I calibrate the internal
osc freq using OSCCAL bits?  Can someone here help?

Thanks.

You really don't need all those pins for those functions. Why not use
one pin for start and stop -they are exclusive after all.  You could
get away with 2 pins if you just use one switch for start and stop
functions and the analog in for the other functions. The key is to
realize that the switches can each add a different current to the
input so that by measuring the input voltage you can decide what
combinations of switches are set. You could even use just one pin with
this method ...

Hope this helps.

MC- Hide quoted text -

- Show quoted text -

Do you mean like the circuit below?  My 12f675 does have 4 analog
inputs.

So AN0 will normally be 2.5V when A nor B is pressed.  If Button A is
pressed then AN0=5V. If button B is pressed then AN0=0V, right?  Good
idea  !!!!

Allen

                      VCC  VCC
                       |    |
        12F675        .-.   o |
       .------.       | |     |=| "A"
       |      |  4.7K | |   o |
       |      |       '-'   |
       |      |        |    |
       |      |  2.5V  |    |
       |   AN0|--------+----+
       |      |        |    |
       |      |        |    |
       |      |       .-.   o |
       |      |       | |     |=| "B"
       '------'  4.7K | |   o |
                      '-'   |
                       |
                       |    |
                      ===  ==> >>>>>                       GND  GND

Yes, that would be OK for 2 buttons. To get more you need to think
about binary coding and about each button being a part of a digital to
analog converter.  The press of each button adds in a current which is
then measured. So, if each button is connected to the pin via a
resistor to Vcc and each resistor value goes as a power of 2 then the
voltage on that pin, measured by a resistor to ground will be binary
coded. The limit is the precision of the resistors and the A/D
converter. With a 10 bit converter you could easily code > 4 buttons
(the theoretical maximum is the bit resolution of the converter, but
with only 5% resistors the maximum is 4) ... Just make sure you use
the whole range of the converter.

With an  A/D converter pin you can do a lot of tricks.

Cheers MC- Hide quoted text -

- Show quoted text -

The circuit below would detect 4 switches at 5v, 3.75, 2.5, 1.25v
idealling at 0V.  Would
this setup work?  How many switches can I connect to my 12F675 running
at 4 MHz, 4.5V Vcc
with 1% resistors if the setup works?

Regards,

Allen

                          VCC
                        +----+
                  T     |    |
                 ---    |   .-.
  12F675     +---o o----+   | |
  .-----.    |              | |1k
  |     |    |         T    '-'
  |     |    |        ---    |
  |     |    +------+-o o----+
  |     |           |        |
  |     |           |       .-.
  |     |           |       | |
  |     |           |       | |1k
  |     |           |  T    '-'
  |     |           | ---    |
  |  AN1|----+---+--+-o o----+
  |     |    |   |  |        |
  '-----'   .-.  |  |       .-.
            | |  -  |       | |
         10k| |  ^  |       | |1k
            '-'  |  |  T    '-'
             |   |  | ---    |
             +---+  +-o o----+
             |               |
             |              .-.
            GND             | |
                            | |1k
                            '-'
                             |
                            GND

(created by AACircuit v1.28.6 beta 04/19/05www.tech-chat.de)

Close, but not quite. Look at it, the top switch connects the pin to
Vcc regardless of the other switches so the pic will only see that
switch. There are a couple of ways of doing it. Try putting the
switches with their coding resistors in parallel to Vcc and all
connected to the input pin. Now, the resistor to ground from the pin
forms a voltage divider (you can also use the input resistance of the
pic alone) with the resistor to Vcc formed by variable numbers of //'d
resistors. The number of those resistors and their values determines
the voltage. So, provided each resistor value is unique, the overall
resistance from the pin to Vcc is uniquely coded by the switches.
The second way is to use each switch to short out a single resistor
from the chain (which may be simpler to think about). Again the value
of each resistor in the chain must be unique and ideally very
different (say powers of 2 (i.e. 1k, 2k, 4k, 8k).  A few (fun :))
minutes with a soldering iron and a multimeter will let you see how it
works -by whatever method. Finally, if the switches are double pole
you can use a R2R ladder (you can google that). The R2R ladder is a
method used to make many D/A converters. You may also want to look up
'Gray coding' to further your knowledge of how to reliably encode
physical parameters for a computer.

Good luck!

MC- Hide quoted text -

- Show quoted text -

Thanks very much MC,

I would need more time to digest what you have said.  Google is my
best friend anyway not forgetting wikidepia as well.  I will post back
here if there's anything I dont understand.

I would like to thanks those answering my post including Bill Bowden
whose web site I frequently visit to get circuit ideas.  I have
another 2 more projects I am going to do: poor man's o'scope using
12F675 and a bike computer using 16F628 for my newly bought bicycle.

Cheers,

Allen.

If you have any spare outputs? can you multiplex and use scan lines
instead of the switches using a fixed source.- Hide quoted text -

- Show quoted text -
Do 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
 
On Nov 17, 7:40 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

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
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
 
On Nov 19, 2:10 pm, Bill Bowden <bper...@bowdenshobbycircuits.info>
wrote:
On Nov 17, 7:40 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

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

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
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 = 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
 

Welcome to EDABoard.com

Sponsor

Back
Top