This article is only for beginners, experts please skip it!
1. Experimental purpose
Use the IO port of the microcontroller to directly control the LED light and learn how to control the LED light.
2. Experimental content
Write a program to make LEDs 0 to 7 light up from both sides to the middle at an interval of 200ms, and finally all light up for 200ms and then turn off.
3. Hardware Principle
The hardware schematic diagram of 8-way direct I/O port controlling LED lights is shown in the figure below. Use a flat cable to connect to terminal P4, then the 0-7 pins of the corresponding port of the microcontroller are connected to the LED0-LED7 pins of terminal P4 (for example, use a flat cable to connect P10 to terminal P4, then the PD0 pin is connected to LED0, the PD1 pin is connected to LED1,... the PD7 pin is connected to LED7). Pins 9 and 10 of terminal P4 are connected to 5V VCC. It can be seen from the figure that the LED is lit at a low level. The corresponding pin of the microcontroller sends a low level, the LED is on, and the corresponding pin of the microcontroller sends a high level, and the LED is off.
4. Experimental reference procedures and annotations
Change the mapping layer 1_AbstractionLayer_HAL.h file
//PortD
#define IO_PD_DIR 0b11111111 //This indicates that pins 0-7 are all output
#define IO_PD_OUT 0b11111111 //This specifies that the default initial state of pins 0-7 is high, that is, when powered on,
/LED0-LED7 pins give high level, transistors are not conducting, and the LED lights are off
////////////////////////////////////////////////////////////////////////////////////
//Function macro definition
#define LED0BIT0
#define LED1BIT1
#define LED2BIT2
#define LED3BIT3
#define LED4BIT4
#define LED5BIT5
#define LED6BIT6
#define LED7BIT7
#define LED0_OPENCLRBIT(PORTD,LED0)
#define LED0_SHUTSETBIT(PORTD,LED0)
#define LED0_TURNCPLBIT(PORTD,LED0)
#define LED1_OPENCLRBIT(PORTD,LED1)
#define LED1_SHUTSETBIT(PORTD,LED1)
#define LED1_TURNCPLBIT(PORTD,LED1)
#define LED2_OPENCLRBIT(PORTD,LED2)
#define LED2_SHUTSETBIT(PORTD,LED2)
#define LED2_TURNCPLBIT(PORTD,LED2)
#define LED3_OPENCLRBIT(PORTD,LED3)
#define LED3_SHUTSETBIT(PORTD,LED3)
#define LED3_TURNCPLBIT(PORTD,LED3)
#define LED4_OPENCLRBIT(PORTD,LED4)
#define LED4_SHUTSETBIT(PORTD,LED4)
#define LED4_TURNCPLBIT(PORTD,LED4)
#define LED5_OPENCLRBIT(PORTD,LED5)
#define LED5_SHUTSETBIT(PORTD,LED5)
#define LED5_TURNCPLBIT(PORTD,LED5)
#define LED6_OPENCLRBIT(PORTD,LED6)
#define LED6_SHUTSETBIT(PORTD,LED6)
#define LED6_TURNCPLBIT(PORTD,LED6)
#define LED7_OPENCLRBIT(PORTD,LED7)
#define LED7_SHUTSETBIT(PORTD,LED7)
#define LED7_TURNCPLBIT(PORTD,LED7)
#define ALL_LED_OPEN //Open all LEDs LED0_OPEN;LED1_OPEN;LED2_OPEN;LED3_OPEN;LED4_OPEN;LED5_OPEN;LED6_OPEN;LED7_OPEN
#define ALL_LED_SHUT //Turn off all LEDs LED0_SHUT;LED1_SHUT;LED2_SHUT;LED3_SHUT;LED4_SHUT;LED5_SHUT;LED6_SHUT;LED7_SHUT
Modify the logic layer 0_logiclayer_main.c file
//Main program
int main(void)
{
//Target initialization, this function will automatically initialize the corresponding peripheral files
TARGET_Init();
//Background main loop
while(1)
{
//Complete your own project logic here
LED0_OPEN;
LED7_OPEN;
TARGET_Delayms(200,1);
LED0_SHUT;
LED7_SHUT;
TARGET_Delayms(200,1);
LED1_OPEN;
LED6_OPEN;
TARGET_Delayms(200,1);
LED1_SHUT;
LED6_SHUT;
TARGET_Delayms(200,1);
LED2_OPEN;
LED5_OPEN;
TARGET_Delayms(200,1);
LED2_SHUT;
LED5_SHUT;
TARGET_Delayms(200,1);
LED3_OPEN;
LED4_OPEN;
TARGET_Delayms(200,1);
LED3_SHUT;
LED4_SHUT;
TARGET_Delayms(200,1);
ALL_LED_OPEN;
TARGET_Delayms(200,1);
ALL_LED_SHUT;
TARGET_Delayms(200,1);
// Feed the dog statement, most projects should not remove it
#if WDT_MODE!=0
TARGET_WatchDogReset();
#endif
}
return 0; // never executed
}
Previous article:AVRWARE++ Development Notes 7: 74HC595 Serial Control LED Light Experiment
Next article:AVRWARE++ Development Notes 5: Buzzer Drive Experiment
Recommended ReadingLatest update time:2024-11-23 15:20
- Popular Resources
- Popular amplifiers
- Siemens PLC from Beginner to Mastery with Color Illustrations (Yang Rui)
- Siemens S7-1200-PLC Programming and Application Tutorial (3rd Edition) (Edited by Shi Shouyong)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Compiler Principles C Language Description (Ampel)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Development Trend of Surge Protectors
- 【RT-Thread Reading Notes】3. RT-Thread Study Chapter 4-5 Reading Notes
- TI DSP 6000 Series Optimization Experience
- HTTP protocol request and data capture
- March
- TMS320F28335 SVPWM source program
- Use of hardware multiplier in MSP430 library
- Make good use of ThinkPad power management software
- UPD78F0888A Renesas MCU peripheral settings
- Review summary: Kanzhi K510 CRB-KIT development kit