Question

In: Computer Science

Write a Program using MPLAB IDE and XC8 compiler to do the followings: 1. When the...

Write a Program using MPLAB IDE and XC8 compiler to do the followings:
1. When the Program Starts it should send your Name and ID# to the Serial Port
2. Display the result on Tera Term.
3. Read PORTB buttons in an infinite loop (Main Loop which is the Read Buttons Loop), your program should not block when reading the Buttons except in De-bouncing..
But you need to de-bounce each button when pressed
3.1 If the user presses PORTB, RB0 button, write Button 0 and
Toggle ALL PORTD buttons.
3.2 If the user presses PORTB, RB1 button, write Button 1 and Toggle RD1
3.3 If the user presses PORTB, RB2 button, write Button 2 and Toggle RD2
3.4 If the user presses PORTB, RB3 button, write Button 3 and Enter a Read serial loop.
Display the bits of the Character that the user Enters on PORTD and store in a buffer.
If the Number reaches 15 characters or the user enters '*', then exit the read serial port loop and Display all characters (string) entered on Ter Term.
Make sure you null terminate the string. But you will be still in the Main Loop which is the read button Loop
3.5 If the user presses PORTB, RB4 button, terminate the Main Loop which is the read button loop then print 'Exit' on the Tera term and go to infinite loop doing nothing which is just while (true) CLRWDT(); written after the main reading loop.


Pic18f4620
Assembly &c
Code

Solutions

Expert Solution

Ans)

#include <stdio.h>

//Implementing stack using array
//Basic operations - push and pop
int main()
{
int n, choice, stack[100], newelement, popelement, top, i;
choice = 0;
top = 0;
//Getting the stack size
printf("Enter the stack size\n");
scanf("%d", &n);
  
while(choice != 4) {
//Get the choice of operation in command line
printf("\n\n1.Push 2.Pop 3.Display 4.Exit\nEnter your choice");
scanf("%d", &choice);
  
switch(choice) {
case 1:
//Push a new element if the stack isnt full
if(top == n) {
printf("\n\nStack size is full");
}
else {
printf("\n\nEnter the element to push into the stack");
scanf("%d", &newelement);
stack[top] = newelement;
top++;
}
break;
case 2:
//Pop out the last element
if(top == 0) {
printf("\n\nStack is empty");
}
else {
top--;
popelement = stack[top];
printf("\n\nPopped Element: %d", popelement);
}
break;
case 3:
//Display the contents of the stack
printf("\n\nDisplaying Stack elements in reverse order of insertion: ");
for(i = top-1; i >= 0; i--) {
printf(" %d ", stack[i]);
}
break;
case 4:
//Exit
break;
default:
//Invalid choice
printf("\n\nEnter a valid choice");
}
  
  
}
return 0;
}

Logic explanation:

Stack is a data structure that follows LIFO(Last In First Out). In this program, stack has been implemented for integers using array in C. The basic operations of stack are push and pop. Push operation involves inserting new element into the stack while pop involves removing the last inserted element from the stack. Additionally, there is an option to display the contents of the stack in the reverse order.

--------------------------**********"""""***********------------------------

if your satisfy above answer please give positive rating or?

if any doubts below comment here

please don't downvote.only upvote or comment

Thank you!


Related Solutions

Control DC Using PIC18f46k20 and MPLAB IDE v8.8, write a program that can 1. Start and...
Control DC Using PIC18f46k20 and MPLAB IDE v8.8, write a program that can 1. Start and Stop the motor 2.Vary The motor Speed 3.Change the direction of the motor rotation 4.Display motor speed in OLED screen using c of MPLAB IDE v8.8 please test the code before posting
To develop a program for the PIC 16F84A using either MPLAB X IDE simulator software. T...
To develop a program for the PIC 16F84A using either MPLAB X IDE simulator software. T he PIC 16F84A has 8 LEDs connected to Port B. The program is to convert your student number (10 ASCII characters), taken in reverse order, one character at a time, to Gray code. Each converted character is to be displayed on 4 of the LEDs connected to Port B (B0 to B3) of the microcontroller. Further, each converted character will be displayed for 3...
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality:...
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality: Configures pin RA2 of the PIC24to be an output to control an attached LED. Configures pin RB13 of the PIC24 to be an input to read the value on an attached switch (this switch will connect to ground when pressed). Configures pin RB13 to use the internal pull-up resistor. After configuration, the LED will be "off" when the push-button is pressed, and "on" when...
Write this program using an IDE. Comment and style the code according to the CS 200...
Write this program using an IDE. Comment and style the code according to the CS 200 Style Guide. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. Monster collector is a game of chance, where the user tries to collect monsters by guessing the correct numbers between 1 and 5. If the user doesn't guess the incorrect number, you catch...
#use MPLAB X IDE # Question 1 for HW 3 # Your solution should implement the...
#use MPLAB X IDE # Question 1 for HW 3 # Your solution should implement the following conditional statement: # if (A < 10) # D = C + 10 # else if (A == 20) # D = C - B # else # D = C + B .global main .data ### THESE VARIABLES ARE SIMPLY GIVEN VALUES TO START ### WITH--CHANGE THEIR VALUES AND VERIFY YOUR PROGRAM ### WORKS APPROPRIATELY IN ALL CASES A: .int 3 B:...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3 Lottery. You will need to include the provided code given below in your program. Task:The program will prompt for a number between 0 and 999. Your program will display the number of attempts it took for the entered number to match a randomly generated number. In the main() method, declare an int named myPick3choice. Create a prompt for myPick3choice as "Enter your Pick 3...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
What does the following statement tell a C compiler to do, and when does it do...
What does the following statement tell a C compiler to do, and when does it do it? #define UCHAR unsigned char
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT