![]() ![]() ![]() Introduction to Embedded Programming - Input Examples GPIO Input Examples. Now that we have covered GPIO inputs, we can explore some example programs that add inputs to the outputs and time delays we have already used. Example 1 - LED Output Follows Button Input. In this program, one GPIO pin will be configured as an output to drive an LED, and one GPIO pin will be configured as an input to read a button. The main program loop will continually read the state of the button input and send that state to the LED output - LED OFF if button not pushed, LED ON if button pushed. Key Concepts. Use of data direction register to set selected GPIO pins to outputs, others to inputs. Use of bit- masking and testing instructions. Example 2 - LED Output Controlled by Two Button Inputs. In this program, one GPIO pin will be configured as an output to drive an LED, and two GPIO pins will be configured as inputs to read two buttons. A standards-compliant and portably written C program can be compiled for a very wide variety of computer. C (programming language) at Wikipedia's. Now for embedded system development people are using operating system to add more features and at the same time reduce the development time of a complex system. This article gives a simple & understandable overview. The main program loop will continually read the state of the button inputs and set the state of the LED output as follows - LED ON if button A is pushed, LED OFF if button B is pushed, LED no change if neither button is pushed. Key Concepts. Use of data direction register to set selected GPIO pins to outputs, others to inputs. Use of bit- masking and testing instructions. Example 3 - LED Output Controlled by Two Button Inputs. Similar to Example 2, one GPIO pin will be configured as an output to drive an LED, and two GPIO pins will be configured as inputs to read two buttons. The main program loop will continually read the state of the button inputs and set the state of the LED output as follows - LED ON if button A is pushed, LED OFF if button B is pushed, LED no change if neither button is pushed. This time, only a single output bit will be set or cleared, as should normally be done, instead of a whole port value being written as in the previous examples. All other port bits will be left in their previous states and only the targeted bit will be altered. Key Concepts. Use of data direction register to set selected GPIO pins to outputs, others to inputs. Use of bit- masking and testing instructions. Use of bit- manipulation instructions. Example 4 - LED Output Moves Left Each Button Push (Demonstrate Button Bounce)In this program, 8 GPIO pins will be configured as outputs to drive 8 LEDs, and one GPIO pin will be configured as an input to read a button. Initially the rightmost LED will be ON. The main program loop will continually read the state of the button input and look for a button transition (an . With every button edge the ON LED will move one position to the left, wrapping around to the right as necessary. The ON LED may move more than one bit position at a time due to button bouncing. This will be the first example where we can observe the phenomenon of button/switch/key bounce. Key Concepts. Use of bit- masking and testing instructions. Use of bit- shifting instructions. Demonstration of button bounce. Example 5 - LED Output Moves Left Each Button Push (Button Debouncing)In this program, 8 GPIO pins will be configured as outputs to drive 8 LEDs, and one GPIO pin will be configured as an input to read a button. Initially the rightmost LED will be ON. The main program loop will continually call a button input function which will debounce any button pushes, and look for a button transition (an . Example C Program: Verifying the Signature of a PE. This section presents the ANSI C version of the demonstration program source code. This program shows how the keypad and LCD display can work together for a simple yet efficient human interface. Sample Program Name Embedded SQL Program Description adhoc: Yes Demonstrates dynamic SQL and the SQLDA structure to process SQL commands. Embedded C Programming for Microcontroller - Chapter 1. How to use Embedded C Coding in Keil - Duration. With every button edge the ON LED will move one position to the left, wrapping around to the right as necessary. The button will now be debounced by looping until a given number of consecutive button states is detected. The exact number is chosen based upon processor speed and maximum button bounce time. ![]() No explicit time delays are used for debouncing, only the implicit delay required for the processor to execute the specified number of loops. Key Concepts. Demonstration of button debouncing without explicit delays. Example 6 - LED Output Moves Left Each Button Push. In this program, 8 GPIO pins will be configured as outputs to drive 8 LEDs, and one GPIO pin will be configured as an input to read a button. Initially the rightmost LED will be ON. The main program loop will continually read the state of the button input and look for a button transition (an . With every button edge the ON LED will move one position to the left, wrapping around to the right as necessary. As in the previous example, the debouncing code loops until a given number of consecutive button states is detected, but in this example a software delay is inserted in the loop , to eventually lead to the concept of using a timer tick for debouncing. The number of consecutive button states for a debounced button is now specified in terms of the number of software delay intervals, and is thus independent of processor speed (but not of button specs). Key Concepts. Demonstration of button debouncing using 5ms software delays in main code. Example 7 - LED Output Moves Left Each Button Push. In this program, 8 GPIO pins will be configured as outputs to drive 8 LEDs, and one GPIO pin will be configured as an input to read a button. Initially the rightmost LED will be ON. The main program loop will continually read the state of the button input and look for a button transition (an . With every button edge the ON LED will move one position to the left, wrapping around to the right as necessary. As in the previous example, the debouncing code looks for a specified number of consecutive button states, with the number representing the number of software delay intervals. By moving the software delays outside of the main code, we have removed any debouncing responsibility from the main code and thus simplify the calls to the debounce routine. Later when we introduce timer interrupts we will replace the software delays with a timer tick and thus combine the concepts of timers, interrupts and debouncing. Key Concepts. Demonstration of button debouncing using 5ms software delays in debounce routine. Next Section: Interrupts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
October 2017
Categories |