1

キーパッド 3*4 用の ScanKey 関数では、数字の長さが 4 未満になるまでうまく機能しますが、このように機能しますnumber = (number * 10)が、4 つ以上の数字を持つこの 123456 のような数字の場合、他の数字が表示されます。私のプログラムは、整数を使用する int で動作します。555555 のような数値を入力すると、31267 に変わります。 IDE CodeVisionAVR ATmega16a用のC言語

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;
}```
4

0 に答える 0