4, Timer T1 through the query mode control LED1 periodic flashing (rotation mode)

Source: Internet
Author: User

Timer T1 control LED1 periodic flicker via query mode

1 /****************************************************************************2 * File name: main.c3 * Author: Amo [www.amoMcu.com single chip microcomputer]4 * Revision: 2014-04-085 * Version: 1.06 * Description: Timer T1 control LED1 periodic flicker via query mode7 ****************************************************************************/8#include <ioCC2540.h>9 Tentypedef unsignedCharUchar; Onetypedef unsignedint  UINT; A  - #defineLED1 P1_0//P1.0 Port Control LED1 -  the /**************************************************************************** - * Name: initled () - * Function: Set the corresponding IO port of the LED lamp - * Entry parameters: None + * Export parameters: None - ****************************************************************************/ + voidInitled (void) A { atP1dir |=0x01;//P1.0 defined as output -LED1 =0;//turn off the LED1 lamp by default - } -  - /**************************************************************************** - * Name: InitT1 () in * Function: Timer initialization, the system does not configure the operating clock by default is 2, that is, 16MHz - * Entry parameters: None to * Export parameters: None + ****************************************************************************/ - voidInitT1 () the { *T1ctl =0x0d;//128-way, auto reload 0x0000-0xffff $t1stat=0x21;//Channel 0, Interrupt activePanax Notoginseng } -  the /**************************************************************************** + * Program Entry function A ****************************************************************************/ the voidMainvoid) + { -Uchar count=0; $      $Initled ();//Call initialization function - InitT1 (); -      the      while(1) -     {Wuyi         if(IRCON >0) the         {  -ircon=0; Wu             if(count++ >=1)//about 1s periodic flashing, oscilloscope measurement of about 1025MS -             { AboutCount=0; $LED1 =! LED1;//LED1 Flashing -             } -         }  -     } A}

The cc254x T1 timer (16-bit) requires configuration of three registers T1ctl, T1stat, IRCON:

So the configuration is as follows:

27/****************************************************************************28 * Name    : InitT1 () 29 *    Energy: Timer initialization, the system does not configure the working clock by default is 2, that is, 16MHZ30 * Entry parameters: No 31 * Export parameters: No 32 ************************************************************ /33 void InitT1 () {     t1ctl = 0x0d;       128 frequency, automatic reloading 0x0000-0xffff     t1stat= 0x21;       Channel 0, interrupt valid   37}

Do not use interrupts can rotation ircon, when the Timer 1 interrupt is set to 1, rotation need to manually clear 0 (using the Interrupt subroutine will automatically clear 0)

Links: Http://pan.baidu.com/s/1bnlWvEJ

4, Timer T1 through the query mode control LED1 periodic flashing (rotation mode)

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.