mardi 26 janvier 2021

How can I turn this If else function to a loop one

How can I turn this If else function to a loop one. I tried using arrays to store the possible input and output then tried suing a for function but it has failed in vain so I would really appreciate it if someone would solve it for me.

void displayoutput (volatile uint8_t input) { volatile uint8_t output;

if(input == 0x00)
{
    output = 0x3F;        //to print character 0 
}
else if (input == 0x01)
{
    output = 0x06;        //to print character 1
}
else if (input == 0x02)
{
    output = 0x5B;         //to print character 2
}


else if (input == 0x03)
{
    output = 0x4F;          //to print character 3
}
else if (input == 0x04)
{
    output = 0x66;          //to print character 4
}
else if (input == 0x05)
{
    output = 0x6D;          //to print character 5
}
else if (input == 0x06)
{
    output = 0x7D;          //to print character 6
}
else if (input == 0x07)
{
    output = 0x07;           //to print character 7
}
else if (input == 0x08)
{
    output = 0x7F;           //to print character 8
}
else if (input == 0x09)
{
    output = 0x6F;           //to print character 9
}
else if (input == 0x0A)
{
    output = 0x77;            //to print character A
}
else if (input == 0x0B)
{
    output = 0x7C;             //to print character b
}
else if (input == 0x0C)
{
    output = 0x39;             //to print character C
}
else if (input == 0x0D)
{
    output = 0x5E;              //to print character d
}
else if (input == 0x0E)
{
    output = 0x79;               //to print character E 
}
else if (input == 0x0F)
{
    output = 0x71;                 //to print character F
}
else 
{
    output = 0x4C;                //to print character error
}

PORTB = output;
Delay100msUsingTimer0();

}

Aucun commentaire:

Enregistrer un commentaire