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 CCS Technical Support

decoding button sequence

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



Joined: 29 Apr 2012
Posts: 2
Location: uk

View user's profile Send private message

decoding button sequence
PostPosted: Tue May 01, 2012 11:24 am     Reply with quote

I am very new to C programming and reading lots and asking lots of questions that most of you probably already know the answers to.
Question: I would like to read the input from 2 push button switches and decode the input and decide what action to take. This is a form of door lock.
Looking at using the PIC 16F627A with CCS software.

The input sequence is as follows.
buttons A , Button B
0,0
0,1
1,1
1,0
0,0

If this sequence happens, another function will be initiated.
If the reverse of this sequence happens another function is initiated.
What is the best way to implement this with C ?
Could both buttons be read at one time and the second line decide which function is going to start, or is it better to read all 5 lines before a decision is made.
Is there a very simple way of doing this?
I can read single button inputs and know what to do from there but feel there is a smarter way.
Thank you all for any time you can spare to help a newbie.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed May 02, 2012 2:31 am     Reply with quote

Try a state-machine approach.

There are loads of examples on this forum.

Mike
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed May 02, 2012 5:59 am     Reply with quote

Look at this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=47522
_________________
The search for better is endless. Instead simply find very good and get the job done.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed May 02, 2012 9:44 am     Reply with quote

If you treat buttons A and B as having values 2 and 1 your sequences then become 0, 1, 3, 2, 0 and 1, 2, 3, 1, 0.

Then look for these sequences as though you were using a parser.

The method can be extended to more characters or longer sequences.

Mike
mgmidget



Joined: 29 Apr 2012
Posts: 2
Location: uk

View user's profile Send private message

PostPosted: Thu May 03, 2012 8:27 am     Reply with quote

Very Happy
Thank you all for your input.
I did search but didn't find the state machine route
I will have a play and get back if I get stuck.
Is there any one book you guys would recommend for Embedded C, or is trial and pain the best learning curve.
Thank you all again.

Best regards
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu May 03, 2012 9:23 am     Reply with quote

Quote:
or is trial and pain the best learning curve


there is no book that teaches the logical steps you must take for a particular action...you can learn syntax but the logic is all yours.

there are several ways you can read buttons (or any other particular action for that matter)
Poll pins individually with If/else
Poll the port as a whole.
use tables
you can do state machines as suggested.
etc...

you can read a book that teaches you to make a state machine, but you wont find a book that teaches you a statemachine specifically for what you need.

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu May 03, 2012 11:29 am     Reply with quote

You've been given hints and links to a useful thread.

Have a go. Try several approaches.

When you get stuck, come back to the forum and someone will probably be able to help, if we can see that you've made an effort.

Many of the guys on the forum have decades of experience and could each dream up dozens of ways to achieve your goal.

You can't aquire that level of expertise overnight.

Mike
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