LAB Manual 8051
LAB Manual 8051
LAB Manual 8051
Under the Guidance of: Dr. SRN Reddy, Associate Professor, CSE
1
LIST OF EXPERIMENTS
Exp No. Description of experiment Page No.
Exp. 2 To Demonstrate the Tool Chain for Keil IDE (Embedded 14-16
Systems Development Tool Chain) with the example of LED
Blinking Program.
Exp. 7 To demonstrate use of general purpose port i.e. Input/ output 31-32
port of two controllers for data transfer between them.
2
Exp.12 To demonstrate serial communication between PC and 43-47
controller using serial UART of controller.
3
Experiment 1
Or Protel.
http://protel-pcb.software.informer.com/1.5/
1.2.2 Hardware Requirement: Soldering Iron, Tweezer, Cutter, Multimeter, Components as per
table1.1.
1.3 Description:
1.3.1 Embedded System:- Embedded systems are those systems that are similar to computer (they
can be termed as computer on a chip) but are designed for some specific task, they may have lesser
components (be in size or in count) associated to it, then PC. They may or may not contain all
components of a computer system. For more definitions one may refer links below.
http://www.dauniv.ac.in/downloads/EmbsysRevEd_PPTs/Chap01Lesson_1Emsys.pdf
http://en.wikipedia.org/wiki/Embedded_system
Unlike PC, Embedded systems are designed to perform some specific task and generally are not
designed for performing multiple tasks.
Memory
Data Program
Output
Input
Switch LCD/LED
Microcontroller
Sensor Printer
Peripheral Interface
Clock SPI I2C ADC UART
4
1.3.3 “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 includes memory elements like ROM/RAM, basic function 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 more information on difference between MPU
and MCU one may visit below mentioned sites.
http://www.atmel.in/Images/MCU_vs_MPU_Article.pdf
http://maxembedded.com/2011/06/05/mcu-vs-mpu/
5
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 AT89S52. P89V51RD2 uses ISP by Atmel AT89S52. P89V51RD2
provides ISP feature using UART pins (RxD, TxD, RST, PSEN) while AT89S52 uses SPI pins
(MOSI, MISO, SCK, RST) for ISP functionality.
NXP’s P89V51RD2 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
1.4.2.2 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.
1.4.2.3 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 P1 is also used for providing SPI interface for flash programming.
6
8-DIP switches are provided on board here for interfacing with any of input port. Inputs from
sensors/ADC/PC may also be connected through port connectors.
*Note: Some instructions or names of SFRs may be changed in different processors of different
manufacturers, e.g. ATMEL NXP for same architecture. Care must be taken here.
8
Figure 1.3: Bareboard PCB for Reprogrammable Embedded System
9
Figure 1.5: Assembled PCB for Reprogrammable Embedded System
10
Table 1.1
1.7 LIST OF COMPONENTS FOR THE
EMBEDDED DEVELOPMENT SYSTEM
Components Qty./board
ICs
P89V51RD2/ AT89S52
1 1
2 MAX232 1
CAPACITORS
1 10uF(electrolytic)/63V 5
2 22pF(ceramic) 2
KEYS
1 DIP 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 FEMALE SINGLE
CONNECTING WIRE 10
TRANSISTORS
1 BC547 1
IC base
1 40-pin 1
3 16-pin 2
PCB 1
11
Figure1.6: Schematic Diagram for reprogrammable Embedded Board
1.7 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 FlashMagic (for P89V51RD2) or 89SXX from Sunrom 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.
1.7.1 Source Code: Table 1.2
; Blinking of LED at port 2.7. Some delay is generated to see LED blinking(LA and LB loop)
ORG 0000
START: NOP
MOV R0, #0FFH;
LB: MOV R1, #0FFH;
12
LA: NOP;
DJNZ R1, LA;
DJNZ R0, LB;
CPL P2.7
SJMP START
END
1.8 Result: Embedded system board ( as shown in figure 1.5) is soldered, checked and found
working.
1.9 Conclusion:- Target board of such types can be designed using very less amount of components
and can be used for many applications.
1.10 Remarks:- Other controllers of 8051 architecture and having same pinouts can also be tested
and used on same target board .
1.11 References:-
1. Datasheet Max232
2. Datasheet P89v51RD2/AT89S52
3. http://www.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_tutorial_en.pdf
6. http://www.mikrocontroller.net/attachment/17909/Protel_99_SE_Traning_Manual_PCB_Desi
gn.pdf
13
Experiment 2
Tool Chain of Keil IDE (Embedded Development Tool Chain) with the example of
LED Blinking Program
2.1 Objective: To understand the procedure of creating source code for reprogrammable embedded
system board using IDE such as Keil µVision.
2.3 Description:
Understanding any processor or controller needs familiarity with its architecture and instruction set.
Any architecture can be best understood using its instruction set through different programs.
One may use assembly language or embedded C for writing programs. Programs written in assembly
language are completely processor dependent and need major changes when converting to other
processor. While programs written in C are generally independent of processor and needs minor
changes during conversion to other processors.
C is thus preferred for programming. But to know and understand a processor better, one must be
familiar with assembly language.
All source code written in this document will be written using assembly language for 8051
architecture.
Some development environment is needed to prepare any application. An editor is needed first to
provide a platform for writing programs i.e. source code.
A source code written in assembly/C language is needed to be converted to machine language (hex
code) before programming into processor. This conversion is done by compiler which converts
assembly/C language code to hex code.
IDE i.e. Integrated development Environment, serves both these purposes as well as provide
debugging facility.
Assembly language file will be stored by extension .asm, C file by extension .c and hex file by
extension .hex.
2.4 Procedure:
Many free software are available for educational purpose e.g. Keil, SDCCDown load free tools for
IDE from
www.keil.com/download/product,
14
https://www.keil.com/demo/eval/c51.htm
IDE for 8051 architecture can be downloaded using these links. It’s an integrated development
environment for creation and compilation of assembly/C source code for any 8051 architecture based
target boards. It also provides debugging facility [1].
Steps:
2.4.1.1 Click on Keil µVision4 icon for getting started.
2.4.1.2 Click on Project tab>Make new project> Select target device.
2.4.1.3 Click on File>New file.
2.4.1.4 Prepare a test code in assembly language as shown in editor window. Save it with .asm
extension.
2.4.1.5 Add this created file to project. One may add one or more than one file in a single
project.
2.4.1.6 Click Target1 ( at left side pane)>Source Group> Right click to add code file.
2.4.1.7 Open Project tab> Options for target target1> Output tab>check „create hex file‟
option.
2.4.1.8 Open Project tab> Build target. This will generate compiled .hex file from the .asm or
.C file, in the project created.
One may refer Help tab for further help for using this tool.
*Many video are there in you tube which may be referred to understand the procedure better.
15
To view register
s/SFRs/memory
status and content
2.5 Result: Sample program for LED blinking is written, compiled and hex file generated.
2.6 Conclusion:- Different programs can be written, debugged and simulated using IDE.
2.7 Remarks:- Different programs should be written and tested using assembly/C language for better
understanding of the tool .
2.8 References:-
[1] https://www.keil.com/demo/eval/c51.htm
16
Experiment 3
3.2.2 Hardware Requirement: Target board with P89V51RD2 controller as per circuit given in
figure 1.6, Serial Cable with DB9 Connector, Power Cable.
NOTE: Choose target processor which supports In-system programming (ISP) e.g. Phillips
P89V51RD2.
3.3 Procedure:
3.3.1 Requirements: Flash Magic works on Windows 2000, XP, Vista and 7. 10Mb of disk space is
required for reliable operation of the said tool.
17
Figure 3.1 FlashMagic Programmer
Options->Advance Options->Hardware Config and uncheck both the options as shown in figure 3.3
18
Figure 3.3 FlashMagic Programmer Communication Advance Options
Once communication between flash magic and target board established, after pressing start button,
flash programmer will show message as in figure 3.4
19
After successful programming Finished message can be 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.
3.4 Result: Sample program for LED blinking is programmed and LED blinking is observed as per
program at target board.
3.5 Conclusion:- Different hex files can be programmed and checked using flash programmer.
3.6 Remarks:- Different programs should be programmed and tested using assembly/C language for
better understanding the tool .
3.7 References:-
[1] www.flashmagictool.com
20
Experiment 4
4.2.2 Hardware Requirement: Target board with Atmel AT89S52 controller as per circuit given in
figure 1.12, Power Cable.
NOTE: Choose target processor which supports In-system programming (ISP) using SPI e.g.
Atmel AT89S52.
4.3 Procedure:
21
Figure 4.2 Application icon
STEP 3
STEP 2
STEP 1
STEP 4
STEP 5
Figure 4.3 Application 89SXX USB ISP Flash Programmer (SPI based)
Connect USB programmer with computer and target board. Steps to be followed are as described
under.
Step1:- Select Device> 8051 MCU>Atmel>AT 89S52>OK
Step2:- Browse intended hex file.
22
Step3:- Selected file will appear here.
Step4:- Click Program to flash program the selected device.
Step5:- During programming, different programming status can be seen here.
Pin configuration for ISP connectors are as shown in figure 4.4.
Figure 4.4 Pin Configuration for USB 89SXX ISP Programmer [3]
23
Figure 4.5 Schematic diagram showing connection between microcontroller and programmer [3]
24
Figure 4.5 Schematic diagram of target board using ATMEL microcontroller
4.5 Result: Target board is programmed and blinking of LED at port p2.7 i.e. pin no 28 of
microcontroller AT89S52 is obtained.
25
4.6 Conclusion: With very low component count and easily and freely available tools, designing and
programming of small and low cost systems can be achieved.
4.7 Remarks: Any IDE and any flash programmer can be used. Keil µVision, FlashMagic and
89SXX USB programmers are recommended and tested here, for their respective purposes. All these
tools are selected due to their easy accessibility, low cost and wide acceptance. Help on these tools are
easily available.
As newer PC/laptops are equipped with USB port, one can also think for USB base programmers. One
option is to choose Universal programmer, they are highly flexible in terms of device selection but are
higher in cost. For simple projects, one can easily rely on chip specific programmer which may not
provide flexibility in device selection, but are quite cheep.
*Note:- USB to RS232 converter will be needed to use Flash magic from PC’s USB port.
4.8 Reference:-
1. www.keil.com
2. www.flashmagictools.com
3. http://www.sunrom.com/337
26
Experiment No. 5
5.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
5.2.2 Hardware Requirement: 2 Sets of target boards with P89V51RD2 controller as per circuit
given in figure 1.6, Serial Cable with DB9 Connector.
5.3 Procedure:
1. Connect circuit as per given block diagram of figure 5.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 5.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.
27
Figure 5.2 Flash programmer settings for multi controller programming
5.4 Result: Both the controllers are programmed simultaneously with same program.
5.5 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.
5.6 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.
5.7 References:-
1. Datasheet Max232
2. Datasheet P89v51RD2
28
3.
Experiment 6
6.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
6.2.2 Hardware Requirement: Target boards with P89V51RD2/AT89S52 controller as per circuit
given in figure 1.6/4.5, Serial Cable with DB9 Connector/USB 89SXX Programmer with cable.
6.3 Procedure:
1. Connect 8 LEDs at port 2 (pin 21 to 28) as per given block diagram of figure6.1. Rest of the
circuit will remain same as figure 1.6/4.5
2. Write program for LED blinking at port.
3. Build/Compile project.
4. Flash program and observe results.
Microcontroller
P89V51RD2
or AT89S52
29
6.4 .1 Source Code : Table 6A
;Program written using assembly language of LCALL DELAY
8051 architecture for P89V51RD2 MOV P2,#0BFH
;This program will lit one LED at a time LCALL DELAY
;starting from port 2.0 to port 2.7 and create MOV P2,#7FH
;LED rotation pattern. All other LEDs will LCALL DELAY
;remain off. LJMP MAIN
ORG 0100
; Subroutine for some delay generation, to
MAIN: MOV P2,#0FEH view ;LED blinking
LCALL DELAY
MOV P2,#0FDH DELAY: MOV R0,#0FFH
LCALL DELAY LOOP1: MOV R1,#05H
MOV P2,#0FBH LOOP2: MOV A,#05H
LCALL DELAY LOOP3: DEC A
MOV P2,#0F7H JNZ LOOP3
LCALL DELAY DJNZ R1,LOOP2
MOV P2,#0EFH DJNZ R0,LOOP1
LCALL DELAY RET
MOV P2,#0DFH END
*Bold lines shows change in instructions
6.5 Result: Output at LEDs observed as per programs, i.e. LED rotating in circular manner is
achieved at port2.
6.6 Conclusion:- with smart use of instructions memory area of controller can be saved as can be
seen from above example.
6.7 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.
30
Experiment 7
7.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
7.2.2 Hardware Requirement: 2 sets of target boards with P89V51RD2/AT89S52 controller as per
circuit given in figure 1.6/4.5, Serial Cable with DB9 Connector/ USB 89SXX Programmer with
cable, some connectors.
7.3 Procedure:
Vcc
+5V
8LEDs at port 2 for checking
GND
31
7.4.1 Source code: Table 7A
;Program for microcontroller1, i.e. for Sender ;Subroutine for delay
;controller DELAY: MOV R0,#02
ORG 0000H LOOP1: MOV R1,#255
START: MOV A,#0FEH LOOP2: MOV R2, #255
LOOP: RR A LOOP3: DJNZ R2, LOOP3
MOV P3,A DJNZ R1, LOOP2
MOV P2,A DJNZ R0, LOOP1
LCALL DELAY RET
SJMP LOOP END
7.5 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 controller1 at port2.
7.6 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.
7.7 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.
7.8 Reference :-
1. Datasheet 89V51RD2/AT89S52
32
Experiment 8
8.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
8.2.2 Hardware Requirement: Target board with P89V51RD2 controller as per circuit given in
figure 1.6, Serial Cable with DB9 Connector.
8.3 Procedure:
1. Write source codes ( e.g. LED blinking at port) , for different blocks of memory.
2. Add all source codes into one µvision project (as described in figure 8.2).
3. Build/Compile project. Compiled file i.e. hex file will contains all source codes into one file.
4. Before programming the controllers, un-check all memory erase options (as described in figure
8.1) in flash programmer.
5. Flash program the controller and observe results.
34
Multiple
source codes
in one project
8.5 Result: Output at LEDs observed as per programs, LED blinking at port2 of controller, at
different port locations as per program. Different source codes are combined into one project as seen
in figure 5.2.
Hex file of this project is as displayed under
:100050000200537B14B2A012005FDBF902010078AA
:0C0060000279FF7AFFDAFED9FAD8F62206
:100200000202037B14B2A212020FDBF90203007890
:0C0210000279FF7AFFDAFED9FAD8F62254
:100300000203037B14B2A312030FDBF9020050783F
:0C0310000279FF7AFFDAFED9FAD8F62253
:100100000201037B14B2A112010FDBF90202007895
:0C0110000279FF7AFFDAFED9FAD8F62255
:00000001FF
35
Yellow highlight shows start of different memory block of different source codes and green highlight
shows same delay routine used in all source codes.
8.6 Conclusion:- Without erasing entire source code a part of it can be altered using memory block
programming as discussed. And hence results in saving time of programming for large programs.
8.7 Remarks: Same labels can be used in different source codes though they belong to same project.
Common routines e.g. .delay routines for different source codes in same project can also be placed at
one location and used by all programs and thus results in memory space saving.
8.8 Reference :-
1. Datasheet 89V51RD2
36
Experiment 9
9.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
9.2.2 Hardware Requirement: Target board with P89V51RD2 controller as per circuit given in
figure 1.6, Serial Cable with DB9 Connector.
9.3 Procedure:
1. Write source code for LED blinking at port, for different blocks of memory. Use source
code of experiment 5.
2. Build/Compile project.
3. At flash programmer, un-check all memory erase options. See figure 9.1.
4. At flash programmer open ISP, select Erase Flash pages. See figure 9.2.
5. Select desired page to be erased (here it is page 4), and then press erase. See figure9.2
6. Program controller with desired code and observe results.
37
Uncheck
all erase
options
38
Figure 9.2 Erase desired page of flash memory
9.5 Result: In source code of experiment 8, only third block is erased using flash page erase and then
flash is programmed with new program for LED output at port2.6.
Results observed as per programs, i.e. LED blinking at port2 of controller, at different port locations as
per program. LED blinking first at port2.0, then port2.1, and then at port 2.6 instead of port2.2 as per
experiment 5 and then at port 2.3.
9.6 Conclusion:- Same as block writing of memory, block erase of memory can also be done for
different blocks.
9.7 Remark:- Each memory location cannot be erased or programmed. This can be done only in
block defined. Means modifications will be done on entire block of memory and not on single
location.
39
Experiment 10
10.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
10.2.2 Hardware Requirement: Target board with P89V51RD2/AT89S52 controller as per circuit
given in figure 1.6/4.5, Serial Cable with DB9 Connector/ USB 89SXX programmer with cable.
10.3 Procedure:
10.5 Result: Results observed as per programs, i.e. one LED blinking at port2.2 of controller, as per
program.
10.6 Conclusion:- As timer is used to generate delay, controller is free to complete other tasks while
generating delay.
10.7 Remarks:- Using timers different functions can be achieved. E.g. generation of fixed time delay,
generation of frequency at, any I/O port etc.
Counter function of timers allow measurement of unknown frequency, event counting etc.
40
Experiment 11
11.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
11.2.2 Hardware Requirement: Target board with P89V51RD2/AT89S52 controller as per circuit
given in figure 1.6/4.5, Display circuit as per figure 11.1, Serial Cable with DB9 Connector/ USB
89SXX programmer with cable.
11.3 Procedure:
1. Connect circuit as per figure 11.1. Connect J1 and J2 between points 2 and 3.Connect
point3 of J1 to port1.6 and point3 of J2 to port1.7 of target board controller (figure1.6/4.5).
2. Short CON5 and CON6 and connect them to CON2 of target board controller
(figure1.6/4.5).
3. Write desired source code.
4. Build/Compile project and program controller with desired code and observe results.
41
11.4 Source Code: Table 11
;Only for two seven segment connected at SETB P1.7
;port2, ;control pins for common cathode type DJNZ R6,NEXTDIG
;Seven segment is connected at port 1.6 and MOV R6,#0FFH
;1.7
INC R4
ORG 0000H DJNZ R3,NEXTDIG
LJMP START1 INC R5
START1: SETB P1.7 MOV A,R5
SETB P1.6 MOV R4,#00H
MOV R5,#00H SETB P1.6
MOV R4,#00H CJNE R5,#0AH,NEXTSEG
MOV R6,#0FFH SJMP START1
NEXTSEG: MOV R3,#0AH ;DELAY ROUTINE
MOV DPTR,#1000H DELAY: MOV R0,#02
NEXTDIG: MOV A,R4 LOOP1: MOV R1,#10
MOVC A,@A+DPTR LOOP2: MOV R2,#100
MOV P2,A LOOP3: DJNZ R2,LOOP3
LCALL DELAY DJNZ R1,LOOP2
CLR P1.7 DJNZ R0,LOOP1
SETB P1.6 RET
MOV A,R5
MOVC A,@A+DPTR ORG 1000H
MOV P2,A DB 03FH, 06H, 05BH, 04FH, 66H,
LCALL DELAY 06DH, 07DH, 07H, 07FH, 067H
CLR P1.6 END
11.5 Result: Two common cathode seven segments LED displays are showing counting starting
from 0 to 99 with fixed time delay.
11.7 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.
11.8 Reference :-
1. Datasheet 89V51RD2/AT89S52
2. http://en.wikipedia.org/wiki/Seven-segment_display
42
Experiment 12
12.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer, Hyper
terminal at PC (download from http://www.hilgraeve.com/hyperterminal-trial/).
12.2.2 Hardware Requirement: Target board with P89V51RD2/AT89S52 controller as per circuit
given in figure 1.6/4.5, Serial Cable with DB9 Connector/ USB 89SXX programmer with cable.
12.3 Procedure:
43
CLR TR1 RET
MOV TMOD, #20H ;After transmit complete give indication at
; Enable interrupt servicing and serial port ;LED connected at port 2.0 and clear transmit
;interrupt, Load fdh in timer1 for 9600 baud ;flag TI
;rate. Set 8 bit UART mode and enable
;reception. After then start timer1. CHKTX: SETB P2.0
MOV IE,#90H CLR TI
MOV TH1,#0FDH RET
MOV TL1,#0FDH END
Open hyper
terminal
Click
start
Figure 12.1 Open hyper terminal for checking serial communication between PC and Target
board
44
Type any
name
Select
communication
port
45
Figure 12.4 Select options for checking serial communication
12.5 Result: Target processor is receiving from PC, and then sent back received data to PC. Results
are observed as per figure 12.5.
46
12.8 Reference :-
Datasheet 89V51RD2/AT89S52
http://en.wikipedia.org/wiki/RS-232
http://www.aggsoft.com/rs232-pinout-cable/serial-port-db9.htm
http://www.hilgraeve.com/hyperterminal/
47
Experiment 13
13.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
13.2.2 Hardware Requirement: Target board with P89V51RD2/AT89S52 controller as per circuit
given in figure 1.6/4.5, Display circuit as per figure 11.1, Serial Cable with DB9 Connector/USB
89SXX programmer with cable.
13.3 Procedure:
SCLK P1.7
MISO P1.6
SPI
SPIMaster
Master SPI Slave
MOSI P1.5
Controller Controller
SS P1.4
48
SERIAL_DATA DATA 08H MOVC A,@A+DPTR
DATA_SAVE DATA 09H MOV DATA_EX,A
DATA_EX DATA 0AH LP2: MOV A,R5
; Define SPI Control Register, MOVC A,@A+DPTR
;Configuration/status register; MOV DATA_EX,A
;Data register and Interrupt registers LJMP LOOP
; Interrupt routine, interrupt at address 0x004B
SFR SPCR = 0XD5;
SFR SPSR = 0XAA; IT_SPI: CPL P2.7
SFR SPDAT = 0X86; MOV R7,SPSR
SFR IEN0 = 0XA8; MOV ACC,R7
SFR IEN1 = 0XE8; JNB ACC.7,BREAK1
ORG 0000H SETB TRANSMIT_OK
LJMP BEGIN MOV SPSR, #00H
ORG 004BH BREAK1: JNB ACC.6, BREAK2
LJMP IT_SPI BREAK2: RETI
ORG 0100H
BEGIN: CLR P2.7 ;Delay routine
MOV R5,#00H DELAY: MOV R0,#20
MOV A,#00H LOOP1: MOV R1,#255
MOV DPTR,#1500H LOOP2: MOV R2,#255
MOVC A,@A+DPTR LOOP3: DJNZ R2,LOOP3
MOV DATA_EX,A DJNZ R1,LOOP2
ORL SPCR,#10h DJNZ R0,LOOP1
SETB P1.4 RET
ORL SPCR,#83h
ANL SPCR,#0FFh ORG 1500H
ORL SPCR,#04h DB 6DH, 38H, 77H, 3EH, 79H
SETB EA END
SETB ES
ORL SPCR,#40h
CLR TRANSMIT_OK
49
DATA_SAVE DATA 09H LOOP: JNB TRANSMIT_OK,$
DATA_EX DATA 0AH CLR TRANSMIT_OK
; Define SPI Control Register, LJMP LOOP
;Configuration/status register;
;Data register and Interrupt registers ; Interrupt routine, interrupt at address 0x004B
IT_SPI: MOV R7,SPSR
SFR SPCR = 0XD5; MOV ACC,R7
SFR SPSR = 0XAA; JNB ACC.7,BREAK1
SFR SPDAT = 0X86; MOV P2,SPDAT
SFR IEN0 = 0XA8; SETB TRANSMIT_OK
SFR IEN1 = 0XE8; MOV SPSR, #00H
ORG 000H BREAK1: JNB ACC.6, BREAK2
LJMP BEGIN BREAK2: RETI
ORG 4BH
LJMP IT_SPI END
13.5 Result: Slave processor is showing data as received from master processor. Seven segment LED
display connected at Port 2 of slave controller shows alphabets SLAUE one by one repeatedly. While
one LED connected at Port2.7 of master process toggles every time it transmits.
13.6 Conclusion:- SPI interfacing is achieved where master controls the slave.
13.7 Remark:- A master can control a number of slaves using slave select. Same source code of
master and slaves can be used for communication between one master and four slaves with changes
only in slave select.
13.8 References:-
1. 89V51Rd2 datasheet/AT89S52
2. http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
3. http://www.ecse.rpi.edu/courses/CStudio/Silabs/Appnotes/AN028.pdf
NOTE:- Program written here are as per P89V51RD2. Please refer Atmel datasheet for any
changes in SFRs used for SPI.
50
Experiment 14
14.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer.
14.2.2 Hardware Requirement: Target board with P89V51RD2/AT89S52 controller as per circuit
given in figure 1.6/4.5, Display circuit as per figure 11.1, Serial Cable with DB9 Connector/USB
89SXX Programmer with cable.
14.3 Procedure:
51
LJMP BEGIN MOV P2,SPDAT
ORG 4BH SETB TRANSMIT_OK
LJMP IT_SPI MOV SPSR, #00H
ORG 0100H BREAK1: JNB ACC.6, BREAK2
BEGIN: CLR P2.7 BREAK2: RETI
MOV R5,#00H ;Delay routine
MOV A,#00H DELAY: MOV R0,#20
MOV DPTR,#1500H LOOP1: MOV R1,#255
MOVC A,@A+DPTR LOOP2: MOV R2,#255
MOV DATA_EX,A LOOP3: DJNZ R2,LOOP3
MOV SPCR,#0D7h DJNZ R1,LOOP2
SETB P1.4 DJNZ R0,LOOP1
SETB EA RET
SETB ES
CLR TRANSMIT_OK ORG 1500H
DB 6DH, 38H, 77H, 3EH, 79H
END
52
14.5 Result: Slave processor is showing data as received from master processor. Seven segment LED
display connected at Port 2 of slave controller show alphabets SLAUE one by one repeatedly. While
eight LEDs connected at Port2 of master process shows 4 LEDs on/off every time it receives data from
slave after it transmits.
14.6 Conclusion:- Bidirectional communication between master and slave controllers using SPI
interface is achieved. It shows that either of the two controller can work as master/slave.
14.7 Remark:- Data communicated between two controllers can be stored in internal /external
memory block. Any of the participating controller can control other controller’s operations.
14.8 References:-
1. 89V51Rd2 datasheet/ AT89S52
2. http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
3. http://www.ecse.rpi.edu/courses/CStudio/Silabs/Appnotes/AN028.pdf
NOTE:- Program written here are as per P89V51RD2. Please refer Atmel datasheet for any
changes in SFRs used for SPI.
53
Experiment 15
15.2.1 Software Requirement: Editor like Keil µvision ver 4 or less, Flash programmer
15.2.2 Hardware Requirement: Target board with P89V51RD2/AT89S52 controller as per circuit
given in figure 1.6/4.5, Serial Cable with DB9 Connector/USB 89SXX programmer with cable, 16x2
LCD , 10K POT, connecting wires.
15.3 Procedure:
1. Connect LCD with target board (figure 1.6/4.5) as per figure 15.1.
2. Write desired source code as per table 15. Refer figure 15.2.
3. Build/Compile project.
4. Program controllers with desired code.
5. Close Flash programmer
6. Observe results.
89V51RD2
54
Figure 15.2 LCD module commands and instruction set
55
15.4 Source Code: Table 15
;one time usable routine for LCD initialization //Subroutine for delay used in display
DELAY1: MOV R0,#01
LCDINT: MOV P1, #00H LOOP11: MOV R1,#0100
SETB P1.0 LOOP12: MOV R2,#0255
56
NOP LOOP33: DJNZ R2,LOOP33
NOP DJNZ R1,LOOP12
MOV P0,#01H DJNZ R0,LOOP11
NOP RET
CLR P1.0 END
LCALL DELAY
15.5 Result: 16x2 LCD interfaced with controller is showing message as ‘WELCOME’ on its first
line as per the source code.
15.7 Remark:- With the same procedure 16x4, 20x2, 20x4, 40x4 etc LCD can also be interfaced. Here
care must be taken in selecting LCD display segment address. Through proper segment address one
can display data anywhere on LCD display panel.
Bidirectional communication between LCD and controller can also be done, where one can use LCD
memory space, can create own characters using CGRAM data space of LCD eg hindi character set.
15.8 References:-
1. Datasheet 89v51RD2/AT89S52
2. https://www.sparkfun.com/datasheets/LCD/ADM1602K-NSW-FBS-3.3v.pdf
57
Design & Development of a mobile design using
Raspberry Pi : A Practical Approach
(Experimental Manual for M.Tech Students)
for SoC and mobile design(Version 1, 2013-14)
with support of MHRD and NOKIA projects
Under the Guidance of: Dr. SRN Reddy, Associate Professor, CSE
58
0 2 1
Paper Code: MMC-520
Paper Title: Embedded System Design Based on ARM/Atmel Lab
59
60