Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

((( Arduino C program ))) You are to build a simple system to convert Binary numbers read in on a bank of 4 switches (dip

((( Arduino C program )))

You are to build a simple system to convert Binary numbers read in on a bank of 4 switches (dip switch) to the corresponding Hex digit and display it on a 7-segment display.

You're to modify this program into a more compact version.

#include

#include

#define HEX_0 0x3F

#define HEX_1 0x06

#define HEX_2 0x5B

#define HEX_3 0x4F

#define HEX_4 0x66

#define HEX_5 0x6D

#define HEX_6 0xFD

#define HEX_7 0x07

#define HEX_8 0x7F

#define HEX_9 0x6F

#define HEX_A 0x77

#define HEX_B 0x7C

#define HEX_C 0x39

#define HEX_D 0x5E

#define HEX_E 0x79

#define HEX_F 0x71

uint8_t x;

int main(void)

{

//setup code goes here

DDRD = 0xFF;

DDRB = 0x00;

PORTB = 0xFF;

while (1)

{

x = PINB & 0x0F; //MASKING THE FIRST FOUR BITS OD PROTB TO 0 AND THE OTHER FOUR TO 1

if (x == 0)

{

PORTD = HEX_0;

}

else if (x == 1)

{

PORTD = HEX_1;

}

else if (x == 2)

{

PORTD = HEX_2;

}

else if (x == 3)

{

PORTD = HEX_3;

}

else if (x == 4)

{

PORTD = HEX_4;

}

else if (x == 5)

{

PORTD = HEX_5;

}

else if (x == 6)

{

PORTD = HEX_6;

}

else if (x == 7)

{

PORTD = HEX_7;

}

else if (x == 8)

{

PORTD = HEX_8;

}

else if (x == 9)

{

PORTD = HEX_9;

}

else if (x == 10)

{

PORTD = HEX_A;

}

else if (x == 11)

{

PORTD = HEX_B;

}

else if (x == 12)

{

PORTD = HEX_C;

}

else if (x == 13)

{

PORTD = HEX_D;

}

else if (x == 14)

{

PORTD = HEX_E;

}

else if (x == 15)

{

PORTD = HEX_F;

}

else

{

PORTD = HEX_0;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago