Microcontroller Lab Manual
Microcontroller Lab Manual
Microcontroller Lab Manual
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
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:
ALGROTHIM
IIET Page 6
MICROCONTROLLER PROGRAMMING LAB
FLOW CHART:
IIET Page 7
MICROCONTROLLER PROGRAMMING LAB
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
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:
ALGORITHM:
IIET Page 12
MICROCONTROLLER PROGRAMMING LAB
FLOW CHART:
DIVISION:
START
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
OUTPUT: Multiplication
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.
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
If no
errors
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
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
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 A with B
MUL AB
End
IIET Page 19
MICROCONTROLLER PROGRAMMING LAB
start
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
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
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
START
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
START
DIVIDE A WITH B
LOAD R1 WITH A
LOAD R2 WITH B
no IS
RO=
1
yes
LOAD B WITH R2
END
PROGRAM:
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
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:
If no
errors
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
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
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
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
increment R0
IIET Page 31
MICROCONTROLLER PROGRAMMING LAB
If
R2=0
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
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:
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:
FLOW CHART:
Start
IIET Page 38
x
MICROCONTROLLER PROGRAMMING LAB
DEC R2
INC
R0
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:
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
IIET Page 41
MICROCONTROLLER PROGRAMMING LAB
PROGRAM 4(B)
SEARCH OF AN ELEMENT IN 10 BYTES OF DATA
SOFTWARE REQURIED:
START
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:
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:
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:
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
If no
errors
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
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
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
If no
errors
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
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:
FLOW CHART
START
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
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
If no
errors
stop
PROGRAM:
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
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
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
If no
errors
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:
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
If no
errors
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
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
If no
errors
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
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.
IIET Page 71
MICROCONTROLLER PROGRAMMING LAB
FLOW CHART:
start
Errors-0
Warnings-0
Desire
d
output
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:
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
Errors-0
Warnings-0
Desire
d
output
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
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:
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
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
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
stop
PROGRAM:
#include<reg51.h>
#define include<stdio.h>
IIET Page 84
MICROCONTROLLER PROGRAMMING LAB
Int main(void)
While(1)
Delay(500)
WRITE(*LED DATA,0xAA);
Delay(1000);
Delay(1000);
Int i,j;
For(i=0;i<count;i++)
For(j=0;j,109;j++);
*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
IIET Page 87
MICROCONTROLLER PROGRAMMING LAB
FLOW CHART:
start
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
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
Errors-0
Warnings-0
Desire
d
output
stop
CIRCUIT DIAGRAM:
IIET Page 91
MICROCONTROLLER PROGRAMMING LAB
THEORY:
PROCEDURE:
PROGRAM:
#include <reg51.h>
sbit KEY8=P3^3;
IIET Page 92
MICROCONTROLLER PROGRAMMING LAB
Data = *keyData;
*ledData = ~Data;
delay(1000);
KEY8 = 1;
}
for(i=0;i<count;i++)
for(j=0;j<113;j++)
;
}
void initKey8(void)
{
IE = 0x84;
IP = 0x04;
IT1 = 1;
}
IIET Page 93
MICROCONTROLLER PROGRAMMING LAB
RESULT:
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
Errors-0
Warnings-0
Desire
d
output
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
ALGORTHIM:
1. start.
PROGRAM 13(B)
DAC INTERFACE
BLOCK DIAGRAM:
CIRCUIT DIAGRAM:
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
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
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.
PROGRAM 13(C)
SERIAL COMMUNICATION
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.
FLOW CHART:
start
Errors-0
Warnings-0
Desire
d
output
stop
CIRCUIT DIAGRAM:
PROGRAM:
#include <reg51.H>
/* 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
delay(100);
}
unsigned char GETCHAR(void) /* to receive a char and set the receive interrupet*/
{
while(RI!=1);
RI=0;
return SBUF;
}
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.
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.
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.
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.
FLOW CHART:
start
Errors-0
Warnings-0
Desire
d
output
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
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.
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.
FLOW CHART:
start
Errors-0
Warnings-0
Desire
d
output
stop
PROGRAM:
#include<reg51.h>
#include<stdio.h>
void delay(unsigned int count);
int main(void)
{
while(1)
{
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
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.
PROGRAM 16
TO DISPLAY MESSAGE
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++);
}
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
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.