I haven't touched a microcontroller for a long time, so I'm a little rusty. I still vaguely remember sitting in front of a computer screen and learning the microcontroller by myself. I went through the basics of microcontrollers and now it's quite interesting. Attached is a small microcontroller program that I learned when I was a beginner. Please give me your advice!
Use P1 port as output port, connect 8-bit LEDs used for logic level display. Design the program to make the LEDs light up first with odd numbers and then with even numbers at intervals of 300ms, and repeat 3 times; one LED lights up and down 3 times; two LEDs flow from both sides to the middle 3 times; then flow from the middle to both sides 3 times; all 8 LEDs flash 3 times; turn off all LEDs and stop.
Comprehensive experimental procedures:
#Library definition
#include #include sbit led=P1^0; #bit definition int i,j,k,num,e,p,m; void delay(int k) #define delay function { while(k--); } void timer0() # Initialization of timer 0 { TMOD=0X01; #Working mode TR0=1; EA=1; # Enable total interrupt ET0=1; TH0=0XDc; #The timing time needs to be converted TL0=0X00; } void Pled() { EA=0; //P1=0xfe; //delay(50000); for(p=0;p<3;p++){ P1=0xfe; for(num=0;num<8;num++) { delay(50000); P1=_crol_(P1,1); #_crol_ (left shift function) if(num==6) { for(e=0;e<6;e++){ delay(50000); P1=_cror_(P1,1); #_cror_ (left shift function) } } } } } void flowmiddle() { for(m=0;m<3;m++) { P1=0x7e; delay(50000); P1=0XBD; delay(50000); P1=0XDB; delay(50000); P1=0XE7; delay(50000); } for(m=0;m<3;m++) { P1=0XE7; delay(50000); P1=0XDB; delay(50000); P1=0XBD; delay(50000); P1=0x7e; delay(50000); } for(m=0;m<3;m++){ P1=0xff; delay(50000); P1=0; delay(50000); } } void main() { timer0(); while(1){ if(j==7) { j=0; Pled(); flowmiddle(); } if(j==0) { P1=0xff; } } } void time0() interrupt 1 #Timer 0 interrupt response { TH0=0Xdc; TL0=0X00; //10ms i++; if(i==30) { i=0; j++; if(j%2==0){ P1=0x55;} if(j%2!=0) { P1=0xaa; } } } Instructions for the experimental implementation: Use timer 0 to set a timer for 300ms. By judging whether the variable j is an odd or even number after the timer expires, light up the corresponding small lights. When the variable reaches 7, clear the variable value and execute left and right shift operations, as well as operations flowing to the middle.
Previous article:51 MCU learning knowledge points
Next article:51 MCU Learning Summary Series (0) MCU Minimum System
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
- On the road to 5G, is GaN technology really important?
- Why is this TVS designed like this?
- I called Knowles today and it was hilarious.
- Is there any sensor that can detect whether there is someone in front through the tinted glass?
- Should the filter capacitor and bleeder resistor in the circuit be placed before or after the anti-reverse polarity diode?
- Which teacher can explain this circuit?
- [2022 Digi-Key Innovation Design Competition] 1. STM32F7508-DK Unboxing
- Some predictions about the national competition questions - about power supply questions
- RFID low frequency and high frequency antenna technology
- First look at Texas Instruments' C2000 series