ZigBee Learning Path (15): Key experiment based on protocol stack

Source: Internet
Author: User

I. Preface

After the last study, I believe that we have initially learned to use the ZigBee protocol to send and receive data. Today, we're going to experiment with keystrokes and learn how to implement key interrupts in the protocol stack.

Two. Experimental function

On the protocol stack to implement the key interrupt, BUT1 Press, LED1 flashing two times.

Three. Code explanation

We also remember that the previous done the button experiment is how to configure it, in fact, based on ZigBee protocol stack principle is similar, we want to the interface and state of the keys is almost, TI has set up a dedicated key configuration of the code file, we only need to modify on the basis of the line. First open hel_key.c to modify, the following is the code

#define Hal_key_sw_6_port P0//1, Configuration IO port (S1 in P0_4)

#define Hal_key_sw_6_bit BV (4)

#define Hal_key_sw_6_sel P0sel

#define HAL_KEY_SW_6_DIR p0dir/* Edge Interrupt */

#define Hal_key_sw_6_edgebit BV (0)

#define Hal_key_sw_6_edge Hal_key_rising_edge//2, P0 rising edge trigger interrupt/* Sw_6 interrupts */

#define Hal_key_sw_6_ien IEN1/* CPU Interrupt Mask Register */

#define Hal_key_sw_6_ienbit BV (5)/* Mask bit for all of PORT_0 */

#define HAL_KEY_SW_6_ICTL P0ien/* Port Interrupt Control Register */

#define Hal_key_sw_6_ictlbit BV (4)/* p0ien-p0.1 enable/disable bit */

#define HAL_KEY_SW_6_PXIFG P0IFG/* Interrupt flag at Source */

The above is to configure the key port, and our normal I/O port initialization is similar.

Then we continue to modify it in Hal_board_cfg.h.

#define PUSH1_BV BV (4)//s1 in P0_4
#define Push1_sbit P0_4

Finally, we make changes in the ONBOARD.C

Default is query mode, now we change it to break mode

Since we are using interrupts, we need to configure and use it to open interrupts in the HAL_KEY.C function.

In this case, the key-related configuration is not much done, just wait for the event function calls in ZigBee line. The following is the handler function for the specific key.

void Sampleapp_handlekeys (uint8 shift, uint8 keys)
{
(void) shift; Intentionally unreferenced parameter

if (Keys & hal_key_sw_6)
{
Haluartwrite (0, "K1", 2); The hint was pressed by the KEY1
Haluartwrite (0, "\ n", 1); //
Halledblink (Hal_led_1, 2, 50, 500); LED1 blinks 2 times, 500ms each time, 50% lights
}

When the button is detected, we can see the effect of the light flashing.

Four. Summary

Through this, I would like to introduce to you the key function in ZigBee and use, according to the different I/O keys corresponding to the change, to achieve their own purposes, the need for specific code of students can contact me.

ZigBee Learning Path (15): Key experiment based on protocol stack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.