键盘功能返回错误的数字

问题描述

在用于键盘 3*4 的 ScanKey 功能中,它可以正常工作,直到数字长度低于 4 它的工作原理是这样的 number = (number * 10) 但是对于像 123456 这样的数字超过 4 个数字,它给了我其他数字我该怎么办?我的程序使用一个整数,我使用整数。 当我输入像 555555 这样的数字时,它会变为 31267。 IDE CodeVisionAVR C 语言用于 ATmega16a

struct User
{
    unsigned long int username;
    unsigned long int password;
    bool role;
};

unsigned long int username;
unsigned long int password;

 do
            {
                lcd_clear();
                lcd_putsf("Enter Username:");
                lcd_gotoxy(0,1);
                sprintf(show,"%d",username);
                lcd_puts(show);
                lcd_gotoxy(0,2);
                lcd_putsf("Enter Password:");
                lcd_gotoxy(0,3);
                password = ScanKey();
                if (!password)
                {
                    break;
                }
                else if (password / 10 < 10)
                {
                    PORTC .1 = 1;
                    lcd_clear();
                    lcd_putsf("At least 3 numbers !");
                    delay_ms(150);
                    PORTC .1 = 0;
                }
            } while (password / 10 < 10);

        if (username && password)
        {
            user[UL].role = false;
            lcd_clear();
            if (currentUser < 0 && !currentUser)
            {
                lcd_putsf("Promote to admin ? ");
                lcd_gotoxy(0,1);
                lcd_putsf("Yes press 1");
                lcd_gotoxy(0,2);
                lcd_putsf("No press 2");
                if (ScanKey() == 1)
                {
                    user[UL].role = true;
                }
                lcd_gotoxy(0,3);
            }
            user[UL].username = username;
            user[UL].password = password;
            UL++;
            PORTC .0 = 1;
            lcd_putsf("User added !!");
            delay_ms(150);
            PORTC .0 = 0;
        }
unsigned long int ScanKey(void)
{
    unsigned long int num = 0;
    _lcd_write_data(0x0F);
    PORTC .2 = 1;
    while (1)
    {
        PORTD .0 = 0;
        PORTD .1 = 1;
        PORTD .2 = 1;
        delay_ms(5);
        if (PIND .3 == 0)
        {
            while (PIND .3 == 0)
                ;
            lcd_putchar('1');
            num = (num * 10) + 1;
        }
        else if (PIND .4 == 0)
        {
            while (PIND .4 == 0)
                ;
            lcd_putchar('4');
            num = (num * 10) + 4;
        }
        else if (PIND .5 == 0)
        {
            while (PIND .5 == 0)
                ;
            lcd_putchar('7');
            num = (num * 10) + 7;
        }
        else if (PIND .6 == 0)
        {
            while (PIND .6 == 0)
                ;
            _lcd_write_data(0x10);
            lcd_putchar(' ');
            _lcd_write_data(0x10);
            num /= 10;
        }

        PORTD .0 = 1;
        PORTD .1 = 0;
        PORTD .2 = 1;
        delay_ms(5);
        if (PIND .3 == 0)
        {
            while (PIND .3 == 0)
                ;
            lcd_putchar('2');
            num = (num * 10) + 2;
        }
        else if (PIND .4 == 0)
        {
            while (PIND .4 == 0)
                ;
            lcd_putchar('5');
            num = (num * 10) + 5;
        }
        else if (PIND .5 == 0)
        {
            while (PIND .5 == 0)
                ;
            lcd_putchar('8');
            num = (num * 10) + 8;
        }
        else if (PIND .6 == 0)
        {
            while (PIND .6 == 0)
                ;
            lcd_putchar('0');
            num = (num * 10) + 0;
        }

        PORTD .0 = 1;
        PORTD .1 = 1;
        PORTD .2 = 0;
        delay_ms(5);
        if (PIND .3 == 0)
        {
            while (PIND .3 == 0)
                ;
            lcd_putchar('3');
            num = (num * 10) + 3;
        }
        else if (PIND .4 == 0)
        {
            while (PIND .4 == 0)
                ;
            lcd_putchar('6');
            num = (num * 10) + 6;
        }
        else if (PIND .5 == 0)
        {
            while (PIND .5 == 0)
                ;
            lcd_putchar('9');
            num = (num * 10) + 9;
        }
        else if (PIND .6 == 0)
        {
            while (PIND .6 == 0)
                ;
            break;
        }
    }
    PORTC .2 = 0;
    _lcd_write_data(0x0C);
    return num;
}```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...