Pic 16f887 giao tiếp bàn phím keypad 4x4
Một trong nhiều ứng dụng mà vi điều khiển có thể thực hiện là giao tiếp với một bàn phím để người sử dụng có thể nhập liệu một cách dễ dàng. Sau đây, dientudieukhien.net chia sẽ cùng bạn một bài học lập trình về giao tiếp bàn phím với pic16f887, ngôn ngữ lập trình C, trình biên dịch Mikroc.Thư viện hàm dùng trong bài này là:
- Keypad_Init
- Keypad_Key_Press
- Keypad_Key_Click
Prototype
|
void Keypad_Init(void);
|
Returns
|
Nothing.
|
Description
|
Initializes port for working with keypad.
|
Requires
|
Global variable :
must be defined before using this function.
|
Example
|
// Keypad module connections
char keypadPort at PORTD;
// End of keypad module connections
...
Keypad_Init();
|
Prototype
|
char Keypad_Key_Press(void);
|
Returns
|
The code of a pressed key (1..16).
If no key is pressed, returns 0.
|
Description
|
Reads the key from keypad when key gets pressed.
|
Requires
|
Port needs to be initialized for working with the Keypad library, see Keypad_Init.
|
Example
|
char kp;
...
kp = Keypad_Key_Press();
|
Prototype
|
char Keypad_Key_Click(void);
|
Returns
|
The code of a clicked key (1..16).
If no key is clicked, returns 0.
|
Description
|
Call to Keypad_Key_Click is a blocking call: the function waits until some key is pressed and released. When released, the function returns 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.
|
Requires
|
Port needs to be initialized for working with the Keypad library, see Keypad_Init.
|
Example
|
char kp;
...
kp = Keypad_Key_Click();
|
![]() |
4x4 keypad - ảnh: mikroe.com |
/*share by dientudieukhien.net
Source: mikroe.com
Mikroc pro*/
0 nhận xét: