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
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking integers until the user enters -100. In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered. Sample Input/Output 1: Input the number: 0 2 3 -9 -6 -4 -100 Number of positive numbers: 2 Number of Negative numbers: 3 Number of Zero: 1
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are not allowed to use library functions for conversion. The output should look exactly as follows: DECIMAL      BINARY                     HEXDECIMAL                      BCD 0                      0000 0000                   00                                            0000 0000 0000 1                      0000 0001                   01                                            0000 0000 0001 2                      0000 0010                   02                                            0000 0000 0010 .                       .                                   .                                               . .                       .                                   .                                               . 255                  1111 1111                   FF                                            0010 0101 0101
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 the code of 4 digit 7-segment display using arduino uno in assembly language by using...
write the code of 4 digit 7-segment display using arduino uno in assembly language by using software AVR STUDIO 5.1?
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT