View previous topic :: View next topic |
Author |
Message |
Ellest96
Joined: 15 Nov 2013 Posts: 17
|
MPLABX and CCS led blink not as I want |
Posted: Fri Nov 15, 2013 3:58 pm |
|
|
I made this program...
http://pastebin.com/WSYK0DsU
what it should do:
-blink all leds from LED1 to LED6 (startup signal)
-set LED1 to 1, wait 50 ms (default value for variable K, blink frequency), set LED1 to 0; and repeat this.
-when I press BUTT1 (stays for BUTTon, non [spam]), the variable i become 1; when I press BUTT2, the variable j become 1.
-when i is 1, k=k+10; and when j is 1, k=k-50, so with those buttons I can adjust the frequency.
What it actually do:
-blink main leds (1-6) (startup sequence)
-blink LED7 forever.
why?????? |
|
![](templates/subSilver/images/spacer.gif) |
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Fri Nov 15, 2013 4:11 pm |
|
|
How is it supposed to get from your first "while(1)" block of code to the second "while(1)" block of code that flashes LED1?
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
![](templates/subSilver/images/spacer.gif) |
Ellest96
Joined: 15 Nov 2013 Posts: 17
|
|
Posted: Fri Nov 15, 2013 4:52 pm |
|
|
If i put all the code in one while(1) the problem is the same.
Last edited by Ellest96 on Sat Nov 16, 2013 5:43 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Fri Nov 15, 2013 6:18 pm |
|
|
So when are you going to fix the problem pointed out to you
by gpsmikey and show the new code that doesn't work? No one here is a
mind reader... _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
Ellest96
Joined: 15 Nov 2013 Posts: 17
|
|
Posted: Sat Nov 16, 2013 12:32 am |
|
|
By making one while with the code from the variables of the buttons to the end.
Delete lines from 64 to 68. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Ellest96
Joined: 15 Nov 2013 Posts: 17
|
|
Posted: Sat Nov 16, 2013 1:29 am |
|
|
Oops...
This afternoon i will test the program with that. |
|
![](templates/subSilver/images/spacer.gif) |
Ellest96
Joined: 15 Nov 2013 Posts: 17
|
|
Posted: Sat Nov 16, 2013 5:43 am |
|
|
so, I've modified the program...
http://pastebin.com/7ziSy40G
the problem is the same:
-6 main leds blink one time.
-LED7 blinks as he wants. |
|
![](templates/subSilver/images/spacer.gif) |
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Sat Nov 16, 2013 7:46 am |
|
|
Are your switches active high or active low? |
|
![](templates/subSilver/images/spacer.gif) |
Ellest96
Joined: 15 Nov 2013 Posts: 17
|
|
![](templates/subSilver/images/spacer.gif) |
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sat Nov 16, 2013 10:21 am |
|
|
Ah yes, missed those two - I've been trying to train myself to write code so the compiler will catch those. The answer is fairly simple - instead of "if ( k = 0 )" which sets K to 0 and is always true, you write it as "if (0 = k)" and the compiler will throw it out at which point, you go "duh" and change it to "if (0 == k)" and all is well. Takes a bit of retraining for these old grey cells though
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
![](templates/subSilver/images/spacer.gif) |
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Sat Nov 16, 2013 2:01 pm |
|
|
That's a great idea gps |
|
![](templates/subSilver/images/spacer.gif) |
|