(a) You have been given the task of designing the input/output sub-system for a
ID: 2084052 • Letter: #
Question
(a) You have been given the task of designing the input/output sub-system for a PIC18 microcontroller. Draw a circuit diagram showing each of the following devices connected to a suitable Input/Output port of a PIC18. Detail the circuit for each interface, including typical values for any resistors used in your circuit.
(i) Two analog voltage signals (0 – 5V)
(ii) Four toggle switches (debounced)
(iii) One 7 segments LED display
(iv) One optically isolated 12 Volt relay
(b) Given that the mathematical formula for a Factorial calculation (written n!) is: n! = n * (n – 1) * (n – 2) * (n – 3) * … * 1 where n is a positive integer
(i) Write a C function called factorial, which:
accepts an integer value n in the range 0 to 10 calculates n! using a loop
and returns the result for the function as a suitably sized variable type. Note that 10! = 3628800 and 0! = 1
(ii) Briefly explain the lines of program which control the loop and determine how many times the loop runs.
(iii) Briefly explain the lines of program which calculate the factorial value and why you chose a particular return value type.
(c) Management of data transfer in a microcomputer system can be classified in three ways, one of which is 'Parallel/Serial Input/Output'.
Briefly describe the three (3) data transfer classifications which combine to form a management technique for data transfer between the microprocessor and any peripheral device.
Explanation / Answer
#include<stdio.h>
int main()
{
float i=1,fact=1,num;
printf("Enter a number: ");
scanf("%d",&num); // Takes input number from the user to calculate its factorial
while(i<=num) // By using while loop we will control the loop and factorial calculation
{
fact=fact*i;
i++;
}
printf("Factorial of %d is: %d",num,fact);
return 0;
}
Sample output:
Enter a number: 11
Factorial of 11 is: 39916800
Floating type datatype is used to get maximum range of values to get ability of calculating more numbers of factorial.
In Parallel Transmission technique a byte or word that is sent in parallel.As all the bits are transmitted parallel between the sender and receiver. Obviously whenever you transmit data in this manner it is very fast because of simultaneous transmission of data (or the bits are going simultaneously).
However, this is possible only over a short distance and this Parallel Transmission is commonly used for transmission of data between the CPU and the memory or between the CPU and other peripherals which are very close to the CPU.
In serial transmission a pair of wire is used for communication of data in bit serial form. Instead of sending in parallel, data are sending bit by bit. and this will also require parallel to serial conversion by the sender and also it will require serial to parallel conversion at the receiving end
it has many advantages and particularly it is very suitable for long distance communication. So serial mode of communication is possible over long distances.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.