For CC2530 Gpio Basics, General Gpio operation about registers, IAR Embedded Workbench IDE software use: TI CC2530 Basic Experiment (ordinary GPIO operation-Light LED)
Schematic diagram of the circuit:
Analysis : You need to press the button to light the light, and do not use the interrupt mode, that is, we need to monitor whether the press is pressed (P0_4 is low, high-level means release).
Settings :
- Lamp LED1 corresponding P1_0 pin for normal I/O, direction output
- Key S1 corresponding P0_4 pin for normal I/O, direction input
program:
/************************************** * Basic Experiment just add the following header file to *************************************/#include < iocc2530.h>/*********************************** * Program Description: Press the button to light the light **********************************/#define LED1 p1_0#define KEY1 p0_4/*********************************** * Function Description: Initialize LED1 **********************************/ void Led1init (void) {P1sel &= ~0x01; function: normal I/O p1dir |= 0x01; Direction: Output LED1 = 1; Make it out of State}/*********************************** * Function Description: Initialize key S1 **********************************/void Key1init ( void) {P0sel &= ~0x10; function: normal I/O p0dir &= ~0x10; Direction: Input}/*********************************** * Function Description: Millisecond delay function **********************************/void delayms ( unsigned int ms) {unsigned int i,j; for (i = ms, I > 0; i--) {for (j = 587; j > 0; j--); }}/*********************************** * Function Description: Scans the status of KEY1 and repairs LED1 **********************************/void Key1scan ( void) {if (0 = = KEY1)//means pressing {LED1 = 0;//low-level to make it leD1 Bright delayms (10);//Shake for (; 1 = = KEY1;)//Determine whether to loosen {LED1 = 1;//give high level to make it LED1 bright}}}void main () {led1init (); Key1init (); for (;;) {Key1scan (); }}
Note: Each creation of a new project will be configured IAR (to do the basic experiment), TI CC2530 Basic Experiment (ordinary GPIO operation-led light) also has IAR related configuration steps
TI CC2530 Basic Experiment (ordinary GPIO operation--click the button to light the light)