Recent Changes - Search:

Introduction to Microcontroller Programming

About PICmicro Chips

Clocking Your PICmicro Devices

E-Blocks

Flowcode Step By Step

PICmicro Projects

Labs

Getting a Phone Number

<^< Seeing ASCII | Course Index | You try it >^>

One good example of gathering long numbers is getting a multiple digit number. This could be a phone number, a password, or a number between 0 and 1023.

Have a look at the macro below. Here is an explanation:

The first 3 Component macros set up the LCD display. Then there is a Calculation icon which sets up the variables used in the program. The variable 'KEY' is used to store the key pressed in ASCII. The string NUMARRAY[10] is used to store the numbers - a maximum of 11 digits. Next there is 'Connection Point A', followed by the Keypad macro that assigns the variable 'KEY' to the keypad input.

The first decision box detects the condition that no key is pressed. This goes to a point at the end of the program where the variable 'OLD_KEY' is assigned to the input. 'OLD_KEY' is used as flag to allow us to monitor whether the input has changed. This helps de-bounce the input so that we do not get, say, 6 digit 1's when we press the '1' key. The next decision box detects if the new input is the same as the old input (KEY = OLD_KEY), and returns the program to the point A if the keypad number is the same.

The next decision box looks for ASCII 42 - the '*' key. This is used to denote a cancel operation. If the '*' key is pressed the first byte of the array is set to 0 and the macro is sent to the end point.

The next decision box looks for ASCII 35 - the '#' key. This is used to denote an Enter operation. If the '#' key is pressed the last byte of the array is set to 0 and the program is routed to the end point.

During the program we use the variable 'PTR' to allow us to track which digit in the string is being entered. The string has 10 characters: 0 to 9. The variable 'PTR' must be increased each time a digit is entered allowing each digit to be stored in a separate character of the string. The next Decision box tests whether this is the first character or not. if it is the first character then the display is cleared.

Next a Calculation icon declares: NUMARRAY[PTR] = KEY. This assigns the current character of the string to be the value entered on the keypad.

This is followed by a Calculation icon where the value 'PTR' is increased by 1: this means that the next character entered on the keypad will be stored in the subsequent character of the array.

The next icon in the main loop then displays the key pressed on the LCD so that the user has visual confirmation that the system has detected the key press.

At the end of the main loop we store the key pressed in 'OLD_KEY' as described above, then wait 100ms, and then loop back to the beginning of the macro.

<^< Seeing ASCII | Course index | You try it >^>

Print - Search - Login

Page last modified on July 26, 2013, at 10:39 AM