Calculator...Dual Mode??

Discussion in 'Programmer's Corner' started by bse2013, Jun 5, 2012.

  1. bse2013

    Thread Starter New Member

    Jun 5, 2012
    Hello Guys..
    I am a bit new to microcontrollers and have a problem with the programming. I am making a calculator as a project using 16x2 LCD display and 4x4 keypad.. the circuit works fine and so does the proteus version...the problem i am facing is the dual mode version of the calculator...along with the calculations i want to run another feature on it but all my keypad keys are occupied and i can't seem to find a solution without damaging the part that works any help on how to program the keypad to switch when i press the key thrice or twice???
  2. absf

    AAC Fanatic!

    Dec 29, 2010
    If I understood you correctly, you want the whole keyboard to mean something else (to remap the keyboard) when a certain function key is pressed and you're running out of extra keys, right?

    In that case, there are 2 options to do it:

    1. Long/short keypress. Just define one of the keys on the keyboard to have this function. When that key is pressed for more than 3 seconds, it would switch to the other mode. Normal keypress should not exceed 3 seconds.

    2. Combination of 2 or 3 keys. Say you want to change mode just press "+,- and /" together. And indicate the mode on the LCD screen. When changing back, press the same keys combination again.

    BTW, which mcu are you using?:)

  3. bse2013

    Thread Starter New Member

    Jun 5, 2012
    Thanx....appreciate the help :)
    I am using AT89C51 microcontroller...
  4. absf

    AAC Fanatic!

    Dec 29, 2010
    Too bad, I have an example for the long/short keypress detection for 12F629 written by Randy Day. See if you can make use of the concept here...

    Code ( (Unknown Language)):
    2. ;Just air code. I'm using timer SFR names
    3. ;from micros I use, so they may not apply
    4. ;to the '675:
    5. Button_Loop
    6.         btfsc GPIO, 0
    7.         goto Button_Loop
    8.         ; enable 3 second timer here
    9. Short_Loop
    10.         btfsc GPIO, 0
    11.         goto  Short_Press
    12.         ; loop until timer expires
    13.         btfss   PIR1, TMR1IF
    14.         goto Short_Loop
    15.         ; if timer manages to expire, the
    16.         ; button is still pressed,
    17.         ; and is considered a 'long' (>3 sec)
    18.         ; press.
    19.         ; turn off timer here
    20. Long_Press      ; keep looping until button is released
    21.         btfss GPIO, 0
    22.         goto Long_Press
    23.         ; run your 'long press' code
    24.         goto Main_Program
    25. Short_Press
    26.         ; if gpio<0> went high before 1sec,
    27.         ; the button was released as a 'short'
    28.         ; (<3sec) press.
    29.         ; turn off timer here
    30.         ; run your 'short press' code
    31.         goto    Main_Program