"CC2530 Intensive Training 03" Timer interval Timing Implementation button N Combo

Source: Internet
Author: User

"CC2530 Intensive Training 03" Timer interval Timing Implementation button N Combo

"topic Requirements"
2018 National Vocational College Skills Competition "Internet of Things technology application" in the national competition (Higher vocational Group) on the development of perceptual layer of the difficulty increased, three topics are completed under the ZigBee protocol stack. One of the first topics, " warehouse temperature and humidity intelligent control system " examined the key click, double click and triple combo . In order to let everyone better grasp the complex process of the key ideas, here through a concrete practical training case, tell through the interval timing to achieve the key n combo of the basic idea.
on the Black ZigBee module of the New World national equipment, or in the xmf09b and xmf09c made by the Bee, Press the button SW1 click to toggle the D5 light switch state; Press the button SW1 double-click , Toggle D6 The switch state of the lamp, the key SW1 three combo , switch the D3 light switch state, the key SW1 four combo , switch the D4 light switch State .
key SW1----------p1_2
D5 lamp--------------p1_3(high-level lit)
D6 lamp--------------p1_4(high-level lit)
D3 lamp--------------p1_0(high-level lit)
D4 lamp--------------p1_1(high-level lit)

"Realization Idea"
Each key press defines a life cycle , which, if it is 0.5 seconds, determines the final state of the key at the end of the life cycle . If a new keystroke is pressed during the life cycle of the key, the life cycle will be recalculated, and then double-clicked. In the lifetime of the double-click, there are new keys pressed, then the life cycle will be recalculated, this is the triple combo. If no new keys are pressed throughout the life cycle, the final key state is three combos. So the analogy.

"Implementation Code"

1#include"ioCC2530.h"2 3 #defineD3 P1_04 #defineD4 p1_15 #defineD5 p1_36 #defineD6 p1_47 #defineSW1 p1_28 #defineSW2 P0_19 TenUnsignedCharcount_t =0; OneUnsignedCharK_num =0; A  - /*======================= Simple delay function ========================*/ - voidDelay (unsignedintt) the { -    while(t--); - } -  + /*====================== Port initialization function ========================*/ - voidInit_port () + { AP1sel &= ~0x1b;//p1_0, P1_1, P1_3, and p1_4 as general-purpose I/O ports atP1dir |=0x1b;//p1_0, P1_1, P1_3, and p1_4 port outputs -    -P1sel &= ~0x04;//P1_2 as a general-purpose I/O port -P1dir &= ~0x04;//p1_2 Port Input -P1INP &= ~0x04;//P1_2 set to pull-up/drop-down mode -P2INP &= ~0x40;//P1_2 set to pull- up in } -  to /*======================= Timer 1 Initialize ========================*/ + voidInit_timer1 () - { thet1cc0l =0xd4;  *t1cc0h =0x30;//16MHz Clock, 128-way, 0.1-second timing $T1cctl0 |=0x04;//turn on Channel 0 output comparison modePanax NotoginsengT1ie =1; -EA =1; theT1ctl =0x0e;//The crossover factor is 128, modulo mode + } A  the /*==================== Timer 1 service function ========================*/ + #pragmaVector = T1_vector -__interruptvoidTimer1_int () $ { $T1stat &= ~0x20;//clears the overflow interrupt flag bit for timer 1 -   if(K_num! =0&& SW1! =0)//keys do not release no calculation life cycle -   { thecount_t++;//Timer 1 Overflow once plus 1, overflow period of 0.1S -   }Wuyi } the  - /*==================== key Scanning processing function ========================*/ Wu voidScan_keys () - { About   if(SW1 = =0) $   { -Delay ( -);//de-jitter processing -     if(SW1 = =0) -     { A        while(SW1 = =0);//wait for the button to release +count_t =0;//Restart calculation of the key life cycle thek_num++;//Change Key State -       if(K_num >4)//Four combos above all sentenced to four combos $       { theK_num =4; the       } the     } the   } -   if(Count_t >5)//end of key life cycle in   {     the     Switch(K_num) the     { About        Case 1://Key Click theD5 = ~D5; the        Break; the        Case 2://Press to Double click +D6 = ~D6; -        Break; the        Case 3://key Triple comboBayiD3 = ~D3; the        Break; the        Case 4://key Four combo -D4 = ~D4; -        Break; the     } theK_num =0;//status clear 0 after each key processing thecount_t =0;//Chronograph 0 the   } - } the  the /*========================= main function =============================*/ the voidMain ()94 { the Init_port (); the init_timer1 (); theD3 =0;98D4 =0; AboutD5 =0; -D6 =0;101    while(1)102   {103 Scan_keys ();104   } the}

" Guangdong Vocational and Technical College Aohaoyuan < bee teacher > [email protected]"

"CC2530 Intensive Training 03" Timer interval Timing Implementation button N Combo

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.