C language realizes button control of running water lamp 51 single chip microcomputer

Yuxian: CSDN content partner, CSDN rising star mentor, rising star creator in the full stack field, 51CTO (Top celebrity + expert blogger), github open source enthusiast (go-zero source code secondary development, game back-end architecture https: //github.com/Peakchen)

The implementation principle of button-controlled running water lamp:

  1. Initialization: Set the 8 LED interfaces to output mode and the two button interfaces to input mode.
  2. Main loop: In an infinite loop, the status of the key is continuously detected.
  3. Detect KEY1 button: If it is detected that the KEY1 button is pressed, it will stop after the water lamp flows once. At this time, set a flag bit key1_pressedto 1 and wait for the KEY1 button to be released.
  4. Detect the KEY2 button: If it is detected that the KEY2 button is pressed, the flag bit will be cleared key1_pressedto 0 and wait for the KEY2 button to be released.
  5. Control the flow of the water lamp: If key1_pressedthe flag is 1, it means that the water lamp should flow. Control the flow effect of the water lamp by changing the level status of the LED interface and the water lamp mode.
  6. Delay function: Use the delay function to control the speed of the running water lamp.

flow chart:

  +---------+
  |  初始化  |
  +----+-+--+
       | |
       | |
       v v
  +---------+
  | 主循环  |
  +----+-+-

Guess you like

Origin blog.csdn.net/feng1790291543/article/details/132708734