Embedded Manual PDF
Embedded Manual PDF
Embedded Manual PDF
Name:
Register number:
Subject code&name: EE3017 EMMBEDDED C PROGRAMMING
Department:EEE
BONAFIDE CERTIFICATE
Certified that this practical work entitled EE3017 Embedded C programming is the Bonafede record of
work done byMr/Ms............................................................................. of V Semester in Department of
Electrical and Electronics Engineering of the College during the year July 2023 – Dec 2023
Submitted for the Anna University B.E. (EEE) Degree Practical Examination held at DR G U Pope College of
Engineering on................................
SYLLABUS
OBJECTIVES:
• To expose the students to the fundamentals of embedded Programming
• To Introduce the GNU C Programming Tool Chain.
• To study the basic concepts of embedded C.
• To teach the basics of 8051 Programming
• To involve Discussions/ Practice/Exercise in revising & familiarizing the
concepts acquired over the
• Units of the subject for improved employability skills.
1. Introduction to IDE (like code blocks, vscode ,etc)and Programming
Environment (like Keil uvision, Proteus)
2. Configuring an I/O port using bitwise programming.
3. Configuring timer for generating hardware delay.
4. Flashing an LED using an interrupt
5. Serial communication using UART port of 8051
6. Interfacing an ADC with 8051
7. Interfacing an analog sensor with 8051
8. Interfacing 16x2 LCD with 8051
9. Configuring timer for generating PWM signal
10. Interfacing a stepper motor with 8051
11. Assignment: Introduction to Arduino IDE, Raspberry Pi
TOTAL: 45 PERIODS
OUTCOMES:
At the end of the course, the student should have the :
CO1: Deliver insight into embedded C programming and its salient features for embedded systems.
CO2: Illustrate the software and hardware architecture for distributed computing in embedded systems
CO3: Develop a solution for problems by using the concept learned in programming using the embedded
controllers
CO4: Develop simple applications with 8051 by using its various features and interfacing with various external
hardware. CO5: Improved Employability and entrepreneurship capacity due to knowledge upgradation on recent
trends in embedded programming skills.
LIST OF EXPERIMENTS
CYCLE – I
CYCLE – II
TOTAL: 45 PERIODS
INDEX
Keil development tools for the 8051 microcontroller family support every level of developer from the professional
applications engineer to the student just learning about embedded software development. The industry-standard Keil
C Compilers, Macro Assemblers, Debuggers, Real-time Kernels, and Single-board Computers support ALL 8051-
compatible derivatives and help you get your projects completed on schedule.
The following table shows the Keil C51 Product Line (across the top) and the Components that are included (along
the left side). You may use this informationto find the development tool kit that best fits your needs.
Introduction
The C51 development tool chains are designed for the professional software developer, but any level of programmer
can use them to get the most out of the 8051 microcontroller architecture.
With the C51 tools, embedded applications can be generated for virtually every 8051 variant. Refer to the µVision
Device Database for a list of currently supported microcontrollers.
Software Development Cycle that describes the steps and tools involved tocreate a project.
Development Tools that describes the major features of the Keil C51development tools including the µVision
IDE and Debugger.
Folder Structure that describes the default location of µVision and the C51 tool chain installation
Development Tools
The Keil C51 development tools offer numerous features and advantages that help you to develop embedded
applications quickly and successfully. Find out more about the supported devices and the possible tool combinations
available for the different 8051 variants.
The following block diagram shows the components involved in the build process.
The µVision IDE is a window-based software development tool that combines project management and a rich-featured
editor with interactive error correction, option setup, make facility, and on-line help. Use µVision to create
source files andorganize them into a project that defines your target application.
C Compiler µVision Integrated Development Environment (IDE)
The Keil Cx51 Compiler is a full ANSI implementation of the C programming language and supports all standard
features of the C language. In addition, numerous extensions have been included to directly support the 8051 and
extended8051 architecture.
Macro Assembler
The Keil Ax51 Macro Assembler supports the complete instruction set of the 8051 and all 8051 derivatives.
Library Manager
The LIBx51 Library Manager allows you to create the object library from object files created by the compiler and
assembler. Libraries are specially formatted, ordered program collections of object modules that may be used by
the linker at a later time. When the linker processes a library, only those object modules necessary to create the
program are used.
Linker/Locater
The Lx51 Linker/Locater creates the final executable 8051 program and combines the object files created by the
compiler or assembler, resolves external and public references, and assigns absolute addresses. In addition, it
selects and includes the appropriate run-time library modules.
µVision Debugger
The µVision Debugger is ideally suited for fast and reliable program debugging. The debugger includes a high-speed
simulator capable of simulating an entire 8051system including on-chip peripherals and external hardware.
The µVision Debugger provides several ways to test programs on target hardware:
Use the Keil ULINK USB-JTAG adapter for downloading and testingyour program.
▪ Install a target monitor on your target system and download
your program using the built-in monitor interface of the µVision
Debugger.
▪ Use the Advanced GDI interface to attach and use the
µVision Debugger front end with your target system.
RTOS Kernel
The RTOS Kernel, describes the advantages of using a real-time kernel like the Keil RTX51 Tiny in embedded
systems.
Start Debugging
Execute Commands
Run the program to the next break point, or type GO in the Command Line.
▪ Halt the program, or press Esc while in the Command Line
Click Reset from the Debug Toolbar or from the Debug — Reset CPUMenu or type
RESET in the Command Line to reset the CPU.
Single-Stepping Commands
To step through the program and into function calls. Alternatively, you canenter TSTEP in the Command
Line, or press F11.
To step over the program and over function calls. Alternatively, you canenter PSTEP in the Command
Line, or press F10.
To step out of the current function. Alternatively, you can enter OSTEP in the
Command Line, or press Ctrl+F11.
On-Chip Peripherals
There are a number of techniques you must know to create programs that can use the various on-chip peripherals
and features of the 8051 family. Use the code examples provided here to get started working with the 8051.
There is no single standard set of on-chip peripherals for the 8051 family. Instead, 8051 chip vendors use a wide
variety of on-chip peripherals to distinguish their parts from each other. The code examples demonstrate how to
use the peripherals of a particular chip or family. Be aware that there are more configuration options available
than are presented in this text.
Follow the links to the on-chip peripherals:
Header Files - use the include files to define peripheral registers of thedevice in use.
RESULT
Thus the introduction of keil uvision and proteus simulation tool was learned.
Experiment-2 CONFIGURING AN I/O PORT USING BITWISE PROGRAMMING – Toggling of LED
Date:
Aim:
To Write a C program for toggle all the bits of P1 continuously.
Software required:-
Keil u vision,,Proteous simulation tool.
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
void main ()
{
P1=0x00; //initialize port 1
P2=0x00; //initialize port 2
while(1)
{
if((switch1==1)&&(switch2==0)) //switch 1 active
{
led1=1; //LED 1 is active
led2=0;
}
if((switch1==0)&&(switch2==1)) //switch 2 active
{
led1=0;
led2=1; //LED 2 is active
}
if((switch1==0)&&(switch2==0)) //ALL switch are off
{
led1=0;
led2=0; //ALL light s are OFF
}
}
}
For using keil uvision tool
Thus the c program for toggle all bits in P1 was executed successfully.
Ex no:3. CONFIGURING TIMER FOR GENERATING HARDWARE DELAY
AIM:
To write an execute the program of timer for generating hardware delay.
Software required:-
Keil uvision and proteous simulation tool.
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
#include<reg51.h>
sbit wave=P1^0;
void delay();
void main()
wave=0;
while(1)
wave=1;
delay();
wave=0;
delay();
}
}
void delay()
unsigned char i;
TMOD=0x10;
for(i=0;i<14;i++)
TH1=0x00;
TL1=0x00;
TR1=1;
while(TF1==0);
TF1=0;
}
For using keil uvision software
Thus the c program for configuring timer for hardware delay was written and executed.
Ex no:4. FLASHING AN LED USING AN INTERRUPT
AIM:
Software required:-
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
#include <reg51.h>
sbit led = P1^0; // LED connected to 1st pin o f port P1
void Timer(void) interrupt 1 // Interrupt No.1 for Timer 0
{ led=~led; // Toggle LED on interrupt
}
main()
{
TMOD = 0x01; // Mode1 of Timer0
TH0=0x00; // Initial values loaded to Timer
TL0=0x00;
IE = 0xff; // Enable interrupt
TR0=1; // Start Timer
while(1); // Do nothing
}
Using keil uvision software
AIM:
To write and execute the program of serial communication using UART port of 8051.
Software required:-
Keil uvision and proteous simulation tool.
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
#include<reg51.h>
void main()
{
SCON=0x50;
TMOD=0x20;
TH1=-3; //baud rate 9600
TR1=1;
SBUF ='I';
while(TI==0)
TI=0;
}
Using keil uvision tool
RESULT:;
Thus the c program for serial communication using UART port was executed successfully
Ex no:6. INTERFACING AN ADC WITH 8051
AIM:
Software required:-
Keil uvision and proteous simulation tool.
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
#include<reg51.h>
#include<intrins.h>
sbit sc1=P2^0;
sbit sda=P2^1;
sbit green=P2^2;
sbit red=P2^3;
void start();
void delay();
void redy();
void write(unsigned char);
void conversion (unsigned char);
void check ();
void nack ();
void stop();
bit c=0;
unsigned char res,v11,v15;
bit d;
unsigned char v1;
void main()
{
green=red=0;
SCON=0x50;
TMOD=0x20;
TH1=-3;
TR1=1;
start();
write(0x90);
write(0x01);
while(1)
{
green=1;
red=0;
start();
write(0x91);
read();
nack();
}
stop();
}
void delay()
{
_nop-();
_nop_();
}
void nack()
{
sda=1;
sc1=1;
delay();
sc1=0;
}
void start()
{
scl=1;
sda=1;
delay();
sda=0;
delay();
sc1=0;
}
void write (unsigned char va1)
{
unsigned char v2=0x80,v3,v5;
v5=va1;
for(v3=0;v3<8;v3++)
{
sda=v5&v2;
sc1=1;
delay();
sc1=0;
v5=v5<<1;
}
c=sda;
sc1=1;
delay();
sc1=0;
if(c==1)
{
red=1;
green=0;
stop();
}
sda=1;
}
void stop()
{
sc1=1;
sda=0;
delay();
sda=1;
sc1=0;
delay();
}
Thus the c program for interfacing for ADC with 8051 was written and executed successfully
Ex no:7. INTERFACING AN ANALOG SENSOR WITH 8051
AIM:
To write and execute the program of interfacing an analog sensor with 8051.
Software required:-
Keil uvision and proteous simulation tool.
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
#include<reg51.h>
sbit sensor=P1^0;
sbit rs=P1^1;
sbit rw=P1^2;
sbit en=P1^3;
sbit buzzer=P3^0;
void lcdint();
void lcddat(unsigned char)
void lcdcmd(unsigned cchar);
void lcddis(unsigned char *);
void delay();
void main()
{
buzzer=0;
sensor=0;
back: lcdinit();
lcddis(" FIRE ALERT " );
lcdcmd(0xc0);
lcddis(" SYSTEM ")
delay();
while(1)
{
if(sensor==1)
{
lcdcmd(0x01);
lcddis("FIRE OCCURED");
buzzer=1;
}
goto back;
}
}
void lcdinit()
{
lcdcmd(0x38);
lcdcmd(0x01);
lcdcmd(0x10);
lcdcmd(0x0c);
lcdcmd(0x80);
}
void lcdcmd(unsigned char val)
{
P2=val;
rs=0;
rw=0;
en=1
delay();
en=0;
}
void lcddat(unsigned char dat)
{
P2=dat;
rs=1;
rw=0;
en=1;
delay();
en=0;
}
void lcddis(unsigned char *s0
{
unsigned char w;
for(w=0;s[w]!='\0';w++)
{
lcddat(s[w]);
}
}
void delay()
{
unsigned int v1;
for(v1=0;v1<10000;v1++);
}
For using keil uvision tool
`
For using proteus simulation tool
RESULT:
Thus the program for 8051 interfacing with analogue sensor was written and executed successfully
EX no : 8. INTERFACING 16×2 LCD WITH 8051
AIM:
To write and execute the program of interfacing 16×2 LCD with 8051.
Software required:-
Keil uvision and proteous simulation tool.
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
#include<reg51.h>
sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P1^2;
void lcdcmd(unsigned char);
void lcddat(unsigned char);
void delay ();
void main()
{
P2=0x00;
while(1)
{
lcdcmd(0x38);
delay()
lcdcmd(0x01);
delay();
lcdcmd(0x10);
delay();
lcdcmd(0x0c);
delay();
lcdcmd(0x81);
delay();
lcddat('E');
delay();
lcddat('M');
delay();
lcddat('B');
delay();
}
}
void lcdcmd(unsigned char val)
{
P2=val;
rs=0;
rw=0;
en=1;
delay();
en=0;
}
void lcddat(unsigned char val)
{
P2=val;
rs=1;
rw=0;
en=1;
delay();
en=0;
}
void delay()
{
unsigned int i;
for(i=0;i<12000;i++);
}
Using keil uvision tool
AIM:
TO write and execute the program of configuring time for generating PWM SIGNAL.
Software required:-
Keil uvision and proteous simulation tool.
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
#include<stdio.h>
#include<reg51.h>
sbit wave=P1^0;
void delay();
void main()
wave=1;
while(1);
delay();
wave=0;
delay();
}
`
Thus the c program for generating the PWM signal using 8051 microcontroller was executed successfully
Ex no:10. INTERFACING A STEPPER MOTOR WITH 8051
AIM:
To write and execute the program of interfacing a stepper motor with 8051.
Software required:-
Keil uvision and proteous simulation tool.
PROCEDURE:
❖ Open keil uvision software
❖ Click on the project menu to create a new uvision project
❖ Save the file and select your microcontroller AT89C51
❖ Click on the new file and save the file in .C format
❖ To write your program for the menu and build your target
❖ To clear the error’s and warning’s and to create a HEX file
❖ To create a HEX file go to target on your project and set the clock frequency then go to output tab create HEX
❖ The hex file was available in your object folder
❖ Then open the proteus software and click on the schematic capture
❖ Go to pic device menu and get your components
❖ Interconnect the all component and double click on the microcontroller select the HEX file and click ok
❖ Click on the RUN button and simulate your project
❖ Finally save your project and exit
PROGRAM:
#include<reg52.h>
#include<stdio.h>
void delay(int);
void main()
{
do
{
P2=0x01; //0001
delay (1000);
P2=0x02; //0100
delay (1000);
P2=0x04; //0100
delay (1000);
P2=0x08; //1000
delay (1000);
}
while (1);
}
Thus the c program for interfacing of stepper motor with 8051 was executed successfully