Can anybody tell me what is wrong in the following coding? I am unable to set P1.5 and P1.6 if I take the set memory from the variable and try to assign it to P1.5 or 6. But I am able to set P1.5 and 6 if directly assign from the saved debounce variable. Here below is the code.
#include <reg51.h> #include <stdio.h> #define bitset(a,b) ((a)|=(1<<(b))) #define bitclear(a,b) ((a)&= (1<<(b))) sbit LEDp17 = P1^7; sbit LEDp15= P1^5; sbit LEDp16=P1^6; sbit LEDp14=P1^4; 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; sbit testbitp15 = ibase^5; sbit testbitp16 = ibase^6; 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<5; x++); if(PB0_0==1) { pb00=1; pb01=0; } } if(PB0_1==1) { for(y=0; y<20; y++); if(PB0_1==1) { pb01=1; pb00=0; } } } void main(void) { if(firstscandone==0) init1(); while(1) { debounce(); if (pb00==1) { bitset(ibase,5); delay1(10); bitclear(ibase,6); } if(pb01==1) { bitset(ibase,6); delay1(10); bitclear(ibase,5); } if(firstscandone==1) bitset(P1,4); if(testbitp15==1) bitset(P1,5); else bitclear(P1,5); if(testbitp16==1) bitset(P1,6); else bitclear(P1,6); //When any of P0.0 and P0.1 is switched on then P1.5 or P1.6 are not getting on but P1.4 goes off. bitset(ibase,2); } }
PS to the homewrecker: if you want to spew bile, do not say "other exist" list them