keil+proteus
The second 51 program: Marquee and running lights
This is a AT89c51 microcontroller tutorial. We will provide blog tutorials and accompanying materials for download every time.
A single-chip microcomputer is a small CPU that is widely used in the electronics field. It can be found in products such as televisions, refrigerators, washing machines, and air conditioners. It is a programmable MCU that can achieve many functions according to different codes.
Today we will enter the second program, the marquee. We will follow the steps, first the hardware, then the software, and draw the schematic diagram first.
After setting up, start writing code
#include void delayms(unsigned int t) { unsigned int i,j; for(i=0; i } void main(void) //Main function { int n; unsigned char a[8] = { //Get table array 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; while(1) { for(n=0; n<8; n++) // loop to get the table water lamp { P1 = a[n]; delayms(500); } } } Write the Keil project and compile to generate a hex file Enter proteus simulation, burn the hex file, and click run... The simulation starts running the ticker. Keil engineering code and proteus simulation schematic package: http://download.csdn.net/download/mbs520/12118172 *Code interpretation 1, #include Include the header file 2, void delayms(unsigned int t)//delay function { int a,b; for(a=0; a } The delay function makes the CPU repeatedly execute an empty instruction to consume time. During this time, the CPU is still working and the values of each register remain unchanged. 3. void main(void) This is the main function, the program starts here In addition, the 51 single-chip microcomputer will also loop the contents of the main function without the while loop statement. 4. int n; unsigned char a[8] = { //Get table array 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; int n; //Here we define n as the count for the for loop unsigned char a[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; What is this array for? I'll convert it to binary and you'll understand. They are 0000 0001 0000 0010 0000 0100 0000 1000 0001 0000 0010 0000 0100 0000 1000 0000 You will find that there is a 1 moving to the left. We think of this 1 as a light that is on, and 0 as a light that is off. If it flows according to this rule, it will become a running light. 5. while(1) { for(n=0; n<8; n++) // loop to get the table water lamp { P1 = a[n]; delayms(500); } } while(1) is an infinite loop, which will execute the contents in it repeatedly for(n=0; n<8; n++) // loop to get the table water lamp {undefined P1 = a[n]; delayms(500); } This is the real code of the marquee. By using the for loop with n increasing by itself, the contents of the array can be output at once. P1: defined in the header file, it is a microcontroller IO port register, 8 bits, each bit stores the high or low level 0 or 1 of P1_0-P1_7 from low to high. Output a[0] a[1], a[2], a[3], a[4]... to port P1 in sequence to achieve a marquee effect Baidu network disk link: https://pan.baidu.com/s/18cVVHyE6O1AzvUvZMsApZA Extraction code: 22pi (If you have any questions, please leave a message. This is my first post. I hope you can give me some pointers if I have any questions.) (You can also send me a private message with questions. I will answer them patiently if you see them. I am happy to communicate with you about technical issues. Scope: circuit design, circuit simulation, PCB design, 51 microcontroller, msp430, arduino, stm32, luinx)
Previous article:51 MCU - asm and C mixed programming
Next article:51 MCU tutorial: 51 MCU drives four 8*8 dot matrix
- 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
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- What circuit can achieve this function?
- Embedded Development - sqlite3 cross compilation
- "Play Board" + Shared Bicycle Control Board-Hardware Modification 2
- Playing with Zynq Serial 12 - Using GIT for project backup and version management 4
- Several considerations in hardware circuit design
- Cause and effect follow-up part broadband power divider layout circuit appreciation
- Learn about PI’s latest products, comment, download and get gifts!
- WB-MQTT Debug Assistant
- Image storage and display system based on SDRAM——Study record
- I stayed up all night again, my friend's mood or my own health