Selecting among 8 (or more) inputs using 2 keys and EEPROM

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Selecting among 8 (or more) inputs using 2 keys and EEPROM

Post by fotios »

Hello
In the current project I have included just 8 inputs, to be compatible with EB004 Led board connected at port D of EB006 multiprogramer. In practice, the number of inputs could be 256 according to the size of an EEPROM location (address) of micro. The EB005 LCD board is connected at port C and is used to indicate the name of Input selected. The EB004 Led board simulates an array of 8 relays for Input selection. The MCU is by default a P16F887 (it could be changed thru configuration menu). The EB007 switch board is connected at port B for using the Port Change state interrupt. Only the nr.5 and nr.6 switches are used. I tried the project in simulator and in active hardware; it works on both just fine. Small corrections of Delays maybe needed, also if you have a better idea to shorten the code it will be welcomed. I gave 8 names commonly used in music devices in Inputs, and the project works exactly like the "zapping" operation in TV sets, i.e. the Inputs are changed in scrolling mode, forward or backwards, using 2 (up & down) keys. The EEPROM(1) location (or address 1) is used to store a unique number that corresponds to each one of the 8 inputs. Thus, each time the microcontroller is re-activated it selects again, the existing input that was stored in EEPROM before its last deactivation. Data in EEPROM of PIC are retained without power, but when the program is launched for first time - i.e. just after the compilation to PIC - the existing number contained in EEPROM(1) is unknown. To not caused a program hang-up in the case that the number is bigger than 7 (that is an issue of the current program structure) in the beginning of the Flow there is an EEPROM initialization sub-routine to prevent this. After this once initialization of EEPROM this subroutine is always bypassed during program start-up. There is the necessary main Loop "While 1" to keep the program running continuously. There are two other macros except the default "Main". The one is the "Man_Switch" and is called each time a Port "change state" (or IOC according to Microchip) interrupt occurs, when either of the 2 momentary switches is pressed. Inside this macro is first checked which of the 2 switches causes the interrupt. If it is the "Input-", the program first reads the number of Input stored in EEPROM(1) and it selects the PREVIOUS Input by changing the EEPROM(1) data with its unique number. And so on. The same happens if the key "Input+" is pressed and the only difference is that the data of EEPROM(1) are updated with the NEXT Input unique number. At the end of the macro the program sets the flag of variable "Input_update" (i.e. = 1). Then the program flow returns in the Main Loop and because the decision "If Input_update is TRUE?" (i.e. =1) is fulfiled, the program flow turned inside the sub-loop "Until Input_update" is TRUE (=1). This loop calls the other macro "Input". In practice, this sub-loop eliminates the possible flickering of LCD display as is executed once, each time a Port change interrupt occurs. Inside the macro "Input" the program first reads the unique number of Input stored in EEPROM(1) previously during the execution of the macro "Man_Switch". In sequence, the number of Input is stored insdide a variable named "Input". Then the program it has to pass thru 8 decisions in sequence, and when the number of variable "Input" matches with the "test" number of a decision it turns into its "Yes" branch. Then the program activates the corresponding output by turning On its own Led that represents an Input relay, deactivates all other outputs and finally prints on the LCD display the name of Input that corresponds to the unique number carried by the variable "Input". That’s all.
I hope this small project will be useful to many people.
Thanks for your time.
Fotios
Attachments
2_BUTTON_INPUT.fcf
(35.35 KiB) Downloaded 350 times
Best Regards FOTIS ANAGNOSTOU

Post Reply