You are on page 1of 40

CHAPTER 1

INTRODUCTION
1.1 INTRODUCTION TO EMBEDDED SYSTEMS
An embedded system is a computer system with a dedicated function within a larger mechanical
or electrical system, often with real-time computing constraints.It is embedded as part of a
complete device often including hardware and mechanical parts. Embedded systems control
many devices in common use today. Ninety-eight percent of all microprocessors are
manufactured as components of embedded systems.
Examples of properties of typically embedded computers when compared with general-purpose
counterparts are low power consumption, small size, rugged operating ranges, and low per-unit
cost. This comes at the price of limited processing resources, which make them significantly
more difficult to program and to interact with. However, by building intelligence mechanisms on
top of the hardware, taking advantage of possible existing sensors and the existence of a network
of embedded units, one can both optimally manage available resources at the unit and network
levels as well as provide augmented functions, well beyond those available.For example,
intelligent techniques can be designed to manage power consumption of embedded systems.
Modern embedded systems are often based on microcontrollers (i.e. CPU's with integrated
memory or peripheral interfaces),but ordinary microprocessors (using external chips for memory
and peripheral interface circuits) are also common, especially in more-complex systems. In either
case, the processor(s) used may be types ranging from general purpose to those specialised in
certain class of computations, or even custom designed for the application at hand. A common
standard class of dedicated processors is the digital signal processor (DSP).
Embedded systems are commonly found in consumer, cooking, industrial, automotive, medical,
commercial and military applications.
Telecommunications systems employ numerous embedded systems from telephone switches for
the network to cell phones at the end user. Computer networking uses
dedicated routers and network bridges to route data.
Consumer electronics include MP3 players, mobile phones, videogame consoles, digital
cameras, GPS receivers, and printers. Household appliances, such as microwave ovens, washing
machines and dishwashers, include embedded systems to provide flexibility, efficiency and
features. Advanced HVAC systems use networked thermostats to more accurately and efficiently
control temperature that can change by time of day and season. Home automation uses wired-
and wireless-networking that can be used to control lights, climate, security, audio/visual,
surveillance, etc., all of which use embedded devices for sensing and controlling.
1.2 INTRODUCTION TO MICRO-CONTROLLER
A microcontroller (or MCU for microcontroller unit) is a small computer on a single integrated
circuit. In modern terminology, it is a system on a chip or SoC. A microcontroller contains one or
more CPUs (processor cores) along with memory and programmable input/output peripherals.
Program memory in the form of Ferroelectric RAM, NOR flash or OTP ROM is also often
included on chip, as well as a small amount of RAM. Microcontrollers are designed for
embedded applications, in contrast to the microprocessors used in personal computers or other
general purpose applications consisting of various discrete chips.
Microcontrollers are used in automatically controlled products and devices, such as automobile
engine control systems, implantable medical devices, remote controls, office machines,
appliances, power tools, toys and other embedded systems. By reducing the size and cost
compared to a design that uses a separate microprocessor, memory, and input/output devices,
microcontrollers make it economical to digitally control even more devices and processes. Mixed
signal microcontrollers are common, integrating analog components needed to control non-
digital electronic systems.
Some microcontrollers may use four-bit words and operate at frequencies as low as 4 kHz, for
low power consumption (single-digit milliwatts or microwatts). They will generally have the
ability to retain functionality while waiting for an event such as a button press or other interrupt;
power consumption while sleeping (CPU clock and most peripherals off) may be just nanowatts,
making many of them well suited for long lasting battery applications. Other microcontrollers
may serve performance-critical roles, where they may need to act more like a digital signal
processor (DSP), with higher clock speeds and power consumption.
1.2.1 TYPES OF MICROCONTROLLERS
As of 2008, there are several dozen microcontroller architectures and vendors including:

1 ARM core processors (many vendors)


1.1 ARM Cortex-M cores are specifically targeted towards microcontroller applications

2 Atmel AVR (8-bit), AVR32 (32-bit), and AT91SAM (32-bit)


3 Cypress Semiconductor's M8C Core used in their PSoC (Programmable System-on-Chip)
4 Freescale ColdFire (32-bit) and S08 (8-bit)
5 Freescale 68HC11 (8-bit), and others based on the Motorola 6800 family
6 Intel 8051, also manufactured by NXP Semiconductors, Infineon and many others
7 Infineon: 8-bit XC800, 16-bit XE166, 32-bit XMC4000 (ARM based Cortex M4F), 32-bit
TriCore and, 32-bit Aurix Tricore Bit microcontrollers[19]
8 MIPS
9 Microchip Technology PIC, (8-bit PIC16, PIC18, 16-bit dsPIC33 / PIC24), (32-bit PIC32)
10 NXP Semiconductors LPC1000, LPC2000, LPC3000, LPC4000 (32-bit), LPC900, LPC700
(8-bit)
11 Parallax Propeller
12 PowerPC ISE
13 Rabbit 2000 (8-bit)
14 Renesas Electronics: RL78 16-bit MCU; RX 32-bit MCU; SuperH; V850 32-bit
MCU; H8; R8C 16-bit MCU
15 Silicon Laboratories Pipelined 8-bit 8051 Microcontrollers and mixed-signal ARM-based 32-
bit microcontrollers
16 STMicroelectronics STM8 (8-bit), ST10 (16-bit) and STM32 (32-bit)
17 Texas Instruments TI MSP430 (16-bit), MSP432 (32-bit), C2000 (32-bit)
18 Toshiba TLCS-870 (8-bit/16-bit)
1.3 INTRODUCTION TO 8051 MICROCONTROLLER
The Intel 8051 is an 8-bit microcontroller which means that most available operations are limited
to 8 bits. There are 3 basic "sizes" of the 8051: Short, Standard, and Extended. The Short and
Standard chips are often available in DIP (dual in-line package) form, but the Extended 8051
models often have a different form factor, and are not "drop-in compatible". All these things are
called 8051 because they can all be programmed using 8051 assembly language, and they all
share certain features (although the different models all have their own special features).
The Intel MCS-51 (commonly termed 8051) is an internally Harvard
architecture, complex instruction set computer (CISC) instruction set, single
chip microcontroller (C) series developed by Intel in 1980 for use in embedded systems.
[1]
Intel's original versions were popular in the 1980s and early 1990s and enhanced binary
compatible derivatives remain popular today.
Intel's original MCS-51 family was developed using N-type metal-oxide-semiconductor
(NMOS) technology like its predecessor Intel MCS-48, but later versions, identified by a letter C
in their name (e.g., 80C51) used complementary metaloxidesemiconductor (CMOS)
technology and consume less power than their NMOS predecessors. This made them more
suitable for battery-powered devices.
Some of the features that have made the 8051 popular are:

1 4 KB on chip program memory.


2 128 bytes on chip data memory(RAM)
2.1 32 bytes devoted to register banks
2.2 16 bytes of bit-addressable memory
2.3 80 bytes of general-purpose memory
3 4 reg banks.
4 128 user defined software flags.
5 8-bit data bus
6 16-bit address bus
7 16 bit timers (usually 2, but may have more, or less).
8 3 internal and 2 external interrupts.
9 Bit as well as byte addressable RAM area of 16 bytes.
10 Four 8-bit ports, (short models have two 8-bit ports).
11 16-bit program counter and data pointer.
12 1 Microsecond instruction cycle with 12 MHz Crystal.

The 8051 requires an external oscillator circuit. The oscillator circuit usually runs around
12MHz, although the 8051 (depending on which specific model) is capable of running at a
maximum of 40MHz. Each machine cycle in the 8051 is 12 clock cycles, giving an effective
cycle rate at 1MHz (for a 12MHz clock) to 3.33MHz (for the maximum 40MHz clock). The
oscillator circuit generates the clock pulses so that all internal operations are synchronized.
One machine cycle has 6 states. One state is 2 T-states. Therefore one machine cycle is 12 T-
states. Time to execute an instruction is found by multiplying C by 12 and dividing product by
Crystal frequency.

1.3.1 INTERNAL ARCHITECTURE OF MCS-51


CHAPTER 2
Creating C applications for 8051 Using SIDE51
2.1 Starting the IDE:

Click on START button and select Programs / SPJ Systems SC51 / SIDE51. The screen
should look something like this:

2.2 Opening a project:

Now select Project/Open Project from the menu. Select the path where you installed SC51
and select the EXAMPLES folder. You will see a list of project files (extention
.P51). From the list, select hello.p51. Click Ok. Doing that will open the project HELLO.P51.
This will also automatically open the file HELLO.C in the editor. This is simple program
which outputs the character string Hello World !\n on the standard output device (i.e. the on-
chip serial port of 8051). If the HELLO.C file is not automatically opened, you can select
File/Open from the menu and then double-click Hello.C from the list of files.
2.3 Compiling the program :

To compile the program, select Compile/Build or Compile/Re-build All from the menu.
Doing this may invoke one or more these applications: C compiler, Assembler, Linker. If there
are no errors, then Intel HEX format file (.HEX) and optionally .BIN file will be produced.
The error and warning messages produced by compiler, assembler, linker will be displayed in
the error window. If there are any errors, you may correct them and repeat the process until all
errors are gone.

2.4 Running the program :

To run (i.e. debug) the program, select Tools/Simulator from the menu. Doing this will
invoke the Simulator program. The screen should look something like this:

Please note that the program window is already open. In our example, the program simply
sends a message Hello World !\n to the serial port. In order to debug the program, we must
monitor the serial port output. It can be monitored in the Serial Port Window which is
already visible. To view / hide the Serial Port Window, select View/Serial window from the
menu.
Similarly, you can show or hide other windows visible as per your need. To monitor
memory locations in the external RAM, select View / External RAM watch. To monitor
memory locations in the internal RAM, select View / Internal RAM watch. To monitor
the status of connected peripheral devices, select View / I/O watch from the menu. To
monitor the internal registers / SFRs of 8051, select View / SFR watch from the menu. To
monitor C program variables, select View / C variable watch from the menu. Once you
have made the required windows visible, you can run the program either in continuous
mode or in single step mode. To single step through your program, select Run / Single
step from the menu or press F7. Doing this will execute on C language statement at a
time. On the contrary, if you select Run/Run from the menu (or press Ctrl.F7), the
program will run in continuous mode.
To stop the program execution, select Run / Terminate program, or press Ctrl.F2.

2.5 More about Project:

2.5.1 What is a project:


A project is a file in which SIDE51 stores all information related to an application. e.g. it
stores the name(s) of C and/or Assembler source file(s), memory model to be used and
other options for compiler, assembler and linker.

2.5.2 Opening a project:


To open an existing project file, select Project / Open Project from the menu.
2.5.3 Creating a new project:
To create a new project, select Project / New Project from the menu.
2.5.4 Changing project settings:
To change the project settings (such as adding or removing C and/or Assembler source
file(s), changing memory model etc.), select Project / Settings from the menu. The screen
should now look like this:
There are 3 tabs in the project settings window:
1) Source Files: This tab is automatically selected when you open the Project Settings
window. When this tab is selected, you can see the list of files that are part of this project.
This list is divided into groups of C files, ASM files, OBJ files and LIB files. To remove a
file from the project, select the filename by clicking on it and then press the Remove
File button. To add a file to project, press the Add File button, select desired file and
then press Open button. The SIDE51 allows adding upto 16 C files, 16 ASM files, 16 OBJ
files and 16 LIB files in a project.
2) SC51: This tab lists some options for the SC51 compiler. You can select the Target micro-
controller by selecting desired manufacturer name from the list and then selecting the
desired 8051 derivative name from the list of micro-controllers. Depending on the
processor selected, the amount of internal data memory (128 or 256 bytes) is usually
automatically set appropriately, however, you may change it if you need so. You can also
enter the crystal frequency used in the target (this information maybe later used by the
Simulator). You may check the Generate debug info option
if you wish to use the simulator. Check the Include C source lines in generated ASM file
option if you desire so.
3) SLINK51: This tab lists some options for SLINK51 linker. You may enter the start and
end address of xdata memory. If you need the ROM image file (.BIN) file, you should
check the option Generate BIN file. If you are going to use an In-Circuit- Emulator
which requires Intel AOMF file for debugging, you may check the option Generate
Absolute OMF file. If this option is checked, then the absolute OMF file will be created;
it will have the same name as project filename but extention will be .AOM.

Set the necessary options in all the 3 tabs and when done, press Ok button. This will save the
changed settings in the project file. To discard the changes made, press Cancel button.

2.6 Using the Visual Code Generator (VCG):

To send data to serial port, first initialize serial port. To initialize serial port go to
Visual Code Generator menu. It will display 3 options (Initialize TMOD/TCON, Initialize
Serial Port and Interrupt Settings). Select Initialize Serial Port.

Initialize Serial Port window will be displayed. Do proper settings to initialize serial port.
1. Serial Port Mode: 1 : 8-Bit UART (Baud Rate: Variable)
2. Enable REN (Receiver Enable)
3. For Baud Rate Use: TIMER 1
4. Desired Baud Rate: 9600
5. Crystal Frequency: 11.0592 (Depending on Hardware)
6. Click on Generate Code
Click on Copy C Code, corresponding code will be copied. Last Line is Please also
initialize TMOD / TCON. We have to initialize TMOD / TCON because we have used
TIMER 1 for Baud Rate Generation. Click on Ok. Paste the code in the program.

To initialize TMOD/TCON go to Visual Code Generator menu. Select Initialize TMOD/TCON.


Initialize TMOD/TCON window will be displayed. Do proper settings to initialize
TMOD/TCON.
1. Enable TR1: Check to run Timer 1
2. Timer 1 Mode: 2 8-Bit Auto Reload Mode
3. Click on Generate Code
From the Compile menu, select Build.
2.7 Using the Simulator:

Now we are ready to simulate this program. To do so, simply select Simulator from the
Tools menu.

Simulator for 8051 is an independent program and it will be launched by this action and the
current project (PROG1) will be automatically opened. The Simulator will automatically
display 5 windows (clockwise, from left-top corner): Program window, Serial window,
Internal RAM watch window, SFR watch window, and Symbols watch window. As the
names indicate, these windows display the corresponding information. So, the same program
that you typed (PROG1.C) will be visible in the Program window.
In Simulator you can Debug the program. Different options available in Run menu to debug
the program are:
1. Insert Breakpoint
2. Single Step
3. Step Over
4. Run
5. Terminate Program
6. CPU Reset
To single step through the program, you may select Single Step from the Run menu.
Pressing F7 key is also equivalent to selecting Single Step from the Run menu.
When you do so, the program window will indicate that one C statement has been
executed and the next statement will be highlighted. You may repeat the same to single
step through the entire program.
While single stepping through the program, the contents of general purpose registers (R0-R7) as
well SFRs will be displayed in the SFR Watch Window. The register /SFR contents can be seen
changing as effect of each executed instruction.
It is also possible to modify register / SFR contents by double clicking on its name. (Contents of
PC cannot be modified). Eg. To modify contents of Port 1 double click on P1 in SFR Watch
Window. Edit SFR P1 window will be displayed. You can Enter Hex Value or change Binary
Representation by clicking on the required bit.
Similarly, it is possible to observe values of variables. To do so, right click in the Variables
Watch Window and select Add from the pop-up menu. Select the desired variable(s) to
watch and click OK button. This will display the names and values of the selected variables in
the variables watch window. It is also possible to modify a variable value by double-clicking on
its name.
The Serial I/O window displays the activity related to 8051 serial port. i.e. any character
transmitted to the serial port is displayed in this window. Similarly, it is possible to simulate
receiving characters. To do so, simply click inside the Serial window and type any character(s)
that you wish to simulate as received.
Now Single Step or Run the program from Run menu. We can see WELCOME message on
Serial I/O Window.
When you are through with debugging, select Exit from File menu to close the Simulator. Then
(if necessary) you may edit the program, build it again and start the simulator to debug again.
Please note, only one instance of Simulator program should be started at any time. It is
recommended to close the Simulator while making any changes to the program.
CHAPTER 3
DOWNLOADING AND RUNNING USER PROGRAMS
Microcontroller P89V51RD2 includes on-chip flash for storing user program and non-volatile
data. This flash is In-System-Programmable (ISP). Therefore it is possible to download user
program into on-chip flash, through serial port connected to PC.
This section describes how to use the software Flash Magic to download program into
P89V51RD2.

3.1 Download program using Flash Magic into P89V51RD2:

Install Flash Magic from CD. After installation, open it.


In Flash Magic go to Options -> Advanced Options-> Hardware
Config. Disable Use DTR and RTS to control RST and PSEN.
Click on OK.

To download program follow the steps as below:


1. Connect power supply.
2. Keep the board in switched off mode.
3. Connect the RS232 port (9-Pin D type Male connector) of TR-51, to COM1 or COM2
of a PC, using the serial communication cable (supplied with the board).
4. Start Flash Magic. You will get the screen as below (Flash magic version 3.42.179)

5. Do proper settings in Flash Magic (COM Port: Suppose COM1, Baud Rate:
4800, Device: 89V51RD2, Interface: None (ISP), Enable Erase blocks used by Hex
File).
6. Click on Verify After Programming. This option will verify that the program loaded in
the flash is same as the hex file selected. Thus if any corruption of data has
occurred then it can be detected.
7. IMPORTANT:
a. DO NOT SELECT: Set Security Bit 1. This will block the further erase and write
cycles on the flash of P89V51RD2.
b. DO NOT SELECT: Fill unused Flash, this will consume lot of time in programming.
c. DO NOT SELECT: Gen Block checksums.
d. DO NOT SELECT: Prog Clocks Bit
8. Click on Browse button.
9. Use the browse option to go to the required directory.
10. Click on the hex file you want to download to the target hardware.
11. Click on open button. Once you do this the file will be selected in the Flash Magic.
12. Click on the Start button. Following message will be displayed:
13. At this point you should power ON the board. If the board is already powered ON,
then you should press the Reset Switch (RST KEY) on the board.
14. After the above, the above message will dis-appear and the programming will start.
15. Once the file is loaded it will be verified.
16. Finally you will get the message on the bottom of the Flash Magic Screen as Finished.
17. To Run the program, RESET the board or Power OFF and Power ON the board again.
CHAPTER 4
EXPERIMENTS
4.1 Experiment 1:To develop and execute program to generate delay and use it in
LED blinking.
Aim: Write a C language program to perform LED blinking after some delay.
Equipments: SC51, PC, TR-51, LED Interface Module.

Source code:
#include<reg51.h>
#define led P2
sbit s = P1^0;
void delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void main()
{
s=0;
while(1)
{
if(s==1)
{
P2=17;
delay(100);
P2=0;
delay(100);
}
else
P2=0;
}
}

Connections:
Connect FRC cable between FRC 2 connector on TR-51 board and FRC 2 connector on LED
Interface Module.
Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 3
Output:
You can see output on LED display.
4.2 Experiment 2: To develop and execute the program for 7 segments LED
display to the Microcontroller 8051.

Aim: Write a C language program to display characters 1,2,3,4,5,6,7,8 and 9 on single 7


segment LED displays.
Equipments: SC51, PC, TR-51, 7 Segment LED Interface Module.

Source Code:
#include<reg51.h>
#define value P1
void delay(unsigned int);
void main()
{
while(1)
{
value=0x3f;
delay(90);
value=0x06;
delay(90);
value=0x5b;
delay(90);
value=0x4f;
delay(90);
value=0x66;
delay(90);
value=0x6d;
delay(90);
value=0x7d;
delay(90);
value=0x07;
delay(90);
value=0x7f;
delay(90);
value=0x6f;
delay(90);
}
}
void delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
{
for(j=0;j<1275;j++)
{}
}
}
Connections:
Connect FRC cable between FRC 2 connector on TR-51 board and FRC 2 connector on 7
Segment LED Interface Module.
Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 4
Output:
You can see characters 1,2,3,4,5,6,7,8 and 9 on single 7 segment LED display.
4.3 Experiment 3: To develop and execute the program to generate square wave on port lines of
port 1 of the microcontroller 8051

Aim: Write a C language program for Microcontroller 8051 to generate square wave of
frequency 1 KHz on all port lines of Port 1.Use hardware delay technique.
Equipments: SC51, PC, TR-51, SDIO8.

Source Code:
#include <Intel\8051.h>
#include <standard.h>
unsigned char g_byData = 0; /* Declare Variable */ void main ()
{
/* Following while loop is an infinite loop.
The action which you want to perform continuously, should be written in this loop. In
this program we are generating square wave on all port pins of Port 1, continuously.
The frequency of the Square Wave is approximately 1KHz */

while(1)
{
P1 = g_byData; /* Make all the port pins of Port 1 low */
delay_ms(500); /* This is a library Function. To see help of this, move
the cursor on the function and press F1 and keep it low
for approx 500*1000 machine cycles. If target
hardware freq is 12 MHz, this will generate
approximately 500 milli seconds delay */
P1 = ~g_byData; /* Make all the port pins of Port 1 high */
delay_ms(500); /* Keep them low for approx. 500ms */
}
}
Connections: Connect one channel of Oscilloscope to any pin of Port 1.
Procedure: To Edit / Compile/ Generate Hex file: Refer Section 2.3
To download and run this program: Refer Chapter 3
Output: You can see the square wave of frequency 1 KHz on oscilloscope.

4.4 Experiment 4: To develop and execute the program to interface 16X2 LCD display to
the Microcontroller 8051
Aim: Write a C language program for Microcontroller 8051 to display
message WELCOME on 16 X 2 LCD display.

Equipments: SC51, PC, TR-51, LCD Interface Board.

Source code:

#include <Intel\8051.h>
#include <standard.h>
BIT RS P3.2 // Register Select. 0 = Cmd , 1 = data
BIT RW P3.1 // Read/Write, 0 = write, 1 = read
BIT EN P3.0 // LCD Enable
#define DATAPORT P2 // Port P2 connected to data lines of the LCD
unsigned char g_byData = 0xff ; //
Variable for data void lcd_cmd (unsigned
char p_byCmd)
{
// sends command to LCD
RS = 0; // select command register
RW = 0; // Make Read write in low
DATAPORT = p_byCmd ;
// Generate a pulse on EN Pin
EN = 1;
asm
nop
asm
nop
EN = 0;
}

void lcd_dat (unsigned char p_byData)


{
// sends data to LCD RS = 1;
RW = 0;
DATAPORT = p_byData ;
// Generate a pulse on EN Pin
EN = 1;
asm nop
asm nop
EN = 0;
}

void lcd_init ()
{

lcd_cmd(0x38) ; // 2 lines and 5x7 matrix


delay(250) ;
lcd_cmd(0x0c) ; // Display on, cursor off
delay(250) ;
lcd_cmd(0x01) ; // clear lcd
delay(250) ;
}

void display_row (unsigned char p_byRow, unsigned char p_byDataArr[16])


{

/* this function is written for 16 char X 2 line LCD row == 0 means first row row == 1
second row */ unsigned char count, ch ;
if(p_byRow) // if row is same as saying if row is non zero, in our
// case its row = 1
lcd_cmd(0xc0); // display on second line
else
lcd_cmd(0x80); //display on first line
delay(250) ;
for(count=0;count<16;count++)
{
if(ch = p_byDataArr[count]) // equate p_byDataArr element to ch and
check if
{ // its value is non zero
lcd_dat(ch); // If not non zero send data to the lcd
delay(250) ;
}
else {
while(count < 16)
{
lcd_dat(' ') ; // insert spaces until end of line
delay(250) ;
count ++ ;
}
}
}
}
void main (){

lcd_init (); while (1)

{
display_row(0,"WELCOME");
}
Connections:
Connect FRC cable between FRC 2 connector on TR-51 board and FRC 2 connector on
LCD Interface Board.

Procedure: To Edit / Compile/ Generate Hex file: Refer Section 2.3


To download and run this program: Refer Chapter 3

Output:
WELCOME will be displayed on LCD
4.5 Experiment 5: To develop and execute the program to interface stepper
motor to the microcontroller 8051
Aim: Write a C language program for Microcontroller 8051 to
rotate stepper motor continuously in clockwise direction. Motor is
interfaced through Port 0 of Microcontroller 8051.

Equipments: SC51, PC, TR-51, Stepper Motor Driver Circuit, Stepper


Motor.

Source Code:
#include <Intel\8051.h>
#include <standard.h>

#define PHASEA 0x09


#define PHASEB 0x05
#define PHASEC 0x06
#define PHASED 0x0a
void main ()
{
while(1)
{
P0 =PHASED;
delay_ms(120) ;

P0 = PHASEC;
delay_ms(120) ;

P0 = PHASEB;
delay_ms(120) ;

P0=PHASEA;
delay_ms(120);
}
}

Connections:
Connect FRC cable between FRC 1 connector on TR-51 board and FRC 1 connector on
Stepper Motor Driver Circuit.
Connect FRC cable between FRC 2 connector on TR-51 board and FRC 2 connector on
Stepper Motor Driver Circuit.
Connect Stepper Motor to SM-CON connector on Stepper Motor Driver Circuit.
If stepper motor requires +5V or +12V external power supply then connect it to +5V or
+12V supply respectively (depending on colour combination of connector pins), present on
main power supply provided along with TR-51 board.
Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3

To download and run this program: Refer Chapter 4

Output:
Stepper motor will rotate in clockwise direction.
4.6 Experiment 6: To develop and execute the program to interface ADC 0809 to the
microcontroller 8051.

Aim: Write a C language program for Microcontroller 8051 to read the digital output of the
ADC and output it on port 1 and on serial port.

Equipments: SC51, PC, TR-51, ADC Interface Board, SDIO8

Source Code:

#include <Intel\8051.h>
#include <standard.h>

/*
8 LEDs are connected to port P1.
So data read from ADC should be sent to P1.
ADC channel selection pins = P2.2, P2.1, P2.0
ADC start of conversion pin = P0.1
ADC ALE pin = P0.2
ADC end of conversion pin = P0.4
ADC output enable pin = P0.0
ADC data =P3

BIT start P0.1

BIT ale P0.2

BIT eoc P0.4

BIT oe P0.0
unsigned char adc_data;

void initser()
{
TH1 = 0xfd ;
TL1 = 0xfd ;
PCON &= 0x7f ;
SCON = 0x50 ;
TMOD = 0x20 ;
TCON = 0x40 ;
}

void main ()
{

initser();
P2 = 0x02; /* select channel IN2 */
ale = 1; /* ale pin = high */
delay_ms(60);
/*
Following while loop is an infinite loop
So ADC data of channel IN2 will be continuously read and sent to P1 and serial
port. Since it is connected to a POTentiometer, output will change when POT is
moved.
*/
while(1)
{

start = 1; /* start of conversion pin = high */


delay_ms(60);

start = 0; /* start of conversion pin = low


ale = 0; */ /* ale pin = low */
while(!eoc) /* monitor EOC pin. It will go high when
conversion completes */
{

/*
}
wait until conversion completes. */
oe = 1;
/* output enable pin = high */
asm nop
delay_ms(60
);
adc_data = P3; /* conversion is complete. Now read ADC data. */

oe = 0; /* output enable pin = low */

printf("ADC = %bu\n",adc_data); /* now output that data to serial port */

P1= ~adc_data; /* now output that data to LEDs connected to P1 */


}
}

Connections:
Connect FRC cable between FRC 2 connector on TR-51 board and FRC 2 connector on
ADC Interface Board.

Procedure:
To Edit / Compile/ Generate Hex file: Refer Section 2.3

To download and run this program: Refer Chapter 3

Output:
Digital value of corresponding analog input can be seen on LEDs (on SDIO8 board)
connected to Port 1 of 8051 microcontroller. If you vary the analog input by varying pot
then corresponding digital value can be seen on LEDs.

You might also like