I. Preface
Today, I will teach you how to light the LED, which is the most basic steps to learn the development Board.
Two. Principle Analysis
cc2530 chip with the core, although it is 51, but it is different from the 51 single-chip microcomputer, 51 microcontroller does not need to configure the IO port, and the cc2530 chip needs to configure the IO port, in order to assign value, need to configure the register has PXSEL,PXDIR,PXINP, X can represent any IO port, such as P1sel.
The following describes the features of Pxsel:
650) this.width=650; "src=" Http://images2015.cnblogs.com/blog/892371/201603/892371-20160318110837615-1608872402.png "/>
The following describes the features of Pxdir:
650) this.width=650; "src=" Http://images2015.cnblogs.com/blog/892371/201603/892371-20160318111023615-244768202.png "/>
The following describes the features of PXINP:
650) this.width=650; "src=" Http://images2015.cnblogs.com/blog/892371/201603/892371-20160318111212053-1547225016.png "/>
By configuring the above register, you can control the IO port de input and output status, whether as a normal IO port.
Three. Procedures
#include <ioCC2530.h>
#define UINT unsigned int #define UCHAR unsigned char
#define LED1 P1_0//define P1_0 Port as LED1 control end #define LED2 p1_1//define P1_1 Port as LED2 control end
#define LED3 p1_4//define P1_4 Port as LED3 control end
/* Function Name: io_init function Description: led_io initialization function input parameter:
None output parameter: None return value: None */
void Io_init (void)
{P1dir |= 0xFF; P1 Port defined as output
LED1 = 0; Light LED1.
LED2 = 0; Light LED2.
LED3 = 0; Light LED3}
/* Function Name: delayms function Description: Millisecond delay input parameter: XMS: Delay time, such as i=xms delay I millisecond 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: Main function Description: LED test (output using universal IO) input parameter: None output parameter: None return value: None */
void Main (void)
{Io_init (); Invoking the initialization program
Delayms (2000); Delay 2s
while (1) {
LED1 = ~ LED1;
LED2 = ~ LED2;
LED3 = ~ LED3;
Delayms (500); Delay 0.5s}}
Four. Summary and Analysis
The main function first executes the initialization program, configures the IO port related register, the other two registers the default value satisfies our request, we only need to configure the P0dir to be able, is the P1 port as the output, then through the delay function, realizes the light flicker effect.
This article from "Persistent to abnormal" blog, reproduced please contact the author!
ZigBee Learning Path (ii): Light LED