Embedded C Program to add array of n numbers using PIC18F MCU in MPLAB IDE

We are using MPLAB IDE to Run this Program and Using PIC18F Microcontroller.

Program for n = 10:

 
#include <xc.h>
void main(void) 
{
    int arr[10] = {1,2,3,4,5,6,7,8,9,10};
    int sum = 0;
    int i = 0;
    int *p;  
    for(i=0;i<10;i++)
    {
        sum = sum + arr[i];
    }    
    p = &i;
    p = &sum;
 return;
}

Output:

Watch for n = 10:

Watch for n = 10



File Register for n=10:
File Register for n=10



BSR for n=10:
BSR for n=10


Program for n = 100:

 
#include <xc.h>
void main(void) 
{
    int arr[10] = {1,2,3,4,5,6,7,8,9,10};
    int sum = 0;
    int i = 0;
    int *p;
    for(i=0;i<10;i++)
    {
        sum = sum + arr[i];
    }
    p = &i;
    p = &sum;

    int arr2[100];// 200 byte
    sum = 0;
    for(i=0;i<100;i++)
    {
        arr2[i] = i+1;
    }
    for(i = 0; i < 100 ; i++)
    {
        sum = sum + arr2[i];
    }    
    return;
}


Output:

Watch for n = 100:
    
Watch for n = 100

File Register for n=100:
File Register for n=100



BSR for n=100:
BSR for n=100


Previous
Next Post »