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

write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199 Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199   Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
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
Overview: You will write a program that reads up to 100 numbers from a file. As...
Overview: You will write a program that reads up to 100 numbers from a file. As you read the numbers, insert them into an array in ascending order. Specifics: 1A. Write a function called insertIntoSortedArray . i. It should take three arguments - a. myArray[ ] : sorted array that should be able to hold at most 100 integers. b. numEntries : the number of elements inserted so far. c. newValue : the incoming value to be inserted into the...
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?
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 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 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
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT