This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

can not set bits in 8051

Hello everybody, I am a new entrant in 8051 programming. I am able to set bits in assembly language. But when I tried to set bits in c using Keil IDE, the bits are not getting set even after using bitset function as preprocessor. The bits are flickering when pressed any button. Otherwise they are stable. Please have a look on my coding for setting the P1 bits. Please tell me what is wrong in the coding below to set bits?

#include <reg51.h>

#define bitset(a,b) ((a)|=(1<<(b)))
#define bitclear(a,b) ((a)&= (1<<(b)))

sbit LEDtest = P1^7;
sbit PB0_0 = P0^0;
sbit PB0_1 = P0^1;
static char bdata ibase;
sbit pb00 = ibase^0;
sbit pb01 = ibase^1;
sbit firstscandone = ibase^2;
sbit testbit1=ibase^3;

void delay1(int counts)
{ int i, j;
for(i=0; i<1000;i++)
for(j=0; j<counts; j++);
}

void init1(void)
{ delay1(20);
P0=0xff;
P1=0x00;
P0=0x00;
P1=0x00;
ibase=0;
//firstscandone=1;
bitset(ibase,2);
testbit1=1;
}

void debounce(void)
{ int x, y;
if(PB0_0==1)
{ for(x=0; x<20; x++);
if(PB0_0==1)
{ pb00=1;
} else pb00=0;
}

if(PB0_1==1)
{ for(y=0; y<20; y++);
if(PB0_1==1)
{ pb01=1;
} else pb01=0;
} }

void main(void)
{ if(firstscandone==0) init1();
bitset(ibase,2);
debounce();
if (pb00==1)
{ bitset(P1,4);
delay1(10);
bitclear(P1,5);
}

if(pb01==1)
{ bitset(P1,5);
delay1(10);
bitclear(P1,4);
} if(firstscandone==1) bitset(P1,7);
}