Você está na página 1de 127

MICROCONTROLLER PROGRAMMING LAB

PROGRAM 1(A&B)
FAMILIARIZATION WITH MICROCONTROLLER KIT
AND SIMULATOR
AIM: To familiarization with microcontroller kit and simulator.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 Keil software/EDSIM 1
2 Window Xp operating system 1

THEORY:

Earlier to Microcontrollers, Microprocessors were greatly used for each and every
purpose. Microprocessors were containing ALU, general purpose register, stack pointer, program
counter, clock counter and so many other features which the today’s Microcontroller also
possesses. But the difference between them exists with respect to the number of instructions,
access times, size, reliability, PCB size and so on.
Microprocessor contains large instruction set called as CISC processor whereas
Microcontroller contains less number of instructions and is called as RISC processor. The access
time is less in case of microcontrollers compared to microprocessors and the PCB size reduces in
case of microcontrollers. There are many versions of microcontrollers 8051, 80528751, AT8951
from Atmel Corporation and many more. In this manual we will study about the 8051
architecture, its features, programming and interfacing. MCS 8051 is an 8-bit single chip
microcontroller with many built-in functions and is the core for all MCS-51 devices.
The main features of the 8051 core are:
1. Operates with single Power Supply +5V.
2. 8-bit CPU optimized for control applications.
3. 16-bit program counter (PC) and 16-bit data pointer (DPTR).
4. 8-bit program status word (PSW).
5. 8-bit stack pointer (SP).
6. 4K Bytes of On-Chip Program Memory (Internal ROM or EPROM).

IIET Page 1
MICROCONTROLLER PROGRAMMING LAB

7. 128 bytes of On-Chip Data Memory (Internal RAM):


8. Four Register Banks, each containing 8 registers (R0 to R7) [Total 32 reg]
9. 16-bytes of bit addressable memory.
10. 80 bytes of general-purpose data memory (Scratch Pad Area).
11. Special Function Registers (SFR) to configure/operate microcontroller.
12. 32 bit bi-directional I/O Lines (4 ports P0 to P3).
13. Two 16-bit timers/counters (T0 and T1).
14. Full duplex UART (Universal Asynchronous Receiver/Transmitter).
15. On-Chip oscillator and clock circuitry.

STEPS TO CREATE AND COMPILE Keil μVision-3/4 PROJECT:


1. Double Click on the  icon on the desktop.
2. Close any previous projects that were opened using – Project -> Close.
3. Start Project – New Project, and select the CPU from the device database
(Database-Atmel- AT89C51ED2 or AT89C51RD2 as per the board).On clicking
‘OK’, the following option is displayed. Choose ‘No’.

4. Create a source file (using File->New), type in the assembly or C program and

IIET Page 2
MICROCONTROLLER PROGRAMMING LAB

save this (filename.asm/filename.c) and add this source file to the project using
either one of the following two methods. (i) Project->Manage->Components,
Environment Books->addfiles-> browse to the required file -> OK
“OR” ii) right click on the Source Group in the Project Window and the Add
Files to Group option.

Set the Target options using -> Project – Options for Target opens the
μ Options for Target – Target configuration dialog. Set the Xtal
(Crystal frequency) frequency as 11.0592 MHz, and also the Options for Target
– Debug – use either Simulator / Keil Monitor- 51 driver.

If Keil Monitor- 51 driver is used click on Settings -> COM Port settings select the COM Port
to which the board is connected and select the baud rate as 19200 or 9600 (recommended).
Enable Serial Interrupt option if the user application is not using on-chip UART, to stop
program execution.
7. Build the project; using Project -> Build Project.  application and links. Any errors in the
code are indicated by – “Target not created” in the Build window, along with the error line.
Debug the errors. After an error free, to build go to Debug mode.

IIET Page 3
MICROCONTROLLER PROGRAMMING LAB

Now user can enter into Debug mode with Debug- Start / Stop Debug session dialog. Or by
clicking in the icon.
9. The program is run using the Debug-Run command & halted using Debug-Stop Running.
Also the (reset, run, halt) icons can be used. Additional icons are (step, step over, and step into,
run till cursor).
10. If it is an interface program the outputs can be seen on the LCD, CRO, motor, led status, etc.
If it is a part-A program, the appropriate memory window is opened using View -> memory
window (for data RAM & XRAM locations), Watch window (for timer program), serial window,
etc.
Note: To access data RAM area type address as D: 0020h. Similarly to access the
DPTR region (XRAM-present on chip in AT89C51ED2) say 9000h location type in X: 09000H.

RESULT: To familiarization with microcontroller kit and simulator has been studied.
APPLICATIONS:
Microcontrollers are mostly used in following electronic equipments :
 Mobile Phones
 Auto Mobiles
 CD/DVD Players
 Washing Machines
 Cameras
 In Computers-> Modems and Keyboard Controllers
 Security Alarms
 Electronic Measurement Instruments.
 Microwave Oven.

IIET Page 4
MICROCONTROLLER PROGRAMMING LAB

ADVANTAGES OF MICROCONTROLLER:
Microcontroller's use increased rapidly. Now these are used in almost every electronic
equipment like Washing Machines, Mobile Phones and Microwave Oven. Following are the
most important facts about Microcontrollers, which causes rapid growth of their use:
You may also like: Difference Between Microcontroller & Microprocessor
 Microcontrollers are cheap and very small in size, therefore they can be embedded on any
device.
 Programming of Microcontrollers is simple to learn. Its not much complicated.
 We can use simulators on Computers to see the practical results of our program. Thus we
can work on a Embedded project without even buying the required Components and
Chips. Thus we can virtually see the working of our project or program.

EXTENSION :
By this we can execute an program.

Viva Questions
1. What do you mean by Embedded System? Give examples.
2. Why are embedded Systems useful?
3. What are the segments of Embedded System?
4. What is Embedded Controller?
5. What is Microcontroller?
6. List out the differences between Microcontroller and Microprocessor.
7. How are Microcontrollers more suitable than Microprocessor for Real Time Applications?
8. What are the General Features of Microcontroller?
9. Explain briefly the classification of Microcontroller.
10. Explain briefly the Embedded Tools.
11. Explain the general features of 8051 Microcontroller.
12. How many pin the 8051 has?
13. Differentiate between Program Memory and Data Memory.
14. What is the size of the Program and Data memory?

IIET Page 5
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 2(A)
8 BIT ADDITION AND SUBTRACTION

AIM: Write an ALP for addition and subtraction of two 8 bit numbers.
SOFTWARE REQURIED:

SNO NAME QUANTITY


1 Keil software 1
2 Window Xp operating system 1

ALGROTHIM

IIET Page 6
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

ADDITION 8 BIT WITHOUT CARRY:

IIET Page 7
MICROCONTROLLER PROGRAMMING LAB

ADDITION 8 BIT WITH CARRY:

IIET Page 8
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:
Addition without carry:
ORG 0000H
MOV A, #DATA 1
ADD A, #DATA 2
MOV 30H,A
SJMP HLT
END

Addition with carry:

ORG 0000H
MOV A,40H
ADD A,41H
MOV 42H,A
CLR 43H
JNC HLT
INC 43H
SJMP HLT
END

IIET Page 9
MICROCONTROLLER PROGRAMMING LAB

SUBTRACTION :

ORG 0000H
MOV A, #DATA 1
SUBB A, #DATA 2
MOV 30H,A
SJMP HLT
END

EXPECTED INPUT/OUTPUTS:

INPUT:
Addition without carry
Memory Data
-- DATA1 =
-- DATA2=

INPUT:
Addition with carry
Memory Data
40H DATA
41H CARRY

INPUT:
Subtraction:
Memory Data
-- DATA
-- DATA

OUTPUT:
Addition without carry
Memory Data
-- DATA1 =
-- DATA2=

OUTPUT:
Addition with carry
Memory Data
42H

IIET Page 10
MICROCONTROLLER PROGRAMMING LAB

43H

OUTPUT:
subtraction
Memory Data
30H

RESULT:
An ALP for addition and subtraction for 8 bit is studied.
APPLICATIONS:
By this student will be knowing how to do the addition and subtraction by binary number.
EXTENSION:
By simple modification we can executed many programs like multiplication,division,etc
VIVA QUESTIONS :
1. List out the differences between Microcontroller and Microprocessor.
2. How are Microcontrollers more suitable than Microprocessor for Real Time Applications?
3. What are the General Features of Microcontroller?
4. Explain briefly the classification of Microcontroller.
5. Explain briefly the Embedded Tools.

IIET Page 11
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 2(A)
MULTIPLICATION AND DIVISION OF 8 BIT

AIM: To write and execute an ALP to multiplication and division of two 8 bit.

SOFTWARE REQURIED:

SNO NAME QUANTITY


1 Keil software 1
2 Window Xp operating system 1

ALGORITHM:

IIET Page 12
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

DIVISION:
START

LOAD 08H WITH A

LOAD 01H WITH B

IIET Page 13
MICROCONTROLLER PROGRAMMING LAB

DIV AB

END

PROGRAM: Multiplication:

ORG 0000H
MOV DPTR,#8250H
MOVX A,@DPTR
MOV B,A
INC DPTR
MOVX A,@DPTR
MUL AB
MOV DPTR,#8300H
MOVX@DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
SJMP HLT
END

Division:
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MOV A,#08H
MOV B,#04H
DIV AB
SJMP HLT
END

;’0INPUT: Multiplication

Memory Address Data


8250H
8251H

OUTPUT: Multiplication

Memory address Data


IIET Page 14
MICROCONTROLLER PROGRAMMING LAB

8300H LOWER ORDER


8300H HIGHER ORDER

Input: Division:
Input is 08h,04h
Output: Division:
Accumulator output is 2h
RESULT:
An ALP for multiplication and division of two 8 bit is studied.
APPLICATIONS:
By this student will be knowing how to do the multiplicationand,division by binary
number.
EXTENSION:
By simple modification we can executed many programs like addition and subtraction
multiplication,division,etc
VIVA QUESTION:
What is the function of accumulator?
1. What are SFR’s? Explain briefly.
2. What is the program counter? What is its use?
3. What is the size of the PC?
4. What is a stack pointer (SP)?
5. What is the size of SP?

IIET Page 15
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 2(B)
16 BIT ADDITION AND SUBTRACTION.

AIM: To write a assembly language program to 16 BIT addition and subtraction.


SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1

ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Executed the program.
4. If no errors and warnings.
5. Note the address and opcode.
6. stop
FLOW CHART:
start

Write the program in keil

Executed the program

If no
errors

Note the address and


opcode

stop

IIET Page 16
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:

ADDITION :

ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MOV DPTR,#1234H
Mov A, #12H
ADD A, DPL
MOV DPL,A
MOV A, #34H
ADDC A, DPH
MOV DPH,A
END

SUBSTRACTION:

ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MOV DPTR,#1234H
MOV A, #12H
SUBB A, DPL
MOV R1,A
MOV A, #34H
SUBB A, DPH
MOV R2,A
end

RESULT: Addition and subtraction of 16 bit is performed.

APPLICATIONS:
By this student will be knowing how to do addition and subtraction the by binary number.
EXTENSION:
By simple modification we can executed many programs like
multiplicationand,division ,etc
VIVA QUESTION:
1. What is the PSW? And briefly describe the function of its fields.
2. What is the difference between PC and DPTR?
3. What is the difference between PC and SP?
4. What is ALE? Explain the functions of the ALE in 8051.

IIET Page 17
MICROCONTROLLER PROGRAMMING LAB

5. Describe the 8051 oscillator and clock.

IIET Page 18
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 2(C)
SQUARE AND CUBE OF DECIMAL NUMBERS

AIM: To write a assembly language program to find square and cube of a given
binary number.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1

FLOWCHART:
SQUARE OF A BINARY NUMBER:

start

Load 20H with A

Load A with B

MUL AB

End

IIET Page 19
MICROCONTROLLER PROGRAMMING LAB

CUBE OF A BINARY NUMBER:

start

Load 20H with A

Load A with R1

Load A with B

MUL AB

Load A with R2

Load B with R1

MUL AB

end

PROGRAM:
SQUARE OF A BINARY NUMBER:
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MovA, #20H
Mov R0,A
Mov B,R0
MUL AB
END

IIET Page 20
MICROCONTROLLER PROGRAMMING LAB

CUBE OF A BINARY NUMBER:


ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MovA, #02H
Mov R0,A
Mov B,R0
MUL AB
Mov B,R0
MUL AB
END

Result:
Square and cube of a given binary number is performed and executed.
APPLICATIONS:
By this student will be knowing how to do Square and cube the by binary number.
EXTENSION:
By simple modification we can executed many programs like multiplication and, division
,etc

VIVA QUESTION:
1. What are the disadvantages of the ceramic resonator?
2. What is the function of the capacitors in the oscillator circuit?
3. Show with an example, how the time taken to execute an instruction can be calculated.
4. What is the Data Pointer register? What is its use in the 8051?
5. Explain how the 8051 implement the Harvard Architecture?

IIET Page 21
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 2(D & E)


LCM AND HCF BINARY NUMBERS.

AIM: To write a assembly language program to find LCM and HCF of a given binary number.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 Keil software 1
2 Window Xp operating system 1

FLOW CHART: LCM of two binary numbers

START

LOAD A WITH 04H

LOAD B WITH 02H

DIVIDE A WITH B

LOAD R2 WITH A

LOAD R3 WITH B

no
IS
R0=
0
yes
LOAD B WITH R2

LOAD A WITH R1

MUL AB

END
IIET Page 22
MICROCONTROLLER PROGRAMMING LAB

HCF of two given number

START

LOAD A WITH 09H


LOAD B WITH 04H

LOAD R0 WITH 02H

DIVIDE A WITH B

LOAD R1 WITH A
LOAD R2 WITH B

no IS
RO=
1
yes

LOAD B WITH R2

END

PROGRAM:

HCF OF TWO BINARY NUMBER:

ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MovA, #09H
Mov B,#04H

IIET Page 23
MICROCONTROLLER PROGRAMMING LAB

Mov RT,B,
Mov R0,#02H
REPEAT: DIV AB,
Mov R1,A
Mov R2,A
Mov A,RT
DJNZ R0,REPEAT
Mov B,R1
END

LCM OF TWO BINARY NUMBER:


ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MovA, #09H
Mov B,#04H
Mov RT,B,
Mov R0,#02H
REPEAT: DIV AB,
Mov R1,A
Mov R2,A
Mov A,RT
DJNZ R0,REPEAT
Mov B,R1
Mov A, R1
MUL AB
END

RESULT: HCF AND LCM of two binary number are studied.

APPLICATIONS:
By this student will be knowing how to do HCF AND LCM the by binary number.
EXTENSION:
By simple modification we can executed many programs like
multiplicationand,division ,etc
VIVA QUESTION:
1. Explain briefly the difference between the Von Neumann and the Harvard Architecture.
2. Describe in detail how the register banks are organized.
3. What are the bit addressable registers and what is the need?
4. What is the need for the general purpose RAM area?
5. Write a note on the Stack and the Stack Pointer.

IIET Page 24
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 3
DATA TRANSFER (A$B)

AIM: (a) To Write an assembly language program to transfer N = ___ bytes of data
from location A: _______h to location B: _______h.
(b)Write an assembly language program to exchange N = ___h bytes of data
at location A: _____h and at location B: _____h.
SOFTWARE REQURIED:

SNO NAME QUANTITY


1 keil software 1
2 8051 microcontroller kit for interfacing 1
ASSUME:
Let N = 05h, A: 30h B: 40h
ALGORTHIM:
7. Start.
8. Write the program in keil .
9. Executed the program.
10. If no errors and warnings.
11. Note the address and opcode.
12. stop
FLOW CHART:
start

Write the program in keil

Executed the program

If no
errors

Note the address and


opcode
IIET Page 25
MICROCONTROLLER PROGRAMMING LAB

stop
PROGRAM:
(a)
ORG 0000H
MAIN: mov r0,#30h //source address
mov r1,#40h //destination address
mov r7,#05h //Number of bytes to be moved
back: mov a,@r0
mov @r1,a
inc r0
inc r1
djnz r7,back //repeat till all data transferred
end

(B)
org 0000h
mainmov r0,#30h //source address
mov r1,#40h //destination address
mov r7,#05h //count, the number of data to be exchanged
back: mov a,@r0
mov r4,a
mov a,@r1
mov @r0,a
mov a,r4
mov @r1,a
inc r0
inc r1
djnz r7,back
end

IIET Page 26
MICROCONTROLLER PROGRAMMING LAB

EXPECTED INPUTS AND OUTPUTS


(a) TRANSFER
Before Execution:

After Execution:

(b)exchange
Before execution

IIET Page 27
MICROCONTROLLER PROGRAMMING LAB

After execution:

RESULT:
An ALP for transfer and exchange the data location studied.
APPLICATIONS:
By this student will be knowing how to do transfer and exchange the by binary number.
EXTENSION:
By simple modification we can executed many programs like
multiplicationand,division ,etc
VIVA QUESTIONS:
1. Explain the Direct Addressing Mode. Explain the Indirect Addressing Mode.
2. Explain the Code Addressing Mode.
3. Explain in detail the Functional Classification of 8051 Instruction set
4. What are the instructions used to operate stack?
5. What are Accumulator specific transfer instructions?

IIET Page 28
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 3(C)
TO BLOCK EXCHANGE 10 BYTES OF DATA
AIM: To write a assembly language program to block exchange 10 bytes of data
between 0x30/0x39 to 0x401/0x49.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1
ALGORTHIM:
1. Start.
2. Load 0H to 09H into 30H to 39H location.
3. Load 10H to 19H into 40H to 49H location.
4. stop

FLOW CHART:
start

Move 0H to 09H into 30H to 39H

move10H to 19H into 40H to 49H

stop

PROGRAM:
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:MOV 30H,#00H
MOV 31H,#01H
MOV 32H,#02H
MOV 33H,#03H
MOV 34H,#04H
MOV 35H,#05H
MOV 36H,#06H
IIET Page 29
MICROCONTROLLER PROGRAMMING LAB

MOV 37H,#07H
MOV 38H,#08H
MOV 39H,#09H
MOV 40H,#10H
MOV 41H,#11H
MOV 42H,#12H
MOV 43H,#13H
MOV 44H,#14H
MOV 45H,#15H
MOV 46H,#16H
MOV 47H,#17H
MOV 48H,#18H
MOV 49H,#19H
END

RESULT: To block exchange 10 bytes of data between 0x30/0x39 to 0x401/0x49 is studied..

APPLICATIONS:
By this student will be knowing how to do Data transfer from peripheral to memory
through DMA the by binary number.
EXTENSION:
By simple modification we can executed many programs like Data transfer from
peripheral to memory through any data.

VIVA QUESTIONS:
1. What is the difference between INC and ADD instructions?
2. What is the difference between DEC and SUBB instructions?
3. What is the use of OV flag in MUL and DIV instructions?
4. What are single and two operand instructions?
5. Explain Unconditional and Conditional JMP and CALL instructions

IIET Page 30
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 3(D)
TO BLOCK 10 BYTES OF DATA
AIM: To write a assembly language program to block exchange 10 bytes of data
between 0x30/0x39 to 0x100010x1009.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1
ALGORTHIM:
1. Start.
2. Load 1000H into DPTR R0,30H &R2,DAA.
3. Load A+@DPTR into A &A into @R0
4. INC DPTR &R0
5. DEC RL.
6. END.
FLOW CHART:
START

LOAD 1000H data DPTR

Load 30H data into R0

Load 0aH data into R2

Load A with address of DPTR

Load A into @RO

increment R0

IIET Page 31
MICROCONTROLLER PROGRAMMING LAB

If
R2=0

LOAD R0 VALUE 01H,02H


03H,04H TO 0AH

STOP

PROGRAM:

ORG 0000H
LJMP MAIN

MAIN:MOV DPTR,1000H
MOV R0,#30H
MOV R2,#0AH
BACK:MOVC A, A+@DPTR
MOV @R0,A
INC DPTR
INC R0
DJNZ R2, BACK
ORG 1000H
SOURCE:DB 01H,02H,03H,04H,05H,07H,08H,09H,0AH
END

RESULT: To block exchange 10 bytes of data between 0x30/0x39 to 0x100010x1009.


is studied.
APPLICATIONS:
By this student will be knowing how to do Data transfer from peripheral to memory
through DMA the by binary number.
EXTENSION:

IIET Page 32
MICROCONTROLLER PROGRAMMING LAB

By simple modification we can executed many programs like Data transfer from
peripheral to memory through any data.

VIVA QUESTIONS:
1. What is the difference between INC and ADD instructions?
2. What is the difference between DEC and SUBB instructions?
3. What is the use of OV flag in MUL and DIV instructions?

IIET Page 33
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 4(A)
LARGEST NUMBER IN A GIVEN ARRAY

AIM: To write and execute an ALP to find the largest number in an given array.

SOFTWARE REQURIED:

SNO NAME QUANTITY


1 Keil software 1
2 Window Xp operating system 1
ALGORITHM:

IIET Page 34
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

IIET Page 35
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:
ORG 0000H
MOV R0,#04H //NO OF DATA-1
MOV DPTR,#8251H
MOVX A,@DPTR
MOV R1,A
L2:INC DPTR
MOVX A,@DPTR
SUBB A,R1
JC L1
MOVX A,@DPTR
XCH A,R1
L2: DJNZ R0,L2
MOV A,R1
MOV DPTR,#8300H
MOVX @DPTR,A
SJMP HLT
END

INPUT:
Memory Address Data
8251 DATA1 =
8252 DATA2=
8253 DATA3=
8254 DATA4=

IIET Page 36
MICROCONTROLLER PROGRAMMING LAB

8255 DATA5=
OUTPUT:
Memory Address Data
8300 Largest number

RESULT:
An ALP for largest number in a given array is studied.
APPLICATIONS:
By this student will be knowing how to do smallest number the by binary number.
EXTENSION:
By simple modification we can executed many programs like smallest number in given
array.
VIVA QUESTIONS:
1. Explain the different types of RETURN instructions.
2. What is a software delay?
3. What are the factors to be considered while deciding a software delay?
4. What is a Machine cycle?
5. What is a State?

IIET Page 37
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 4(A)
SMALLEST NUMBER IN A GIVEN ARRAY

AIM: To write and execute an ALP to find the smallest number in an given array.

SOFTWARE REQURIED:

SNO NAME QUANTITY


1 Keil software 1
2 Window Xp operating system 1

FLOW CHART:

Start

Load 30H data to 01H

Load 31H data to 03H

Load 32H data to 0CH

Load 33H data to 05H

Load 34H data to 06H

Load 35H data to 0AH

Load 36H data to 02H

Load 37H data to 01H

Load 38H data to 04H

Load 39H data to 00H

IIET Page 38

x
MICROCONTROLLER PROGRAMMING LAB

DEC R2

INC
R0

LOAD B DATA TO REGISTER R0

LOAD CJNE A,B LOOP2

JC
LOOP
3

LOAD A,B

DJNZ TO
R2,LOOP
1

STOP

IIET Page 39
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:

ORG 0000H
LJMP MAIN
ORG 0030H
MOV 30H,#01H
MOV 31H,#03H
MOV 32H,#0CH
MOV 33H,#05H
MOV 34H, #06H
MOV 35H,#0AH
MOV 36H,#02H
MOV 37H,#01H
MOV 38H,#04H
MOV 39H, #00H
MOV R0,#30H
MOV R2,#10
MOV A,@R0
DEC R2
LOOP1:INC R0
MOV B@R0
CJNE A,B,LOOP2
LOOP2:JC LOOP3
MOV A,B
LOOP3:DJNZ R2,LOOP1
END
EXPECTED OUTPUT:

Smallest number in an given array is:


R0=39
R2=00
A=00
B=00
RESULT:
An ALP for smallest number in an given array is studied.
APPLICATIONS:
By this student will be knowing how to do smallest number the by binary number.
EXTENSION:
By simple modification we can executed many programs like largest number in given
array.

VIVA QUESTIONS:
1. Explain the need for Hardware Timers and Counters?
2. Give a brief introduction on Timers/Counter.

IIET Page 40
MICROCONTROLLER PROGRAMMING LAB

3. What is the difference between Timer and Counter operation?


4. How many Timers are there in 8051?
5. What are the three functions of Timers?

IIET Page 41
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 4(B)
SEARCH OF AN ELEMENT IN 10 BYTES OF DATA

AIM: Searching for an element in the 10 bytes of data from 0x30-0X39

SOFTWARE REQURIED:

SNO NAME QUANTITY


1 keil software 1
2 Window Xp operating system 1
ALGORITHM:
1. START
2. LOAD #2AH to #3BH into 30H TO 39H addresses.
3. Move #30h,#0AH,#OOH,#10H into registers R0,R1,R3,A
4. MOV R0 into B
5. Compare loop2
6. Increment R3 and R0
7. Decrement when r2=0 to loop1
8. End
FLOWCHART:

START

MOV 30H,2AH TO 39H,33H

MOVRO=30H;R2=0AH;R3=00H;A=10H

MOV B,@R0

CJN LOOP2

INCREMENT R3 AND R0

DJNE R2,LOOP1

STOP

IIET Page 42
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:
ORG OOOOH
LJMP MAIN
MAIN: MOV 30H,#2AH
MOV 31H,#3CH
MOV 32H,#1AH
MOV 33H,#09H
MOV 34H,#10H
MOV 35H,#6EH
MOV 36H,#8AH
MOV 37H,#1EH
MOV 38H,#7AH
MOV 39H,#3BH
MOV R0,#30H
MOV R1,#0AH
MOV R3,#00H
MOV A,#10H
LOOP1: MOV B, @R0
CJNE LOOP2
JNC R3
LJMP EXIT
LOOP2: INC R0
DJNE R2, LOOP2
EXIT:END

RESULT:
Searching for an element in the 10 bytes of data from 0x30-0X39 is studied.
APPLICATIONS:
By this student will be knowing how to do smallest number the by binary number.
EXTENSION:
By simple modification we can executed many programs like largest number in given
array.

IIET Page 43
MICROCONTROLLER PROGRAMMING LAB

VIVA QUESTIONS:
1. Explain the need for Hardware Timers and Counters?
2. Give a brief introduction on Timers/Counter.

IIET Page 44
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 4(C)
ASCENDING ORDER

AIM: To write and execute an ALP to sort an array of number using the bubble
sort algorithm in an ascending order.

SOFTWARE REQURIED:

SNO NAME QUANTITY


1 keil software 1
2 Window Xp operating system 1
ALGORITHM:

FLOW CHART:

IIET Page 45
MICROCONTROLLER PROGRAMMING LAB

IIET Page 46
MICROCONTROLLER PROGRAMMING LAB

STOP

PROGRAM:

ORG 0000H
MAIN:MOV R6,#04H
LOOP1: MOV R0,#50H
MOV A,R6
MOV R7,A
LOOP2: MOV A,@R0
MOV R1,A
INC R0
MOV A,@R0
SUBB A,R1
JNC Continue 2
SWAP NUBER: MOV A,@R0
XCH A,R1
MOV @R0,A
DEC RO
MOV A,R1
MOV @R0,A
INC R0
Continue 2:
DJNZ R7,LOOP2

IIET Page 47
MICROCONTROLLER PROGRAMMING LAB

Continue 2:
DJNZ R7,LOOP2
SJMP HLT
END

INPUT:

Memory Address Data


50H
51H
52H
53H
54H

OUTPUT:
Memory Address Data
50H
51H
52H
53H
54H

RESULT:
Sort of an array of number using the bubble sort algorithm in an ascending order
is studied.
APPLICATIONS:
By this student will be knowing how to ascending order the by binary number.
EXTENSION:
By simple modification we can executed many programs like descending order in given
array.

VIVA QUESTIONS:
1. What are the different modes of operation of timer/counter?
2. Give a brief introduction on the various Modes.
3. What is the count rate of timer operation?
4. What is the difference between mode 0 and mode 1?
5. What is the difference Modes 0,1,2 and 3?

IIET Page 48
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 4(D)
DESCENDING ORDER

AIM: To write and execute an ALP to sort an array of number using the bubble
sort algorithm in an descending order.

SOFTWARE REQURIED:

SNO NAME QUANTITY


1 keil software 1
2 Window Xp operating system 1
ALGORITHM:

FLOW CHART:

IIET Page 49
MICROCONTROLLER PROGRAMMING LAB

IIET Page 50
MICROCONTROLLER PROGRAMMING LAB

STOP

PROGRAM:

ORG 0000H
MAIN: MOV R0,#05H //count (N-1) array size = N
loop1: MOV DPTR, #9000H //array stored from address 9000h
MOV R1,#05H //initialize exchange counter
loop2: MOVX A, @DPTR //get number from array and store in B register
MOV B, A
INC DPTR
MOVX A, @DPTR //next number in the array
CLR C //reset borrow flag
MOV R2, A //store in R2
SUBB A, B //2nd-1st No, since no compare instruction in 8051
JC NOEXCHG // JC - FOR DESCENDING ORDER
MOV A,B //exchange the 2 nos in the array
MOVX @DPTR,A
DEC DPL //DEC DPTR - instruction not present
MOV A,R2
MOVX @DPTR,A
INC DPTR
NOEXCHG: DJNZ R1,LOOP2 //decrement compare counter
DJNZ R0,LOOP1 //decrement pass counter

IIET Page 51
MICROCONTROLLER PROGRAMMING LAB

END

BEFORE EXECTION

AFTER EXECTION

RESULT:
Sort of an array of number using the bubble sort algorithm in an
descending order is studied.
APPLICATIONS:
By this student will be knowing how to descending order the by binary number.
EXTENSION:
By simple modification we can executed many programs like ascending order in given
array
VIVA QUESTIONS:
1. How do you differentiate between Timers and Counters?
2. Explain the function of the TMOD register and its various fields?
3. How do you control the timer/counter operation?
4. What is the function of TF0/TF1 bit
5. Explain the function of the TCON register and its various fields?

IIET Page 52
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 5(A)
2’S COMPLEMENT
AIM: To write a assembly language program to 2’S COMPLEMENT
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1

ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Executed the program.
4. If no errors and warnings.
5. Note the address and opcode.
6. stop
FLOW CHART:
start

Write the program in keil

Executed the program

If no
errors

Note the address and


opcode

stop

IIET Page 53
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:

ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:MOV A,04H
CMP A
ADD A,01H
MOV B,A
END

RESULT: 2’S complement is performed.

APPLICATIONS:
By this student will be knowing how to 2’S complement the by binary number.
EXTENSION:
By simple modification we can executed many programs like 1’s complment
VIVA QUESTIONS:
1. Explain how the Timer/Counter Interrupts work.
2. Explain how the 8051 counts using Timers and Counters.
3. Explain Counting operation in detail in the 8051.
4. Explain why there is limit to the maximum external frequency that can be
5. counted.
6. What’s the benefit of the auto-reload mode?

IIET Page 54
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 5(B)
Packed to Unpacked CONVERSION

AIM: To write a assembly language program to packed to unpacked


SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1

ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Executed the program.
4. If no errors and warnings.
5. Note the address and opcode.
6. stop
FLOW CHART:
start

Write the program in keil

Executed the program

If no
errors

Note the address and


opcode

stop

PROGRAM:

IIET Page 55
MICROCONTROLLER PROGRAMMING LAB

ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: LDA 3000H
MOV B,A
MVI C,04
ANI F0
L1: RRC
DCR C
JNZ L1
STA 3001
MOV A,B
ANI 0F
STA 3002
HLT
ENDDB 98H

RESULT: Packed to unpacked is performed.

APPLICATIONS:
By this student will be knowing how to Packed to unpacked the by binary number.
EXTENSION:
By simple modification we can executed many programs like bcd to hexadecimal
conversion.
VIVA QUESTIONS:
1. Write a short note on Serial and Parallel communication and highlight their advantages
and disadvantages.
2. Explain Synchronous Serial Data Communication.
3. Explain Asynchronous Serial Data Communication.
4. Explain Simplex data transmission with examples.
5. Explain Half Duplex data transmission with examples.

IIET Page 56
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 5(C)
ASCII TO BCD CONVERSION

AIM: To write and execute an ALP for convert ASCII TO BCD Conversion.
SOFTWARE REQURIED:

SNO NAME QUANTITY


1 keil software 1
2 Window Xp operating system 1

FLOW CHART
START

Load #20h and #40H value into r0,r1

Move 30address into A

ANL between of r0 and A then SWAP it

INC R0 and @r0 move to A

Again ANL b/w A,#0fH

ORL R2 and A

END

IIET Page 57
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:
ORG 0000H
LJMP MAIN
MAIN:MOV R0,#20H
MOV R1,#40H
MOV A, @ R0
ANL A,#0FH
SWAP A
MOV R2,A
INC R2,A
MOV A, @R0
ANLA,#0FH
ORLA,R2
MOV @R1,A
SJMP
END

INPUT:
Memory Data

OUTPUT
Memory Data

RESULT:
An ALP for convert ASCII to BCD Conversion is studied.
APPLICATIONS:
By this student will be knowing how to ASCII toBCD conversion
EXTENSION:
By simple modification we can executed many programs like hexadecimal to BCD
conversion.
VIVA QUESTIONS:
1. Explain Full Duplex data transmission with examples.
2. What is Baud rate?
3. What is a Modem?
4. What are the various registers and pins in the 8051 required for Serial communication?
Explain briefly.

IIET Page 58
MICROCONTROLLER PROGRAMMING LAB

5. Explain SCON register and the various fields.

IIET Page 59
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 6(A)
TIMERS AND COUNTERS
AIM: To write a assembly language program to timers and counters
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1

ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Executed the program.
4. If no errors and warnings.
5. Note the address and opcode.
6. stop
FLOW CHART:
start

Write the program in keil

Executed the program

If no
errors

Note the address and


opcode

stop
PROGRAM:

TIMER 0 COUNTER MODE:


ORG 0000H
LJMP MAIN

IIET Page 60
MICROCONTROLLER PROGRAMMING LAB

ORG 0030H
MAIN:MOV A, TMOD(TMOD=89)
ORL A, #05H
MOV TMOD,A
SETB TRO(TRO=8C)
LCALL 68EAH
MOV DPTR, 30194h
Mov A,TLO(TLO-8A)
MOVX @DPTR,A
INC DPTR
MOV A, THO(THJO=8C)END
MOVX @DPTR,A
LCALL 6748H
SJMP LOOP

RESULT: timers and counters is performed.

APPLICATIONS:
By this student will be knowing how to timers and counters conversion
EXTENSION:
By simple modification we can executed many programs like BCD to hexadecimal
conversion.
VIVA QUESTIONS:
1. Explain in detail the Multiprocessor communication Mode in the 8051.
2. Explain the significance of the 9th bit in the Multiprocessor communication Mode.
3. Explain the Serial data mode 3 in the 8051.
4. What are interrupts and how are they useful in Real Time Programming?
5. Briefly describe the Interrupt structure in the 8051.

IIET Page 61
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 6(A)
UP/DOWN HEXDECIMAL COUNTER

AIM: To Write an assembly language program to implement UP/DOWN hexadecimal counter.


APPARATUS:

SNO NAME QUANTITY


1 keil software 1
2 8051 microcontroller kit for interfacing 1

ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Executed the program.
4. If no errors and warnings.
5. Note the address and opcode.
6. stop
FLOW CHART:
start

Write the program in keil

Executed the program

If no
errors

Note the address and


opcode

stop

IIET Page 62
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:
ORG 0000H
LJMP MAIN
MAIN:
MOV R0,#30H
MOV @R0,#00H
CJNE R0,#00H,DOWN
UP: MOV A,#00H
L1: INC A
CLJNE A,#0FH,L1
LJMP MAIN
DOWN: MOV A,#0FH
L2:DEC A
CJNE A,#00H,L2
LJMP MAIN
END

EXPECTED OUTPUT :
Move #30H to R0, #00H to @R0
Compare R0 with ooH for down count.
Load A with 0FH for up count from 00H to 0FH.

RESULT:
An ALP for UP/DOWN hexadecimal counter is studied.

APPLICATIONS:
By this student will be knowing how to UP/DOWN decimal counter
EXTENSION:
By simple modification we can executed many programs UP/DOWN HEX counter
VIVA QUESTIONS:
1. Explain about vectored and non-vectored interrupts in general.
2. What are the five interrupts provided in the 8051?
3. What are the three registers that control and operate the interrupts in 8051?
4. Describe the Interrupt Enable (IE) special function register and its various bits.
5. Describe the Interrupt Priority (IP) special function register and its need.

IIET Page 63
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 6(B)
UP/DOWN BCD COUNTER

AIM: To Write an assembly language program to implement UP/DOWN BCD counter should
be check @R0=0x30. If 0x30=0 then up count else down count.
APPARATUS:

SNO NAME QUANTITY


1 keil software 1
2 8051 microcontroller kit for interfacing 1

ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Executed the program.
4. If no errors and warnings.
5. Note the address and opcode.
6. stop
FLOW CHART:
start

Write the program in keil

Executed the program

If no
errors

Note the address and


opcode

stop
IIET Page 64
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:
ORG 0000H
LJMP MAIN
MAIN: MOV 30H,#00H
MOV R0,#30H
CJNE @R0,#00H,DOWN
UP:MOV A, #00H
LOOP1:MOV R5,A
ADD A, #01
DA,A
LJMP LOOP1
DOWN: MOV A,#99H
LOOP2: MOV R5,#A
ADD A,#99H
DA,A
LJMP LOOP2
END

EXPECTED OUTPUT :
Compare R0- down counter start from 99H TO 00H.
Else up counter start from 00H TO 99H.

RESULT:
An ALP for UP/DOWN BCD counter is studied.

APPLICATIONS:
By this student will be knowing how to UP/DOWN BCD counter
EXTENSION:
By simple modification we can executed many programs UP/DOWN decimal counter
VIVA QUESTIONS:
1. Explain in detail how the Timer Flag interrupts are generated.
2. Explain in detail how the Serial Flag interrupt is generated.
3. Explain in detail how the External Flag interrupts are generated.
4. What happens when a high logic is applied on the Reset pin?
5. Why the Reset interrupt is called a non-maskable interrupt?

IIET Page 65
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 7(A)
DELAY USING TIMERS

AIM: To write and execute an ALP for delay using timers .


APPARATUS:

SNO NAME QUANTITY


1 Keil software 1
2 Window Xp operating system 1

ALGORTHIM:
1. Start
2. Load A as ooH.
3. Long call to back.
4. Move oFH to R0.
5. Compare R0 with 00h.
6. Loop continue until R0 is 00h.
7. Accumulator value start from 1 to 6.
8. End.

PROGRAM:
ORG 0000H
LJMP MAIN
MAIN:
MOV A,#00H
BACK: LCALL DELAY
INC A
CJNE A,#06H BACK
MOV R0,#0FH
HERE: DJNZ R0,HERE
RET: LCALL
END

RESULT:
An ALP for delay using timers is studied.
APPLICATIONS:
By this student will be knowing how to Boolean and logical instruction.
EXTENSION:
By simple modification we can executed many programs UP/DOWN decimal counter

IIET Page 66
MICROCONTROLLER PROGRAMMING LAB

VIVA QUESTIONS:
1. Why do we require a reset pin?
2. How can you enable/disable some or all the interrupts?
3. Explain how interrupt priorities are set? And how interrupts that occur simultaneously are
handled.
4. What Events can trigger interrupts, and where do they go after getting triggered?
5. What are the actions taken when an Interrupt Occurs?

IIET Page 67
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 7(B)
DELAY USING INSTRUCTIONS

AIM: To implement a delay using timers.


SOFTWARE REQURIED:

SNO NAME QUANTITY


1 keil software 1
2 8051 microcontroller kit for interfacing 1
ALGORTHIM:
1. Start
2. Load 00H into A
3. Call delay 01H into TMOD
4. Move oFH into R0
5. Decrement R0 = 0FH to 00H
6. Call delay
7. Here: DJNZ R0,here
8. end
FLOW CHART:
start

Write the program in keil

Executed the program

If no
errors

Note the address and


opcode

stop

IIET Page 68
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:

ORG 0000H
LJMP MAIN:
ACALL DELAY
MOVA,0FFH
ACALL DELAY
DELAY:
MOV TMOD #01H
MOV R0#OFH
L1: MOV TL0,#01H
MOV TH0,#00H
SETB T,R0
HERE: JNB TF0,HERE
CLR TR0
CLR TFO
DJNZ R0,L1
RET: END

EXECPTED INPUTS AND OUTPUTS:


A=00H; R0=0FH, DEC=R0 TO 00H
THE A=1,2.3.4.5,6,7…
TIME DELAY IS 16

RESULT:
An ALP for implement a delay using timers is studied.
APPLICATIONS:
By this student will be knowing how to Boolean and logical instruction.
EXTENSION:
By simple modification we can executed many programs UP/DOWN decimal counter
VIVA QUESTIONS:
1. What are the actions taken when an Interrupt Occurs?
2. What are Software generated interrupts and how are they generated?
3. What is RS232 and MAX232?
4. What is the function of RS and E pins in an LCD?
5. What is the use of R/W pin in an LCD?

IIET Page 69
MICROCONTROLLER PROGRAMMING LAB

IIET Page 70
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 8(A)
TO GENERATE A SQUARE WAVE.

AIM: Write a C program for generating a square wave.


SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Compile and debug
4. Satisfy the output.
5. Create the exectable file.
6. By using unipro software emulate the burn into AT89C51.
7. Test the output on target,
8. Stop.

IIET Page 71
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Write the program in keil

Errors-0
Warnings-0

Desire
d
output

Create exectable HEX file

Using unipro burn into the chip

Test the ouput on target

stop

CIRCUIT DIAGRAM:

IIET Page 72
MICROCONTROLLER PROGRAMMING LAB

PROGRAM

#include<regx51.h>
delay(viod);

int main(void)
{

P1_5=0;
while(1)
{
TMOD=0x01;
TH0=0xFF;
TL0=0xF2;
delay(1000);
}
}

IIET Page 73
MICROCONTROLLER PROGRAMMING LAB

delay(void)
{
TR0=1;
while(TF0!=1);
P1_5=~P1_5;
TF0=0;
TR0=0;
}

OUTPUT

IIET Page 74
MICROCONTROLLER PROGRAMMING LAB

RESULT:

Generating a square wave is studied.

APPLICATIONS:
By this student will be knowing how to to generate square wave.

EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.
VIVA QUESTIONS:
1. What is the significance of DA instruction?
2. What is packed and unpacked BCD?
3. What is the difference between CY and OV flag?
4. When will the OV flag be set?
5. What is an ASCII code?

IIET Page 75
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 9(A)
INTERFACING OF SWITCHES TO LED’S KEY
AIM: To make an LED connected to por 1.5 light up for specification time on pressing a swith
connected to port 2.3.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
PROCEDURE:
1. Start.
2. Write the program in keil .
3. Compile and debug
4. Satisfy the output.
5. Observe the SFR’s, registers R0-R7,memory location
6. Stop.

IIET Page 76
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Write the program in keil

Errors-0
Warnings-0

Desire
d
output

Create exectable HEX file

Using unipro burn into the chip

Test the ouput on target

stop

PROGRAM:

#include<reg51.h>
#define KEYE –ADDRESS 0X1200
#DEFINE LED – ADDRESS 0X1600
S bit KEY 8 =P3A3;
Void write (unsigned char address,unsigned char date);
Unsigned .char read(unsigned .char address);
Void int key 8(void);

IIET Page 77
MICROCONTROLLER PROGRAMMING LAB

Void delay(int count);


Data unsigned char xdata *key data=KEYE-ADDRESS
Data unsigned charx Data *LED data=LED-ADDRESS
INT MAIN (void)
{
Int key8()
Delay(500)
Write (*led data,0xAA
Write (*LED data,0xAA
White(1);
}
Void key 8-ISR(void)
{
Unsigned char data:
Data=*key data:
*led data =Ndata;
Delay();
Key 8=1;
}
Void delay (int count)
Int i,i;
For(i=0,i<count,i++)
For(j=0;j<113:j++)
}
Void write(unsigned char address,unsigned char dat)
{
*Led data=dat:
}
Void init key 8(void)
{
Ie=0x84;
Ip=0x04;
It1=1
}

RESULT:
To make an LED connected to por 1.5 light up for specification time on pressing a swith
connected to port 2.3 is studied.

.
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.
IIET Page 78
MICROCONTROLLER PROGRAMMING LAB

VIVA QUESTIONS:
1. What are the different addressing modes supported by 8051 Microcontroller ?
2. Explain the Immediate Addressing Mode.
3. Explain the Register Addressing Mode.
4. Explain the Direct Addressing Mode. Explain the Indirect Addressing Mode.
5. Explain the Code Addressing Mode.

IIET Page 79
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 9(A)ii
LED PIN 1.7 BLINK AT A SPECIFIC RATE

AIM: to write a program to make LED connected to 1.7 blink at a specific rate.
SOFTWARE REQURIED:

SNO NAME QUANTITY


1 keil software or EDSIM51 1

Algorithm:
1. Initialize stdio.h header files
2. Initialize calling function into count
3. Initialize port 1.7 with 0
4. Set delay time 500ms
5. Make port 1.7 with 1
6. Set delay time 500ms
7. Set i<count;j<113
8. Stop

PROGRAM:
#include <reg51.h>
#include<stdio.h>
Void delay(int count);
Main()
{
p1^T=0;
delay(5000);
p1^7=1:
delay(5000);
}
Void delay(int count)
{
Int I,j;
For(i=0;i<count;i++)

IIET Page 80
MICROCONTROLLER PROGRAMMING LAB

For(j=0;j<113;j++)
}
FLOWCHART:

START

Initialize stdio.h1 reg 51h header files

Initialize calling function intocount

Initialize port 1.7 with 0

Set delay time 500ms

Make port 1.7

Set delay time 500ms

Set i<count;j<113

stop

RESULT:
Thus an LED connected to 1.7 blink at a specific rate is studied .

APPLICATIONS:
By this student will be knowing how LED display with 89 C 51.

EXTENSION:
By simple modification we can executed many programs like interface LED display to
generate square wave.
VIVA QUESTIONS:

IIET Page 81
MICROCONTROLLER PROGRAMMING LAB

1. Explain in detail the Functional Classification of 8051 Instruction set


2. What are the instructions used to operate stack?
3. What are Accumulator specific transfer instructions?
4. What is the difference between INC and ADD instructions?
5. What is the difference between DEC and SUBB instructions?

IIET Page 82
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 9(B)
RELAY CONTROLLER AC 230V LAMP
AIM: To write a program for relay controller AC 230v lamp.
SOFTWARE REQURIED:
A system loaded with keil or EDSIM51.
ALGORTHIM:
1. Start
2. Initialize reg51 header file
3. Initialize LED address is 0x1600
4. Initialize LED data equal to LED address
5. Initialize while with 1
6. Set delay as 500ms
7. Write LED data and address
8. Set dalay as 1000ms
9. Initialize integer I,j
10. Set i<count and j=109
11. End

IIET Page 83
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Initialize reg51 header file

Initialize LED address is 0x1600

Initialize LED data equal to LED


address

Initialize while with 1

Set delay as 500ms

Write LED data and address

stop

PROGRAM:
#include<reg51.h>

#define include<stdio.h>

#define LED-ADDRESS .0x1600

Data unsigned char xdata

*LED DATA =LED-ADDRESS;

IIET Page 84
MICROCONTROLLER PROGRAMMING LAB

Void WRITE(unsigned char address,unsigned char data);

Void delay(unsigned int count);

Int main(void)

While(1)

Delay(500)

WRITE(*LED DATA,0xAA);

Delay(1000);

WRITE(*LED DATA, 0x55);

Delay(1000);

Void delay(unsigned int count)

Int i,j;

For(i=0;i<count;i++)

For(j=0;j,109;j++);

Void WRITE(unsigned char address,unsigned char data)

*LED data=data;

IIET Page 85
MICROCONTROLLER PROGRAMMING LAB

RESULT:
Relay controller AC 230v lamp has been studied.
APPLICATIONS:
By this student will be knowing how for displaying character ECE in a seven segment
display.

VIVA QUESTIONS:
1. How many Timers are there in 8051?
2. What are the three functions of Timers?
3. What are the different modes of operation of timer/counter?
4. Give a brief introduction on the various Modes.
5. What is the count rate of timer operation?

IIET Page 86
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 10(A)
INTERFACING OF SEVEN SEGMENT DISPLAY

AIM: Write a C program program to interfacing of seven segment display.


SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
ALGORTHIM:
1. Start.
2. Load 30H to 39H with different values
3. Load 30H data into R0
4. Load address of R0 into A
5. Load R1,A
6. Increment R0
7. If condition is not satisfy go back
8. Stop.

IIET Page 87
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Load 30H to 39H with different values

Load 30H data into R0

Load address of R0 into A

Load R1,A

Increment R0

If
R0=8AH

stop
PROGRAM:
ORG 0000H
LJMP MAIN
MAIN: MOV 30H,#0C0H
MOV 31H,#0F9H
MOV 32H,#94H
MOV 33H,#0B0H
MOV 34H,#099H
MOV 35H,#092H
MOV 36H,#082H

IIET Page 88
MICROCONTROLLER PROGRAMMING LAB

MOV 37H,#0F8H
MOV 38,#080H
MOV 39H,#030H
LOOP1: MOV R0,#30H
BACK:MOV A,@R0
MOV R,A
INC R0
CJNE R0,#3AH,BACK
LJMP LOOP
END

RESULT: T o interfacing of seven segment display is studied.


APPLICATIONS:
By this student will be knowing how for display program LCD
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.
VIVA QUESTIONS:

1. What is the difference between mode 0 and mode 1?


2. What is the difference Modes 0,1,2 and 3?
3. How do you differentiate between Timers and Counters?
4. Explain the function of the TMOD register and its various fields?
5. How do you control the timer/counter operation?
6. What is the function of TF0/TF1 bit

IIET Page 89
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 11(A)
3X4 KEYBOARD INTERFACING
AIM: Write a C program for keypad interfacing for 8051(4X4 matrix).

SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 8051 microcontroller kit for interfacing 1
3 Window Xp operating system 1
4 Target board 1
5 Unipro ppprrrogrammer kit 1
6 Unipro software 1
ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Compile and debug
4. Satisfy the output.
5. Create the exectable file.
6. By using unipro software emulate the burn into AT89C51.
7. Test the output on target,
8. Stop.

IIET Page 90
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Write the program in keil

Errors-0
Warnings-0

Desire
d
output

Create exectable HEX file

Using unipro burn into the chip

Test the ouput on target

stop

CIRCUIT DIAGRAM:

IIET Page 91
MICROCONTROLLER PROGRAMMING LAB

THEORY:

PROCEDURE:

PROGRAM:

#include <reg51.h>

#define KEYE_ADDRESS 0x1200

#define LED_ADDRESS 0x1600

sbit KEY8=P3^3;

IIET Page 92
MICROCONTROLLER PROGRAMMING LAB

void write(unsigned char address, unsigned char dat);


unsigned char read (unsigned char address);
void initKey8(void);
void delay(int count);
data unsigned char xdata *keyData = KEYE_ADDRESS;
data unsigned char xdata *ledData = LED_ADDRESS;
int main(void)
{
initKey8();
delay(500);
write(*ledData,0xAA);
while(1);
}
void key8_ISR(void) interrupt 2
{
unsigned char Data;

Data = *keyData;
*ledData = ~Data;
delay(1000);

KEY8 = 1;
}

void delay(int count)


{
int i,j;

for(i=0;i<count;i++)
for(j=0;j<113;j++)
;
}

void write(unsigned char address, unsigned char dat)


{
*ledData = dat;
}

void initKey8(void)
{
IE = 0x84;
IP = 0x04;
IT1 = 1;
}

IIET Page 93
MICROCONTROLLER PROGRAMMING LAB

RESULT:

Keyboard interfacing for 8051 is studied.

APPLICATIONS:
By this student will be knowing how for Keypad interfacing for 8051.
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.
VIVA QUESTIONS:
1. Explain the function of the TCON register and its various fields?
2. Explain how the Timer/Counter Interrupts work.
3. Explain how the 8051 counts using Timers and Counters.
4. Explain Counting operation in detail in the 8051.
5. Explain why there is limit to the maximum external frequency that can be
counted.
6. What’s the benefit of the auto-reload mode?

IIET Page 94
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 12
INTERFACE DC MOTOR
AIM: To Write a C program to interface DC motor.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 8051 microcontroller kit for interfacing 1
3 Window Xp operating system 1
4 Target board 1
5 Unipro ppprrrogrammer kit 1
6 Unipro software 1
ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Compile and debug
4. Satisfy the output.
5. Create the exectable file.
6. By using unipro software emulate the burn into AT89C51.
7. Test the output on target,
8. Stop.

IIET Page 95
MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Write the program in keil

Errors-0
Warnings-0

Desire
d
output

Create exectable HEX file

Using unipro burn into the chip

Test the ouput on target

stop

CIRCUIT DIAGRAM:

IIET Page 96
MICROCONTROLLER PROGRAMMING LAB

THEORY:
DC motors are used in many applications like process control and automation in an
industry, robotics, consumer electronics, office automation equipment like printers and scanners
etc. One can consider the use of a DC motor wherever there is need to control the motion of an
object. Speed control of the motor is important in the applications involving them. For example,
in an audio system, the DC motor that drives the cassette should always run at a fixed speed.
Like wise, there are applications where the speed of the DC motor has to change according to
some defined conditions. The DC motor used in this interface module is a 12V, 4W motor that
can be seen in many electronic equipments. The circuit to control the speed of the motor follows
a general concept and can be applied to DC motors of higher capacity also.
The pulse width modulation technique is used to vary the speed of the DC motor. The
frequency of the pulses is 120Hz. Keeping the frequency constant, the width of the pulses is used
to change the speed. When the pulse width is minimum, the speed is minimum and when the
width is maximum, the speed is maximum (2400rpm). The ramp and pedestal technique is used
to change the pulse width and thereby the speed.
PROCEDURE:
1. Switch ON the power supply and Microcontroller kit and interface board.
2. Enter the opcode of the program.
3. Execute the program.
4. Monitor the speed of DC motor.
5. Verify its output.

IIET Page 97
MICROCONTROLLER PROGRAMMING LAB

PROGRAM:

#include <REG51xD2.H>
sbit inr= P3^2; //speed increment switch
sbit dcr= P3^3; //speed decrement switch
main()
{
unsigned char i=0x80;
P0 = 0x7f; /*Run the motor at half speed.*/
while (1)
{
if (!inr)
{
while (!inr);
if(i>10)
i=i-10; //increase the DC motor speed
}
if(!dcr)
{
while(!dcr);
if(i<0xf0)
i=i+10; //decrease the DC motor speed
}
P0=i;
}
}

RESULT:
Interface DC motor is studied.

APPLICATIONS:
By this student will be knowing how for Interface DC motor for 8051.

IIET Page 98
MICROCONTROLLER PROGRAMMING LAB

EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.

VIVA QUESTIONS:
1. Write a short note on Serial and Parallel communication and highlight their advantages
and disadvantages.
2. Explain Synchronous Serial Data Communication.
3. Explain Asynchronous Serial Data Communication.
4. Explain Simplex data transmission with examples.
5. Explain Half Duplex data transmission with examples.

IIET Page 99
MICROCONTROLLER PROGRAMMING LAB

PROGRAM 13(A)
ADC INTERFACE

AIM: To write a program for to interface the ADC.


SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1
CIRCUIT DIAGRAM:

ALGORTHIM:
1. start.

IIET Page 100


MICROCONTROLLER PROGRAMMING LAB

2. initialize Reg51h header file


3. Initialize voi main
4. Initialize while with (1)
5. Initialize data into display
6. stop
PROGRAM:
#include <reg51.h>
Extern delay_us(unsigned char);
Extern data_disp()
Void main(void)
{
While(1)
{
//set_point(adc_data);
Data_disp();
//channel_disp(channel);
}
}

RESULT: to interface the ADC is studied.


APPLICATIONS:
By this student will be knowing how for converting an analog signal.
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.
VIVA QUESTIONS:
1. Explain Full Duplex data transmission with examples.
2. What is Baud rate?
3. What is a Modem?
4. What are the various registers and pins in the 8051 required for Serial communication?
Explain briefly.
5. Explain SCON register and the various fields.
6. Explain serial communication in general (synchronous and asynchronous). Also

IIET Page 101


MICROCONTROLLER PROGRAMMING LAB

PROGRAM 13(B)
DAC INTERFACE

AIM: To write a program to interface DAC.


SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 Window Xp operating system 1

BLOCK DIAGRAM:

CIRCUIT DIAGRAM:

IIET Page 102


MICROCONTROLLER PROGRAMMING LAB

PROCEDURE:
1. Connect the DAC interfacing board with microcontroller kit and also connect CRO to
its output (DAC)
2. Switch ON the power supply and Microcontroller kit and CRO.
3. Enter the opcode of the program.
4. Execute the program.
5. Trace the output waveform and calculate its frequency.
6. Verify its output.
PROGRAM:
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MOV A,#80H
MOV DPTR,#CNTRL(4003)
MOVX @DPTR,A
START MOV A,#00H
MOV DPTR,#PORTA(4000)
MOVX @DPTR,A

IIET Page 103


MICROCONTROLLER PROGRAMMING LAB

LCALL DELAY
MOV A,#0FFH
MOV DPTR,#PORTA
MOVX @DPTR,A
LCALL DELAY
SJMP START
DELAY MOV R1,#10H
L1 MOV R0,#0FFH
L2 DEC R0
CJNE R0,#00H,L2
DEC R1
CJNE R1,#00H,L1
RET
END

RESULT: To write and execute an ALP interface DAC is studied.

APPLICATIONS:
By this student will be knowing how for square wave signal by using DAC.
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.

VIVA QUESTIONS:
1. How the Serial data interrupts are generated?
2. How is data transmitted serially in the 8051? Explain briefly.
3. How is data received serially in the 8051? Explain briefly.
4. What are the various modes of Serial Data Transmission? Explain each mode briefly.
5. Explain with a timing diagram the shift register mode in the 8051.

IIET Page 104


MICROCONTROLLER PROGRAMMING LAB

PROGRAM 13(C)
SERIAL COMMUNICATION

AIM: Write a C program to perform an serial communication .


.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 8051 microcontroller kit for interfacing 1
ALGORTHIM:

1. Start.
2. Write the program in keil .
3. Compile and debug
4. Satisfy the output.
5. Create the exectable file.
6. By using unipro software emulate the burn into AT89C51.
7. Test the output on target,
8. Stop.

IIET Page 105


MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Write the program in keil

Errors-0
Warnings-0

Desire
d
output

Create exectable HEX file

Using unipro burn into the chip

Test the ouput on target

stop

CIRCUIT DIAGRAM:

IIET Page 106


MICROCONTROLLER PROGRAMMING LAB

PROGRAM:

#include <reg51.H>

/* DECLERATION OF FUNCTIONS REQUIRED FOR SERIAL COMMUMICATION */


#define NULL '\0'
void PUTCHAR(unsigned char);
unsigned char GETCHAR(void);
void PUTSTRING(unsigned char *);
void SERIALINT(void);
void LINEFEED(void);
void delay(unsigned int count);

/* MAIN PROGRAM */

int main(void)
{
unsigned char ch;
SERIALINT();
PUTSTRING("INDUR INISTITUTE OF ENGG & TECH");
LINEFEED();
while(1)
{
ch=GETCHAR();
PUTCHAR(ch);

}
}

/* FUNCTION RE DEFINATIONS */
IIET Page 107
MICROCONTROLLER PROGRAMMING LAB

void SERIALINT(void) /* To initilize the serial communication by setting SFRS of 8051 */


{
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xfd;
TL1 = 0xfd;
TR1 = 1;
}

void PUTCHAR(unsigned char byte)/* To putting a char in SBUF to transmit */


{
SBUF = byte;
while(TI!=1);
TI = 0;
}

void PUTSTRING(unsigned char *serptr)


{
unsigned char i;
for(i=0; serptr[i]!=NULL;i++)
PUTCHAR(serptr[i]);

delay(100);

}
unsigned char GETCHAR(void) /* to receive a char and set the receive interrupet*/
{
while(RI!=1);
RI=0;
return SBUF;
}

void LINEFEED(void) /* to print in a new line*/


{
PUTCHAR(0x0A);
PUTCHAR(0x0D);
}

/* TO PROVIDE SOME DELAY BETWEEN CHAR TO CHAR */


void delay(unsigned int count)
{

IIET Page 108


MICROCONTROLLER PROGRAMMING LAB

int i,j;

for(i=0;i<count;i++)
for(j=0;j<109;j++);
}

OUTPUT:
By using KIT the following output is coming in HYPER TERMINAL.

IIET Page 109


MICROCONTROLLER PROGRAMMING LAB

IIET Page 110


MICROCONTROLLER PROGRAMMING LAB

With out KIT the following output is coming in serial WINDOW

IIET Page 111


MICROCONTROLLER PROGRAMMING LAB

RESULT:
Serial communication is studied.

APPLICATIONS:
By this student will be knowing how for Serial communication.
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.

VIVA QUESTIONS:
1. What is the use of the serial communication mode 0 in the 8051?
2. Explain in detail the Serial Data Mode 1 in the 8051.
3. Explain how the Baud rate is calculated for the Serial Data Mode 1.

IIET Page 112


MICROCONTROLLER PROGRAMMING LAB

4. How is the Baud rate for the Multiprocessor communication Mode calculated?
5. Explain in detail the Multiprocessor communication Mode in the 8051.
6. Explain the significance of the 9th bit in the Multiprocessor communication Mode.

IIET Page 113


MICROCONTROLLER PROGRAMMING LAB

PROGRAM 14
BURN EXECUTABLE CODE INTO FLASH MEMORY FOR
89C51
AIM: To burn and execute the code in AT89C51 in the flash memory.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 8051 microcontroller kit for interfacing 1
3 Window Xp operating system 1
4 Target board 1
5 Unipro ppprrrogrammer kit 1
6 Unipro software 1
ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Compile and debug
4. Satisfy the output.
5. Create the exectable file.
6. By using unipro software emulate the burn into AT89C51.
7. Test the output on target,
8. Stop.

IIET Page 114


MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Write the program in keil

Errors-0
Warnings-0

Desire
d
output

Create exectable HEX file

Using unipro burn into the chip

Test the ouput on target

stop

PROCEDURE
1. Write a program in keil IDE (integrated development enable)..after satisfying with your
code by using debugging option keil.create Hex file
2. To create hex file select for forget option and activitate create hex file option and adjust
the frequency to 11.0592MHZ
3. After creating of the file open unipro software.
4. Connect USB cable to unipro kit.
5. Power on unipro kit
IIET Page 115
MICROCONTROLLER PROGRAMMING LAB

6. Open software menu nd load the program by hex file name.


7. Insert 8051 chip into sip socket of unipro kit with specified direction.
8. Select program option at that instant software shows and raise pevious program, blank
check, program burning and verification process with the 3,4 seconds
9. In unipro kit green colour light indicate program is succed otherwise we need to check
chip options &pins of unipro kit connection.
10. Verified hardware output by insert the programmed chip on the embedded sytem.
PROGRAM:
Example program:
MEMORY Hex Code Mnemonics
ADDRESS
ORG 0000H
START MOV DPTR,#9200
MOV R2,#08
MOVX A,@DPTR
PUSH DPH(83)
PUSH DPL(82)
MOV DPTR,#CNTL PORT(4003)
MOVX @DPTR,A
POP DPL
POP DPH
INC DPTR
LOOP 1 MOVX A,@DPTRPUSH DPH
PUSH DPL
MOV DPTR,#PORT A(4000)
MOVX @DPTR,A
POP DPL
POP DPH
INC DPTR
MOVX A,@DPTR
PUSH DPH

IIET Page 116


MICROCONTROLLER PROGRAMMING LAB

PUSH DPL
MOV DPTR,#PORTB(4001)
MOVX @DPTR,A
LCALL DELAY
POP DPL
POP DPH
INC DPTR
DJNZ R2,LOOP1
SJMP START
DELAY MOV R7,#10H
LOOP4 MOV R5,#FFH
LOOP3 MOV R6,#FFH
LOOP2 NOP
NOP
DJNZ R6,LOOP2
DJNZ R5,LOOP3
DJNZ R7,LOOP4
end

RESULT:
To burn and execute the code in AT89C51 in the flash memory is studied..

APPLICATIONS:
By this student will be knowing how for code in AT89C51 in the flash memory.
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.
VIVA QUESTIONS:
1. Explain the Serial data mode 3 in the 8051.
2. What are interrupts and how are they useful in Real Time Programming?
3. Briefly describe the Interrupt structure in the 8051.
4. Explain about vectored and non-vectored interrupts in general.

IIET Page 117


MICROCONTROLLER PROGRAMMING LAB

5. What are the five interrupts provided in the 8051?


6. What are the three registers that control and operate the interrupts in 8051?

IIET Page 118


MICROCONTROLLER PROGRAMMING LAB

BEYOND THE SYLLABUS


PROGRAM 15
TO TOGGLE THE PORTS WITH SPECIFIED TIME INTERVAL

AIM: To interface the toggle the ports with the specified time interval.
SOFTWARE REQURIED:
SNO NAME QUANTITY
1 keil software 1
2 8051 microcontroller kit for interfacing 1
3 Window Xp operating system 1
4 Target board 1
5 Unipro programmer kit 1
6 Unipro software 1
ALGORTHIM:
1. Start.
2. Write the program in keil .
3. Compile and debug
4. Satisfy the output.
5. Create the exectable file.
6. By using unipro software emulate the burn into AT89C51.
7. Test the output on target,
8. Stop.

IIET Page 119


MICROCONTROLLER PROGRAMMING LAB

FLOW CHART:

start

Write the program in keil

Errors-0
Warnings-0

Desire
d
output

Create exectable HEX file

Using unipro burn into the chip

Test the ouput on target

stop

PROGRAM:

#include<reg51.h>
#include<stdio.h>
void delay(unsigned int count);
int main(void)
{
while(1)

IIET Page 120


MICROCONTROLLER PROGRAMMING LAB

{
P0=0XAA;
delay(1000);
P0=0x55;
delay(1000);

P3=0x44;
delay(1000);
P3=0x88;
delay(1000);
}
}
void delay(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<109;j++);
}

OUTPUT

IIET Page 121


MICROCONTROLLER PROGRAMMING LAB

RESULT:
Toggle the ports with specified time interval has been studied.

APPLICATIONS:
By this student will be knowing how to toggle the ports with specified time interval
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.

VIVA QUESTIONS:
1. Describe the Interrupt Enable (IE) special function register and its various bits.
2. Describe the Interrupt Priority (IP) special function register and its need.
3. Explain in detail how the Timer Flag interrupts are generated.
4. Explain in detail how the Serial Flag interrupt is generated.

IIET Page 122


MICROCONTROLLER PROGRAMMING LAB

5. Explain in detail how the External Flag interrupts are generated.

IIET Page 123


MICROCONTROLLER PROGRAMMING LAB

PROGRAM 16
TO DISPLAY MESSAGE

AIM: To display message on given address, in memory window.


SOFTWARE REQURIED:

SNO NAME QUANTITY


1 keil software 1
2 8051 microcontroller kit for interfacing 1
3 Window Xp operating system 1

PROGRAM:

#include<reg51.h>
#include<stdio.h>
void delay(unsigned int count);
data unsigned char xdata *name=0x1600;
int main(void)
{
while(1)
{
int i=0;
char a[30]="INDUR INISTITUTE OF ENGG &TECH";
for(i=0;i<30;i++)
{
*name=a[i];
name++;
delay(1000);
}
for(i=30;i>0;i--)
{
*name='*';
name--;
delay(1000);
}
}
}
void delay(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<109;j++);
}

IIET Page 124


MICROCONTROLLER PROGRAMMING LAB

OUT PUT:

RESULT:
Displaying the message has been studied.
APPLICATIONS:
By this student will be knowing how for Displaying the message.
EXTENSION:
By simple modification we can executed many programs like interface LCD display to
generate square wave.

VIVA QUESTIONS:
IIET Page 125
MICROCONTROLLER PROGRAMMING LAB

1. Why the Reset interrupt is called a non-maskable interrupt?


2. Why do we require a reset pin?
3. How can you enable/disable some or all the interrupts?
4. Explain how interrupt priorities are set? And how interrupts that occur simultaneously are
handled.
5. What Events can trigger interrupts, and where do they go after getting

IIET Page 126


MICROCONTROLLER PROGRAMMING LAB

REFERENCES
1. “The 8051 Microcontroller and Embedded Systems – using assembly and C ”-, by Muhammad
Ali, Mazidi and Janice Gillespie Mazidi and Rollin D. McKinlay; PHI, 2006 / Pearson, 2006
2. “MSP430 Microcontroller Basics”, John Davies, Elsevier, 2010
3. “The 8051 Microcontroller Architecture, Programming & Applications”, 2e Kenneth J.
Ayala ;Penram International, 1996 / Thomson Learning 2005.
4. “The 8051 Microcontroller”, V.Udayashankar and MalikarjunaSwamy, TMH, 2009
5. “Microcontrollers: Architecture, Programming, Interfacing and System Design”,Raj Kamal,
“PearsonEducation,2005.

IIET Page 127

Você também pode gostar