Question

In: Electrical Engineering

Write a program to display (on 7-segment) continuous up-counting numbers from 00 to 99 (in decimal...

Write a program to display (on 7-segment) continuous up-counting numbers from 00 to 99 (in decimal system) when switch SW2 is pressed and released, and down-counting when switch SW3 is pressed and released.

PLEASE CODE IN C.

PROVIDE ALGORITHM ALSO.

Solutions

Expert Solution

ALGORITHM--

For common cathode 7-seg led Hex code corresponding to digits {0,1,2,3,4,5,6,7,8,9}
will be{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82, 0xF8,0x80,0x90}

Step 1: Start
Step 2: Declare variables SW2,SW3,LED1,LED2,i,j
Step 3: Initialize hex code array LED_CODE[] 
Step 4: Define a delay function delay() to generate 200ms delay

Step 5: Read SW1 & SW2 from user.
Step 6: If SW2=1
        i=0;
      Repeat the steps until i<10
        j=0;
      6.1 Repeat the steps until j<10 
            LED2 = LED_CODE[j]
            call delay() function
            j=j+1
      6.2 LED1 = LED_CODE[j]
      6.3 i=i+1     
Step 7: If SW3=1
        i=9 
       Repeat the steps until i>=0
        J=9;
      7.1 Repeat the steps until j>=0 
            LED2 = LED_CODE[j]
            call delay() function
            j=j-1
      7.2 LED1 = LED_CODE[j]
      7.3 i=i-1  
Step 8: Stop 

C CODE--(For 8051 microcontroller)

#include <reg51.h> 
#define LED1 P2 //PORT2.0 is connected to segment '1'
#define LED2 P1 //PORT1.0 is connected to segment '2'

void msdelay()  // Function for creating delay of 200 milliseconds.
{
    unsigned i;    
    for(i=0;i<25000;i++);
}

void main()
{
unsigned char i,j;
unsigned int sw2,sw3;
unsigned char seg_code[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82, 0xF8,0x80,0x90};

if(sw2==1)
{
        for(i=0;i<10;i++)
        {
                LED1=seg_code[i];
                for(j=0;j<10;j++)
                {
                        LED2=seg_code[j];
                        msdelay();
                }
        }
}
        
if(sw3==1)
{
        for(i=9;i>=0;i--)
        {
                LED1=seg_code[i];
                for(j=9;j>=0;j--)
                {
                        LED2=seg_code[j];
                        msdelay();
                }
        }
}
                
}

Related Solutions

In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers...
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
A system is needed to control a 7 segment display. The input is all of the...
A system is needed to control a 7 segment display. The input is all of the possible binary codes 0000 to 1111. The output will be a 7 segment display of the hexadecimal digits 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f. How many K-maps are needed to solve this problem?
Write a program that checks if all the input numbers cover 1 to 99. Each ticket...
Write a program that checks if all the input numbers cover 1 to 99. Each ticket for the Pick-10 lotto has 10 unique numbers ranging from 1 to 99. Suppose you buy a lot of tickets and like to have them cover all numbers from 1 to 99. Write a program that reads the ticket numbers from a file and checks whether all numbers are covered. Assume the last ending number in the file is 0. Suppose the file contains...
Write a program to convert the input numbers to another number system. 1. Decimal to Binary...
Write a program to convert the input numbers to another number system. 1. Decimal to Binary 2. Binary to Decimal 3. Hexadecimal to Decimal 4. Decimal to Hexadecimal 5. Binary to Hexadecimal 6. Hexadecimal to Binary The user will type in the input number as following: Binary number : up to 8 bits Hexadecimal number: up to 2 bytes Decimal number: Less than 256 As a result, print out the output after the conversion with their input numbers. The program...
The program will enquiry from the user a name and four decimal numbers: m, a, b...
The program will enquiry from the user a name and four decimal numbers: m, a, b and h. With this information, the program will evaluate moments of inertia (a physical property) for various 3D objects and print them. Use the Scanner class to accept input from the user. Prompt the user for her/his name (i.e. “Ferdinand”). Using her/his name, prompt the user for a value for mass in pounds and save it in a variable (m). Prompt the user for...
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and...
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and results for a 4-bit adder. The inputs are unsigned 4-bit binary numbers. The outcome is a 4-bit binary adder with LED display. First you need to create a symbol for the HEX-to-seven segment display converter. Then implement a 4-bit adder using VHDL. Finally, connect three HEX-to-seven segment display converters to display input X, input Y, and sum S.
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> c++ project. need help.
Write a program that takes a set of m numbers up to size n and save...
Write a program that takes a set of m numbers up to size n and save them in an array. The program then allows you to search for any number in the array with O(1).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT