1. Io Configuration
Three registers are required for the configuration of the IOS port of the standard.
IO port register |
P0 |
P1 |
P2 |
Address |
0x80 |
0x90 |
0xa0 |
Pxsel |
P0sel |
P1sel |
P2sel |
Address |
0xf3 |
0xf4 |
0xf5 |
Px [] function to set registers. The default is normal IO port (0: normal IO port 1: second function) |
Pxdir |
P0dir |
P1dir |
P2dir |
Address |
0xfd |
0xfe |
0xff |
Px [] input and output settings register (0: Input 1: Output) |
Pxindium |
P0indium |
P1indium |
P2indium |
Address |
0x8f |
0xf6 |
0xf7 |
Px [] the circuit mode register when the input port is used (0: up/down 1: three States) |
2. Led Wiring
Connect led1 to p1_0
Led2 connected to p1_1
3. Implement Functions
Led1 and led2 flash alternately after power-on
4. Some code analysis
Configure p1_0 and p1_1 ports
P1sel & = ~ 0x03;
P1dir | = 0x03;
P1indium & = ~ 0x03;
5. complete code
1 #include <ioCC2530.h> 2 3 #define LED1 P1_0 4 #define LED2 P1_1 5 6 #define uchar unsigned char 7 #define uint unsigned int 8 9 void ledInit();10 void delayms(uint ms);11 12 void ledInit()13 {14 P1SEL &= ~0x03;15 P1DIR |= 0x03;16 P1INP &= ~0x03;17 18 LED1 = 1;19 LED2 = 0;20 }21 22 void delayms(uint ms)23 {24 uint i,j;25 for(i=ms; i>0; i--)26 for(j=587; j>0; j--);27 }28 29 void main()30 {31 ledInit();32 while(1)33 {34 delayms(1000);35 LED1 = !LED1;36 LED2 = !LED2;37 }38 }
ZigBee module Basic Experiment (1) Light up led