S Suraj143 Active Member Nov 13, 2011 #1 I need to check STATUS bits with C code. Will this code works? Code: number = number/2; if (STATUS.B0==1){ //check carry bit PORTB.B0=1; clk();} if (STATUS.B0==0){ PORTB.B0=1; clk(); {
I need to check STATUS bits with C code. Will this code works? Code: number = number/2; if (STATUS.B0==1){ //check carry bit PORTB.B0=1; clk();} if (STATUS.B0==0){ PORTB.B0=1; clk(); {
Mr RB Well-Known Member Nov 13, 2011 #2 I saw you used MikroC in another thread, so with that compiler it should work.
S Suraj143 Active Member Nov 13, 2011 #3 Oops sorry I didn't mentioned what compiler I used.I use mikroC.
P Pommie Well-Known Member Most Helpful Member Nov 13, 2011 #4 I don't think the carry flag will still be valid as you don't know what code will be generated. The better way to do that is, Code: if (number & 1){ //check carry bit PORTB.B0=1; clk(); }else{ PORTB.B0=1; clk(); { number = number/2; //or you can do number>>=1; Edit, should both lines say PORTB.B0=1; ? Mike. Last edited: Nov 13, 2011
I don't think the carry flag will still be valid as you don't know what code will be generated. The better way to do that is, Code: if (number & 1){ //check carry bit PORTB.B0=1; clk(); }else{ PORTB.B0=1; clk(); { number = number/2; //or you can do number>>=1; Edit, should both lines say PORTB.B0=1; ? Mike.
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Nov 14, 2011 #5 I don't think you can check the status bit after a math operation in C.. There is too much code overhead... Use signed variables... After reading pommies again... if your shifting... then that's how to do it. Last edited: Nov 14, 2011
I don't think you can check the status bit after a math operation in C.. There is too much code overhead... Use signed variables... After reading pommies again... if your shifting... then that's how to do it.