Variable Delay (controlled with push switches)

Thread Starter

Malsch

Joined Mar 19, 2011
23
Hi, I am using the 8051 to create a delay function with a variable (in this case BPMtime). At first the BPMtime variable is set to 100 and when i push and release the switch (on P0.0), the BPMtime becomes 101 hence the delay is increased. The same goes for the switch on P0.1 but instead of incrementing by one, i would like it to be decremented by one.

To know if it is working correctly, I outputted BPMtime to port 3 to see if the value is changed whenever i press one of the buttons. So far for some reason the program isn't working correctly. When one of the switches is pushed, the BPMtime stays 100. P0 doesn't have internal pull ups. The program is compiling successfully.

The program so far:

#include <reg51.h>

void BPMDelay();
unsigned char BPMtime;

void main(void)
{
P0=0xFF;
BPMtime=100;

while(1)
{
P2 = 0x00;
BPMDelay();
P2 = 0xFF;
BPMDelay();
}
}

void BPMDelay()
{
if (P0^0==0)
{
BPMtime=BPMtime ++;
P3=BPMtime;
}

if(P0^1==0)
{
BPMtime=BPMtime --;
P3=BPMtime;
}

else
{
unsigned int u,v;
for(u=0;u<BPMtime;u++);
for(v=0;v<190;v++);
}
}



Thanks for your time.
 

Attachments

Last edited:
Top