按下按钮后如何return回到初始画面?

How to return back to the initial screen when button is pressed?

我在 LCD 中有三个屏幕连接到 8051 微控制器,当按下按钮时它们会滚动到不同的屏幕,但我想 return 再次按下按钮时返回到初始屏幕。我该怎么做,谢谢?

#include <stdio.h>
#include <string.h>
#include <stdint.h>

void change_screen(void);    
int count = 0;

void change_screen(void)
  { 
    if (modebutton == 1) {      // when button is pressed       
        if (count == 0) {                       
        count++;
        delay(100);
        display_screen1();      
        modebutton=0;            
        }
    else if (count == 1) {          
        count++;            
        delay(100);
        display_screen2();      
        modebutton=0;
    }
    else if (count == 2) {          
        display_screen3(); 
        count = 0;       
        } 
     } 
   }

您可以为此使用余数运算符 %

示例:

void change_screen(void) {
    static unsigned count = 0;

    if(modebutton) {
        delay(100);
        modebutton = 0;       

        switch(count) {
        case 0: display_screen1(); break; // first   fourth  ...
        case 1: display_screen2(); break; // second  fifth
        case 2: display_screen3(); break; // third   sixth
        }

        count = (count + 1) % 3;   // 0,1,2 then 0,1,2 etc...
    }
}