Micro Controller Lab Manual 1
Micro Controller Lab Manual 1
OF
ELECTRONICS AND COMMUNICATION
ENGINEERING
MICRO CONTROLLER
LAB MANUAL
FOR
BE YEAR 2ND SEMESTER
EXPERIMENT NO. 1
Familiarity with ESA 31 micro controller kit:
Main features of ESA 31 (8031 based):
ESA 31 can be operated either from on board keyboard or from a CRT
terminal through its RS 232-C interface.
Keyboard and serial monitor programs support the entry of users program,
editing, debug facilities like breakpoints & single stepping, & full execution
of user programs.
1-pass Assembler can assemble any memory resident assembly language
program.
1-pass Dis assembler dis assembles the object code into standard INTEL
mnemonics.
Total of 120KB memory is provided of which 64KB of memory is program
memory and 56KB of memory is data memory.
The monitor of the trainer occupies 32KB out of 64KB of program memory.
Standard bus compatible signals available on the bus connector for easy
expansion.
SPECIFICATIONS:
Microcontroller: 8031/8051 operated at 11.0592 MHz
Memory
follows.
ADDRESS RANGE
TYPE OF MEMORY
27256
0000-7FFF
Program memory
62256
8000-FFFF
62256
0000-7FFF
62256
8000-DFFF
The dip switch settings for either mode of operation are as follows:
For Hexadecimal keypad mode: All switches in OFF position.
For Serial mode
KEYBOARD MONITOR
In the keyboard mode, the user enters the commands and data by pressing
the appropriate keys on the keypad. Responses are displayed by the system
on the seven-digit 7-segment LED display.
The RESET key causes a hardware reset and restarts the monitor. The
monitor displays the sign-on message ESA 51 across the address & data
fields of the display.
KEYBOARD & DISPLAY
The display consists of 7 seven segment LED displays, separated into three
fields. The leftmost single digit forms the special field. Next four digits
form the address field.
Note: address can be 64KB or 256B max.
Last two digits form the data field.
EXPERIMENT NO 2 & 3
Execution of simple programs using ESA-31 in keyboard mode.
Program Examples:
1. Write a program in 8051 to add two 16-bit numbers.
The numbers are 3CE7H and 3B8DH. Place the sum in registers
R7 and R6; R6 has the lower byte.
Address
OBJECT Code
Mnemonic
8000
C3
CLR C
8001
74 E7
MOV A, #0E7H
8003
24 8D
ADD A, #8DH
8005
FE
MOV R6, A
8006
74 3C
MOV A, #3CH
8008
34 3B
ADDC A, #3BH
800A
FF
MOV R7, A
800B
80 FE
HERE:SJMP
HERE
Format:
<EXAMREG><EXAMREG><BITMEM>6<NEXT><NEXT>
2. Write an 8051 program to copy the value 55H into RAM memory
11
12
3)
Sample data: (50) =10h, (51)=25h, (52)=2AH, (53)=4Fh, (54)=60h,
(55)=3Fh
Result = (60)=4Dh
(61)=01h (MS byte)
014Dh
Source Code
MOV R0, #50h
MOV R2, #06h
CLR A
MOV R7, A
AGAIN: ADD A, @R0
JNC NEXT
INC R7
NEXT : INC R0
DJNZ R2, AGAIN
MOV 60h, A
MOV 61h, R7
HERE : SJMP HERE
; Counter
; initial sum=0
; clear R7 to save carry
; Keep track of carries
; store LSBy of sum
; store MSBy of sum
13
; Source pointer
; destination pointer
; counter
10101010
14
; multiplier in B reg
; multiplicand in A reg
15
8. Write a 8051 program to find the number 64h from the set of five
Readings starting from address location 50H to 54h. If present
store 00h in R0,otherwise store FFh in R0.
Sample Problem (1):
i)
(50) =76h, (51) =45h, (52) =64h, (53) =25h, (54) =22h.
Result = (R0) =00h
16
17
18
; COUNT = 4
19
MOV B, @R1
CJNE A, B, NEXT
INC R0
DEC R1
MOV P1, #Y
NEXT: NOP
END
20
EXPERIMENT -4
CODE CONVERSION
2) ASCII to Packed BCD Conversion
Write a program to convert two ASCII decimal digits available in
RAM locations 30H and 31H into packed BCD number and store the
result in RAM location 40H.
Sample data:- (30) =34H 4
(31)=37H 7
Result= (40) =47H (packed BCD)
Source code listing
MOV R0, #30H
MOV R1, #40H
MOV A,@R0
ANL A, #0FH
SWAP A
: A=40H
INC R0
MOV 02H,@R0
ANL R2, #0FH; mask upper nibble (R2=07H)
ORL A, R2
SJMP HERE.
21
;A=29H,packed BCD
; copy of BCD data in R2
;point to result location
;mask upper nibble
;make it an ASCII,A=39H
;save it
;get the packed BCD again
;mask lower nibble
;A=32H
;save ASCII
;store ASCII character
;in memory locations
; in memory locations
22
EXPERIMENT NO. 5
TIMER PROGRAMMING USING 8051
Task:
Assuming XTAL = 11.0592MHz, write a program for timer 1 in mode 1 to generate
a square wave of 2KHz frequency on Pin P1.5 (Pin No. 6) GND (Pin 20)
Steps:
T = 1/f = 1/2 KHz = 500s.
Delay time = T/2 = 250s.
250s/1.085s = 230 clocks.
65536 230 = (65306)10
Initial count value = FF1A h
TL1 = 1AH
TH1 = FFH
PROGRAM:
MOV TMOD, #10H
; timer1, mode1
; Start timer 1
; Stay until timer rolls over
CLR TR1
; Stop timer
CPL P1.5
CLR TF1
SJMP AGAIN
; reload timer
Note: SFR address of TMOD = 89H, TL1 = 8BH, TH1 = 8DH, TR1 = 8EH, TF1 = 8FH,
P1.5 = 95H.
Note: Observe the output waveform across Pin 6 & 20 on CRO; and note down time
period.
Write a program using timer 1 to generate a square wave of 2KHz frequency on Pin
P1.5 (Pin 6) in mode 2 configuration (auto reload mode) GND (Pin 20)
XTAL = 11.0592 MHz
T = 1/f = 500s.
Delay time = T/2 = 250s.
250s/1.085s = 230 clocks.
256 230 = (26)10 = 1A H
Load TH1 with initial count value of 1AH.
PROGRAM:
MOV TMOD, #20h; timer1, mode2
MOV TH1, #1Ah
SETB TR1
BACK: JNB TF1, BACK
CPL P1.5
CLR TF1
SJMP BACK; mode 2 is auto reload.
Note: Observe the output waveform across Pin 6 & 20 on CRO; and note down time
period.
Experiment No.6
Communication with a Host Computer System
ESA 31 operating in the serial mode, can be connected to either a CRT terminal or a
host computer system.
When a computer system is the controlling element, it must be executing driver software
to communicate with the ESA 31 target kit.
ESA 31 is supplied with DOS communication driver package XT51 which allow the user
to establish serial communication between the trainer and a host PC thro its
Asynchronous com ports (COMI and COM2).
INSTALLATION
a) Configure ESA 86/88E for serial mode of operation and set the serial port of
ESA 86/88E for 9600 Baud rate and No parity(keep DIP switches 1 and 4 in
ON position)
b) Connect the PC to ESA 31 trainer over COM1/COM2 serial port using the
RS232C serial interface cable connecter.
Steps involved in creating a HEX file are as follows:Step1:Select the path folder directory
C:\> cd
C:\> cd51
C:\> edit filename
Step2:Create a source file using the DOS text editor and save it as filename.asm.
Example:
Write a source program for 16 bit addition using DOS text editor. The
numbers are 3CEH and 3B8DH. Place the sum in R7 and R6; R6 should have the
lower byte.
Org 8000h
CLR C
Mov a ,#0E7h
Add a,#8Dh
Mov r6,a
Mov a,#3ch
Addc a,#3bh
Mov r7,a
Here :sjmp here
Save and exit from editor,
Let the source file be saved as add 16.asm
Step3:Assemble the source file add16.asm using X8051 to create an object file
add16.obj as follows
C:\51 x8051
Listing destination <N,T,D,E,L,P<CR>=N>:d
Generate cross reference?<Y/N <CR>=N>:n
Input Filename : add16.asm
Output Filename:
8051 CROSS ASSEMBLER-VERSION 4.00f
Input Filename :
add16.asm
Output Filename :
add16.obj
Lines Assembled:________
Assembly Errors:_______
C:\51
Options(D,S,A,M,X,H,E,T,1,2,3,(CR)=Default):h
Link Errors:________
Output Format:_______
C:\51
Step5:-(Optional)
Check the directory to see the files
Created for add 16
C:\51 dir
Also check the list file for add16 as
C:\51 edit add16.list
Step6:Set the system in the serial communication mode using the XT51 command
C:\86>xt51
Now the following message will appears on the Screen
__________________XT51 Version x, y_____________________
ELECTRO SYSTEM ASSOCIATES PVT LTD
BANGALORE
Press any Key to Continue
_____________________________________________________________
XT51 Checks for the presence of communication ports COM1 and COM2
If Serial communication is established successfully the command
prompt . Appears on the screen otherwise the communication parameters
are set appropriately using ALT+S command and continue.
Subsequently during the POWER ON RESET, the following sign on
message appears on the screen followed by command prompt.
ESA 31 MONITOR VERSION x.y
Step7:Download the program hex file from host PC to ESA 51 trainer using the
CTRL+D command
CTRL+D
Specify download filename
Add16.hex
Specify memory type
Specify starting address
Specify ending address
:P
: 8000
:
Downloading program
Run the program using G command as
G 8000
Press Break Key
Note:
If input data is to be entered use >md commands to enter the data.
Press ESC key to return to command Prompt. >
Use the M (Modify memory) command to examine the contents of specified
memory locations.
Further, if the locations are in RAM, their contents can be altered if desired.
Format: - M {P|D|I|B} addresses 1[address 2] <cr>
Ex 1: Examine a series of RAM locations starting at 8820H and modify the
contents of the location 8822H.
>MD88220
88220 XX<CR>
88221 XX<CR>
88222 XX 55<CR>
> 88220 XX<ESC>
EX 2:
To enter data at int RAM locations starting at 40H.
>MI 40<CR>
40 XX 21<CR>
41 XX 22<CR>
43 XX 55<CR>
>44 XX<ESC>
(2) M (Display Memory) Command.
This command is used to display the contents of the Program or
External or Internal Memory.
Foramt:
M {P|D|I}, address1.address2<CR>
EX:
To display the Contents of 5 Bytes from location 8020H.
>Md8020, 8024<CR>.
MICROCONTROLLER LAB
EXPERIMENT NO.6
Generation of Waveforms using DAC interface module
AIM:
To write and execute program in 8051 assembly language for interfacing a DAC
interface module with ESA 31 microcontroller trainer kit.
APPARATUS:
1. ESA 31 Microcontroller trainer kit
2. Dual channel DAC module
3. Power supply units
4. 26 Pin connector cable
5. CRO
DESCRIPTION:
To use DAC, initialize 8255A for mode 0 operation with port A and port B as
output. Output data on the appropriate port and observe output wave form at Xout and
Yout of the DAC using CRO.
The 16 bit port addresses for 8255A available at J2 connector are:
Port A
Equ E800H
Port B
Equ E801H
Port C
Equ E802H
Port D
Equ E803H
Note: Port A controls Xout and Port B controls Yout of DAC interface module.
PROGRAMS:
1.
2.
3.
4.
Program 7.1
; Assume the DAC interface is connected over J2 of the ESA 31 trainer.
ORG
PORT_A
PORT_B
PORT_C
8000H
EQU E800H
EQU E801H
EQU E802H
CWR
EQU E803H
; Program to generate Continuous up going saw tooth.
MOV
MOV
MOVX
CLR
AGAIN: MOV
MOVX
INC
MOVX
INC
SJMP
DPTR,#0E803H
A,#80H
@DPTR,A
;initialize 8255A for mode 0 with
PA&PB as OUT
A
;Start with value 00H
DPTR, #0E800H;Point to Port A
@DPTR,A
;Out to Port A and
DPTR
@DPTR,A
;Out to Port B
A
;increment DAC input
AGAIN
;Repeat forever.
DPTR,#0E803H
A,#80H
@DPTR,A
A,#0FFH
DPTR,#0E800H
@DPTR,A
DPTR
@DPTR,A
A
AGAIN
DPTR,#0E803H
A,#80H
@DPTR,A
A
DPTR,#0E800H
@DPTR,A
DPTR
@DPTR,A
A
A,#0FFH,UP
DPTR,#0E800H
@DPTR,A
DPTR
@DPTR,A
A
A,#00H,DOWN
SJMP
UP
; Program to generate Symmetrical Square Wave
MOV
MOV
MOVX
BACK:MOV
MOV
MOVX
MOV
DLY1:DJNZ
MOV
MOVX
MOV
DLY2:DJNZ
SJMP
DPTR,#0E803H
A,#80H
@DPTR,A
A,#0FFH
DPTR,#0E800H
@DPTR,A
R0,#0FFH
R0,DLY1
A,#00H
@DPTR,A
R0,#0FFH
R0,DLY2
BACK
DPTR,#0E803H
A,#80H
@DPTR,A
A,#00H
A,#33H
DPTR,#0E800H
@DPTR,A
R0,#0FFH
R0,DLY1
A,#0FFH,RPT
A
@DPTR,A
R0,#0FFH
R0,DLY2
RPT
DPTR,#0E803H
A,#80H
@DPTR,A
A,#0FFH
DPTR,#0E800H
@DPTR,A
R0,#0FFH
R0,DLY1
C
SUBB
MOVX
MOV
DLY2: DJNZ
CJNE
DEC
SJMP
A,#33H
@DPTR,A
R0,#0FFH
R0,DLY2
A,#00H,AGAIN
A
RPT
EXPERIMENT NO.8
Interfacing of Traffic Light Controller Using 8051
The traffic light interface simulates the control and operation of traffic lights at a junction
of four roads. The interface provides a set of 6 LED indicators at each of the four
corners. Each of these LED s can be controlled by a port line. Thus the interface allows
the user to simulate a variety of traffic simulations using appropriate software routines.
DESCRIPTION OF THE CIRCUIT :
The organization of 6 LED s is identical at each of the four corners. The organization
with reference to the LED s at South-West corner is shown in figure.1
R = SOUTH RED
A = SOUTH AMBER
L = SOUTH LEFT
S= SOUTH STRAIGHT
Rg=SOUTH RIGHT
DL=SOUTH
PEDESTRIAN
The five LED s (except
Pedestrian) will be ON or
OFF depending on the state
of corresponding port line
LED is ON, if the Port line
is Logic HIGH and LED
is OFF, if it is at logic
LOW.
The last LED
marked DL is a set of two
dual color LED s and they
both will be either RED or GREEN depending on the state of the corresponding port line
RED if the port line is logic HIGH and GREEN if the port line is logic LOW.
24 LEDS AND CORRESPONDING PORT LINES:
PORT A:
D7
D6
D5
D4
D3
D2
D1
D0
_____________________________________________
ER
PORT B:
EA
ERg
EL
SR
SA
SRg
SL
D7
D6
D5
D4
D3
D2
D1
D0
_____________________________________________
WR
WA
WRg WL
NR
NA
NRg
NL
PORT C:
D7
D6
D5
D4
D3
D2
D1
D0
____________________________________________
EP
SP
WP
NP
SS
ES
NS
WS
There are four such sets of LED s and these are controlled by 24 port lines of 8255A.
Each port line is inverted and buffered using 7406 (open collector inverter buffers) and is
used to control an LED. Dual color LEDs are controlled by a port line and its
complement.
INSTALLATION:
The interface module has 26 pin connector at one edge of the card. This is used for
connecting the interface over J2 of the ESA 31 trainer. The trainer can be in
KEYBOARD MODE or SERIAL MODE.
PROBLEM STATEMENT:
Generate the sequence for PA, PB, and PC such that the following traffic situations are
simulated.
1. Vehicles from SOUTH can go NORTH and WEST
Vehicles from WEST can go NORTH
Vehicles from NORTH can go SOUTH
Pedestrians can cross on EAST
2. Vehicles from EAST can go WEST and SOUTH
Vehicles from WEST can go EAST
Vehicles from SOUTH can go WEST
Pedestrians can cross on NORTH
3. Vehicles from EAST can go SOUTH
Vehicles from NORTH can go SOUTH and EAST
Vehicles from SOUTH can go NORTH
Pedestrians can cross on WEST
4. Vehicles from EAST can go WEST
EQU
EQU
EQEU
EQU
8000H
E800H
E801H
E802H
E803H
DPTR,#0E803H
A,#80H
@DPTR,A
DPTR,#PORTS
A,@DPTR
DPL
DPH
DPTR,#0E800H
@DPTR,A
DPH
DPL
DPTR
A,@DPTR
DPL
DPH
DPTR,0E801H
@DPTR,A
DPH
DPL
DPTR
A,@DPTR
DPL
DPH
DPTR,#0E802H
@DPTR,A
DPH
;Port A value.
;Port B value.
;Port C value.
POP
INC
LCALL
MOV
CJNE
SJMP
DELAY: MOV
LOOP3: MOV
LOOP2: MOV
LOOP1: DEC
CJNE
DEC
CJNE
DEC
CJNE
RET
DPL
DPTR
DELAY
A,DPL
A,#1EH,NEXTST
AGAIN
R2,#06
R4,#0FFH
R3, #0FFH
R3
R3,#00,LOOP1
R4
R4,#00,LOOP2
R2
R2,#00,LOOP3
;Provide delay
;Delay routine
; Enter the data mentioned below from 0000H to 001EH in data memory.
PORTS:
DB
DB
DB
DB
DB
DB
DB
DB
DB
DB
DB
;state 1
;All Ambers ON
;State 2
;All Ambers ON
;State 3
;State 4
;State 5
;Dummy