Write a program (ATMega128) that reads two different positive numbers from two D
ID: 3688502 • Letter: W
Question
Write a program (ATMega128) that reads two different positive numbers from two DIP Switches (8-bits each) on UNI-DS6 board. The program should also read another input of two control or mode bits (2 of the switches on another DIP-switch pack) to control the processing that will be done on the two numbers. The program will first read all control and I/O values and save them to registers, and then display some data processing results on the UNI-DS6 LCD display:
Actual processing of each mode should be implemented within a subroutine, i.e. once the inputs are read from the pins, one of the four subroutines should be called, depending on the control value. Each subroutine should determine the string(s) that will be printed to the LCD string, and call another LCD subroutine to output the result on LCD. After the subroutine is done, the code should go back to the main portion and read the input pins again (in an infinite loop). Remember to initialize the stack pointer at the beginning of your code for correct operation. The program should work seamlessly on UNI-DS6 development board i.e. when input data and/or control bits are changed through the switches on the board, the corresponding processing result should be “immediately” displayed on the LCD.
Mode Control Processing Result on LCD Display 0 First number appended with an odd parity bit – displayed result should be binary 1 First number appended with an even parity bit – displayed result should be binary 2 The larger of the two input numbers in Hexadecimal on the LCD Screen - if numbers are equal output should display “EQ” instead on the LCD display 3 The difference of the two input numbers on the LCD screen in hexadecimal and in binary at the same time. Use positive logic; that means make sure you are subtracting smaller number from the bigger number and providing the magnitude of the difference. Inputs from DIP switches should be interchangeable i.e. the result should display the same regardless of which of the DIP switch inputs is subtracted from the other.Explanation / Answer
//#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
// #include <conio.h>
int main()
{
int dip1, dip2;
scanf("%d", dip1);
scanf("%d", dip2);
int modeBit1, modeBit2;
scanf("%d", modeBit1);
scanf("%d", modeBit2);
int reg1, reg2, reg3, reg4;
reg1 = dip1;
reg2 = dip2;
reg3 = modeBit1;
reg4 = modeBit2;
printf("%d", reg1);
printf("%d", reg2);
printf("%d", reg3);
printf("%d", reg4);
return 0; // exit
} // end of main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.