STATUS Reg with C Language

Status
Not open for further replies.

Suraj143

Active Member
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 saw you used MikroC in another thread, so with that compiler it should work.
 
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:
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:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…