You are on page 1of 38

DEPARTMENT

OF

ELECTRONICS AND COMMUNICATION


ENGINEERING

MICRO CONTROLLER
LAB MANUAL

FOR

BE ¾ YEAR 2ND SEMESTER

1
BE ¾ (ECE) 2nd Semester

MICRO CONTROLLER LAB

LIST OF EXPERIMENTS

Exp No. 1- Familiarity and use of 8051 Micro controller Trainer.

Exp No. 2- Instruction set for simple programs for data transfer,
& 3 manipulation, arithmetic operations, branching operations,
logical operations and testing condition of bit in a byte.

Exp No. 4- Code conversion programs.

Exp No. 5- Timer and counter programming using 8051

Exp No. 6- Serial mode operation of 8051

Exp No. 7- Interfacing DAC module using 8051

Exp No. 8- Interfacing Traffic signal control using 8051

Exp No. 9- Interfacing 7-segment display using 8051

Exp No.10-Interfacing Stepper motor control using 8051

Exp No.11-Familiarity with MCBX51 board and writing programs for


MCBX51. Program for Blinking of LEDs.

Exp No.12-Real time clock using 8051.

2
BE ¾ (ECE) 2ND SEMESTER

MICRO CONTROLLER LAB

LIST OF EXPERIMENTS

Experiment No.1:

Familiarity and use of 8051 (ESA-31) Micro controller kit trainer.

Experiment No.2:

Simple programs in 8051 Assembly code and their execution.

Program 1: Addition of two 16 bit numbers using registers.

Program 2: Copying of byte data in RAM memory locations using


a) Direct addressing
b) Register indirect addressing
c) Using loop structure.
Program 3: Sum of a series of byte elements

Program 4: Copying a data block from source to destination.

Program 5: Count number of 1’s in a byte.

Program 6: Multiplication of two unsigned 8-bit binary numbers.

Program 7: Division of two unsigned 8-bit binary numbers.

Program 8: Searching of a byte element in a data block.

Experiment No.3:

Arithmetic, Logical & Branching operations.

Program 9: Multi byte binary addition

Program 10: Multi byte BCD addition

3
Program 11: Multi byte binary subtraction

Program 12: Testing condition of a bit in a byte of data.

Program 13: Finding largest element in a block of data array.

Program 14: Checking a character string for a palindrome.

Experiment No. 4:

Code conversion Programs.

Program 15: ASCII to Packed BCD conversion.

Program 16: Packed BCD to ASCII conversion.

Program 17: BCD to Binary conversion.

Experiment No. 5:

Timer Programming using 8051

Experiment No. 6:

Communication with host computer system.

Experiment No. 7:

Interfacing of DAC using 8051 and its programming.

Experiment No. 8:

Interfacing of traffic signal control using 8051 and its programming.

Experiment No. 9:

Interfacing of 7-segment display using 8051 and its programming.

4
Experiment No. 10:

Program to control Stepper motor using 8051 .

Experiment No. 11:

Introduction to KEIL Software and MCBX51 kit.

Experiment No. 12:

Blinky : LED flasher program.

Experiment No. 13:

Interfacing elevator simulator control using 8051.

5
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 : Four 28-pin JEDEC sockets offer 120KB of memory as


follows.

32KB of firmware in one 27256 (Program memory)

32KB of SRAM using one 62256 (User program memory)

56KB of SRAM as data memory using two 62256s.

6
The memory map is as follows:

DEVICE ADDRESS RANGE TYPE OF MEMORY

27256 0000-7FFF Program memory

62256 8000-FFFF User program memory

62256 0000-7FFF User data memory

62256 8000-DFFF User data memory.

The dip switch settings for either mode of operation are as follows:

For Hexadecimal keypad mode: All switches in OFF position.

For Serial mode : Switches 1 and 4 in ON position.

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.

7
The 36 key keypad consists of the following group of keys.

A). Hex pad – 16 keys representing hex digits 0 through F.

B). Command Group – 13 command keys.

C). Memory Group – 4 keys (PRGMEM, EXTDATA, BITMEM,


INTDATA) to select the type of memory.

D). System Operation keys – RESET, BREAK, and EXEC keys

BREAK can be used to stop the execution without affecting the register
contents.

MONITOR COMMANDS

The keyboard monitor is capable of executing fifteen individual commands.

 EXAMINE/MODIFY MEMORY

Displays/modifies the contents of a memory location.


Syntax Format:

EXAM MEM {PRG MEM/EXT DATA/BIT MEM/INT DATA}


Addr1 NEXT [[[data] NEXT/PREV]….] EXEC

After pressing EXAM MEM key, enter the type of memory by pressing
PRGMEM, EXTDATA, BITMEM, or INTDATA key.

A dot appears at the last digit of the address field indicating that an address
entry is required.

Enter the memory address of the byte to be examined. (Memory address are
evaluated modulo 64K if it is program memory or data memory and modulo
256 if it is internal data memory or bit memory).

The value is displayed in the address field of the display.

 EXAMINE/MODIFY REGISTER

8
This command is used to examine and optionally modify the contents of
some of the 8031/8051’s registers.

EXAM REG [reg key] [[Data] NEXT/PREV]….] EXEC.

Note: When any of the registers R0-R7 has to be examined, press


EXAMREG key and then BITMEM key. Now press keys 0-7 on the hex
keypad, which corresponds to registers R0-R7.

The displayed registers contents of R0-R7 is w.r.t the current bank selected.

 GO COMMAND:

Is used to transfer control of the system from the monitor to the user’s
program.

GO [Starting addr] EXEC

To abort execution of user program press RESET key. By doing so all


registers information about user program is lost. In any case, contents of the
user portion of the RAM area are not altered by the monitor.

There are two ways to break the user program execution.

a) Set breakpoints at specific addresses, and enable them


b) Press ‘BREAK’ key.

If BREAK key is pressed, control returns to the monitor which saves all the
registers and displays the address where the program broke and the data at
that address on the display. It displays U on the special field of 7-segment
display.

9
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

(Relative address = Target address – PC contents )

Enter the codes using the format given below.

<EXAMMEM><PRGMEM> 8000 <NXT> DATA


<NXT>…..<NXT>EXEC

Note: After executing the program using GO<8000>EXEC press BREAK


key.
Press EXAMREG key twice to check result in regs R6 and R7
respectively.

10
Format:

<EXAMREG><EXAMREG><BITMEM>6<NEXT><NEXT>

2. Write an 8051 program to copy the value 55H into RAM memory
locations 40H to 44H using

A) Direct addressing mode


B) Register addressing mode without using Loop and
C) With a Loop.

3. Six bytes of data are stored in memory locations starting at 50H.


Add all the bytes. Use reg R7 to save any carries gtenerated.
Store the sum at memory locations 60H&61H.

(50) = 10h, (51) = 25H, (52) = 2AH, (53) = 4FH, (54) = 60H, (55) = 3FH

2)
A)Using direct addressing mode

MOV A,#55h
MOV 40h,A ;copy A to RAM Location
MOV 41h,A
MOV 42h,A
MOV 43h,A
MOV 44h,A
HERE : SJMP HERE

11
2.B) Using reg-indirect addressing mode without loop

MOV A.#55h
MOV R0,#40h
MOV @R0,A
INC R0
MOV @R0,A
INC R0
MOV @R0,A
INC R0
MOV @R0,A
INC R0
MOV @R0,A
HERE :SJMP HERE

2)
C) With Loop.

MOV A,#55h
MOV R0,#40h
MOV R2,#05h ;Counter
AGAIN : MOV @R0,A
INC R0
DJNZ R2,AGAIN
HERE :SJMP HERE

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 ; Counter
CLR A ; initial sum=0
MOV R7, A ; clear R7 to save carry
AGAIN: ADD A, @R0
JNC NEXT
INC R7 ; Keep track of carries
NEXT : INC R0
DJNZ R2, AGAIN
MOV 60h, A ; store LSBy of sum
MOV 61h, R7 ; store MSBy of sum
HERE : SJMP HERE

1) Format: for entering, executing & Checking results.

Enter source code


<EXM MEM> <PRG MEM> 8000 <NXT> DATA <NXT>…….
<EXEC>
Feed Sample Data
<EXM MEM> <INTDATA> 50 <NXT> DATA <NXT> DATA……..
<EXEC>
<EXM MEM> <INTDATA> 60 <NXT>00XT>00<EXEC>

Run the Program


<GO><8000> <EXEC>
Reset
Check Results
<EXM MEM> <INT DATA> 60 <NXT>….

13
4. Write an 8051 program to copy a block of 10 bytes of data from
RAM locations starting at 35h to RAM locations starting at 60h.

Sample Prob
Source block
(35)=10h, (36) =20h, (37) = 30h, (38) = 40h, (39) = 50h,
(3A) = 60h, (3B) = 70h, (3C) = 80h, (3D) = 90h, (3E) =A0h

MOV R0, #35h ; Source pointer


MOV R1, #60h ; destination pointer
MOV R3, #0Ah ; counter
BACK: MOV A,@R0
MOV @R1, A
INC R0
INC R1
DJNZ R3, BACK
HERE: SJMP HERE.

5. A byte is stored in register R0. Write a 8051 Program to find the


Number of 1’s in a byte stored in RO and Store the number of
1’s in register R2.

Let R0 = AAh 10101010

MOV R0, #AAh


MOV A, R0
MOV R2, #00h
MOV R1, #08h
LOOP: RLC A
JNC CONT
INC R2
CONT: DJNZ R1, LOOP
HERE: SJMP HERE

14
6. Write a 8051 program to multiply two unsigned 8-bit binary
Numbers. The numbers are stored in memory locations 8050h
and 8051h. Store the result in 8060h and 8061h.
Sample data:
(8050)= 41h (65)10
(8051)= 08h
(8060)= 08h
(8061)= 02h

i.e. 65X8 = (520)10 = 0208h

MOV DPTR, #8051H


MOVX A,@DPTR
MOV 0F0h, A ; multiplier in B reg
MOV DPTR, #8050h
MOVX A,@DPTR ; multiplicand in A reg
MUL AB
MOV DPTR, #8060h
MOVX @DPTR, A
INC DPTR
MOV A, 0F0h
MOVX @DPTR, A
HERE: SJMP HERE

7. Division of two unsigned 8-bit binary numbers.

Divide the number in 8050h by the number in 8051h.Store the quotient


and remainder in 8060h & 8061h of data memory respectively.

Sample data: (8050) =41h dividend


(8051)=08h divisor
Result : (8060) =08h quotient
(8061)=01h reminder

Hint: Similar to multiplication program.


Store initial divisor in B reg and dividend in A reg.
Use instruction DIV AB in place of MUL AB,
After division operation, quotient is in A reg & remainder is in B 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

MOV R1, #50h


MOV R2, #05h
LOOP: CJNE @R1, #64H, CONT
MOV R0, #00h
HERE1: SJMP HERE1
CONT: INC R1
DJNZ R2, LOOP
MOV R0, #FFh
HERE2: SJMP HERE2

Sample prob (2)


Replace data in (52) by 94h
Result = (R0) =FFh.

16
Program No 9: Multi byte Binary Addition.

Write a Program to add 4627342AH to 32B35642H.The two binary


strings starts (LSB first) in RAM memory 20H and 30H respectively
and save the result in RAM Memory locations starting at 30H replacing
the second binary string.

Sample Proof: - 4627342A H


+32B35642 H
78DA8A6CH

Sample data.

(20) =2AH, (21) =34H, (22) =27H, (23) =46H


(30) =42H, (31) =56H, (32) =B3H, (33) =32H
Result= (30) =6CH, (31) =8AH, (32) =DAH, (33) =78H.

Source Code Listing

MOV R0, #20H


MOV R1, #30H
MOV R3, #04H; Count=4
CLR C
CLR A
AGAIN: MOV A,@R0
ADDC A,@R1
MOV @R1, A
INC R0
/ INC R1
DJNZ R3, AGAIN
HERE: SJMP HERE.

17
Program N0 10: Multi byte BCD Addition.

Write a Program to add 4 byte packed BCD 46273420H to 32105644H


and save the BCD result in RAM memory locations starting at 30H.
The two BCD Strings starts (LSB first) from RAM Locations 20H &
30H respectively.

46273420
+32105644
78379064
Source code listing
MOV R0, #20H

MOV R1, #30H

MOV R3, #04H; COUNT=4

CLR C

CLR A

AGAIN: MOV A,@R0

ADDC A,@R1

DAA

MOV @R1, A

INC R0

INC R1

DJNZ R3, AGAIN

HERE: SJMP HERE.

18
Program No 11: Multi byte Binary Subtraction

Write a Program to subtract 14DF35B8H from 2F5BA7C3H, and


save the result in RAM memory location Starting at 30H.The two
binary strings starts(LSB first)from RAM location 20H & 30H
respectively

2F5BA7C3H
- 14DF35B8H
1A7C720BH

Source code listing

MOV R0, #20H


MOV R1, #30H
MOV R3, #04H ; COUNT = 4
CLR C
CLR A

AGAIN: MOV A,@R0


SUBB A,@R1
MOV @R1, A
INC R0
INC R1
DJNZ R3, AGAIN
HERE: SJMP HERE.

19
Program No 12: Checking a character string for a Palindrome.

Write a program to check if the character string of length 7, stored in


RAM locations 50H onwards is a Palindrome. If it is, output ‘Y’ to P1.

Solution:

A Palindrome is a string in which the characters are the same whether the
string is read in the forward or backward direction. Example, ‘MADAM’,
‘RADAR’.

MOV R2, #03 ; take half the string length as counter value

MOV R0, #50H ; take R0 as pointer to the forward reading

MOV R1, #56H ; take R1 as pointer for the backward reading


Of the string

Back: MOV A, @R0 ; move into A the character pointed by R0

MOV B, @R1 ; move into B the character pointed by R1

CJNE A, B, NEXT ;compare it with the character pointed by R1

INC R0 ; increment the forward counter

DEC R1 ; decrement the backward counter

DJNZ R2, BACK ; repeat until all characters are compared

MOV P1, #’Y’ ; since the string is a Palindrome output ‘Y’

NEXT: NOP ; if not equal, do nothing since it is not a


Palindrome

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 ; mask upper nibble (A=04H)

SWAP A : A=40H

INC R0

MOV 02H,@R0

ANL R2, #0FH; mask upper nibble (R2=07H)

ORL A, R2 ; A=47H, packed BCD

MOV @ R1, A ; store packed BCD

HERE: SJMP HERE.

21
2) Packed BCD to ASCII Conversion

PROGRAM:

Assume that register A has Packed BCD ,write a program to convert


packed BCD to two ASCII numbers and place them in RAM memory
location 40H and 41H respectively.
Source code listing

MOV A, #29H ;A=29H,packed BCD


MOV R2, A ; copy of BCD data in R2
MOV R0, #40H ;point to result location
ANL A, #0FH ;mask upper nibble
ORL A, #30 ;make it an ASCII,A=39H
MOV R6, A ;save it
MOV A, R2 ;get the packed BCD again
ANL A, #0F0H ;mask lower nibble
SWAP A
ORL A, #30H ;A=32H
MOV R7, A ;save ASCII
MOV @R0, 06 ;store ASCII character
INC R0 ;in memory locations
MOV @R0, 07 ; in memory locations
HERE: SJMP HERE

22
3) BCD to binary Conversion

PROGRAM
Sample example (40) = 6910 (packed BCD)
Result= (50) = 45H (Binary equivalent)
Steps.

1. Split the packed BCD into unpacked BCD digit BCD1 & BCD2
01101001  BCD1 00001001
BCD2 00000110
2. Multiply BCD2 by 10
3. Add BCD1 to the answer in step2

Source code listing

MOV R0, #40H


MOV R1, #50H
MOV A, @R0 ;get packed BCD in A reg
MOV R2, A ;save it in R2 reg
ANL A, #0FH ;mask the lower nibble
MOV R3, A ;BCD1 IN R3
MOV A, R2 ;get packed BCD again
ANL A, #0F0H ;mask the upper nibble
SWAP A ;BCD2 in A reg
MOV 0F0H, #0AH ;Reg B loaded with 10 decimal
MUL AB
ADD A, R3 ;add to BCD1`
MOV @R1, A ;store binary equivalent
HERE : SJMP HERE.
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 = 500µs.

Delay time = T/2 = 250µs.

250µs/1.085µs = 230 clocks.

65536 – 230 = (65306)10

Initial count value = FF1A h


TL1 = 1AH
TH1 = FFH

PROGRAM:

MOV TMOD, #10H ; timer1, mode1

AGAIN: MOV TL1, #1AH

MOV TH1, #0FFH

SETB TR1 ; Start timer 1

BACK: JNB TF1, BACK ; Stay until timer rolls over

CLR TR1 ; Stop timer

CPL P1.5 ; complement P1.5 to get HI, LO

CLR TF1 ; clear timer flag

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 = 500µs.

Delay time = T/2 = 250µs.

250µs/1.085µs = 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.

The Serial mode of operation

a) Supports for downloading user programs in to the target ESA 31 kit from a
Host computer system in INTEL HEX format.
b) Also supports for uploading user program to host PC and saving them as
HEX files o a system.

Using of X8051 Cross Assembler

A convenient way of creating a file to be downloaded in to ESA31 is to use a


cross assembler for 8051 that can generate the object code in extended HEX
format. X8051 is such a package.
It is a powerful cross assembler for 8051. It can run on any PC/XT/AT
compatible system and supports all the standard mnemonics, pseudo opcodes
(directives) and addressing modes of 8051.

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
Step4:-
Link the single file add16.obj
Specify code offset and options H for HEX format.
This process creates a hex file add16.hex that can download into
ESA 31 kit.

C:\51 link51

Linker copyright<c>1985-version 4.00g


Input Filename:add16.obj

Enter Offset For ‘CODE’ : 0


Input Filename:
Output Filename:

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 :P


Specify starting address : 8000
Specify ending address :

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. Write an ALP to generate Saw tooth (Up-going and down-going)


2. Write an ALP to generate Triangular waveform.
3. Write an ALP to generate Symmetrical Square wave.
4. Write an ALP to generate
A). Up going stair case with 5 steps.
B). Down going stair case with 5 steps.

Program 7.1

; Assume the DAC interface is connected over J2 of the ESA 31 trainer.

ORG 8000H
PORT_A EQU E800H
PORT_B EQU E801H
PORT_C EQU E802H
CWR EQU E803H
; Program to generate Continuous up going saw tooth.

MOV DPTR,#0E803H
MOV A,#80H
MOVX @DPTR,A ;initialize 8255A for mode 0 with
PA&PB as OUT
CLR A ;Start with value 00H
AGAIN: MOV DPTR, #0E800H;Point to Port A
MOVX @DPTR,A ;Out to Port A and
INC DPTR
MOVX @DPTR,A ;Out to Port B
INC A ;increment DAC input
SJMP AGAIN ;Repeat forever.

; Program to generate continuous down going Sawtooth

MOV DPTR,#0E803H
MOV A,#80H
MOVX @DPTR,A
MOV A,#0FFH
AGAIN: MOV DPTR,#0E800H
MOVX @DPTR,A
INC DPTR
MOVX @DPTR,A
DEC A
SJMP AGAIN

; Program to generate continuous triangular waveform

MOV DPTR,#0E803H
MOV A,#80H
MOVX @DPTR,A
CLR A
UP: MOV DPTR,#0E800H
MOVX @DPTR,A
INC DPTR
MOVX @DPTR,A
INC A
CJNE A,#0FFH,UP
DOWN :MOV DPTR,#0E800H
MOVX @DPTR,A
INC DPTR
MOVX @DPTR,A
DEC A
CJNE A,#00H,DOWN
SJMP UP
; Program to generate Symmetrical Square Wave

MOV DPTR,#0E803H
MOV A,#80H
MOVX @DPTR,A
BACK:MOV A,#0FFH
MOV DPTR,#0E800H
MOVX @DPTR,A
MOV R0,#0FFH
DLY1:DJNZ R0,DLY1
MOV A,#00H
MOVX @DPTR,A
MOV R0,#0FFH
DLY2:DJNZ R0,DLY2
SJMP BACK

; Program for Stair case (Up-going) with 5 steps.

MOV DPTR,#0E803H
MOV A,#80H
MOVX @DPTR,A
MOV A,#00H
RPT: ADD A,#33H
MOV DPTR,#0E800H
MOVX @DPTR,A
MOV R0,#0FFH
DLY1: DJNZ R0,DLY1
CJNE A,#0FFH,RPT
INC A
MOVX @DPTR,A
MOV R0,#0FFH
DLY2: DJNZ R0,DLY2
SJMP RPT

; Program for Stair case (down-going) with 5 steps

MOV DPTR,#0E803H
MOV A,#80H
MOVX @DPTR,A
MOV A,#0FFH
MOV DPTR,#0E800H
RPT: MOVX @DPTR,A
MOV R0,#0FFH
DLY1: DJNZ R0,DLY1
AGAIN:CLR C
SUBB A,#33H
MOVX @DPTR,A
MOV R0,#0FFH
DLY2: DJNZ R0,DLY2
CJNE A,#00H,AGAIN
DEC A
SJMP 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 EA ERg EL SR SA SRg SL

PORT B:
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


Vehicles from WEST can go EAST and NORTH
Vehicles from NORTH can go EAST
Pedestrians can cross on SOUTH

5. No vehicle movement
Pedestrians can cross on all four roads.

The system moves from one state to another state after fixed time delay. The state
transition is indicated by turning ON all the AMBER LEDs and all Pedestrians RED
LEDs for a fixed duration. The sequence of the above states is repeated again and again.

; Program memory from 8000H to 804FH

ORG 8000H
PORTA EQU E800H
PORTB EQU E801H
PORTC EQEU E802H
CWR EQU E803H

MOV DPTR,#0E803H
MOV A,#80H
MOVX @DPTR,A
AGAIN: MOV DPTR,#PORTS
NEXTST: MOVX A,@DPTR
PUSH DPL
PUSH DPH
MOV DPTR,#0E800H ;Port A value.
MOVX @DPTR,A
POP DPH
POP DPL
INC DPTR
MOVX A,@DPTR
PUSH DPL
PUSH DPH
MOV DPTR,0E801H ;Port B value.
MOVX @DPTR,A
POP DPH
POP DPL
INC DPTR
MOVX A,@DPTR
PUSH DPL
PUSH DPH
MOV DPTR,#0E802H ;Port C value.
MOVX @DPTR,A
POP DPH
POP DPL
INC DPTR
LCALL DELAY ;Provide delay
MOV A,DPL
CJNE A,#1EH,NEXTST
SJMP AGAIN
DELAY: MOV R2,#06 ;Delay routine
LOOP3: MOV R4,#0FFH
LOOP2: MOV R3, #0FFH
LOOP1: DEC R3
CJNE R3,#00,LOOP1
DEC R4
CJNE R4,#00,LOOP2
DEC R2
CJNE R2,#00,LOOP3
RET

; Enter the data mentioned below from 0000H to 001EH in data memory.

PORTS: DB 10H, 81H, 7AH ;state 1


DB 44H, 44H, 0F0H ;All Ambers ON
DB 08H, 11H, 0E5H ;State 2
DB 44H, 44H, 0F0H ;All Ambers ON
DB 81H, 10H, 0DAH ;State 3
DB 44H, 44H, 0F0H
DB 11H, 08H, 0B5H ;State 4
DB 44H, 44H, 0F0H
DB 88H, 88H, 00H ;State 5
DB 44H, 44H, 0F0
DB 00H ;Dummy

You might also like