new to programing PIC and need some help

Thread Starter

onextwo12

Joined Mar 31, 2014
3
Hi,
I am very new to programing PIC in C and need some help. I have been looking on the net for some sample code to do the following:

I what to use one switch to turn on different outputs e.g.

1st short switch push, turn on o/p 1
2nd short switch push, keep o/p 1 on and turn on o/p 2
3rd long hold , turn off o/p 1 and 2 (plus turn of o/p 1 if only 1st short switch used).

Plus
1st long hold, turn on o/p 1 then short delay (keep o/p 1 on) turn on o/p 2
3rd long hold , turn off o/p 1 and 2

But I cannot find any examples of using a switch this way.

If anyone can help and point me in the right direction I would be grateful.

Thanks

 

MrChips

Joined Oct 2, 2009
30,824
When you are new to programming, take one step at a time.

Step 1. Write a program to turn on an LED.

Step 2. Write a program to make the LED flash once every second, i.e. on for half a second, off for half a second.

Step 3. Write a program to make the LED turn on while a button is pressed.

Step 4. Write a program to make the LED turn on when the button is pressed and released and turn off when the button is pressed and released a second time. Repeat the same sequence on subsequent presses of the button.

There is more to come but this will get you programming for awhile.

When you learn the art of programming you do not have to rely on other people's code.
 

ErnieM

Joined Apr 24, 2011
8,377
That looks good to me too. I do notice the 4 rightmost steps duplicate steps on the left, so you could join the code and only write it once.

For problems like this a state diagram can also be very useful. Flow charts are fine but once you code as well as you speak you'll stop using them, but state diagrams will always be useful.
 

Thread Starter

onextwo12

Joined Mar 31, 2014
3
That looks good to me too. I do notice the 4 rightmost steps duplicate steps on the left, so you could join the code and only write it once.

For problems like this a state diagram can also be very useful. Flow charts are fine but once you code as well as you speak you'll stop using them, but state diagrams will always be useful.
Yes I see what you mean is this better?

What is a state diagram, any usefully links ?
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
That looks good to me too. I do notice the 4 rightmost steps duplicate steps on the left, so you could join the code and only write it once.

For problems like this a --->> state diagram <<--- can also be very useful. Flow charts are fine but once you code as well as you speak you'll stop using them, but state diagrams will always be useful.

Like that?
 
Top