Search Projects

Blogroll

Final year degree project for engineers DAC0800 based project circuit diagram and interfacing with pic mirocontroller Final year projects based on microcontrollers on programmable peripheral interface 8255
Microcontroller based different projects abstract and source code
PIC 16f877 microcontroller projects Motion control
PIC16f877 motor controller and other light projects
Tutorials of microcontroller PIC16f877, A step by step easy to use self learning rapidex

Tuesday, June 22, 2010

C-Language Algorithms For PIC Microcontrollers - post # 2

This is in continuation to my older post for algorithms of pic problems in c languages.

Problem Program # 7:
Write a program using a "while" statement to clear all ten elements of an integer array M.
Solution:
As shown in the program that follows, NUM is defined as 10 and variable j is used as the loop counter: The program is follows.
#define NUM 10
void main()
{
int M[NUM];
unsigned char j = 0;
while (j < NUM)
{
M[j] = 0;
j++;
}
}

Program Problem # 8:
Write a program in c-language for PIC microcontrollers to convert the temperature from C to F starting from 0C, in steps of 1C up to and including 100C, and store the results in an array called F.
Solution :
Given the temperature in C, the equivalent in F is calculated using the formula:
First of all we need the formula to convert the temperature in C to Temperature in F. And this formula is available in all thermodynamics or heat and temperature related books.
The conversion formula is as follows:
F = (C - 32)/1.8
The next step is to generate a loop:
A for loop is used to calculate the temperature in F and store in array F:
In this loop we will use above formula at every step (increment) and the result will be stored in an array of intergers.
The required program is as follows.

void main()
{
float F[100];
unsigned char C;
for(C = 0; C <= 100; C++)// as required the range is from 1 to 100 in the steps of 1 degree C.
{
F[C] = (C – 32.0) / 1.8;// conversion and storage in an array.
}
}

Now there are some work for you to do.
Exercises
1. Write a C program to set bits 0 and 7 of PORTC to logic 1.
2. Write a C program to count down continuously and send the count to PORTB.
3. Write a C program to multiply each element of a ten element array by 2.
4. Write a C program to add two matrices P and Q. Assume that the dimension of
each matrix is 3 X 3 and store the result in another matrix called W.
5. Repeat Exercise 4 but this time multiply matrices P and Q and store the product in matrix R.
6. What do the terms variable and constant mean?
7. What does program repetition mean? Describe the operation of while, do-while,and for loops in C.
8. What is an array? Write example statements to define the following arrays:
a) An array of ten integers
b) An array of thirty floats
c) A two-dimensional array having six rows and ten columns.
9. Write a program to calculate whether a number is odd or even.
10. Write a program to calculate the sum of all positive integer numbers from 1 to 100.
11. Write a program to evaluate factorial n, where 0! and 1! evaluate to 1 and n! = n X (n – 1)!
12. Write a program to calculate the average value of the numbers stored in an array. Assume that the array is called M and has twenty elements.
13. Modify the program to find the smallest and largest values of the array. Store the smallest value in a variable called Sml and the largest value in a variable called Lrg.

No comments:

Post a Comment

Hi: This is PICINF.blogspot.com comments section. Here you are requested to write your question or problems in detail. Write the question in such a way that, it have all necessary information, sothat i can understand and reply.If you want to send pictures and codes then e-mail me (rghkk@hotmail.com).Thanks.

Blog Archive