On a separate sheet, define, explain, discuss the purpose of each of the followi
ID: 3630177 • Letter: O
Question
On a separate sheet, define, explain, discuss the purpose of each of the following numbered lines. Be complete with your answer. Explain what the code does and its purpose.
1. #include <hidef.h>
#include "derivative.h"
2. void MSDelay(unsigned int);
void main(void) {
3. DDRB = 0xFF;
4. DDRJ = 0xFF;
5. PTJ=0x0;
for(;;)
{
6. PORTB = 0x55;
7. MSDelay(500);
8. PORTB = 0xAA;
MSDelay(500);
}
EnableInterrupts;
for(;;) {
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
9. void MSDelay(unsigned int itime)
{
10. unsigned int i; unsigned int j;
for(i=0;i<itime;i++)
for(j=0;j<3310;j++);
}
Explanation / Answer
1. #include <hidef.h>
This line is used to include the header file “hidef.h”. This header file contains Machine/compiler dependent declarations. Here it is used for EnableInterrupts macro.
2. void MSDelay(unsigned int);
This line is defining a function prototype. MSDelay is a function which returns nothing (void). It takes one argument of unsigned int type.
3. DDRB = 0xFF;
This line sets all Port B pins to output. By this line the outputs are given through Port B.
4. DDRJ = 0xFF;
This line sets Port J ddr to output.
5. PTJ=0x0;
This line sets Port J low to enable Port B pins. By enabling port B the output can be given through it.
6. PORTB = 0x55;
This line sends 0x55 to Port B data port. This will toggle all bits of port B.
7. MSDelay(500);
This line calls the function MSDelay with passing 500 as parameter. The functionality of the function is executed here.
8. PORTB = 0xAA;
This line sends 0xAA to Port B data port. This will toggle all bits of port B.
9. void MSDelay(unsigned int itime)
This line is the function header. The declaration of the function is given after specifying the function header. As in the prototype the function header contains the same details of return type and parameter details. “itime” is a variable which receives the value sent by the function call from main function.
10. unsigned int i; unsigned int j;
This line declares the local variables (local to the function here) I and j as unsigned int type. These variables are used with in the function.
The functionality of the program is, it makes Port B as an out put port and enables it. Then it will send data to the Port B and then waits for some time and then it sends some other data to Port B again, waits for some time.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.