+ Reply to Thread
Page 3 of 3
First 1 2 3
Results 31 to 32 of 32

Thread: PIC 16F877 timer

  1. #31
    Matt(Pic progger) Newbie
    Join Date
    Apr 2004
    Location
    UK
    Posts
    147

    Default

    :idea:

    The other way to record port (switch/button) changes using int's it to use 2 regisiters and a flag in the in sub.......

    OLD_PORTB
    SW_VALUE_B
    SW_FND_FLG (flag bit)

    theory for int code, generated via say timer 0 evey 10ms......

    *************************************************

    read port b

    compare port b to OLD_PORTB

    same?
    Yes, exit int.....

    No, Store current port B into OLD_PORTB

    is SW_FND_FLG set?
    Yes, exit int.....

    No, Store current port B into SW_VALUE_B, set SW_FND_FLG

    exit int

    *************************************************

    OK, so how does this help?

    well, you code checks the SW_FND_FLG, if set, you know a switch has been pressed sometime between 0->10MS, look at SW_VALUE_B to see which one...... then clear SW_FND_FLG, the int code will set the flag on another change of the switch, this will debounce the switch for you....

    Why use the flag?? Well this means that if the switch value changes again before you test the SW_FND_FLG, the change will be saved.....

    Why bother with this when I can use int on change on portB??? Well you can use this code on any port also the int on change will pick up every "bounce" on the switch contacts, so you will need to impliment a timer/flag etc to get rid of these anyway. AND if you are using a timer anyway it's like getting extra for free (sort of!) AND it's just nice to do things a bit differnt!! :wink:
    Regards


    MATT!


  2. #32
    patricktran Newbie
    Join Date
    Apr 2004
    Posts
    47

    Default

    Oh, thanks alot evryone. I am very appreciate for your helps. I realise that this forum is very useful, speacially to newbies like me.
    Thanks :P

+ Reply to Thread
Page 3 of 3
First 1 2 3

Tags for this Thread