Article Directory
9 matrix keyboard
It is 11111110 during initialization, which is 0xfe (counting from the high bit):
When S1 is pressed, it becomes 0xee:
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:
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:
T1CTL settings:
mark frequency/128, free run from 0x0000 to 0xffff.
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:
Select channel 0:
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;
}
}
}
}