4 x 4 Key Pad Interfacing Exercise (ATM Machine Design) Write a C18 Program to c
ID: 3734727 • Letter: 4
Question
4 x 4 Key Pad Interfacing Exercise (ATM Machine Design) Write a C18 Program to check if the 4 digits entered by the user correspond to the expected secret pin code. Assume that the 4 digit secret codes are entered serially from the ATM card to the ATM machine's HCS12 microcontroller (through its pin PORT T-bit 0- "Data" signal) every time there is a low to high transition on pin PORT T-bit 1 ("Ena" Signal). A Green LED connected to PORT T-bit 2 is then switch on in case the entered code matches the secret code. Otherwise a Red ATM Machine Ena ATM Card HCS12 Easy Data Sim CardExplanation / Answer
Keypad_Init it initializes port for working with keypad. It returns noting. For example
char keypadPort at PORTB;
Keypad_Init();
Keypad_Key_Press it reads the key from keypad when key is pressed. It returns the code of pressed key. If no key is pressed it returns 0. For this port needs to be initialized for working with the Keypad library. For example
char key;
key = Keypad_Key_Press();
Keypad_Key_Click this function is blocking call which means the function waits until some key is pressed and released. When the key is released, the function returns key code from 1 to 16, depending on the key. If more than one key is pressed simultaneously the function will wait until all pressed keys are released. After that the function will return the code of the first pressed key. It returns the code of a clicked key. If no key is clicked it returns 0. For example
char key;
key = Keypad_Key_Click();
C-CODE FOR KEYPAD INTERFACING WITH PIC16F877A
Just like for LCD, MikroC also provides built-in library functions for a 4×4 Keypad. These library routines, however, can be used with other sizes of keypad as well. Functions, such as keypad_init, keypad_key_clicketc, simply needs to be defined in the program, and rest of the inner operations are performed by the mikroC compiler.Write the following code in mikroC to interface keypad with PIC MCU:
A variable ‘kpi’ is declared in the beginning of the code, that takes value from the keypad and displays it on the LCD screen.The program first displays‘Keypad Interface’ and ‘Press a key’ on the LCD screen, separated by a 0.5s delay. The program then enters the ‘do-while’ loop and waits for a key to be pressed. As soon as any key is pressed, the inner ‘while’ loop is initiated and the ASCII code of that key is compared with the ASCII codes of all the characters present on the keypad. In case of a match, the program comes out of the while loop, displays the pressed key on the LCD screen and returns to the start of ‘do-while’ loop to wait for the next key press. The process is repeated, until program is aborted.
APPLICATION
Keypads have been used extensively in automotive applications as well as food industries. Programmed Keypads can be used in automated attendance system at schools, offices etc, where you enter your ID, which is displayed and at the same time stored, to mark your presence. Automatic door locks are usually accessed with a keypad control system in which a particular code is dialed on the keypad to open the door.To downlaod circuit diagram and code
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.