Internet of Things|Matrix Keyboard|Basic Development of Timers and Counters|Bluetooth 4.0 BLE Basics of the Internet of Things-Study Notes (5)

9 matrix keyboard

It is 11111110 during initialization, which is 0xfe (counting from the high bit):
insert image description here

When S1 is pressed, it becomes 0xee:insert image description here

After a period of detection, if it is still 0xee, it means that the button is pressed, and the status of other buttons can be obtained in the same way.

Example: when 2 is pressed:insert image description here

insert image description here

10 Basic Development of Timers and Counters

Turn on and off once every 1s, turn on for 0.5s, and turn off for 0.5s.
LED circuit schematic diagram:
insert image description here

T1CTL settings: insert image description here
insert image description here
mark frequency/128, free run from 0x0000 to 0xffff.insert image description here
insert image description here

The system default clock is divided by 2, namely 32MHZ/2=16MHZ, mark frequency/128, namely 16M/128=0.125M (timer frequency) 1/.125M=8us, 8us each time, free running 0XFFFF=
65535,65535 *8=524280us=524.28ms, which is about 0.5s.

T1STAT settings:insert image description here

Select channel 0:
insert image description here
insert image description here
insert image description here

Sample code:

#include <ioCC2540.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define LED1 P1_0
void ledinit(void)
{
  P1DIR |= 0x01; //00000001
  LED1 = 0;
}
void T1init(void)
{
  T1CTL = 0x0d;//128分频,自由运行从0x0000至0xffff
  T1STAT = 0x21;//0010 0001 溢出复位Timer 1 counter-overflow interrupt flag选择0通道

}
/***************************
//主函数
***************************/
void main(void)
{
  uchar count = 0;
  ledinit();
  T1init();
  while(1)
  {
    if(IRCON > 0) //有中断进入
    {
      IRCON = 0; //清除中断(必要)
      if(count++ >=1) //记录1s
      {
        count = 0; //清除计数
        LED1=~LED1;
      }
    }
  }

}

Summary of parameter settings:

insert image description here

Guess you like

Origin blog.csdn.net/Medlar_CN/article/details/130624832
Recommended