[go: up one dir, main page]

0% found this document useful (0 votes)
29 views56 pages

Embedded Manual PDF

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 56

DR.G.U.

POPE COLLEGE OF ENGINEERING


POPE NAGAR SAWYERPURAM-628 251
Thoothukudi District

Name:
Register number:
Subject code&name: EE3017 EMMBEDDED C PROGRAMMING
Department:EEE

Staff In-charge H. O.D


DR.G.U.POPE COLLEGE OF ENGINEERING
POPE NAGAR SAWYERPURAM-628 251
Thoothukudi District

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

Staff In – Charge Head of the Department

Submitted for the Anna University B.E. (EEE) Degree Practical Examination held at DR G U Pope College of
Engineering on................................

Internal Examiner External Examiner


EE3017 EMBEDDED C- PROGRAMMING (LAB)

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

11. 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

CYCLE – II

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
INDEX

SL. PAGE SIGNAT


TITLE OF EXPERIMENT DATE MARKS
NO. NO. URE
INDEX

SL. PAGE SIGNAT


TITLE OF EXPERIMENT DATE MARKS
NO. NO. URE
EX. NO.: 1. INTRODUCTION TO IDE KEIL UVISION AND
PROTEUS PROGRAMMING
DATE:
INTRODUCTION
Earlier to Microcontrollers, Microprocessors were greatly used for each and every purpose.
Microprocessors were containing ALU, general purpose register, stack pointer, program
counter, clock counter and so many other features which the today’s Microcontroller also
possesses. But the difference between them exists with respect to the number of instructions,
access times, size, reliability, PCB size and so on. Microprocessor contains large instruction set
called as CISC processor whereas Microcontroller contains less number of instructions and is
called as RISC processor. The access time is less in case of microcontrollers compared to
microprocessors and the PCB size reduces in case of microcontrollers. There are many versions
of microcontrollers 8051, 80528751, AT8951 from Atmel Corporation and many more. In this
manual we will study about the 8051 architecture, its features, programming and interfacing.
MCS 8051 is an 8-bit single chip microcontroller with many built-in functions and is the core
for all MCS-51 devices.
The main features of the 8051 core are:
Operates with single Power Supply +5V.
 8-bit CPU optimized for control applications.
 16-bit program counter (PC) and 16-bit data pointer (DPTR).
 8-bit program status word (PSW).
 8-bit stack pointer (SP).
 4K Bytes of On-Chip Program Memory (Internal ROM or EPROM).
 128 bytes of On-Chip Data Memory (Internal RAM):
 Four Register Banks, each containing 8 registers (R0 to R7) [Total 32 reg]
 16-bytes of bit addressable memory.
 80 bytes of general-purpose data memory (Scratch Pad Area).
 Special Function Registers (SFR) to configure/operate microcontroller.
 32 bit bi-directional I/O Lines (4 ports P0 to P3). Two 16-bit timers/counters (T0 and T1).
 Full duplex UART (Universal Asynchronous Receiver/Transmitter).
 On-Chip oscillator and clock circuitry.
STEPS TO CREATE AND COMPILE Keil µVision-
1. Double Click on the icon on the desktop.vision keil
2. Close any previous projects that were opened using – Project -> Close.
3. Start Project – New Project, and select the CPU from the device database (Database-Atmel-
).On clicking ‘OK’, the following option is displayed. Choose ‘No’.
4. Create a source file (using File->New), type in the assembly or C program and save this
(filename.asm/filename.c) and add this source file to the project using either one of the following
two methods.
(i) Project->Manage->Components, Environment Books->add files-> browse to the required file -
> OK “OR”
ii) right click on the Source Group in the Project Window and the Add Files to Group option.
5. Set the Target options using -> Project – Options for Target opens the µ Options for Target –
Target configuration dialog. Set the Xtal (Crystal frequency) frequency as 11.0592 MHz, and also
the Options for Target – Debug – use either Simulator / Keil Monitor- 51 driver.
6. If Keil Monitor- 51 driver is used click on Settings -> COM Port settings select the COM Port to
which the board is connected and select the baud rate as 19200 or 9600 (recommended). Enable
Serial Interrupt option if the user application is not using on-chip UART, to stop program
execution.
7. Build the project; using Project -> Build Project. application and links. Any errors in the code
are indicated by – “Target not created” in the Build window, along with the error line. Debug the
errors. After an error free, to build go to Debug mode.
8. Now user can enter into Debug mode with Debug- Start / Stop Debug session dialog Or by
clicking in the icon.
9. The program is run using the Debug-Run command & halted using Debug-Stop Running. Also
the (reset, run, halt) icons can be used. Additional icons are (step, step over, and step into, run
till cursor).
10. If it is an interface program the outputs can be seen on the LCD, CRO, motor, led status, etc.
If it is a part-A program, the appropriate memory window is opened using View -> memory
window (for data RAM & XRAM locations), Watch window (for timer program), serial window,
etc.
Note: To access data RAM area type address as D: 0020h. Similarly to access the DPTR region
(XRAM-present on chip in AT89C51ED2) say 9000h location type in X: 09000H

C51 Development Tools

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.

This introduction includes a brief explanation of the:

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

µVision provides several ways to invoke debugging commands:

Commands used from the menu Debug or the Debug


Toolbar. Commands entered manually in the Command
Window.
▪ Commands available from the Context Menu of the Editor or Disassembly
window.

Debug Functions executed from an initialization file.

Start the Debugger


▪ Use the Start/Stop Debug Session button from the Debug
Toolbar to start or stop a debugging session.
▪ The current instruction or high-level statement (the one about to
execute) is marked with a yellow arrow. For each step-command, the
arrow moves to reflect the new current line or instruction.
▪ Depending on the Options for Target — Debug configuration,
µVision loads the application program and runs the startup code
(Run to main ()).
▪ µVision saves the editor screen layout and restores the screen layout
of the last debug session. When program execution stops, µVision
opens an Editor window with the source text or shows MCU
instructions in the Disassembly Window.

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.

Startup Code - initializes the microcontroller and transfers control to the


main function.
Special Function Registers - explains how to use Special FunctionRegisters (SFRs).
Register Banks - explains how to use Register Banks.
Interrupt Service Routines - lists the different interrupt variants on 8051devices.
Interrupt Enable Registers - shows how to enable the interrupts.
Parallel Port I/O - explains how to use standard I/O ports.
Timers/Counters - explains standard timers and counters.
Serial Interface - explains the implementation of serial UART
communication.

Create new u vision project Procedure:-

Create new u vision project


Select the folder (newly created) to save the project

Save the project


Select the vendor “Atmel” and device “AT89C51”

Addition of STARTUP.A51 to project folder


STARTUP.A51 is added

The program to print “welcome to ECE department” is written


The program is saved as prg3.c

Prg3.c is to be added to Source Group1


Select the program prg3

Now prg3.c is added to Source Group 1


Build the target

Debugging the target


New window evaluation mode appeared. Press ok

Run the program


Selecting for UART#1 from serial windows

Check the output at UART#1 window


Select Port1 from i/o ports in peripherals

Port1 window is displayed with D0 as 0


Port1 window is displayed with D0 as 0

Stop debugging process


After debugging, window appears in this format

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:

#include<stdio.h> //HEADER file


#include<reg51.h> //initialize register51

sbit switch1=P1^0; //INPUT


sbit switch2=P1^1; //INPUT

sbit led1=P2^0; //OUTPUT


sbit led2=P2^1; //OUTPUT

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

For using proteus simulation tool


RESULT:

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

For using proteus simulation


RESULT:

Thus the c program for configuring timer for hardware delay was written and executed.
Ex no:4. FLASHING AN LED USING AN INTERRUPT

AIM:

To write and execute the program of flashing an LED using an interrupt.

Software required:-

Keil uvision and proteus 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 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

Using proteus simulation software


RESULT:
Thus the c program for flashing an LED using interrupt was executed successfully.
Ex no:5 SERIAL COMMUNICATION USING UART PORT of 8051

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

Using proteus simulation software

RESULT:;

Thus the c program for serial communication using UART port was executed successfully
Ex no:6. INTERFACING AN ADC WITH 8051

AIM:

TO write and execute the program of interfacing an ADC 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>
#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();
}

void conversion (unsigned char va1)


{
unsigned char v12,v13,v14;
v12=va1;
v13=v12/10;
v14=v12%10;
v13=v13|0x30;
v14=v14|0x30;
SBUF=v13;
while(TI==0);
TI=0;
SBUF=v14;
while(TI==0);
TI=0;
SBUF=0x0D;
while(TI==0);
TI=0;
}
void read ()
{
unsigned char ch=0x00,v16;
bit m=0;
for(v16=0;v16<=7;v16++)
{
sc1=1;
delay();
m=sda;
sc1=0;
if(m==1)
{
ch|=0x01;
}
if(v16<=6)
ch=ch<<1;
delay();
}
conversion(ch);
}
END
Using keil uvision tool

Using proteus simulation tool


RESULT:;

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

For using proteus simulation software


RESULT:
Thus the c program for interfacing 8051 with 16x 2 LCD display was written and executed successfully
Ex no:9. CONFIGURING TIME FOR GENERATING PWM SIGNAL

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();

}
`

For using keil uvision tool

For using proteus simulation tool


RESULT:

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);
}

void delay (int k)


{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{}
}
}
For using keil uvision software

For using proteus simulation software


RESULT:

Thus the c program for interfacing of stepper motor with 8051 was executed successfully

You might also like