View previous topic :: View next topic |
Author |
Message |
orhanli1
Joined: 27 May 2010 Posts: 6
|
6 led control problem |
Posted: Wed Jul 07, 2010 1:56 am |
|
|
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
|
|
Posted: Wed Jul 07, 2010 2:01 am |
|
|
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
|
|
Posted: Wed Jul 07, 2010 2:44 am |
|
|
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
|
|
Posted: Wed Jul 07, 2010 2:46 am |
|
|
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: 19568
|
|
Posted: Wed Jul 07, 2010 9:33 am |
|
|
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
|
|
Posted: Thu Jul 08, 2010 12:49 am |
|
|
Yes you are too right with your opinions. In this program the useful instruction is while not goto.
Thanks for your help.
regards |
|
|
|