Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THIS NEEDS TO BE IN C!!! YOU ARE NOT ALLOWED TO USE THE FUNCTION \"ITOA\"! THE V

ID: 3604106 • Letter: T

Question

THIS NEEDS TO BE IN C!!!

YOU ARE NOT ALLOWED TO USE THE FUNCTION "ITOA"!

THE VALUES INSIDE OF THE TABLE ARE NOT CORRECT, BUT IT SHOULD STILL WORK THE SAME. WE SIMPLY NEED TO MATCH UP WHATEVER VALUE IN THE TABLE THAT CORRESPONDS TO THE INPUT VALUES NUMBERS. SO IF WE GIVE THE FUNCTION 55, IT SHOULD RETURN WHATVER TABLE[5] IS TWICE. SO IN THIS CASE IT SHOULD RETURN "0x7F7F"

You need to develop an algorithm to convert the provided value to a

32-bit value that would display correctly on the seven segment display. You are required to only return

the necessary information without displaying leading zeros. For example, if value = 5, then the function would return the seven-segment conversion that would display 5 and not 05.

/* The function below takes two arguments: value which is the value in decimal

* to be displayed by the seven-segment displays and a character array that have the encoding

* to display the provided value in decimal on the seven-segment displays. The provided value

* can range from 0 - 999. The seven-segment displays must output the entire range correctly.

*/

unsigned char table[10] = { 0x3f, 0x06, 0x5b, 0x2F, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f}; -- these values map to a 7segment hex display. the values are 0,1,2,3,4,5,6,7,8,9. So when you give the function below a number, for example 11, you would just need to return "0x0606" which is two 1's in the above array.

TO DO:

*****************************************************************

int HEX3to0_display (int value, unsigned char * table)

{

   /* YOU NEED TO COMPLETE THIS CONVERSION FUNCTION. */

}

**********************************************************

Explanation / Answer

include<reg52.h>
sbit ledenable=P1^0;
void delay(void);

void main()
{
    P2 = 0x00;
    ledenable=0;
while(1)                  //indefinite loop
{
     ledenable=1;           // Enable pin for Common cathode display
   P2=0x3f;                          //Display digit 0
   delay();
   P2=0x06;                          //Display digit 1
   delay();
   P2=0x5b;                          //Display digit 2
   delay();
   P2=0x4f;                          //Display digit 3
   delay();
   P2=0x66;                          //Display digit 4
   delay();
   P2=0x6d;                          //Display digit 5
   delay();
   P2=0x7c;                          //Display digit 6
   delay();
   P2=0x07;                          //Display digit 7
   delay();
   P2=0x7f;                          //Display digit 8
   delay();
   P2=0x6f;                          //Display digit 9
   delay();
}
}
void delay(void)
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}

—————————————–

Instead of a long code you can also use Array as below

First initialize all the segment hex values of the digits in an array.

unsigned char digit[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};

Now take for loop and assign array values to the PORT2 with some time delay.

Here is the code using Array :

——————————————————-

#include<reg52.h>

sbit ledenable=P1^0;
void delay();
unsigned char digit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
unsigned int k;
void main()
{
    P2 = 0x00;
    ledenable=0;
    
while(1)                  //indefinite loop
   {
    ledenable=1;         // Enable pin for Common cathode display
     
       for(k=0;k<10;k++)
        {
           P2=digit[k];
           delay();
        }
   }
}

void delay()
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}