0% found this document useful (0 votes)
23 views

MC Lab Manual Cbcs 2021

Uploaded by

Guru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

MC Lab Manual Cbcs 2021

Uploaded by

Guru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

National Education Society ®

JAWAHARLAL NEHRU NEW COLLEGE OF ENGINEERING,


SHIVAMOGGA

DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING

LABORATORY MANUAL

MICROCONTROLLER LABORATORY
IPCC Course Code 21EE43

Name of the Student: ___________________________________________________

University Seat No. : ___________________________________________________

Semester: _________________ Section: _______________________

Batch No. : ________________

Dept. of EEE, JNNCE Page 1


JAWAHARLAL NEHRU NEW COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING

INSTITUTE VISION

 To be a pacesetting institute in technical & management education and research for


producing highly competent engineers, managers & entrepreneurs to meet the needs
of industry and society.

INSTITUTE MISSION

 Impart quality education through flexible and innovative teaching learning process.
 Enable and Ignite young minds to excel in their career and life with entrepreneurial
spirit, professional ethics and human values.
 Facilitate invention based research and collaborate with industries to address societal
needs.

DEPARTMENT VISION

 To be a premier department in Electrical and Electronics Engineering by excelling in


imparting education and facilitating research through team work to cater the ever
growing needs and aspirations of industry and society.

DEPARTMENT MISSION

M1. Strive to deliver quality technical education through continuous teaching and learning
process.

M2. Incorporating emerging technologies in the core and related areas of Electrical
Engineering combined with professional ethics and managerial skills for the students to excel
in their career.

M3. Encouraging students to take up need based project / research for the societal needs.

Dept. of EEE, JNNCE Page 2


PROGRAM EDUCATIONAL OBJECTIVES

PEO1: Graduates of the Program will acquire Professional and Academic excellence in the
field of Electrical & Electronics Engineering and Associated fields.

PEO2: Graduates of the Program will apply their Knowledge in the Operation, Control and
Maintenance of Power sector and related industries.

PEO3: Graduates of the Program will acquire Multi-disciplinary Knowledge and Skills to
Development of solutions for Societal and Industrial needs.

PROGRAM SPECIFIC OUTCOMES

PSO1: Apply the acquired Knowledge of Power generation, Transmission, Distribution,


Control and Protection of Power system equipment’s.

PSO2: Use the fundamentals of Electrical Machines, Power electronics and Control systems
in solving Real-time problems of industry.

PSO3: Explore the Opportunities in Energy Conservation and Use of Renewable Energy for
Societal needs.

Dept. of EEE, JNNCE Page 3


PROGRAM OUTCOMES (POs)

Engineering Graduates will be able to:

PO1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
PO2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3. Design/development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
PO4. Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data, and
synthesis of the information to provide valid conclusions.
PO5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modelling to complex engineering
activities with an understanding of the limitations.
PO6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
PO7. Environment and sustainability: Understand the impact of the professional
engineering solutions in societal and environmental contexts, and demonstrate the knowledge
of, and need for sustainable development.
PO8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
PO9. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
PO10. Communication: Communicate effectively on complex engineering activities with
the engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give and
receive clear instructions.
PO11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
PO12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological change.

Dept. of EEE, JNNCE Page 4


MICROCONTROLLER LABORATORY
SYLLABUS

COURSE OUTCOMES

At the end of the course, the students will be able to,

1. Apply the fundamentals of assembly level programming to demonstrate simple applications.


2. Develop assembly level programs to simulate code conversions and sorting operations.
3. Implement embedded C programs & APL using Keil µVision-5 Embedded Workbench tools.
4. Interface 8051 Microcontroller to peripheral devices.

CO- PO Mapping:

CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
3 - - - 2 - - - 2 - - -

2 - 3 - 2 - - - 2 - - -

2 - 3 - 3 - - - 2 - - -

3 - 3 - 3 - - - 2 - - -

2.5 - 3 - 2.5 - - - 2 - - -

Dept. of EEE, JNNCE Page 5


CO- PSO Mapping:

PSO1 PSO2 PSO3


21EE43
- 2 -

2 - -

- 2 -

2 - -

2 2

CIE Evaluation Scheme & Rubrics:

Parameter Marks Allocated


Weekly Lab Assessment 30
Test 20
Total marks 50

Weekly assessment Marks Allocated


a) Write-up 06
b) Viva 06
c) Conduction 12
d) Attentiveness 06
Total marks 30

Dept. of EEE, JNNCE Page 6


JAWAHARLAL NEHRU NEW COLLEGE OF ENGINEERING, SHIVAMOGGA
DEPARTMENT OF ELECTRICAL & ELECTRONICS ENGINEERING

LAB ASSESSMENT Batch:

Lab Name: Microcontroller Lab code: 21EE43

Faculty in charge: VSM & MRS Academic year: 2022-23


Student name: Sem. & Section: 4th SEM
USN: Max. Marks: 50

Sl. Date Expt Write Viva Conduction Attentiveness Total Signature


No. . No. up(6) (6) (12) (6) (30)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Average lab Marks

Lab Marks (30) Test (20) Total (50) Faculty Signature

INDEX
Dept. of EEE, JNNCE Page 7
SL. PAGE
TITLE OF THE EXPERIMENT
NO. NO.

10

11

12

13

14

15

Dept. of EEE, JNNCE Page 8


Microcontroller Lab Manual

A microcontroller is a small computer on a single integrated circuit containing a


processor core, memory, and programmable input/output peripherals. Unlike a
microprocessor, a uC is completely integrated and consists of all the required devices.
In fact, a uP is a component present within a uC as already described.

Microcontrollers are used in a variety of applications. Most of the modern day devices
cannot work without a microcontroller. These single chip devices are multifunctional
and have high bit handling capabilities.

Microcontrollers need to be programmed in a specific way in order to perform a given


task. The programming can be done using a normal computer via software like Keil
uVision etc. After the programming is done, this series of instructions needs to be
copied to the required uC. This is called dumping a program.

The most widely used uC’s are the 80xx series and the MSP series.

Dept. of EEE, JNNCE Page 9


Write an ALP to initialize a value to register A and copy the content of A to registers of
Bank 0.

Start

Initialize value to A
register

Copy the content of A to


R0-R7 register

End

Label Mnemonic Address Op-code Comments


Start: org 0000
MOV A,#09
MOV R0,A
MOV R1,A
MOV R2,A
MOV R3,A
MOV R4,A
MOV R5,A
MOV R6,A
MOV R7,A
END: END

MOV DESTINATION, SOURCE

Dept. of EEE, JNNCE Page 10


1. A Write an ALP to transfer block of 5 datas from location x (internal RAM) to
location Y (internal RAM).

It is assumed that location X & Y starts from RAM location 30H & 40H respectively.

Label Mnemonic Address Comments

Defining code location to start from location


org 0000 0000.

Initializing r0 as memory pointer to location x.


mov r0,#0x30
mov r1,#0x40 Initializing r1 as memory pointer to location y.

Number of data in the array is defined as a


mov r2,#0x05 count .

loop: mov a,@r0 Reads a data from location x.

mov @r1,a Transfers data to location y.

inc r0 Points to next location in x.

inc r1 Points to next location in y.

Repeats data transfer until all the data are


djnz r2,loop transferred.

exit: sjmp exit Specifies logical end of the program.

end Specifies physical end of the program.

Dept. of EEE, JNNCE Page 11


1. B Write an ALP to exchange block of 5 data between two locations (Internal RAM)

It is assumed that location X & Y starts from RAM location 30H & 40H respectively.

OPCODE Label Mnemonic Address Comments

Defining code location to start from location


org 0000 0000.

Initializing r0 as memory pointer to location x.


mov r0,#0x30
mov r1,#0x40 Initializing r1 as memory pointer to location y.

Number of data in the array is defined as a


mov r2,#0x05 count .

loop: mov a,@r0 Reads a data from location x.

mov r3,a Copies data to a temporary register

mov a,@r1 Reads a data to acc from location y

mov @r0,a Transfers data to location x

mov a,r3 From temp register move data to acc

mov @r1,a Transfers data to location y

inc r0 Points to next location x

Inc r1 Points to next location y

Repeats data transfer until all the data are


Djnz r2,loop transferred.

exit: sjmp exit Specifies logical end of the program.

end Specifies physical end of the program.

Dept. of EEE, JNNCE Page 12


1. C Write an ALP to to find Largest number in array block size =5.

Label Opcode Mnemonic Comments

Org 0000

Mov r0,#30h Move r1 with address of data array

Mov r1,#05H R1 is loaded with block size. Here it is 5

Mov B,#00H B holds Largest numb, initially B=0

loop1: mov a,@r0 Get first data into accumulator

Cjne a,b,loop2 Compare A[first data] with B[largest num], if not equal jump
to label loop2 location
loop2: Jc loop3 If A < B, c =1, then jump to label Loop3

Mov b,a If A > B, then mov A to B. Always B hold largest num

loop3: Inc r0 Increment r0 by 1, to get next data

Djnz r1,loop1 Decrement R1, if R1 not zero, jump to label loop1

Sjmp $ Unconditional short jump to the current address, essentially


creating an infinite loop
END

Note: check largest number should be in ‘B’ register.

Dept. of EEE, JNNCE Page 13


1. D Write an ALP to arrange an array in Ascending order [ Array of 5 data ].

Label Opcode Mnemonic Comments

Org 0000H

Mov r7,#04h Load r7 with 04 [5-1=4] to do 4


comparison
Main: Mov r0,#30h Load r0 with source location address

Mov r6,#04h

up: Mov a,@r0 Mov Acc with content of address present in


R0
Inc r0 Increment r0 by 1

Mov b,@r0 Move B reg with content of address present


in r0
CJNE A,b,next Compare two data [A-B]

next: JC noexchange If A < B jump to label noexchange

Mov @r0,A If A > B move Acc content to address point


by R0
Dec r0 Decrement R0 by 1

Mov @r0,B Move B reg content to address present in


R0
Inc r0 Again increment R0 by 1, After exchange
again come to next location
noexchange: DJNZ r6,up Decrement R6, if not equal to zero, jump to
label UP
Djnz r7,Main Decrement R6, if not equal to zero, jump to
label main
Sjmp $ Unconditional short jump to the current
address, essentially creating an infinite loop
end

Dept. of EEE, JNNCE Page 14


2. A Write an ALP for arthmatic & logic instructions [AT89C51]

Label Mnemonic Comments

Mov a,#25h
load 25H into acc
Mov b,#12h Load 12h into b reg

Add a,b Add contents of a into b, result stored in a

Mov 40h,a Store result in location 40h from acc

Mov a,#25h Again load acc by a value

Subb a,b Subtract with borrow from acc with B

Mov 41h,a Store result in location 41h

Mov a,#25h Again load acc by immediate value

MUL AB Multiplication acc and B

Mov 42h,a Result lower byte in acc

Mov 43h,b Result higher byte in B

Mov a,#25h load 25H into acc

Mov b,#12h Load 12h into b reg

DIV AB Divide a by b result acc= quotient, B = remainder.

Mov 44h,A Store quotient in location 44h

Mov 45h,B Store remainder in location 45h

Mov a,#25h load 25H into acc

Mov b,#12h Load 12h into B reg

ANL A,B Logical AND content of Acc with B

Mov 46h,a Store result location 46h

Mov a,#25h load 25H into acc

Mov b,#12h Load 12h into B reg

ORL A,B Logical OR content of Acc with B

Mov 47,a Store result location 47h

HERE: SJMP HERE stay in this loop

END end of asm source file

Dept. of EEE, JNNCE Page 15


3. B Write an ALP to implement an 8 bit UP/DOWN BCD counter. [AT89C51]

Label Mnemonic Comments

Org 0000h

LJMP 8000H

ORG 8000H

MOV A,#99H

BACK : ACALL DELAY

ADD A,#99H

DA A

JNZ BACK

HERE : SJMP HERE

DELAY: MOV R1,#0FFH

DECR1 : MOV R2,#0FFH

DECR : MOV R3,#0FFH

DJNZ R3,$

DJNZ R2,DECR

DJNZ R1,DECR1

RET

END

Note: view - watch window - watch1 and watch2, to edit name press F2 key on watch
window and value will change in real time.

Dept. of EEE, JNNCE Page 16


3) Counter
3a) Write an ALP to generate Hex up counter.
3b) Write an ALP to generate Hex down counter.
3c) Write an ALP to generate BCD up counter
3d) Write an ALP to generate BCD down counter.
3a) Write an ALP to generate Hex up counter

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV A,#00H load the accumulator with 00H
LCALL DELAY call delay
UP:
INC A increment accumulator by 1
CJNE A,#40H,UP compare accumulator with 40h if not equal jump up
LCALL 0003H end
MOV R0,#0FFH load r0 by FFH
DELAY:
MOV R1,#0FFH load r1 by FFH
BACK1:
MOV R2,#0FFH load r2 by FFH
BACK:
DJNZ R2,HERE decrement r2 if not equal to zero jump here
HERE:
DJNZ R1,BACK decrement rl if not equal to zero jump Back
DJNZ R0,BACK1 decrement 0 if not equal to zero jump Back1
RET return to main
END

3b) Write an ALP to generate Hex down counter

Dept. of EEE, JNNCE Page 17


Label Opcode and Comments
Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV A,#020H load the accumulator with 20H
UP: LCALL DELAY call delay
DEC A decrement accumulator by 1
CJNE A,#00H,UP compare accumulator with 00h if not equal jump up
LCALL 0003H end
MOV R0,#0FFH load r0 by FFH
DELAY:
MOV R1,#0FFH load r1 by FFH
BACK1:
MOV R2,#0FFH load r2 by FFH
BACK:
DJNZ R2,HERE decrement r2 if not equal to zero jump here
HERE:
DJNZ R1,BACK decrement R1 if not equal to zero jump Back
DJNZ R0,BACK1 decrement 0 if not equal to zero jump Back1
RET return to main
END

Dept. of EEE, JNNCE Page 18


3c) Write an ALP to generate BCD up counter

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV A,#00H load the accumulator with 00H
LCALL DELAY call delay
UP:
ADD A,#01H Add accumulator with 01H
DA A Decimal adjust accumulator
CJNE A,#30H,UP compare accumulator with 30h if not equal jump up
LCALL 0003H end
MOV R0,#0FFH load r0 by FFH
DELAY
:
MOV R1,#0FFH load r1 by FFH
BACK1
:
MOV R2,#0FFH load r2 by FFH
BACK:
DJNZ R2,HERE decrement r2 if not equal to zero jump here
HERE:
DJNZ R1,BACK decrement rl if not equal to zero jump Back
DJNZ R0,BACK1 decrement 0 if not equal to zero jump Back1
RET return to main
END

Dept. of EEE, JNNCE Page 19


3d) Write an ALP to generate BCD down counter

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV A,#30H load the accumulator with 30H
UP: LCALL DELAY call delay
ADD A,#99H Add accumulator with 99H
DA A Decimal adjust accumulator
CJNE A,#00H,UP compare accumulator with 00h if not equal jump up
LCALL 0003H end
DELAY: MOV R0,#0FFH load r0 by FFH
BACK1: MOV R1,#0FFH load r1 by FFH
BACK: MOV R2,#0FFH load r2 by FFH
HERE: DJNZ R2,HERE decrement r2 if not equal to zero jump here
DJNZ R1,BACK decrement rl if not equal to zero jump Back
DJNZ R0,BACK1 decrement 0 if not equal to zero jump Back1
RET return to main
END

Dept. of EEE, JNNCE Page 20


4a) Write an ALP to compute the following.

IF X=0; THEN NUM1 (AND) NUM2, IF X=1; THEN NUM1 (OR) NUM2,
IF X=2; THEN NUMI1 (XOR) NUM2, ELSE RES =00, RES IS 23H LOCATION
Using logical instructions in byte level

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV A,20H Store the content of 20H in A
MOV R1,A Store the value of A in R1
MOV A,21H Store the content of 21H in A
CJNE R1,#0,CKOR compare the content of R1 with zero, if yes go to ckor
otherwise go to next instruction

ANL A,22H A=A and content of 22H


MOV 23H,A move the content of A in 23H
SJMP END1 End
CJNE If R1 is not equal to 1 go to ckxor, otherwise go to
CKOR: R1,#1,CKXOR next instruction
ORL A,22H Or the content of A with content of 22H
MOV 23H,A move the content of A in 23H
SJMP END1 end
CJNE if R1 is not equal to 2 go to other, otherwise go to
CKXOR: R1,#2H,OTHER next instruction
XRL A,22H Ex-or the content of A with content of 22H
MOV 23H,A move the content of A in 23H
SJMP END1 end
OTHER: CLR A A=0
END1: MOV 23H,A move the content of A in 23H
HERE: SJMP HERE unconditional jump to here
END end

Dept. of EEE, JNNCE Page 21


5a) Write a program to toggle all the bits of port 1 continuously by sending the values
55H and AAH using call and return instructions
55= 01010101
AA=10101010

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV R5,#05H r5=05h
GO: MOV A,#55H a=55h
MOV P1,A store the number in from memory location
LCALL 300H Long call to 300h i.e delay program
MOV A,#0AAH move the content aaH to A
MOV P1,A move the content of A in P1
LCALL 300H Long call to 300h i.e delay program
DJNZ R5,GO R5=R5-1, if R5 is not equal to zero then jump to go
LCALL 0003H Long call to 300h i.e delay program
ORG 300H Start delay program
HERE: MOV R0,#0FFH RO=FFH
BACK1: MOV R1,#0FFH R1=FFH
BACK: DJNZ R2,BACK R2=R2-1, if R2 is not equal to zero then jump to back
DJNZ R1,BACK1 R1=R1-1, if R1 is not equal to zero then jump to back1
DINZ RO,HERE RO=R0-1, if R2 is not equal to zero then jump to here
RET ; Return to main program
END

Dept. of EEE, JNNCE Page 22


5b) Write an ALP to find factorial of a number using call and return instructions

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV A,40H Move the content of 40H in A
MOV R0,A Move the content of A in RO
LCALL 9000H call 9000h
LCALL 3000H call 3000h
ORG 9000H Originate 9000h
FACT: CJNE R0,#01H,NEXT if RO is not equal to 1 then jump to next
RET Return to main program
NEXT: DEC R0 R0=R0-1
MOV B,R0 Move the content of RO in b
MUL AB A=AxB
MOV 41H,A Move the content of A in R5
LJMP 9000H Go to 9000h
END end

Dept. of EEE, JNNCE Page 23


6 ) Code conversion programs – BCD to ASCII, ASCII to BCD, ASCII to decimal, Decimal to ASCII,
Hexa decimal to and Decimal to hexa.
6a) Write an ALP to convert hexadecimal number to decimal number.
6b) Write an ALP to convert decimal number to hexadecimal number.
6c) Write an ALP to convert packed BCD number to ASCII number.
6d) Write an ALP to convert ASCII number to BCD number
6a) Write an ALP to convert hexadecimal number to decimal number

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H dptr=8500h
MOVX A,@DPTR copy the contents of memory location pointed by DPTR into
register A
MOV B,#64H B=64H
DIV AB division A/B
INC DPTR increment DPTR=8501H
MOVX @DPTR,A copy the contents of memory location pointed by DPTR
into register A
MOV A,B move the content of B into A register
MOV B,#0AH Store the number OAH into register B
DIV AB division A/B
INC DPTR increment DPTR=8502H
MOVX @DPTR,A store the contents of register A in memory location pointed
by DPTR
INC DPTR increment DPTR=8503H
MOV A,B move the content of B into A register
MOVX @DPTR,A store the contents of register A in memory location pointed
by DPTR
LCALL 0003H end of asm file
END

Dept. of EEE, JNNCE Page 24


6b) Write an ALP to convert decimal number to hexadecimal number

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H dptr=8500h
MOVX A,@DPTR copy the contents of memory location pointed by DPTR
into register A
MOV B,#64H B=64H
MUL AB multiply A and B
MOV R2,A store the contents of A in register r2
INC DPTR increment DPTR=8501H
MOVX A,@DPTR copy the contents of memory location pointed by DPTR
into register A
MOV B,#0AH Store the number OAH into register B
MUL AB division A/B
MOV B,R2 store the contents of R2 in register B
ADD A,B add register A and B
MOV B,A store the contents of A in register B
INC DPTR increment DPTR=8502H
MOVX A,@DPTR copy the contents of memory location pointed by DPTR
into register A
ADD A,B add register A and B
INC DPTR increment DPTR=8503H
MOVX @DPTR,A store the contents of register A in memory location
pointed by DPTR
LCALL 0003H end of asm file
END

Dept. of EEE, JNNCE Page 25


6c) Write an ALP to convert packed BCD number to ASCII number

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV dptr=8500h
DPTR,#8500H
MOVX A,@DPTR copy the contents of memory location pointed by DPTR into
register A
MOV R0,A move the content of A to r0
ANL A,#0FH make logical AND function with register A and immediate
data OFH
ORL A,#30H make logical OR function with register A and immediate data
30H
INC DPTR increment DPTR
MOVX @DPTR,A save the result in memory location 8501H
MOV A,R0 get the once again BCD number in register A
ANL A #0F0H make logical AND function with reg A and immediate data
0F0h
SWAP A swap the contents of register A
ORL A,#30H make logical OR function with reg A and immediate data 30h
INC DPTR increment DPTR
MOVX @DPTR,A save the result in memory location 8502H
LCALL 0003H end of asm file
END

Dept. of EEE, JNNCE Page 26


6d) Write an ALP to convert ASCII number to BCD number

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV dptr=8500h
DPTR,#8500H
MOVX copy the contents of memory location pointed by
A,@DPTR DPTR into register A
ANL A,#0FH make logical AND function with register A and
immediate data OFH
MOV B,A store in register B
INC DPTR increment DPTR
MOVX save the result in memory location 8501H
A,@DPTR
ANL A #0FH make logical AND function with reg A and
immediate data 0F0h
SWAP A swap the contents of register A
ORL A,B make logical OR function with reg A and B
INC DPTR increment DPTR
MOVX save the result in memory location 8502H
@DPTR,A
LCALL 0003H end of asm file
END

Dept. of EEE, JNNCE Page 27


7) Programs to generate delay, Programs using serial port and on-chip timer/counters.
7a) Write an ALP to toggle the content of port 0 continuously using timer delay in between.
7b) Write an ALP to transmit characters to a PC HyperTerminal using the serial port and display on
the serial window.
7a) Write an ALP to toggle the content of port 0 continuously using timer delay in between.

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV R0,#0AH ; R0=0AH
GO: MOV A,#55H ; A=55H
MOV P0,A ; Move the content of A in P0
ACALL DELAY ; Call delay program
MOV A,#0AAH ; A=AAH
MOV P0,A ; Move the content of A in P0
ACALL DELAY ; Call delay program
DJNZ R0,GO ; R0=R0-1, if R0 is not equal to zero then jump to
GO
LCALL 0003H ; End of main program
DELAY : MOV TMOD,#01H ; load TMOD
START : MOV TL0,#00H ; Load TL0
MOV TH0, #00H ; Load TH0
SETB TR0 ; TR0=1;
HERE : JNB TF0, HERE ; if TF0 is not equal 1 then jump to here
CLR TR0 ; TR0=0
CLR TF0 ; TF0=0
RET ; return to main program
END

Dept. of EEE, JNNCE Page 28


7b) Write an ALP to transmit characters to a PC HyperTerminal using the serial port and display on
the serial window.

Label Opcode and Comments


Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV TMOD, #20H ; TMOD = 20H
MOV TH1,#-3H ; TH1=-3H
MOV SCON,#50H ; SCON=50H
SETB TR1 ; TR1=1
MOV A,#’H’ ; Load letter ‘H’ in Acc
ACALL TRANS ; Call transmit program
MOV A,#’I’ ; Load letter ‘I’ in Acc
ACALL TRANS ; Call transmit program
MOV A,#’T’ ; Load letter ‘T’ in Acc
ACALL TRANS ; Call transmit program
LCALL 0003H ; Stop the program
TRANS : MOV SBUF,A ; Load SBUF with letter stored in A
HERE: JNB TI,HERE ; if TI is not equal 1 jump to here
CLR TI ; Clear TI
RET ; Return
END ;End

Dept. of EEE, JNNCE Page 29


C-PROGRAM for INTERFACING
1. Write 8051 C program to interface microcontroller kit to run stepper motor for
full/half step with desired stepping speed & direction

Start

Initialize all port with ff

Place either full step or half step


sequence pulse available on the
data bus ( P2 )

Place address 07h in the


address bus P0 to latch pulse
available on the data bus P2

Apply T/2 delay, where


T=1/f , f=speed in
revolution/second

Rotor rotate at constant


speed

Block Diagram:

Dept. of EEE, JNNCE Page 30


#include<reg51.h> // Include header file
void delay (unsigned int count); // Call subroutine function for delay
void main (void) // Start program execution
{
unsigned int n; // Initialize ‘n’ as variable
unsigned char fstep[]={0x09,0x0a,0x06,0x05}; //Declare full/half step delay value
while(1) // Loop execute for infinite times
{
for(n=0;n<4;n++) // Select pulse location for full/half step delay
{
P2=fstep[n]; // Assign ‘n’ as step through P2
P0=0x07; // Assign by latching 0x07 on port address P2
P0=0xff; // Delatch the port
delay(30); // Call subroutine function for delay
}
}
}
void delay (unsigned int count) // Function prototype
{
unsigned int i; // Initialize ‘i’ as integer variable
TMOD=0x01; // Select timer mode 1 (assign TMOD)
TR0=1; // Start timer 0
for(i=0;i<count;i++)
{
TH0=0x4b; // Initialize the value to TH0
TL0=0xd3; // Initialize the value to TL0
TR0=1; // Start timer
While(!TF0); // Whether TF0 overflows from 00 to ff
TF0=0; // Timer flag=0
}
TR0=0; // Stop timer
}

Dept. of EEE, JNNCE Page 31


2. Write 8051 C program to interface microcontroller kit to run DC motor with
desired speed & direction

Start

Initialize all ports with ff

Place either 02h or 01h on data bus P2

Place 07h on address bus to P0,


to latch from the data bus P2

Place ff on the address bus P2 to disable


the delatch, apply T/2 delay time T=1/f ,
f=speed rotation/second

Motor rotates at constant speed

Place 00 on data bus P to stop


rotation

Block Diagram:

Dept. of EEE, JNNCE Page 32


#include<reg51.h> // Include header file
void delay (unsigned int count); // Delay subroutine declaration
void main (void) // Start program execution

{
while(1) // Executes for infinites times
{

P2= 0x02; // 0x01-clock,0x02-anti clock


P0=0x07; // Place 07 on address bus to latch pulse variable
P0=0xff; // Delatch P0
delay(250); // Call subroutine function delay
}
}

void delay (unsigned int count) // Function prototype


{
unsigned int i;
TMOD=0x01; // Select timer mode 1 (assign TMOD)
TR0=1; // Start timer 0
for(i=0;i<count;i++)
{
TH0=0xf8;
TL0=0xcc;
while(!TF0);
TF0=0;
}
TR0=0; // Stop timer
}

Dept. of EEE, JNNCE Page 33


3. Square Wave Generation Program

Start

Initialize all port with ff

Enable the DAC by placing 21h


on address bus (P0)

Place 00h on data bus P2 to


generate active low pulse

Call a function to apply a delay

Place ffH on data bus P2 to


generate active high pulse

Call a function to apply a delay

Square wave is obtained on


CRO

Block Diagram:

Dept. of EEE, JNNCE Page 34


include<reg51.h> // Include header file
void delay (unsigned int i); // Call subroutine function delay
void main (void) // Start program execution
{
while(1)
{
P2=0x00;

P0=0xff;
P0=0x21;
delay(50); //offtime

P2=0xff;

P0=0xff;
P0=0x21;
delay(50); //ontime
}
}

void delay (unsigned int i)


{
unsigned int x;
TMOD=0x01; // Select timer mode 1 (assign TMOD)
TR0=1; // Start timer 0
for (x=0;x<i;x++)
{
TH0=0xfc;
TL0=0x66;

while(!TF0);
TF0=0;
}
TR0=0; // Stop timer
}

Dept. of EEE, JNNCE Page 35


4. Saw tooth wave form GENERATION

Start

Initialize all ports with FFh

Enable DAC by placing 21h address


of DAC on address bus (P0)

Initialize pattern char variable


with 00h

Place pattern value on data bus


P2 to pass data line of DAC

Increment the pattern value

Pattern will be appeared


with constant frequency

Block Diagram:

Dept. of EEE, JNNCE Page 36


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

sbit P20=P2^0; // Declaration

sbit P21=P2^1;

sbit P22=P2^2;

sbit P23=P2^3;

sbit P24=P2^4;

sbit P25=P2^5;

sbit P26=P2^6;

sbit P27=P2^7;

sbit P30=P3^0;

sbit P31=P3^1;

sbit P32=P3^2;

sbit P33=P3^3;

sbit P34=P3^4;

sbit P35=P3^5;

sbit P36=P3^6;

sbit P37=P3^7;

void delay (unsigned int i);

void main (void) // Start program execution

unsigned char pattern=0xff;

unsigned int i;

while(1) // Loop execute for infinite times

Dept. of EEE, JNNCE Page 37


for(i=0;i<=255;i++) // Height of wave (Max value)

P3=pattern;

P20=P37;

P21=P36;

P22=P35;

P23=P34;

P24=P33;

P25=P32;

P26=P31;

P27=P30;

P0=0xff;

P0=0x21;

delay(1); // Call delay function

pattern++;

if(pattern==0xff)

pattern=0x00;

void delay (unsigned int i)

unsigned int x;

Dept. of EEE, JNNCE Page 38


TMOD=0x01; // Timer 0 mode

TR0=1; // Start timer 0

for(x=0;x<=i;x++)

TH0=0xff; // Load TH0

TL0=0xee; // Load TL0

while(!TF0)

TF0=0;

TR0=0;

Dept. of EEE, JNNCE Page 39


5. Write a C Program to display the message “Welcome to JNNCE” on the LCD
display with suitable delay for each character and also scroll the message
right/left. Also read the LCD status before writing command/data

Start

Declare the various functions used


in the program, assign different
port bit to the flag, rw, rs, en

Call LCD initialize function

Call LCD command function

for( i=0; i<17; i++)

for( j=0; j<40000; j++)

Call LCD write data function

Dept. of EEE, JNNCE Page 40


for( i=0; i<17; i++)

for( j=0; j<40000; j++)

Call LCD command function

End

is lcdbusy

Pass the value 0xff to port P2, use


data register, make LCD to read

while
(flag)

End the execution of


function
Push 00 & ff to latch and delatch
port P0

Dept. of EEE, JNNCE Page 41


lcd writedata

Declare variable d to
receive passed data

is lcdbusy

Pass the received value in d to


P2, set rs=1, set rw=0, zero to
write latch and delatch P0 with ff

End the execution of function

lcd command

Declare variable c to
receive passed value

is lcdbusy

Pass the received value in c to


P2, set rs=0, set rw=0, to write
latch and delatch P0 with 00 & ff

End the execution of function

Dept. of EEE, JNNCE Page 42


lcd initialize

Place port 1 & port 2, set


en=0 to turn on the LCD

lcd command (0x01)

lcd command (0x38)

lcd command (0x0c)

End the execution of function

Block Diagram:

Dept. of EEE, JNNCE Page 43


#include<reg51.h> // Include header file
void is_lcdbusy(void); // Function to check LCD status
void lcd_command (unsigned char c); // Function to read data
void lcd_writedata (unsigned char d); // Function to write data to P2
void lcd_initialize (void); // Function to initialize the LCD
sbit flag =P2^7; // Used for conditional while
sbit rw =P1^7; // Bit to decide read/write
sbit rs =P1^6; // Bit to select register
sbit en =P1^2; // Enable bit 7
void main (void) // Start program execution
{
unsigned char message[]=”WELCOME TO JNNCE”;
unsigned int i,j;
lcd_initialize ();
lcd_command (0xc0); // For cursor to 2nd line
for(i=0; i<17; i++)
{
for(j=0; j<40000; j++); // To srt delay
lcd_writedata (message[i]); // Write data to latch
}
for(i=0; i<17; i++)
{
for(j=0; j<40000; j++);
lcd_command (0x1c); // To scroll display to right
}
}
void is_lcdbusy(void)
{
P2=0xff;
rs=0; // Select data register
rw=1; // Select read option
while(flag)
{
P0=0x00; // Latch P0
P0=0xff; // Delatch P0
}
}
void lcd_writedata (unsigned char d)
{
is_lcdbusy();
P2=d; // Write data d to P2
rs=1; // Select register

Dept. of EEE, JNNCE Page 44


rw=0; // Write data
P0=0x00; // Latch P0
P0=0xff; // Delatch P0
}
void lcd_command (unsigned char c)
{
is_lcdbusy();
P2=c;
rs=0;
rw=0;
P0=0x00;
P0=0xff;
}

void lcd_initialize (void)


{
en=0;
lcd_command (0x01); // To clean display of LCD
lcd_command (0x38); // To initialize 16x2 LCD matrix
lcd_command (0x0c); // Display on, cursor off
}

Dept. of EEE, JNNCE Page 45

You might also like