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); }
#define bitclear(a,b) ((a)&= (1<<(b))) If the above is exactly maching your bitclear, then please tell me what you think should happen if "a" have the value 255 (0xff) and "b" happens to have the value 4? What would be the end result?
My freind i am glad to help with real advice.
Oh, yeah.
Zeusti>
Oh by the way dr. Zeusti, it is "friend", not "freind".
Now it is time for you to thank ME for some great advise :-)
Tapeer, my dearest freind.
it is always good to get advise from freinds and it is always good to thank the poeple who give good advise.
sometimes the advise does not have to be followed. remember the reasons for the choice may be many and not always known to them whot given it.
please accept it and do not truble yourself trying to understand.
i go now. i can return in the future and see how my stoodent is progressed.
always yo're freind.
Zeusti.
;)