CC2530 timer configuration note 1 (basic timing function configuration)

foreword

CC2530 has two 8-bit timers, they are timer 3 and timer 4 respectively. Compared with the 8-bit timer of the traditional 51 single-chip microcomputer, the timer on the CC2530 has several features such as input capture, output comparison, and variable counting direction of the timer.

Timer Timing Function Register Configuration

Taking timer 3 as an example, if you want to perform timing operation through timer 3, you need to configure the T3CTL register, the IEN1 register, and the TIMIF register.

T3CTL register introduction

T3XTL is an 8-bit register.

Rank name reset value Read and write permissions configure
7:5 DIV[2:0] 000 read/write Timer division factor
- - - - 000: system clock divided by 1
- - - - 001: System clock divided by 2
- - - - 010: System clock divided by 4
- - - - 011: System clock divided by 8
- - - - 100: system clock divided by 16
- - - - 101: system clock divided by 32
- - - - 110: System clock divided by 64
- - - - 111: system clock divided by 128
4 START 0 read/write timer start flag
- - - - 0: Turn off the timer
- - - - 1 : Start the timer
3 OVFIM 1 read/write Timer overflow interrupt enable flag
- - - - 0: Disable timer overflow interrupt
- - - - 1: Enable timer overflow interrupt
2 CLR 0 read/write Timer count value clear bit, only 0 can be read when reading this bit
- - - - 0 : invalid
- - - - 1: Clear the timer count value
1:0 MODE[1:0] 00 read/write Timer working mode configuration
- - - - 00 : Free run, counting repeatedly from 0x00 to 0xFF
- - - - 01: Down counting mode, counting from T3CC0 to 0x00
- - - - 10: Up counting mode, counting repeatedly from 0x00 to T3CC0
- - - - 11: Up and down counting mode, counting repeatedly from 0x00 to T3CC0 to 0x00

IEN1 register introduction

IEN1 is an 8-bit register.

Rank name reset value Read and write permissions configure
3 T3IE 0 read/write Timer 3 interrupt enable flag
- - - - 0: Disable Timer 3 interrupt
- - - - 1: Enable timer 3 interrupt

Introduction to the TIMIF register

TIMIF is an 8-bit register.

Rank name reset value Read and write permissions configure
2 T3CH1IF 0 read/write Timer 3 channel 1 interrupt trigger flag
- - - - 0: Reset timer 3 channel 1 interrupt trigger flag
- - - - 1: Set timer 3 channel 1 interrupt trigger flag
1 T3CH0IF 0 读/写 定时器3通道0中断触发标志
- - - - 0 :复位定时器3通道0中断触发标志
- - - - 1 :置位定时器3通道0中断触发标志
0 T3OVFIF 0 读/写 定时器3溢出中断触发标志
- - - - 0 :复位定时器3溢出中断触发标志
- - - - 1 :置位定时器3溢出中断触发标志

范例

    #include <ioCC2530.h>

    void Timer3_Init( void )
    {
        //    TIMIF &= ~0x01;
        //    IEN1 |= 0x08;
        //    T3CTL = 0xFC;

        // 复位T3CTL寄存器
        T3CTL = 0x00;

        // 配置定时器3时钟为系统时钟128分频
        T3CTL |= 0xE0;
        // 清空定时器3计数器
        T3CTL |= 0x04;
        // 复位定时器溢出中断标志
        TIMIF &= ~0x01;
        // 开启定时器3溢出中断
        T3CTL |= 0x08;
        // 开启定时器3中断
        IEN1 |= 0x08;

        // 启动定时器3
        T3CTL |= 0x10;

        // 开启单片机总中断
        EA = 1;
    }

    int main( void )
    {
        Timer3_Init();
        while(1);
    }

    #pragma vector = T3_VECTOR
    __near_func __interrupt void TIM3_ISR_Handler( void )
    {
        // 复位定时器3中断溢出标志
        TIMIF &= ~0x01;
    }

演示程序

[1]. CC2530数据手册

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325641600&siteId=291194637