Advice and information connecting Hex coded rotary switch

Status
Not open for further replies.

Barry

New Member
Hello esteemed forum,
I am a complete novice in electronics and to the wonderful world of the PIC (slowly but surely getting there!).I am working on a PIC project whereby i set the count how many times a switch is pressed before illuminating a LED i.e. LED lights up after the switch is pressed 8 times or 10 times or 12 times etc. This count should be set outside of the PIC and once set is constant until the "count" is changed. I thought of doing this with a Hex/Binary coded rotary switch (See image). This rotary switch would connect to four pins on the PIC with a single input to the rotary switch. My questions are the following :
1. Is this the correct way to achieve this?
2. On a Hex coded switch there are 16 switch settings and only four connections. How are 16 options achieved with only four inputs?
3. Am I correct in assuming that this rotary switch would give me 16 options i.e. 6/8/10/12/14/16 etc different key press options to light the LED?
4. How would the software in the PIC detect 16 options if 16 options in fact is what I will get?
Thank you in advance.
Barry.
 

Attachments

  • switch_703.jpg
    2 KB · Views: 519
Re: Advice and information connecting Hex coded rotary switc


It looks good to me!.

2. On a Hex coded switch there are 16 switch settings and only four connections. How are 16 options achieved with only four inputs?

Presumably, as it's called a 'HEX coded switch', the output on the four pins is the HEX value of the number selected - 0x00 to 0x0F.

3. Am I correct in assuming that this rotary switch would give me 16 options i.e. 6/8/10/12/14/16 etc different key press options to light the LED?

I would have thought so.

4. How would the software in the PIC detect 16 options if 16 options in fact is what I will get?

It's very, very, easy - just connect the switch to the lower 4 bits of a port (with pullup resistors). Then simply read the port in to W, AND it with 0x0F (to clear the upper nibble), the W register them holds the selected value.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…