The LPC2148 development board of Litian Electronics has four running lights. They are connected to the SN74HC595D and then connected to the 2148 processor. First light up the two on the sides (16, 19), then light up the two in the middle (17, 18). When turning off, turn off the two on the sides first, then the one in the middle. The program is shown in the figure below:
#include #define SCLK 0x01<<24 #define MISO 0x01<<5 #define MOSI 0x01<<6 #define RCK 0x01<<7 void Delayn(unsigned long n); void HC595_Init(void); void Write595(void); unsigned int HC595_DATA = 0; //Initialize 595 interface void HC595_Init(void) { IO0DIR |= MOSI|RCK; IO1DIR |= SCLK; IO1CLR |= SCLK; IO0DIR |= RCK; HC595_DATA = 0xFFFFFFFF; Write595(); } //Write bytes void WriteByte(unsigned char data) { unsigned char i; //IO0CLR = RCK; for(i=0;i<8;i++) { if(data&0x01) IO0SET=MOSI; else IO0CLR=MOSI; IO1SET=SCLK; data>>=1; IO1CLR=SCLK; } //IO0SET = RCK; } //Refresh 595 data void Write595(void) { IO0CLR = RCK; WriteByte(HC595_DATA&0xff); WriteByte((HC595_DATA&0xff00)>>8); WriteByte((HC595_DATA&0xff0000)>>16); WriteByte((HC595_DATA&0xff000000)>>24); IO0SET = RCK; } main(void) { // Initialize 74HC595 HC595_Init(); //Main loop while(1) { HC595_DATA &=~(1<<16);Write595(); HC595_DATA &=~(1<<19);Write595(); Delayn(1000000); HC595_DATA &=~(1<<17);Write595(); HC595_DATA &=~(1<<18);Write595(); Delayn(1000000); HC595_DATA |=(1<<16);Write595(); HC595_DATA |=(1<<19);Write595(); Delayn(1000000); HC595_DATA |=(1<<17);Write595(); HC595_DATA |=(1<<18);Write595(); Delayn(1000000); } } //Delay cycle number void Delayn(unsigned long n) { while(n--); }
Previous article:arm7 Litian Electronics lpc2148 GPIO key input test
Next article:arm7 Litian Electronics lpc2148 GPIO 2 single-channel LED control experiment
Recommended ReadingLatest update time:2024-11-16 13:32
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Advanced MCU Serial Port Programming
- Live streaming now open: TE's smart building solutions - sensing and connectivity, the key to smart building design
- [Hua Diao Experience] 16 Use Beetle ESP32 C3 to control 8X32-bit WS2812 hard screen
- It’s hard to believe that this pair of high-speed signals changed the vias so many times!!!
- What is the purpose of adding a capacitor to the source and drain of a MOS tube?
- FPGA Design Tips
- Antenna Basics-Huawei
- [Infineon XENSIV PAS CO2 sensor] Simple unboxing
- An article to understand the analysis and calculation of electrolytic capacitor life
- FreeRTOS in the JIHAI APM32E103VET6 review