Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 81

Introduction To

Embedded Systems
DEPARTMENT OF INFORMATION TECHNOLOGY SUBMITTED BY;
NAME: Harshal Ashok Patil
CLASS: S.Y.BSc.IT
ROLL NO: 208020
SUBJECT: Introduction To Embedded Systems

SUBMITTED TO:
MS. Vrushali Thakur
INDEX

Sr. No Title
1. Design and develop a reprogrammable embedded computer
using 8051 microcontrollers and to show the following
aspects.
a. Programming
b. Execution
c. Debugging
2. a. Configure timer control registers of 8051 and develop a
program to generate given time delay.
b. To demonstrate use of general purpose port i.e. Input/ output
port of two controllers for data transfer between them.
3. a. Port I/O: Use one of the four ports of 8051 for O/P interfaced
to eight LED's. Simulate binary counter (8 bit) on LED's
b. To interface 8 LEDS at Input-output port and create different
patterns.
c.
To demonstrate timer working in timer mode and blink LED
without using any loop delay routine.
4. a. Serial I/ 0: Configure 8051 serial port for asynchronous serial
communication with serial port of PC exchange text messages
to PC and display on PC screen. Signify end of message by
b. carriage return.

To demonstrate interfacing of seven-segment LED display and


c. generate counting from 0 to 99 with fixed time delay.

Interface 8051 with D/A converter and generate square wave


of given frequency on oscilloscope.
5. a. Interface 8051 with D/A converter and generate triangular
wave of given frequency on oscilloscope
b. Using D/A converter generate sine wave on oscilloscope with
the help of lookup table stored in data area of 8051.
6. a. Interface stepper motor with 8051 and write a program to
move the
b.
motor through a given angle in clock wise or counter clock
wise direction
7. Generate traffic signal.
8. Implement temperature control.
9. Implement Elevator control.
10. a. To demonstrate the procedure for flash programming for
reprogrammable embedded system board using Flash Magic
b. To demonstrate the procedure and connections for multiple
controllers programming of same type of controller with same
source code in one go, using flash magic.

PRACTICAL 1
DESIGN AND DEVELOPMENT OF A REPROGRAMMABLE EMBEDDED
SYSTEM
(COMPUTER) (RES) USING 8051 MICROCONTROLLER (MC)

Objective:

Design and develop reprogrammable embedded system board using 8051


microcontrollers and to show following aspect.
1. Programming.
2. Execution
3. Debugging

Software Requirement:
Editor for schematic drawing like Eagle:
https://www.cadsoftusa.com/download-eagle/freeware/

Or
Protel
http://protel-pcb,software.informer.com/1.5/

Hardware Requirement:

Soldering Iron, Tweezer, Cutter, Multimeter, Components as per tablel.1.

Description:
Embedded System:

Embedded systems are those systems that are Similar too computer (they can
be termed as Computer on a chip) but are designed for Some specific task, they
may lesser components (be in size or in count) associated to it, then PC. They may
or may not contain in all components of computer system. For more
definitions one may refer links below.

http://www.dauniv.ac.in/downloads/EmbsysRevEd_PPTs/Chap01Lesson_I
Emsys.pdf

http://en.wikipedia.org/wiki/Embedded_system

Unlike PC and Embedded systems are designed to perform some specific task
Generally are not designed to perform multiple task.

Block Diagram of an Embedded System:

"Components of a Computer"

Basic component of an embedded system is its controller which could be a


microprocessor unit (MPU) or a microcontroller unit (MCU). MPU needs more
peripherals to accomplish a task and hence results in complex circuit and higher
Power consumption whereas MCU units mostly have on chip peripherals that
incudes elements like ROM/RAM basic elements like Timers/Counters/interrupts
and special interfaces like UART/ SPI/I2C/CAN etc. And thus resulting in lesser
component count and lesser power consumption. For information on difference
between MPU and MCU one
may visit sites

http://www.atmel.in/Images/MCU_vs_MPU_Article.pdf

http://maxembedded.com/2011/06/05/mcu-vs-mpu/
Re-programmable Embedded System (RES):

in its easiest definition, a re-programmable embedded system application


an be re programmable a number of times easily while in system or in
applications
and with minimum component requirement i.e. there is no need to pull out
MCU every time one wants to program and hence provide flexibility in
programming
And operations . It’s developed using 8051 compatible microcontrollers
manufacturers by NXP/ Atmel. In addition execution of intended program RES
also provide debugging facility and chip programming tor other user.

The Reprogrammable embedded system consists of


 Sockets for placing microcontroller- 40 pin
 DC socket for external power supply (DC SV)
 1-LED 1or power on indication and 1 push button for reset
 11.0592 MHz Quartz Crystal Oscillator
 8 LEDs for output pin state indication at port Po
 1 DIP switch (8 switch) for input pin activation
 Connector and driver for serial communication RS232
 Multiple-pin connectors for direct access to 1/0 ports
 / Connector for SPI programming
 1 Piezo buzzer for audio /frequency output
 Additional power supply connectors

Selection of component for a given application

Every application circuit is build around some components which should be


Selected as per the functionality application availability of component cost of
entire system procurement time tor component and most importantly meeting of
some critical parameters of intended application.

Selection of Processor:
Selection should be based mainly on architecture, availability, cost, time to
prototype and market, testability and debug-ability. As per the requirement a
microcontroller will be suitable for this purpose. Intel/Atmel 8051 architecture is
Suitable for beginners due to its easy understandability, easy availability of
architecture description and instruction set. Some advance controllers of 8051
architecture provide boot-loader, in system programming and in application
programming. NXP's P89V51RD2 and Atmel's AT89S52 are such general purpose
Controllers, based on 8051 architecture. Re-programmability is achieved using
ISP (In-System-Programming) feature provided by NXP P89V51RD2 or by Atmel
Al89S52. P89V51RD2 uses ISP by. Atmel AT89s52. P89V51RD2 provides ISP
Features using UART pins (RXD, TXD, RST, PSEN) while AT89S52 uses SPI pins
MOSI, MISO, SCK, RSK) for ISP functionality. NXP's P89V51iRD2 and Atmel's
AT89S52 features include ;

 8-bit, 40-pin controller in DIP package


 Operating voltage +5V
 Operating frequency 0 to 40 MHz
 32-Input / Output pins
 3-16 bit Timers
 8-Interrupt levels
 1-UART
 1-SPI
 1 KB of user RAM
 64 KB of Flash

Selection of other components:

Serial communication interface

UART (Universal Asynchronous Receiver Transmitter) is required for ho


loader/ 1SP/IAP programming and also for applications that include PC
MAX232 is one such chip which provide serial communication interface
Interfacing between personal computer and microcontroller chip. It is selected
due to its
easily availability and low cost. Operating voltage requirement is +5V.

Oscillator:

Oscillator is used as a clock signal generator. Crystal oscillators are used for
their frequency stability and hence should be chosen over other type of
oscillators.
Piezo electric crystal oscillator of 11.0592MHz frequency is used here as this
frequency is most
suitable for generation of precise baud rate and easy interfacing with PC.
Besides, it is also possible to select internal RC oscillator during chip
programming/Operations.

Connector

DB9 Female PCB Mount:- 3 pins of DB9 connector (pin 2-RD, pin 3-TXD
and pin 5-GND) are used for connections between PC and UART IC i.e. MAX232.
Connectors for direct access to Ports
In order to enable microcontroller ports to be directly connected to additional
components, each of them is connected to 8 pin, on-board connector.
Upper Port Pl is also used for providing SPI interface for flash programming
Input Selection
8-DIP switches are provided on board here for interfacing with any of inpu
port. Inputs from
Sensors/ADC/PC may also be connected through port connectors.
Output Selection:

LED: 8-LEDs are connected at port0 with 1KOhm resistor network RN1. They
may be used for initial configurations and testing as well as to view outputs.

LCD: 16x2, LCD may be connected using I/0 port connectors. They may
used for displaying Messages /values. LCD supports ASCII display.

Output at PC/DAC/Motors (through drivers) is also supported.


Power Supply

There is a connector on the development board enabling connection


external power supply source (DC-5V). Besides, voltage necessary 1or
operation can also be obtained from PC via USB cable at connector J7/J8.

Selection of tools

Some tools, and editors are required to prepare assembly language program
compiling i.e. hex file generation, and its writing this hex file to flash
memory.
Free downloadable Kevil uvision version 4. editor is used for writing asset
Assembly language program and its compiling.
Free downloadable Flash Magic or UDB programmer 13 use Flash or
programming.
Hyper terminal available with windows is used for debugging purport

Schematic Diagram

Discussion and explanation: Refer schematic

1. Microcontroller 89V51RD2 is biased with +5V power supply connected at p


40, GND connected at pin 20. A 0.1 MFD ceramic capacitor is connected
between pin 40 and GND to suppress supply spikes.
2. Enable Access (EA), pin 31 and PSEN pin 29 are all connected with Vcc.
PSEN bar is connected to high logic as only internal flash memory is in use.
3. Cathode of all 8 LEDs are connected at different pins of portO i.e. from pin
32 to 39 of controller, LED anode will be connected to Vcc through 1KOhm
resistance network RN1. These LEDs will be used in program to view
outputs or to check proper functioning by blinking them with different
delays.
4. A 16 pin DIP switch (8 on/off switches) can be connected through 10KOhm
resistance network RN3 at any port for switch inputs. At on condition port
will be at low level.
5. A 11.0592 MHz crystal oscillator is connected between pin 18 and 19 of
controller, with two 22pf ceramic capacitors connected between pin 18, 19
and GND.
6. As controller requires logic high voltage for short duration to get itself
reset, a reset circuit is Connected at RST pin i.e. pin 9 of controller. It
consists of a push-to-on switch connected between Vcc and pin 9, a 10K'
resistor connected between pin 9 and GND and an electrolytic Capacitor of
10MFD/25V, connected between Vcc and pin9 of controller.
7. For serial UART working, pin 10 of controller i.e. receive pin at port3 (P3.0)
and pin 11 of Controller i.e. transmit pin at port3 (P3.1) are connected with
serial UART IC, MAX232 pin 9 and 10 respectively. Pin 9 of MAX232 is
R20UT i.e. receive out pin, which outputs data Received from PC through
serial cable via pin 8 i.e. R2IN of MAX232. Pin 10 of MAX232 is T2IN i.e.
transmit input, which inputs data from controller. This input data is then
sent to PC through serial cable via pin7 i.e. T20UT of MAX232.
8. IC MAX232 is biased with +5V supply at pin 16, GND at pin 15. Rest of its
biasing is done as per recommended circuitry. Four number 10 MFD/63v
electrolytic capacitors are connected as recommended.
9. DB9 connector is connected between MAX232 and PC.
TABLE 1
1 LIST OF COMPONENTS FOR THE EMBEDDED DEVELOPMENT SYSTEM

Components. Qty./board
ICs
1. P89V51RD2/ AT89S52. 1
2. MAX232. 1
CAPACITORS
1. 10uF(electrolytic)/63V. 5
2. 22pF(ceramic). 2
KEYS
1. switch. 1
2. ON/OFF(push to On push to OFF). 1
CRYSTAL
1. 11.0592 MHz. 1
LEDS
1. LED(3mm). 9
RESISTANCES
1.. 10K RESISTANCE NETWORK(9 -pin). 2
2. 1K RESISTANCE NETWORK(9 -pin). 1
3. 470E. 1
4. 1k. 1
CONNECTORS
1. SERIAL PORT( DB-9) RIGHT ANGLED
FEMALE. 1
2. SERIAL PORT( DB-9) MALE. 1
3. SERIAL PORT (DB-9) FEMALE. 1
4. CONNECTOR (8-PIN) MALE+ FEMALE. 2
5. CONNECTOR (2-PIN) MALE+FEMALE. 2
6. BERGSTICK MALE. 1
7. CASING (DB-9 CONNECTOR). 2
8. FEMALE TO FËMALE SINGLE
CONNECTING WIRE. 10
TRANSISTORS
.1. BC547. 1
IC base
1. 40-pin. 1
3 16-pin. 2
PCB. 1

Programmer
The purpose of the programmer is to transfer HEX code from PC to
appropriate pins and provide regular voltage levels during chip programming as
well. For this development system, the programmer is freely available Flash Magic
(for P89VSIRD2) or 89SXX from Sunroom Technologies (for AT89S52) connected
to PC via Serial cable/ USB cable. When the process of programming is
completed, microcontroller pins used for it are automatically available for other
application.
Source Code: Table 1

Blinking of LED at port 2.7. Some delay is generated to see LED blinking(LA and
LB loop)

ORG 0000
START NOP
MOV RO, #OFFH;
LB: MOV R1, #OFFH;

LA: NOP;
DJNZ R1, LA;
DJNZ RO, LB;
.CPL P2.7
SJMP START
END

Result:
Embedded system board (as shown in figure. 1) is 'soldered, checked and
found Working.
Conclusion:
Target board of such types can be designed using very less amount of
components and can be used for many applications.
References:

1. Datasheet Max232
2. Datasheet P89v51RD2/AT89S52
3. http://uww.cadsoftusa.com/shop/eagle-hobbyist and-education/
4. https://www.cadsoftusa.com/ download-eagle/
5. http://www.cadsoft.de/wp-content/uploads/2011/05/V6_ tutorialen.pdf
6. http://www.mikrocontroller.net/attachment/17909/ Protel 99 SE_Traning
Manual PCB_Designpdf

PRACTICAL 2 – A

CREATING TIME DELAY USING TIMERS IN 8051 MICROCONTROLLER

objective:

Configure timer control registers of 8051 and develop a program to genera


given time delay.

Software Requirement:

Editor like Kevil uvision ver 4 or less, Flash programmer.

Hardware Requirement:
Target boards with P89V51RD2/AT89S52 controller
Time delay generation was one of the important concepts dealing with the
8051 Microcontroller and also it holds significance in almost all Mc applications.
There are many ways to create a time delay using 8051 however no methods will
be precise to above method of creating delay using inbuilt timers in
Microcontrollers. So to do this 8051 has packed with timers which is capable o
generating required time delay and can serve as a counter. The above circuit
diagram was designed in a simple way to illustrate the generation of time delay
using timers in 8051 microcontroller. Here Port 2 was toggled from high to low
and from low to high for every five seconds delay. Before move into the
programming you need to understand the structure and functions of the time
registers in the 8051 Microcontroller.

8051 TIMERS REGISTERS:

8051 has two inbuilt 16-bit timer register known as Timer0 and Timer1. The
values of the timer register increases one by one with each machine cycle. This
timer registers can count values from 0000H to FFFFH which is a total of 65536
counts. The timer registers are accessed by means of two different (Upper and
lower registers) one for upper bytes and other one for the lower bytes. They are
indicated by THO and TLO for upper and lower byte of timer 0. TH1 and TL1 for
upper and lower byte of the timer 1 register.

TIMER TMOD REGIREGISTE:

TMOD is nothing but a 8 bit register used for configuring the timer for desired
Operation. This TMOD register splits into (TMOD,.0-TMOD.3) are for the timer o
and (TMOD.4 -TMOD.7) for timer. Gate Dit was used to, enable and disable the
timer 1 by means of a signal brought into the Interrupt pin. C/t was used assign
the timer register as timer or as a counter. When the C/T bit is low, timer is used
for time keeping whereas high signal in C/T will turn the timer into a counter.

TIMER TCON REGISTER :

TCON is also a 8 bit register used for the direct control of the timer operation.
This TCON register can be bit addressed for easy timer operation. TF is meant for
denoting the end of each count (0000H to FFFFH) in the timer operation and set
by the hardware on the timer overflow. This bit should be cleared by the software
for continuous counting of the timer. IE is interrupt edge flag, set by hardware
when external interrupt is detected and cleared after processing. IT is interrupt
type control bit, set/cleared by software to specify the falling edge/low level
triggered external interrupts.

FIVE SECONDS DELAY:

The value of the timer register increases by one after every machine cycle
One machine cycle is the 1/12th of the frequency of the crystal attached to the
controller. We are here using 6MHz crystal, then a single machine cycle will take
6/12 - 0.5 MHz
Each count takes 1/0.5 MHz resulting in 2us, so when timer1 counts fro
0000H to FFFFH (65535 counts) it takes
2us x 65535 0.131 seconds
So TF1 is set for every 0.131 seconds and we need to increase the count an
clear the TF1 flag for every increment we make For a delay of 5 Seconds
should give a count value of
5 sec/ 0.131 38
10sec/0.131 76 (For ten seconds delay)
Source Code

#include<stdio.h>
#include<reg51.h>
unsigned char count;
void main()
{
TMOD-0x10;. // Selecting timer mode MO (TIMO) refer above diagram "of
TMOD reg
TH1-0x00; // Setting upper bits of timer register TRI to 0000
TLI-Ox00;. // Setting lower bits of timer register TR1 to 0000
TCON-Ox40; //Starting the timer1(TR1) refer the above diagram or
TCON reg
P2-0x00;
while(1)
{
if(TF1-=1). //Checking the timer overflow flag for completion of count
{
count++;
TF1-0; //Clearing the TF flag through software to continue
Counting
}
if(count==38) // Toggle the status of port 2 if the count reachces 38
{
P2-P2;
count-0;. //Clearing count value to restart counting
}
}
}

Conclusion:

produce a five seconds delay using the timer registers


References:

http://www.gadgetronicx.com/timers-in-8051-microcontroller-tutorial/
PRACTICAL 2-B

USE OF 1/0 PINS FOR DATA TRANSFER BETWEEN CONTROLLERS

Objective
To use general purpose port i.e. Input/ output port of two controllers for data
transfer between them.

Software Requirement:
Editor like Kevil uvision ver 4 or less, Flash programmer.

Hardware Requirement:
2 sets of target boards with P89V51 RD2/AT89S52 controller, Serial Cable
with DB9 Connector/ USB 89SXX Programmer with cable, some connectors.

Procedure:
1. Connect target boards as per given block diagram of figure 1.
2. Write programs, for both the controllers.
3. Build/Compile project.
4. Flash program both the controllers with respective source codes and observe
results.
:Program for microcontroller1, i.e. for Subroutine for delay
Sender; controller

ORG 0000OH
START MOV A, #OFEH
LOOP: RRA
MOV P3,A
MOV P2,A
LCALL DELAY
SJMP LOOP
Subroutine for delay
DELAY; MOV RO,#02
LOOP1; MOV R1,#255
LOOP2; MOV R2,#255
LOOP3; DUNZ R2, LOOP3
DJNZ R1, LOOP2
DUNZ RO, LOOP1
RET
END

Source code:

Program tor microcontroller2, i.e. for receiver controller. These controllers are
Connected through port3. No delay program is written here as delay will be take
care by controller1 ;routine.

ORG 000OH
START NOP
LOOP1:. MOV A,P3
MOV P2,A
SJMP LOOP1
END
Source code:
Result:
Output observed at LEDs, of both the target boards as per programs, i.e. LED
lighting in circular manner, is achieved at port2 of controller2 same as of
controller 1l at port2.
Conclusion:
General purpose Input/output pins can also be used to transfer data
between ports. However this process will be slow but benefit lies in its
easiness.
Remark:
Both controllers can send and receive data from other controller at different
as well as at same port but not at the same time. Different programs can be
tested for such functionalities.
Reference
1. Datasheet 89V5 1 RD2/AT89S52
PRACTICAL 3-A

INTERFACING PROGRAM FOR BLINKING LED

Objective
Port I/O: Use one of the four ports of BO51 for o/P interfaced to eight LED'.
Simulate binary counter (8 bit) on LED's.

Software Requirement:
CodeWizardAVR V1.23.2 Evaluation, Proteus ISIS design suite

Hardware Requirement:
Chip type : AT90S8051
Clock frequency: 4.000000 MHz
Memory model: Small
Internal SRAM size: 512
External SRAM size:0

Source code:
#include <90s805 1 .h>
#include <delay.h>
int i-0;
void main(void)
{
PORTA=0x55;
DDRA=0x00;
while (1)
{
for(i-1;i<-256;i++)
{
PORTA=i;
delay_ms(100);
}
};
}

OUTPUT:
PRACTICAL 3-B

INTERFACING LEDS AT INPUT/ OUTPUT FOR*

objective:
To interface 8 LEDs at Input-output port and create different pattern

software Requirement:
Editor like Kevil uvision ver 4 or less, Flash programmer.
OR CodeWizardAVR V1.23.2 Evaluation, Proteus ISIS design suite

Hardware Requirement:
Target boards with P89V51RD2/AT89852 controller as per circuit give
figure 1.6/4.3, Serial Cable with DB9 Connector/USB 89SXX Programmer with
cable.

Procedure:
1. Connect, 8 LEDs at port 2 (pin 21 to 28) as per given block diagram of figures
6.1. Rest of the Circuit will remain same as figure 2. Write program Tor u
blinking at port.
3. Build/Compile project.
4. Flash program and observe results.
Source Code

Patten 1

#include<reg51.h>. //header file//


void main(). //the program execution stat point//
unsigned int i;. //data type//
while(1) //for continuous loop//
P0=0x55;. //send the hexa value to the port0//
For(i-0;ie30000;i++) //normal delay//
P0=-0x3AA //send the hexa value to the port0/ /
For(i-0;i«30000;i++) //normal delay//
}
}1

OUTPUT
01010101
10101010
Patten 2

#include<reg51.h>
void main()
{
unsignedint i;
unsigned char j,b;
while(1)
{
P0=0x01;
b=P0;
forij-0;j<3000;j++);
for(j-0;j-8;j++)
{
b-b<<1;
P0=b;
For(j-0;j<3000;j++);
}
}
}

OUTPUT

00000001
o0000010
00000100
10000000
Patten 3

#inchudes<reg51.h>
void main()
{
unsignedint i;
while(1)
{
P0=0x0F;
for(j-0j«3000j++);
P0=0xF0;
forj-0j<3000j++);
}
}
OUTPUT

00001111
111100000

Result:
Output at LEDs observed as per programs, i.e. LED rotating in circular
manner is achieved at port2.
Conclusion:
with smart use of instructions memory area of controller can be saved as can
be seen from above example.
Remarks:
Different LED patterns can be generated and tested e.g. blinking of all LEDs,
Blinking of alternate LEDs, 8 bit/4bit binary pattern generation, BCD number
pattern generation, dancing LED etc.
Reference
Datasheet 89V51RD2/ AT89S52
PRACTICAL 3-C

TIMER IN TIMER MODE

Objective:
To achieve timer working in timer mode and blink LED without using any
loop delay routine.

Software Requirement:
Editor like Kevil vision ver 4 or less, Flash programmer.

Hardware Requirement:
Target board with P89V5 I RD2/AT89S52 controller, Serial Cable with DB9
Connector/ USB 89SXX programmer with cable.

Procedure:
1. Write source code e.g. LED blinking at port.
2. Build/Compile project.
3. Program controller with desired code and observe results.

Source Code:
Timer0 is used timer mode. Runs from ;0000 to fffh and blink LED at port
2.2, Timer ;0 ISR, Timer0 in mode 1
ORG 0000H
LJMP START
ORG 000BH
MOV TMOF, #01H
START: MOV TLO,#0OH
MOV THO,#0OH
SETB EA
SETB ETO
SETH ERO
LJMP $
;Timer0 ISR routine
TMRO_INT: CLR TRO
CLR TFO
CPL P2.2
MOV TLO, #00H
MOV THO,#0OH
SETB TRO0
RETI
END

Result:
Results observed as per programs, i.e. one LED blinking at port2.2 of
controller, as per program.

Conclusion:
As timer is used to generate delay, controller is free to complete other tasks
while generating delay.

Remarks:
Using timers different functions can be achieved. E.g. generation of fixed time
delay, generation of frequency at, any 1/0 port etc. .
Counter function of timers allow measurement of unknown frequency, event
counting etc.

Reference
Datasheet 89V51RD2/AT89S52
PRACTICAL 4-A

R$232 SERIAL COMMUNICATION BETWEEN PC AND CON

objective:
To achieve serial communication between PC and controller using serial
UART of controller.

Software Requirement:
Editor like Kevil uvision ver 4 or less, Flash programmer, Hyper terminal
downloads from
http://www.hilgraeve.com/hyperterminal-trial/).

Hardware Requirement:
Target board with P89V5IRD2/AT89S52 controller as per circuit given in
Figure 1.6/4.5, Serial Cable with DB9 Connector/ USB 89SXX programmer with
Cable

Procedure:
1. Write desired source code.
2. Build/Compile project.
3. Program controllers with desired code.
4. Close Flash programmer.
5. Connect target board with PC through DB9 serial connector, open hyper
terminal for desired communication.
6. Set hyper terminal as shown in figures 1 to 4. Select Com port, baud rate as
9600, data bits as 8, parity as none, stop bit as 1 and flow control as none.
7.Observe results.

This code enables controller to Communicate; with PC at 9600 baud- rate.


Data sent from PC ; will b echoed; back to PC. Timer1 of ; controller is
Used or generating baud rate. ; Serial interrupt routine resides at 0023h.
LED at port 2.0 is used for indication.; Stack pointer set at 08h. Timer1 is|
used in mode 2 ; i.e. auto reload mode.

ORG 0000H
JMP 0100H
MOV SCON, #50H
ANL PCON, #7FH
SETB TR1
AGAIN: JMP AGAIN

; Serial interrupt routine for checking transit or; receive. Only if RI


flag is set, receive will occur else transmit. Receive indication is;
given by LED at port 2.0. Read data from; SBUF, this is data
received from PC, clear Rl; flag and load SBUF with same data to
sent back to PC .

SR_INT: JNB RI,CHKTX


CLR P20
MOV A, SBUF
CLR RI
MOV SBUF,A

CLR TR1 RET


MOV TMOD, #20H After transmit complete give
enable interrupt servicing and serial indication at ;LED connected at port
port interrupt, Load fdh in timer1 for 2.0 and clear transmit flag TI
9600 baud rate. Set 8 bit UART mode
and enable reception. After then start CHKTX: SETB P2.0
Conclusion:
Controller is communicating with PC using serial UART.

Remark
Communication between two controllers can also be achieved using serial UART.

Reference
1. Datasheet 89V51 RD2/AT89S52
2. http://en.wikipedia.org/wiki/ RS-232
3. http://www.aggsoft.com/rs232pinout-cable/ serial-port-db9. html
4. http://www.hilgraeve.com/hyperterminal/
PRACTICAL 4-B

SEVEN SEGMENT LED DISPLAY INTERFACING

Objective:
. To achieve interfacing of seven segment LED display and generate
Counting From 0 to 9 with fixed time delay .

Software Requirement:
Editor like Kevil uvision ver 4 or less, Flash programmer.

Hardware Requirement:
Target board with P89V51RD2/AT89S52 controller as per circuit given in
Figure 1.5/.3, Display circuit as per figure 11.1, Serial Cable w
DB9 connector/ USB 895AA programmer with cable.

Procedure:
1. Connect circuit as per figure 11.1. Connect J1 and J2 between points 2 and
3. Connect points of J1 to port1.6 and point3 of J2 to portl.7 of target board
controller (figure1.6/4.5).
2. Short CON5 and cON6 and connect them to CON2 of target board controller
(figurel.6/4.5).
3. Write desired source code.
4. Build/Compile project and program controller with desired code and observe
Results
Source Code:
;Only for two seven segment connected at port2, control pins for common cathode type Seven segment is
Connected at port 1.6 and; 1.7
ORG 0000OH
LJMP START1
START1:. SETB P1.7
SETB P1.6
MOV R5,#0ÖH
MOV R4,#0OH
MOV R6,#OFFH
NEXTSEG: MOV R3,#OAH
MOV DPTR,#1000H
NEXTDIG: MOV A,R4
MOVC A@A+DPTR
MOV P2,A
Result:
Two common cathode seven segments LED displays are showing counting
starting from 0 to 99 with fixed time delay.

Conclusion:
Interfacing of seven segment LED displays is achieved.

Remark:
More than two seven segment LED displays can be connected at same port
with different control pins. Alpha-numeric displays can also be connected in
similar manner.

Reference:
1.Datasheet 89V51 RD2/AT89S52
2. http://en.wikipedia. org/wiki/ Seven-segment_display
PRACTICAL 4-C

SQUARE WAVE IN MICROCONTROLLER 8O51.

objective:
Interface 8051 with D/A converter and generate square wave of given
frequency on oscilloscope.

software Requirement:
CodeWizardAVR V1.23.2 Evaluation, and Proteus ISIS design suite

Hardware Requirement:
Chip type : AT9OS805 1
Clock frequency: 4.000000 MHz
Memory model: Small
Internal SRAM size : 512
External SRAM size: 0

Source code:
#include <90s8051.h>
int tc=0;
interrupt (TIMO_OVF] void tim0_ovf_isr(void)
{
TCNTO=6;
if (++tc==20)
PORTA=PORTA ^0x01;
tc-0;
}
}
void main(void)
{
PORTA=0x55;
DDRA=0xff
TCCRO=0x01;
TCNTO=0;
TIMSK=Ox01;
#asm(“sei")
while(1)
{
};
}
Output:
PRACTICAL 5-A

TRIANGULAR SINE WAVE IN MICROCONTROLLER


8051

Objective:
Interface 8051 with D/A converter and generate triangular wave or
given Frequency. on oscilloscope.

Software Requirement:
CodeWizardAVR VI.23.2 Evaluation, Proteus ISISS design suite

Hardware Requirement:
Chip type : AT90S8051
Clock frequency: 4.000000 MHz
Memory model Small
Internal SRAM size :512
External SRAM size 0

Source code:
#include <90s8051.h>
#include<delay.h>
void main(void)
{
int i=0;
PORTA=0x00;
DDRA=0xff;
while (1)
{
for(i=0;i<=255;i++)
PORTA=i;
For(i-255;i>0;i--)
PORTA=i;
};
}

OUTPUT:
PRACTICAL 5-B

SINE WAVE IN MICROCONTROLLER 8051


Objective:
Using D/A converter generate sine wave on oscilloscope with the help of
lookup table stored in data area of 8051.

Software Requirement:
CodeWizardAVR V1.23.2 Evaluation, Proteus ISIS design suite

Hardware Requirement:
Chip type: AT9OS8O51
Clock frequency: 4.000000 MHz
Memory model: Small
Internal SRAM size : 512
External SRAM size: 0

Source code:
#include <90s8051.h>
#include <delay.h>
void main(void)
{
int i,j,count;
PORTA=0x55;
DDRA=0xf
while(1);
{
for(i=0;i<=255;i++);
{
if(i==0||i==255);
count=150;
else if(i<10)
count=3;
else if(i<180)
count=2;
else
count=3;
for(j=0;j=count;j++)
PORTA=i;
}
For(i=255;I>=0;i--);
{
If(i==0||i==255)
Count=150;
else ifi(<10)
count=3;
else if(i<180)
count=2;
else
count=3;
for(j=0;j<=count;j++)
PORTA=i;
}
};
}

OUTPUT:
PRACTICAL 6
THE STEPPER MOTOR INTERFACE

Objective:
Interface stepper motor with 8051 and write a program to move the motor
through a given angle in clock wise or counter clock wise direction.

Software Requirement:
Editor like Kevil uvision ver 4 or less, Flash programmer.

Hardware Requirement:
Target board with P89V5IRD2/AT89S52 controller.
It is often desirable in an application to accurately position a load or device.
Conventional DC or AC motors are ill-suited in such cases because it is difficult
to determine the exact position of the load, motor speed, or how much total
movement has been produced; unless external positioning sensors, encoders and
controlling devices are used. In such applications, using stepper motor is a better
option.
Stepper motor is an electromechanical device which converts electrical pulses
into discrete mechanical movements.

Features of Stepper Motor:


1. Angle of rotation is proportional to the number of input pulses.
2. Speed is proportional to the frequency of input pulses.
3. Bi-directional Operation.
4. Open-loop system. No position feedback is required.
5. Non-cumulative positioning error.
6. Excellent low speed and high torque characteristics. No need for gear
reduction.
7.Holding torque when energized.
8. Absence of brushes for longer trouble free life.

Disadvantages of Stepper Motor:


1. Resonance can occur if not systematically controlled.
2. Cannot be used for applications demanding extremely high speed.
3. If torque is exceeded beyond limit, all knowledge of position is lost.
4.Produces much less torque as compared to that produced by DC/AC motor
of comparable size.
5. Expensive.

Source Code:
#include <reg51.h>
sbit SW=P2^7;
void MSDelay(unsigned int value);
void main()
// Start of main() function

P1=0x00;
SW=1;. // Initialize Port 1 as Output Port
while(1); // Infinite Loop
{
if (SW==0)
{
Pl=0X66;
MSDelay(50);
P1=0XCC;
MSDelay(50);
P1=0X99;
MSDelay(50);
P1=0x33;
MSDelay(50);
}
else
{
P1=0X66;
MSDelay(50);
P1=0X33;
MSDelay(50);
P1=0X99;
MSDelay(50);
P1=0XCC
MSDelay(50);
}
}
}
void MSDelay(unsigned int value)
{
unsigned int x, y;
for (x=0;x<1275;x++);
for(y=0;y<value;y++};
}

PRACTICAL 7
INTERFACING PROGRAM FOR TRAFFIC LIGHT SIMULATOR

Objective:
Generate traffic signal.

Software Requirement:
Editor like Kevil uvision ver 4 or less, Flash programmer.

Hardware Requirement:
Target board with P89V51 RD2/AT89S52 controller.
#include<AT89x5 1.h>
void ms_delay(unsigned char);
void signal_1();
void signal_1_yellow();
void signal_2();
void signal_2_yellow();
void signal_3();
void signal_3_yellow();
void signal_4();
void signal4 yellow();
sbit red_1=P0^0;
sbit yellow_1 = P0^1;
sbit green_1 = P0^2;
sbit green_left_1 = PO^3;
sbit green_right_1 = PO^4;
sbit red_2 =P0^5;
sbit yellow_2 =P0^6;
sbit green_2 =P0^7;
sbit green_left_2 =P1^0;
sbit green_right_2=P1^1;
sbit red_3=P1^2;
sbit yellow_3 =P1^3;
sbit green_3 =P1^4;
sbit green_left_3 = P1^5;
sbit green_right_3 = P1^6;
sbit red_4 =P1^7;
sbit yellow_4 =P2^0;
sbit green_4 = P2^1;
sbit green left_4 =P2^3;
sbit greenright_4= P2^4;
void main()
{
red_1=0;
yellow_1=0;
green_1= 0;
green_left_1=0;
green_right_1=0;
red_2 =0;
yellow_2= 0;
green_2 =0;
green_left_2= 0;
green_right_2 =0;
red_3 =0;
yellow_3= 0;
green_3 =0;
green_left_3 =0;
green_right_3 =0;
red_4=0;
yellow_4 =0;
green_4-=0;
green_left_4 =0;
green_right_4 =0;
while(1);
signal_1();
ms_delay(1000);
signal_1_yellow();
ms_delay(100);
signal_2();
ms_delay(1000);
signal_2 yellow();
ms_delay(100);
signal_3();
ms_delay(1000);
signal_3_yellow();
ms_delay(100);
signal_4();
ms_delay(1000);
signal_4_yellow();
ms_delay(100);
}
}
void signal_1()

red_1=0;
yellow_1=0;
green_1=1;
green_left_1=1;
green_right_1=1;
red_2= 1;
yellow_2 = 0;
green_2= 0;
green_left_2=1;
green_right_2 =0;
red_3= 1;
yellow_3= 0;
green_3=0;
green_left_3=1;
green_right_3 = 0;
red_4=1;
yellow_4 = 0;
green_4=0;
green_left_4=1;
green_right_4 =0;
return;
}
void_signal_1_yellow()
{
red_1=0;
yellow_1=1;
green_1 =1;
green_left_1 =1;
green_right_1 = 1;
red_2 =1;
yellow_2 =0;
green_2= 0;
green_left_2 =1;
green_right_2 =0;
red_3=1;
yellow_3=0;
green_3= 0;
green_left_3 =1;
green_right_3 = 0;
red_4 =1;
yellow_4=0;
green_4= 0;
green_left_4 = 1;
green_right_4= 0;
return;
};
void signal_2()
{
red_1=1;
yellow_1=0;
green_1= 0;
green_left_1=1;
green_right_1 = 0;
red_2 =0;
yellow_2 = 0;
green_ 2 = 1;
green_left_2 =1;
green_right_2 =1;
red_3=1;
yellow_3 = 0;
green_3=0;
green_left_3= 1;
green_right_3=0;
red_4=1;
yellow_4= 0;
green_4= 0;
green_left_4=1;
green_ right_4 =0;
return;
};
void signal_2_yellow()
{
red_1 =1;
yellow_1=0;
green_1=0;
green_ left_1=1;,
green_right1 = 0;
red_2=0;
yellow_2=1;
green_2 =1;
green_left_2 =1;
green_right_2= 1;
red_ 3 =1;
yellow_3 =0;
green_3=0;
green_left_3 =1;
green_right_3= 0;
red_4= 1;
yellow_ 4= 0;
green_4=0;
green_left_4 =1;
green_right_4 = 0;
return;
void signal_3()
red_1 =1;
yellow_1 = 0;
green_ 1 =0;
green_left_1 = 1;
green_right_1 = 0;
red_2 =1;
yellow_2= 0;
green_ 2= 0;
green_left_2 =1;
green_right_2= 0;
red_3= 0;
yellow_3=0;
green_3 =1;
green_left_3 =1;
green_ right_3= 1;
red_4 =1;
yellow_4= 0;
green_4= 0;
green_left_4= 1;
green_right4= 0;
return;
void signal_3_yellow()
red_1 =1;
yellow_1=0;
green_1=0;
green_left1=1
green_right_1 =0;
red_2= 1;
yellow_2 =0;
green_2 =0;
green_left_2= 1;
green_right_2 = 0;
red_3 =0;
yellow_3 = 1;
green_3 =1;
green_left_3= 1;
green_right_3= 1;
red_4 =1;
yellow_4 =0;
green_4 =0;
green_left 4=1;
green_right_4 =0;
return;
void signal_4()
red_1 =1;
yellow_1=0;
green_1= 0;
green_left_1 =1; .
green_right_1 = 0;
red_2 =1;
yellow_2=0;
green_ 2= 0;
green_left_2 =1;
green_right_2= 0;
red_3 =1;
yellow_3 = 0;
green_3=0;
green_left_3= 1;
green_right_3=0;
red_4 =0;
yellow_4=0;
green_4= 1;
green_left4 =1;
green_right_4 = 1;
return;
}
void signal 4_yellow()
{
red_1 =1;
yellow_1=0;
green_1=0;
green_left_1= 1;
green_right_1 = 0;
red_2 =1;
yellow_2= 0;
green_2= 0;
green_left_2 =1;
green_right_2 = 0;
red_3 =1;
yellow_3 = 0;
green_3= 0;
green_left_3 = 1;
green_right_3 = 0;
red_4= 0;
yellow_4 = 1;
green_4= 1;
green_left_4= 1;
green_right_4 =1;
return;
}
void ms_delay(unsigned char itime)
{
int k;
int i;
int j;
for(k-0;k<10;k++)
{
for(i-0;i<itime;i++)
{
for(j-0j<1275j++);
}
}
return;

PRACTICAL 8
C PROGRAM TO INTERFACE TEMPERATURE CONTROLLER

objective:
Implementation temperature controller

Software Requirement:
Editor like Kevil uvision ver 4 or less, Flash programmer.

Hardware Requirement:
Target board with PIC16F877A /AT89S52 controller.

The software PID temperature controller


In PlD temperature control the drive control signal, u(t), to the heating
element is derived from the feedback from past and present temperature
controller 1irst determines the error difference signal e(t) that indicates the
difference between the target and the current temperature. It then generates
control signal that is a sum of three quantities, one proportional to e(t), another
dependent on the time accumulated (integral) error and another dependent on
how fast the error is changing with time i.e. the error derivative.
Source code 1
#include <at89c51xd2.h>
#include<intrins.h>
#incude "lcd.h”
unsigned int Adc;
#define setup PINB0_bit
#define up. PINB1_bit
#define down PINB2_bit
#define save PINB3&bit
#define heater PORTD0_bit
#define cooler PORTD1_bit
#define Fault_H PORTD2_bit
#define Fault_C PORTD3_bit
#define ee_t_high 0x0
#define ce_t_low 0x4
#define ee_t_delta 0x8
#define ee_pass_times 0xE

sbit LCD_RS at PORTC2_bit;


sbit LCD_EN at PORTC3_bit;
sbit LCD_D4 at PORTC4_bit;
sbit LCD_D5 at PORTC5_bit;
sbit LCD_D6 at PORTC6_bit;
sbit LCD_D7 at PORTc7_bit;
sbit LCD_RS_Direction at DDC2_bit;
sbit LCD_EN_Direction at DDC3_bit;
sbit LCD_D4 Direction at DDC4_bit;
sbit LCD_D5 Direction at DDC5_bit;
sbit LCD_D6_ Direction at DDC6_bit;
sbit LCD_D7_Direction at DDC7_bit;
bit h;
bit c;
float t=0.0;
float temp=0.0;
unsigned long pass=0;
unsigned int t_low=0;
unsigned int t_high=0;
unsigned int t_delta=0;
unsigned char pass_times=0;
void setup_mcu();
unsigned char scan_keys();
unsigned long adc_avg();
void temp_display();
void settings();
signed int inc_dec(signed int variable, signed int max,signed int min,unsigned
char x,unsigned char y);
void display_common(unsigned char x,unsigned char y,unsigned char
convert);
void compare_temp();
void controller_state(unsigned short state);
void check fault(unsigned short stat);
void read_memory();
void fault_messages();
void settings_demanded();

void all_tasks();
void main();
setup_mcu();
read_memory();
while(1)
all_tasks();
void setup_mcu();
Lcd_Init();
Sound_Init(&PORTD,4);
Led_Cmd(LCD_CLEAR);
Lcd_Cmd(LCD_CURSOR_OFF);
DDRD=0xFF;
PORTD=0x00;
DDRB=0x00;
C=0;
H=0;
unsigned char scan_keys()
if(setup)
Sound_Play(888,99);
return 1;
else (ifup)
Sound_Play(900,9);
return 2;
else (ifdown)
Sound Play(700,9);
return 3;
else if(save)

Sound Play(800,99);
return 4;
else
return 0;
unsigned long_adc_avg();
unsigned char sample=0;
register unsigned int adc=0;
for(sample=0;sample<64;sample++)
adc+=((float)ADC_Read(0));
delay_us(20);
adc=adc>>6;
return adc;
void temp_display()
register unsigned long conv=0;
unsigned char ch=0;
t=((adc_avg())*48.9);
temp=(t*0.01);
conv=t;
ch=(conv/1000);
Lcd_Chr(2,1,(48+ch));
Ch=(conv/100)%10);
Lcd_Chr_CP(48+ch));
Lcd_Chr_CP(46);
Ch=(conv/10)%10;
Lcd_Chr_CP(48+ch};
Ch=(conv)%10;
Lcd_Chr_CP(48+ch);
Led_Out_CP("C");
Delay_ms(100);

void settings()
Lcd_Cmd(LCD_CLEAR);
read_memory();
if(h||c)
lcd_out(1,1,"Reset Alarm?” );
Icd_out(2,1,” Up-Yes Down-No”);
do
if(scan_ keys()==2)
c=0;
h=0;
break;
if(scan_keys()==3)
break;
while(1);
Lcd_Cmd(_LCD_CLEA);
delay_ms(500);
lcd_out(1,1,"Settings Step 1/3 :”);
lcd_out(2,1,"High Temp. Limit:");
lcd_out(3,4,"C");
t_high= inc_dec(t_high,99,0,1,3);
if(t_high>=0)&&(t_high<=99)
eeprom_write(ee_t_high,t_high);
Lcd_Cmd(_LCD_CLEAR);
delay_ms(500);
lcd_out(1,1,'Settings Step 2/3);
lcd_out(2,1, Low Temp. Limit:");
lcd_out(3,4,"C");
t_low=inc_dec(t_low,99,0, 1,3);
if(t_low>=0 && t_low<= 99)
eeprom_writelee_t_low,t_low);
Lcd_Cmd(_LCD_CLEAR);
delay_ms(500);
lcd_out(1,1,"Settings Step 3/3");
lcd_out(2,1,"No. of passes: ");
pass_times=inc_dec(pass_times,99,0,1,3);
if(pass_times>=0 && pass_times<=99)
eeprom_write(ee_pass_times,pass_times);
Led_Cmd(_LCD_CLEAR);
delay_ms(500);
pass_times=(eeprom_read(ee_pass_times);
t_high=(eeprom_read(ee_t_high));
t_low=(eeprom_read(ee_t_low));
t_delta=(((t_high-t_low)/2));
eeprom_write(ee_t_delta,t_delta);
delay_ms(100);
signed int inc_dec(signed int variable,signed int max,signed int min,unsigned
char x,unsigned char y)
do
display_common(x,y,variable);
if(scan_keys()==2)
variable+=1;
if(scan_keys()==3)
variable=1;
if(variable>max)
variable=min;
if(variable<min)
variable=max;
if(scan_keys()==4)
return variable;
if(scan_keys()==1)
return (max+1);
while(1);

void display_common(unsigned char x,unsigned char y, unsigned convert)

unsigned char t=0;


t=(convert/10);
Lcd_Chr(y,x,(48+t));
t=(convert%10);
Lcd_Chr(y,(++x),(48+t));
void compare_temp()
if(temp>=t_high)
Lcd_Out(3,1,"High Temperature!");
controller_state(1);
if(temp=t_low)
Lcd_Out(3,1, Low Temperature! "%);
controller_state(2);
if(temp<t_high)&&temp>=(t_high=t_delta)| |
(temp>t_low)&&temp<(t_delta+t_low))
Lcd_Out(3,1,"Within Limit.”);
controller_state(0);
void controller_state(unsigned short state)
if(state==1)
if(c=0)
heater=0;
cooler= 1;
check fault(1);
else if(state==2)
if(h=0)
heater=1;
cooler =0;

check fault(2);
else
,
Heater=0
Cooler=0;
void check fault(unsigned short stat)
if(stat==1)
pass++;
if(temp>=t_high)&&((pass==(pass_times* 10)))
Fault C=1;
C=l;
heater=0;
cooler=0;
pass=0;
if((temp<=(t_high=t_delta))&&((pass==(pass_times*10))
heater=0;
cooler=0;
c=0;
pass=0;
if(stat=2)
pass++;
if(temp<=t_low)&&(pass==(pass_times* 10))
fault_H=1;
h=1;
heater=0;
cooler=0;
pass=0;
if(temp>(t_low+t_delta))&&(pass==(pass_times*10))
heater=0;
cooler=0;
h=0;
pass=0;
delay_ms(100);
void read_memory()
pass_times=(eeprom_read(ee_pass_times);
delay_ms(30);
t_high=(eeprom_read(ee_t_high));
delay_ms(30);
t_low=(eeprom_read(ee_t_low);
delay_ms(30);
if(pass_times>99)
eeprom_write(ee_passtimes, 45);
delay_ms(30);
passtimes=(eeprom_read(ee_pass_times)
delay_ms(30);
if(high>99)
eeprom_write(ee_t_high, 40);
delay_ms(30);
t_high=(eeprom_read(ee_t_high));
delay_ms(30);
if(low>99)
eeprom_write(ee_t_low, 20);
delay_ms(30);
t_low=(eeprom_read(ee_t_low)
delay_ms(30);
t_delta=(t_high=t_low)/2));
eeprom_write(ee_t_delta,t_delta);
delay_ms(30);
void fault_messages()
if(h==0) && (c==0)
lcd_Out(4,1, System Okay.”);
Fault_C=0;
Fault_H=0;

if(h==1) ||(c==1))
Sound_Play(550,150);
if(h==1) && (c==0))
Led Out(4,1,"Alarm! Heater Fault.”);
delay_ms(600);
else if((h==0) && (c==1))
Lcd_Out(4,1,"Alarm! Cooler Fault.");
delay_ms(600);
else if(h==1)&&(c==1)
Lcd_Out(4,1,"System Failed.”);
delay_ms(600);
void settings_demanded()
if(scan_keys()==1)
delay_ms(9);
while(scan_keys(==1);
settings();
void all tasks()
Lcd_Out(1,1,"Active Temperature: ");
temp_display();
fault_messages ();
settings_demanded();
compare_temp();

PRACTICAL 9

INTERFACING PROGRAM FOR ELEVATOR SIMULATOR


objective:
Implement Elevator control

Software Requirement:
Editor like Kevil uvision ver 4 or less, Flash programmer.

Hardware Requirement:
Target board with PIC16F877A /AT89852 controller.

Source Code
#include<at89x51.h>
unsigned char current_f1;
unsigned char requested_f1;
void delay(unsigned char);
void out(unsigned char);
sbit sw1 =P1^0;
sbit sw2 = P1^1;
sbit sw3= P1^2;
sbit sw4 = P1^3;
sbit sw1_r = P0^4;
sbit sw2_r = P0^5;
sbit sw3_r = P0^6;
sbit sw4_r= P0^7;
sbit a_7442 =P9^0;
sbit b_7442= P0^1;
sbit c_7442 =P0^2;
sbit d_7442= P0^3;
sbit current_f1_0 = ACC^0;
sbit current_f1_1 = ACC^1;
sbit current_f1_2 =ACC^2;
sbit current_f1_3 =ACC^3;
void main()
{
sw1_r =0;
sw2_r=0;
sw3_r = 0;
sw4_r =0;
sw1_r=1;
sw2_r = 1;
sw3_r =1;
sw4_r=r1;
current_f1= 0x00;
ACC= current_f1;
a_7442 =current_f1_0;
b_7442= current_f1_1;
c_7442= current_f1_2
d_7442= current_f1_3;
while(1)
{
if(sw1==1)
{
requested_f1 = 0x00;
while(current_f1<=requested_f1 )
{
current_f1++;
}
while(current_f1>requested_1f)
{
current_f1--;
out(current_f1 );
}
sw1_r=0;
delay(10);
sw1_r= 1;
}
if(sw2==1)
{
requested_f1= 0x03;
while(current_f1<=requested_f1 )
{
out(current_f1);
current_f1++;
}
while(current_f1>requested_f1)
{
current_f1--;
out(current_f1);
}
sw2_r = 0;
delay(10);
sw2_r =r;
}
if(sw3==1)
{
requested_f1 =0x06;
while(current_f1<=requested_f1 )
{
out(current_f1);
current_f1++;
}
while(current_f1>requested_f1)
{
current_f1--;
out(current_f1);
}
sw3_r=0;
delay(10);
sw3_r=1;
}
If(sw4==1)
{
requested_f1 = 0x09;
while(current_f1<=requested_f1)
{
out(current_f1);
current_f1 ++;
}
while(current_f1>requested_f1 )
{
current_f1--;
out(current_f1);
}
sw4_r=0
delay(10);
sw4_r=1;
}
void out(unsigned char current_f1_temp)
{
ACC =current _f1_temp;
a_7442= current_f1_0;
b_7442 =current_f1_1;
c_7442 =current_f1_2;
d_7442= current_f1_3;
delay(100);
return;
}
void delay(unsigned char itime)
{
int i,j;
for(i=0;i<=time;i++)
for(j=0;j<=1275;j++);
return;
}

PRACTICAL 10-A

FLASH PROGRAMMING USING SERIAL UART FLASH PROGRAMMER-


FLASHMAGIC

objective:
To understand the procedure of Nash programming source code for
reprogrammable embedded system board using NXP's Flash Magic.

Software Requirement:
Flash Magic.

Hardware Requirement:
Target board with P89V51RD2 controller, Serial Cable with DB9 Connector, Power
Cable.

NOTE: Choose target processor which supports In-system programming (1SP]


e.g. Phillips P89V51RD2.

Procedure:
1. Down load free tools for flash programmer from
www.flashmagictool.com
Save and run FlashMagic.exe
A serial port flash programmer will be downloaded then.

Requirements:
Flash Magic works on Windows 2000, XP, Vista and 7. 10Mb of disk space is
required for reliable operation of the said tool.
Once install, Flash magic will look like figure 1.
Recommended settings for flash magic are as shown in figure 1.
Connect target board with serial port of PC using Serial cable (standard 9 pin
cable is recommended).
Flash magic tool steps are described as under.

Step1:- Select target device, choose serial COM port, baud rate and
Interface as None.
Step2:- Choose desired option for flash erase.
Step3: -Browse desired hex file that to be flash programmed into target
controller.
Step4:- Select desired options for programming. Verify after programming
is recommended.
Beginners should not use other options as they may. lock their target
device.
Step 5 :- After all setting are done press Start programming button.
Once communication' between flash magic. and target board established, after
pressing start Reset Device button, lash programmer will show message as in
Reset the device into ISP mode now figure 4 Reset processor at target board.
Flash Cancel programming will be started then. After successful programming
Finished Fig. 4: Reset Message can b seen at bottom left, corner of flash
Programmer screen. Target board is now ready to be used. It will run as per the
hex file loaded.

Result:
Sample program for LED blinking is programmed and LED blinking is
observed as per program at target board.

Conclusion:
Different hex files can be programmed and checked using lash programmer.

Remarks:
Different programs should be programmed and tested using assembly/C
language for better understanding the tool.
References:
www.flashmagictool.com

PRACTICAL 10-B
MULTIPLE CONTROLLERS PROGRAMMING USING FLASH MAGIC

objective:
To understand the procedure and connections for multiple controllers
programming of same type of controller with same source code in one g0, Using
flash magic.

Software Requirement:
Editor like Keil uvision ver 4 or less, Flash programmer.

hardware Requirement:
2 Sets of target boards with P89V5 1 RD2 controller, Serial Cable with DB9
Connector.

Procedure:
1. Connect circuit as per given block diagram of figure 1. These connections will
facilitate programming of multiple controller of same type, simultaneously:
Here it is checked for 2 controllers.
2. Use source code of experiment 1.
3. Set flash programmer for programming as per given figure 2.
4 Open Options-> advance option-> Misc->Check, disable device signature
checking.
5. Start flash programming.
6. Reset both the target controllers simultaneously when prompted.
7. Click ok for warning message.

Result:
Both the controllers are programmed simultaneously with same program.

Conclusion:
Multiple controllers can be programmed in one go with same source code and
hence beneficial in time saving for large production. Target board there can be
designed with some jumper settings to facilitate multiple programming
connections.
Remarks:
Single max232 interface is used here to program multiple controllers and
hence care must be taken as this may increase voltage levels of max232 which
may result in its damage.

References:
1. Datasheet Max232
2. Datasheet P89v51RD2,

You might also like