Zigbee learning path (Part 2): Light up the LED

Publisher:GoldenSerenityLatest update time:2021-07-02 Source: eefocusKeywords:zigbee  core Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I. Introduction

Today, I will teach you how to light up the LED, which is also the most basic step in learning the development board.


2. Principle Analysis

Although the cc2530 chip is the core of 51, it is different from the 51 microcontroller. The 51 microcontroller does not need to configure the IO port, but the cc2530 chip needs to configure the IO port before it can be assigned a value. The registers that need to be configured are PXSEL, PXDIR, and PXINP. x can represent any IO port, such as P1SEL.

The following are the functions of PXSEL:

The following are the functions of PXDIR:

The following describes the functions of PXINP:

By configuring the above registers, you can control the input and output status of the IO port and whether it is used as a normal IO port.


III. Procedure

#include CC2530.h>

#define uint unsigned int #define uchar unsigned char

#define LED1 P1_0 //Define P1_0 as the control port of LED1 #define LED2 P1_1 //Define P1_1 as the control port of LED2

#define LED3 P1_4 //Define P1_4 as the LED3 control port

/* Function name: IO_Init Function description: LED_IO initialization function Input parameters:

NONE Output parameter: NONE Return value: NONE */

void IO_Init(void)

{ P1DIR |= 0xff; //P1 port is defined as output    

LED1 = 0; //Turn on LED1    

LED2 = 0; //Turn on LED2    

LED3 = 0; //Turn on LED3 }

/* 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: main Function description: LED test (output use of general IO) Input parameter: NONE Output parameter: NONE Return value: NONE */

void main ( void )

{ IO_Init (); //Call the initialization program  

Delayms (2000); //Delay 2s      

while ( 1 ) {    

LED1 = ~LED1;    

LED2 = ~LED2;    

LED3 = ~LED3;

Delayms ( 500 ); // Delay 0.5s } }


4. Summary and Analysis

In the main function, the initialization program is executed first to configure the registers related to the IO port. The default values ​​of the other two registers meet our requirements. We only need to configure P0DIR to use P1 port as the output port, and then use the delay function to achieve the flashing effect of the light.


Keywords:zigbee  core Reference address:Zigbee learning path (Part 2): Light up the LED

Previous article:PWM adjusts the brightness of 2 LEDs from 00 to FF, with 255 levels of brightness automatically adjusted
Next article:Zigbee Learning Path (I): Zigbee Introduction 1. Introduction

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号