Embedded Programming Lab II
Embedded Programming Lab II
AIM:
ALGORITHM:
i. Set approx.=better
ii. Better=0.5*(approx.+n/approx.)
PROGRAM:
Def newtonsqrt(n):
approx.=0.5*n
better=0.5*(approx.+n/approx)
While better!=approx:
approx=better
better=0.5*(approx.+n/approx.)
Return approx
Print(newtonsqrt(100))
OUTPUT:
RESULT: Thus, the Python program for finding the square root of a given number
by Newton’s Method is executed successfully and the output is verified.
EX:2 TO FIND THE FIRST N PRIME NUMBERS DATE:
AIM:
ALGORITHM:
print it.
PROGRAM:
# Driver code
N = 100;
#check for every number from 1 to N
for i in range(1,N+1):
#check if current number is prime
if(isPrime(i)):
print(i,end=" ")
OUTPUT:
RESULT: Thus the Python Program to find the first n prime numbers is executed
successfully and the output is verified.
EX :3 LINUX PROGRAMMING TOOL – UBUNTU DATE:
AIM:
Write an Ubuntu C program to print the strings.
SOFTWAREREQUIRED:
THEORY:
Ubuntu uses Linux desktop environments for its interface. Ubuntu is an open-
source operating system (OS) based on the Debian GNU/Linux distribution.
Ubuntu incorporates all the features of a Unix OS with an added customizable
GUI, which makes it popular in universities and research organizations. Ubuntu is
primarily designed to be used on personal computers, although a server edition
does also exist.
Ubuntu consists of many software packages, which are licensed under GNU
General Public License. This allows users to copy, change, develop and
redistribute their own version of the program. Ubuntu comes with a wide range of
software programs, including Firefox and LibreOffice. There is also proprietary
software that can be run on Ubuntu. Ubuntu consists of many software packages,
which are licensed under GNU General Public License. This allows users to copy,
change, develop and redistribute their own version of the program. Ubuntu comes
with a wide range of software programs, including Firefox and LibreOffice. There
is also proprietary software that can be run on Ubuntu.
PROCEDURE:
• C file is created in the path and double click on the program editor.
• Compile the output by using command gcc. -o and give name to output
file.
PROGRAM:
#include <stdio.h>
int main()
printf(“Hello world\n”);
return 0;
}
OUTPUT:
Hello World
AIM:
Write an Ubuntu C program to find the sum of numbers.
SOFTWAREREQUIRED:
THEORY:
PROCEDURE:
• C file is created in the path and double click on the program editor.
• Compile the output by using command gcc. -o and give name to output
file.
#include<stdio.h>
int main()
scanf(“%d%d”,&n1,&n2);
sum=n1+n2;
return 0;
}
OUTPUT:
successfully.
DATE:
EX:5 PROGRAMMING AND SIMULATION IN GUI SIMULATORS-
MATLAB
AIM:
SOFTWARE REQUIRED:
MATLAB R2007b
THEORY:
Starting MATLAB:
Graphical user interface, is a form of user interface that allows users to interact
with electronic devices through graphical icons and audio indicator such as
primary notation, instead of text-based UIs, typed command labels or text
navigation. GUIs were introduced in reaction to the perceived steep learning
curve of CLIs (command-line interfaces) which require commands to be typed
on a computer keyboard.
PROCEDURE:
• Open MATLAB R2007b
Project
program
PROGRAM:
gui_Singleton = 1;
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
else
gui_mainfcn(gui_State, varargin{:});
end
handles.output = hObject;
guidata(hObject, handles);
varargout{1} = handles.output;
set(hObject,'BackgroundColor','white');
end
function textbox3_Callback(hObject, eventdata, handles)
set(hObject,'BackgroundColor','white');
end
a1=str2num(get(handles.textbox1,'string'))+str2num(get(handles.textbox2,'string'))
set(handles.textbox3,'string',a1)
OUTPUT:
RESULT: Thus a program for GUI Simulation using MATLAB was executed
successfully.
DATE:
EX:6 PROGRAMMING & SIMULATION IN PYTHON SIMULATOR
AIM:
To write a python program to find sum of arrays using PyCharm IDE.
SOFTWARE REQUIRED:
THEORY:
PROCEDURE:
• Declare a variable to store the sum and Calculate the length of the array
• Add each element to the variable for sum one by one and Return sum
• Declare the array and Call function and execute the result
PROGRAM:
import array as ar
def SumofArray(arr):
sum=0
n=len(arr)
for i in range(n):
sum=sum+arr[i]
return sum
a=ar.array(‘i’,[10,21,12,13])
#displaysum
successfully.
EX:7 STUDY ON MATLAB SIMULATION TOOLS DATE:
AIM:
INTRODUCTION TO MATLAB:
THEORY:
MATLAB is an interactive system whose basic data element is an array that does
not require dimensioning. This allows you to solve many technical computing
problems, especially those with matrix and vector formulations, in a fraction of the
time it would take to write a program in a scalar non-interactive language such as
C or FORTRAN.
Typical uses include:
• Math and computation
• Algorithm development
• Modeling, simulation, and prototyping
• Data analysis, exploration, and visualization
• Scientific and engineering graphics
• Application development, including graphical user interface building
MATLAB BASICS
MATLAB is started by clicking the mouse on the appropriate icon and is ended by
typing exit or by using the menu option. After each MATLAB command, the
"return" or "enter" key must be depressed.
Starting MATLAB:
You can customize the arrangement of tools and documents to suit your needs.
Now, we are interested in doing some simple calculations. We will assume that
you have sufficient understanding of your computer under which MATLAB is
being run. You are now faced with the MATLAB desktop on your computer,
which contains the prompt (>>) in the Command Window. Usually, there are 2
types of prompts: >> for full version EDU> for educational version.
Quitting MATLAB:
To end your MATLAB session, type quit in the Command Window, or select File
Exit MATLAB in the desktop main menu.
AIM:
To write MATLAB programs for auto correlation and cross correlation.
APPARATUS REQUIRED:
HARDWARE: COMPUTER
SOFTWARE: MATLAB
PROCEDURE:
1. Start the MATLAB program.
6. If any error occurs in the program correct the error and run it again
clc; clear
all;close
all;
clc;
close all;
clear all;
stem(fliplr(y));
ylabel('amplitude');
xlabel('n->');
title('Outputsequence')
fliplr(y);
OUTPUT: (Auto Correlation Function)
RESULT: Thus, the MATLAB programs for auto correlation and cross correlation
written and the results were plotted.
EX:9 LED BLINKING PROGRAM USING EMBEDDED C DATE:
AIM:
To write program for 8051 micro controller for blinking an LED using
keil software and implement it using MCBx51.
SOFTWARE REQUIRED:
Keil micro vision version3 IDE.
HARDWARE REQUIRED:
8051programmer
MCBx51developmentboard
Serial cable (RS232C)
PROCEDURE:
File New.
Debug Run.
PROGRAM:
#include<reg51.h>
Void Delay();
void main()
{
P1=0x55;
delay ();
P1=0xAA;
Delay();
}
Void Delay()
{
TMOD=0X01;
TL0=0X00;
TH0=0X35;
TR0=1;
while(TF0== 0); TR0=0; TF0=0;
}
RESULT: Thus, embedded C program for blinking an LED using 8051
microcontroller is written and the output was successfully executed.
EX:10 STUDY ON PROTEUS SIMULATION TOOLS DATE:
AIM:
With the use of this engineering software, you can construct and simulate
laptops.
them practically.
practical circuit.
Circuit simulations provide the main feature that some components of
circuits are not practical then you can construct your circuit on proteus.
component in proteus.
The electronic tools that are very expensive can easily get in proteus such as
an oscilloscope.
Using proteus you can find different parents of circuits such as current, a
voltage value of any component and resistance at any instant which is very
First of all, click on proteus Icon in your computer and click on a new file option
Step 2:
After that, you will see the drawing sheet. Save it according to your project
Step 3:
After a move to the component option and select the elements for your
projects.
Step 4:
After clicking on components mode, you will see two buttons P and L. If
you move to P button you will see Pic from Libraries
Step 5:
When you will click on the P button you will see box. Type your component
for a circuit.
As I type button and you can see a button in right figure that different
buttons are shown you can select according to your use.
Step 6:
When you will select components for your project you will see them in a
box.
I have also selected some components for designing of a simple circuit.
Step 7:
When you connect all components in the circuit like run button in left bottom
Step 8:
When you will observe the simulation of your circuit than click on stop button
on the left bottom to stop the working of the circuit.
AIM:
Introduction to OrCAD
After selecting the new project option, dialog box obtained on the screen,
We can give the name of our project like here in the picture name of the
to the need.
Then select the location for the project where it is to be stored. We can select
This is the screen where we can create our circuit & can run our circuit.
On just above the blank screen of the software, we have different options
like different types of markers, voltage and current probes, run pspice, edit
Likewise, on the right side of the screen also we have different options.
We can select the different types of components by selecting: Place -> Part.
feature.
So in order to view all the components, first select all library function.
We can also select the components from the icons given on the right side of
the screen.
click (on the component) ->Rotate. So we can create our circuit asper our
requirement.
After selecting the components, we can connect all the components by wire
The option of wire can be available by: Place -> Wire. Or it is also available
Here, we can select the simulation and analysis type is selected as ‘DC
Sweep’.
Also we can select the sweep variable, sweep type, start value, end value &
When we run our circuit, we can see the graph This phenomenon of running