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 #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.
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
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- [MM32 eMiniBoard Review] + SysTick Second Timer
- DSP realizes the source code of the water light style
- Controlling Hardware with Python - Low Voltage Startup and Reliability Testing
- HDB3 Codec Design Based on FPGA.pdf
- Data sharing on the transmission power of 2.4G wireless RF chip CC2530
- A talented person actually analyzed power MOS like this, it is very rare information!
- MicroPython has made several adjustments to USB functions
- Commonly used algorithms for drones - Kalman filter (IV)
- About the use of memory AT45DB041
- Be the first to experience the Mir MYS-8MMX embedded single board computer for free!