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); }
my freind,
look at yo're function main. where does it end? what do you think it will do when main finishes.
think about this and correct it and then look to see whether the rest works.
Zeusti.
Look at the instructions for posting legible source code: www.danlhenry.com/.../keil_code.png
sorry I did not see this instruction. In future I will place code between these two brackets.
Thanks Dr. YOur instructions helped me to resolve the issue. I inserted while loop in Main.
Did the web page hide one character, or is this your full definition of a bit clear?
#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?
Another thing - shouldn't code that have a bitset() and bitclear() also have a bittest()?
My freind i am glad to help with real advice.
#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?
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.
;)
#define bitset(a,b) ((a)|=(1<<(b))) bitset(ibase,2);
compare the generated assembler for the above to
sbit firstscandone = ibase^2; firstscandone =1;// even better firstscandone = TRUE;
erik
What "button" are you talking about?
He is talking about the buttons on his keypad that he is reading and debouncing.
"why use inefficient instructions?"
for many reasons, none of which could you apparently comprehend.
for many reasons, none of which could you apparently comprehend. what a worthless answer, or is it that you are incapable of mentioning any and just have to spew some bile?
Erik
just check T0's maximum clock rate and you will know.