CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

6 led control problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
orhanli1



Joined: 27 May 2010
Posts: 6

View user's profile Send private message Send e-mail

6 led control problem
PostPosted: Wed Jul 07, 2010 1:56 am     Reply with quote

i wanna control 6 led with 6 button but when i run the program in simulation, it didn't work.Where is my fault?ı wait your helps

Quote:

#use delay(4000000)
#use fast_io(a)
#use fast_io(b)
int1 x,y,z,a,b,c ;


void main()
{

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

set_tris_a(0b00011111);
set_tris_b(0b00000001);

while(1)

x=input(pin_a0);
output_bit(pin_b0,x);

y=input(pin_a1);
output_bit(pin_b1,y);

z=input(pin_a2);
output_bit(pin_b2,z);

a=input(pin_a3);
output_bit(pin_b3,a);

b=input(pin_a4);
output_bit(pin_b4,b);

c=input(pin_b0);
output_bit(pin_b0,c);

}
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 2:01 am     Reply with quote

There are no fuse settings.

Code:

set_tris_b(0b00000001);

while(1)

x=input(pin_a0);
output_bit(pin_b0,x);


You use pin_b0 as output but you have configured it as input in your tris statement.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 2:44 am     Reply with quote

Code:
while(1)

x=input(pin_a0);
output_bit(pin_b0,x);
...
The while statement repeats the block directly after the expression. A block starts with a '{' character and ends with and '}', in your program these are missing. The net result is that only the first statement after the expression will be executed, similar to:
Code:
while(1)
{
   x=input(pin_a0);
}

// never get here.
output_bit(pin_b0,x);
...
orhanli1



Joined: 27 May 2010
Posts: 6

View user's profile Send private message Send e-mail

PostPosted: Wed Jul 07, 2010 2:46 am     Reply with quote

Thanks everybody. I fix the problem.

It's unbelievable. I changed the while(1) and I used

start:
.
.
.
.
goto start:

It solved. I didn't understand.

Thanks again
Ttelmah



Joined: 11 Mar 2010
Posts: 19339

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 9:33 am     Reply with quote

Don't use the goto, just add the brackets to the while.
There are a few (very few) cases where a goto may be justified/worthwhile, but it is better for style, and future readability, to use forms like while. In some programming courses you will receive severe 'minus marks', if you use goto unecessarily...

On the original code:
Code:

   while(1) {

      x=input(pin_a0);
      output_bit(pin_b0,x);

      y=input(pin_a1);
      output_bit(pin_b1,y);

      z=input(pin_a2);
      output_bit(pin_b2,z);

      a=input(pin_a3);
      output_bit(pin_b3,a);

      b=input(pin_a4);
      output_bit(pin_b4,b);

      c=input(pin_b0);
      output_bit(pin_b0,c);
   }
}

Now, the 'bracket matching' tool, will tell you what code is associated with the while (with goto, this won't happen), and the indentation, also makes it doubly clear what you expect to be done by this.

Best Wishes
orhanli1



Joined: 27 May 2010
Posts: 6

View user's profile Send private message Send e-mail

PostPosted: Thu Jul 08, 2010 12:49 am     Reply with quote

Yes you are too right with your opinions. In this program the useful instruction is while not goto.

Thanks for your help.

regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group