program such that 8085 appears to multitask

Thread Starter

sssss9539

Joined Apr 22, 2014
1
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
 

fernan82

Joined Apr 19, 2014
26
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

Rich (BB code):
 char btn1pushed = 0, btn2pushed = 0;
 int btn1cnt = 0, btn2cnt = 0;
  
 while (1)
 {
     if (btn1pushed)
     {
         if (PORT & 1)
             btn1pushed = 0;
     }
     else
     {
         if (!(PORT & 1))
         {
             btn1cnt++;
             btn1pushed = 1;
         }
     }
  
     if (btn2pushed)
     {
         if (PORT & 2)
             btn2pushed = 0;
     }
     else
     {
         if (!(PORT & 2))
         {
             btn2cnt++;
             btn2pushed = 1;
         }
     }
 }
 
Last edited:

t06afre

Joined May 11, 2009
5,934
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
 

THE_RB

Joined Feb 11, 2008
5,438
...
with the normal 'read port, implement logic' format i miss some presses.
...
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.
 

Brownout

Joined Jan 10, 2012
2,390
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.
 

THE_RB

Joined Feb 11, 2008
5,438
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.
 
Top