I. Introduction
Through the previous experiment, I believe everyone has a certain understanding of cc2530 program writing. This time we will operate and experiment with the key module on cc2530.
2. Principle Analysis
Let's first look at the schematic diagram of the button:
According to the schematic diagram, we can conclude that the value is 0 when the button is not pressed, because it is grounded. Therefore, when the button is about to be pressed, the input values of BUT1 and BUT2 are 1. When they are detected to be 1, the button is in the pressed state. Because the default state of P0DIR is input, there is no need to configure the IO register. When the button is pressed, the state of the LED changes to verify the experiment.
III. Procedure
#define LED1 P1_0 //LED1 is controlled by P1_0 port
#define LED2 P1_1 //LED2 is controlled by P1_1 port
#define LED3 P1_4 //LED3 is controlled by P1_4 port
#define KEY1 P0_4 //KEY1 is the control port of P0_4
/***************** Function name: Delayms Function description: millisecond delay Input parameter: xms: delay time, such as i=xms, that is, delay i milliseconds Output parameter: none Return value: none *********************/
void Delayms(uint xms) { uint i,j; for(i=xms;i>0;i--) for(j=587;j>0;j--); }
/ Function name: InitLed Function description: LED IO initialization Input parameter: none Output parameter: none Return value: none *************/
void InitLed(void)
{ P1DIR |= 0xff; //P1 port is defined as output
LED1 = 1; //LED1 is off
LED2 = 1;
LED3 = 1; }
/******************** Function name: KeyScan Function description: Key detection function Input parameter: none Output parameter: none Return value: 0: No key is pressed 1: Key is pressed **************************/
uchar KeyScan(void)
{
if(KEY1==0)
{ Delayms(2); //Delay debounce
if(KEY1==0)
{ while(!KEY1); // Release detection, if the key is pressed, it will stop at this statement
return 1; //A button is pressed }
} return 0; //No button pressed }
/************************* Function name: main Function description: KEY test (for general IO input/output) Input parameter: NONE Output parameter: NONE Return value: NONE **************************/
void main(void) { InitLed(); //Call initialization function
while(1)
{ if(KeyScan())
{LED1=~LED1; //Button changes LED status
LED2=~LED2;
LED3=~LED3; }
} }
IV. Conclusion
Through this experiment, we learned how to use buttons to control the peripherals of cc2530, and use the keyboard scanning function to detect changes in button status. The function calls a delay function for delay debouncing to increase system stability. However, continuous detection will occupy the CPU's working time. The next lecture will introduce a better way.
Previous article:Zigbee Learning Path (I): Zigbee Introduction 1. Introduction
Next article:Zigbee learning path (IV): key control (interrupt mode)
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Fluke High Resolution Thermal Imager - Even the smallest details are captured! Free trial registration is open
- The capacitor on the PCBA cracked and short-circuited. How could it be the design's fault?
- Serial port download of TMS320LF2407
- 【Bluesun AB32VG1 RISC-V Evaluation Board】Development of example programs
- 2nd day to go!! Pre-registration for the prize live broadcast | ON Semiconductor image sensors help the automotive, machine vision and artificial intelligence fields....
- 【AT-START-F425 Review】USB to CAN Preview Post
- Abnormal sound from the front transformer of the power factor circuit
- Packaging issues of double-row pluggable connectors
- Japanese auto parts giant exposed to large-scale fraud for 20 years! Affecting 10 Japanese automakers...
- 【AT32WB415 Review】03 SPI Drive TFT LCD Screen