PIC menu - where to put the buttons?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

PIC menu - where to put the buttons?

Post by echase »

I am still struggling with writing a menu.

Anyone got any ideas on best strategy for connecting my Menu, Up, Down and Enter(optional) buttons to PIC (16F886)?

Do I:-

1) put one (Menu) switch on Port B0, interrupt on change, with the rest anywhere, not on interrupts. Pressing Menu jumps to a fast macro where all the other buttons are polled regularly and menus drilled down.

2) or put all 3 to 4 switches on Port B upper nibble, interrupt on change. Then any one pressed leads to an interrupt. BUT I am concerned that this may cause my macros to keep restarting when buttons pressed so, having drilled down a menu, it keeps jumping back to the beginning of menu.

3) do I need the 4th (Enter) key? Anyone wrtten a menu running with just 3 swiches?

My first prototype used 2) but am leaning towards 1) for next one as makes selection of PIC pins easier.

My main code runs really slowly with delays of say 5sec so the menu macro needs to be much faster to react to the buttons quickly.

My menu hardware/software is supposed to be much like the one you get on a PC monitor that sets brightness etc. except using text lines on 16x2 LCD rather than graphics. It enables variables to be set on/off to select modes of operation or incremented/decremented with the Up/Down buttons. Also selects which parameters to display on screen.

See also http://matrixmultimedia.com/mmforums/vi ... ght=echase

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello

I would use option 2. To stop the interrupts macro from restarting while you are inside it you can simple disable the interrupt and then reenable.

Eg

Interrupt Macro

1. Disable Interrupts
2. Check which switch was pressed
3. Perform task
4. Add debounce delay if needed
5. Enable interrupts

You can then use an enter key or you can wait a number of tmr0 timeouts.

Eg timeout rate of 75Hz. If there has been 75 timeouts without a port change interrupt then enter otherwise keep timeing out.

echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

Post by echase »

Excellent, had not spotted that an Interrupt can be turned off with Flowcode.

Think my code was suffering because I had both Port B interrupts and a read Port B command in action at same time.

echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

Post by echase »

1) I have set a Port B change interrupt on the upper 4 bits. Does this consume extra power and/or take up extra instructions cycles? If so can I slow it down to save power using Flowcode without slowing down the main code? I only need to pole my 4 switches say every 100mS. Not quite clear whether the interrupt is done using hardware in the PIC or a piece of code that Flowcode writes that constantly poles the port between doing its other jobs.

2) As these data lines are shared with outputs to the LCD can the PIC/Flowcode manage to NOT register a new output nibble as a port B change to which it needs to respond? I assume it switches the port to an output, sends the new nibble, then switches it back to an input and waits for the switches to change. Thus anything that happen when it's an output is ignored by the interrupt routine.

Tried to understand the PIC datasheet on interrupts but its written in a language that is rather opaque to an electronics engineer. Think you need to be a software engineer to understand it.

I use a 16F886 with 125kHz clock.

Post Reply