Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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 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.

Latest threads

New Articles From Microcontroller Tips

Back
Top