program such that 8085 appears to multitask

Discussion in 'Embedded Systems and Microcontrollers' started by sssss9539, Apr 22, 2014.

  1. sssss9539

    Thread Starter New Member

    Apr 22, 2014
    1
    0
    i need to write a program for reading two push buttons(together as connected on same port) and i need to count each and every push.
    with the normal 'read port, implement logic' format i miss some presses.
    i would like to do this without using interrupts.

    thanks in advance
     
  2. fernan82

    New Member

    Apr 19, 2014
    26
    9
    And the multitasking part?

    assuming debouncing is done in the hardware and that you count each push once (you don't count again until the button is released), and the pushed state is LOW you can do something like this in C

    Code ( (Unknown Language)):
    1.  
    2.  char btn1pushed = 0, btn2pushed = 0;
    3.  int btn1cnt = 0, btn2cnt = 0;
    4.  
    5.  while (1)
    6.  {
    7.      if (btn1pushed)
    8.      {
    9.          if (PORT & 1)
    10.              btn1pushed = 0;
    11.      }
    12.      else
    13.      {
    14.          if (!(PORT & 1))
    15.          {
    16.              btn1cnt++;
    17.              btn1pushed = 1;
    18.          }
    19.      }
    20.  
    21.      if (btn2pushed)
    22.      {
    23.          if (PORT & 2)
    24.              btn2pushed = 0;
    25.      }
    26.      else
    27.      {
    28.          if (!(PORT & 2))
    29.          {
    30.              btn2cnt++;
    31.              btn2pushed = 1;
    32.          }
    33.      }
    34.  }
    35.  
     
    Last edited: Apr 26, 2014
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I guess this call for some bit manipulation. Which should be quite easy in the 8085. Anyway then you say "program for reading two push buttons(together as connected on same port)" you refer to reading from PPI chip like the Intel 8255 chip
     
  4. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    One possibility is that your "implement logic" is taking too long, so while that is executing a task you miss the next button press.

    One solution is to test the buttons in a function, then "poll" that function often, even when exectuing the slow tasks.

    If the function detects a new button press it puts it in a "queue" list so when all tasks are done, the program checks the list to see if any more buttons have been pressed.

    At can also be a good idea to put the button testing in a timer interrupt, and the interrupt adds the button press requests onto the list.
     
  5. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    I agree with using interrupts. That's what they are there for, and unless you have a very, very good reason to not use them, then that's exactly what you should be doing. I've never seen a multi-tasking system that doesn't rely extensively on interrupts.
     
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Agreed!

    Something like a 1mS timer interrupt is very useful. You can use it for button debouncing, button data collecting, and real-time timing tasks like user interface pauses (pauses between display data or LED flashes etc) etc.
     
Loading...