Practical
Manual
Microcontroller
Prof. Suraj R. Gaikwad
Prof. Suraj R. Gaikwad MIC
Exp: 1) To write an assembly language program for arithmetic operations.
Program:
1) MOV A,#20H
MOV F0,#20H
ADD A,F0
RET
2) MOV A,#20H
MOV F0,#10H
SUB A,F0
RET
3) MOV A,#04H
MOV F0,#02H
MUL A,F0
RET
4) MOV A,#10H
MOV F0,#02H
ADD A,F0
RET
Results:
Addition: A = 40H
Subtraction: A = 0AH
Multiplication: A = 08H
Division: A = 05H
Prof. Suraj R. Gaikwad MIC
Exp:2) To develop an assembly language program to transfer block of 10
bytes stored in internal data memory from location 40H to 60H.
Program:
ORG 0000H
MOV R0,#40H
MOV R1,#60H
MOV R2,#0AH
LOOP:MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2, LOOP
END
Prof. Suraj R. Gaikwad MIC
Exp:3) To develop an assembly language program to get square of numbers.
Program:
ORG 0000H
MOV R0,#40H
MOV R1,#60H
MOV R2,#0AH
LOOP1:MOV A,@R0
MOV B,@R0
MUL AB
MOV @R1,A
INC R0
INC R1
DJNZ R2,LOOP1
END
Result:
Input:
Output:
00H = 0D
01H = 1D
04H = 4D
09H = 9D
10H = 16D
19H = 25D
24H = 36D
31H = 49D
40H = 64D
51H = 81D
Prof. Suraj R. Gaikwad MIC
Exp:4) To develop program for arranging 10 numbers in descending order.
Program:
ORG 00H
ARR EQU 70H
L0:MOV R1,#ARR
MOV R0,#ARR
MOV R2,#0AH
MOV R3,#00H
DEC R2
L1:MOV A,@R0
MOV B,A
INC R1
SUBB A,@R1
JNC L2
MOV A,B
XCH A,@R1
MOV @R0,A
MOV R3,#01H
L2:INC R0
DJNZ R2,L1
CJNE R3,#00,L0
SJMP $
END
Result:
Input:
Output:
Prof. Suraj R. Gaikwad MIC
Exp:5) To develop a program to generate Square wave over port pins.
Program:
ORG 0000H :initialization
MOV TMOD,#10H :move 10H into timer/counter mode control resister
UP:
MOV TL1,#0D2H :move 0D2H into timer 1 low byte
MOV TH1,#0FFH :move offH into timer 1 high byte
SETB TR1 :addressed TR1 is set, TR1=timer 1 run control bit
WAIT:
JNB TF1,WAIT :jump if addressed TR1 is 0, otherwise
proceed with next instruction
CLR TR1 :adressed TR1 is cleared
CPL P1.5 : complement the addressed P1.5
CLR TF1 : adressed TF1 is cleared, TF1=timer 1 overflow flag
SJMP UP :program branches unconditionally to address indicated
END :end
Result:
Prof. Suraj R. Gaikwad MIC
Exp:6) To generate Square wave using DAC.
Circuit Diagram:
C Program:
#include <REG51xD2.H>
#include <stdio.h>
sbit Amp = P3^3; /* Port line to change amplitude */
sbit Fre = P3^2; /* Port line to change frequency */
void delay(unsigned int x) /* delay routine */
{
for(;x>0;x--);
}
main()
{
unsigned char on = 0x7f,off=0x00;
unsigned int fre = 100;
while(1)
Prof. Suraj R. Gaikwad MIC
{
if(!Amp) /* if user choice is to change amplitude */
{
while(!Amp); /* wait for key release */
on+=0x08; /* Increase the amplitude */
}
if(!Fre) /* if user choice is to change frequency */
{
if(fre > 1000) /* if frequency exceeds 1000 reset to default */
fre = 100;
while(!Fre); /* wait for key release */
fre += 50; /* Increase the frequency */
}
P0=on; /* write amplitude to port */
P1=on;
delay(fre);
P0 = off; /* clear port */
P1 = off;
delay(fre);
}
}
Output Waveform:
Prof. Suraj R. Gaikwad MIC
Assembly Program:
ORG 0000H
MOV DPTR, #8000H
UP:MOV DPL,#40H
MOV DPH,#40H
CLR A
MOVC A,@A+DPTR
SETB P1.5
WAIT:JNB P1.5,WAIT
CLR P1.5
SJMP UP
END
Output Waveform:
Prof. Suraj R. Gaikwad MIC
Exp:7) To write a program to drive Stepper Motor.
Theory:
Driving Unipolar Stepper Motor with 8051:
Unipolar stepper motors can be used in three modes namely the Wave Drive, Full
Drive and Half Drive mode.
Half Drive Stepping Sequence
Prof. Suraj R. Gaikwad MIC
Interfacing Using L293D:
Interfacing Using ULN2003:
Prof. Suraj R. Gaikwad MIC
Programs:
Keil C Code for Wave Drive:
Prof. Suraj R. Gaikwad MIC
Keil C Code for Full Drive:
Prof. Suraj R. Gaikwad MIC
Keil C Code for Half Drive:
Prof. Suraj R. Gaikwad MIC
Result:
1) Wave drive stepper sequence:
Prof. Suraj R. Gaikwad MIC
2) Full drive stepping sequence:
Prof. Suraj R. Gaikwad MIC
3) Half wave stepping sequence:
Prof. Suraj R. Gaikwad MIC
Prof. Suraj R. Gaikwad MIC
Prof. Suraj R. Gaikwad MIC
Exp:8) To write a program to drive Stepper Motor in clockwise direction and
anti-clockwise direction.
Program:
ORG 0000H
MOV R2,#12H
MOV A,#88H
LOOP1: MOV P2,A
RR A
DJNZ R2, LOOP1
MOV R2,#12H
MOV A,#11H
LOOP2: MOV P2,A
RL A
DJNZ R2, LOOP2
END
Result:
Prof. Suraj R. Gaikwad MIC
Prof. Suraj R. Gaikwad MIC
Prof. Suraj R. Gaikwad MIC
Exp:9) To write a program to read keyboard and display code.
Diagram:
Program:
• Program to interface matrix keyboard 4x4
• Rows are connected to the Port pins P1.0-P1.3 & Columns are connected to
Port pins P2.0-P2.3
• Rows are grounded one by one and read columns Seven segment display is
connected at port P0
ORG 00H
AJMP START
ORG 13H
RETI
START:MOV P0,#00H
MOV P2,#0FH ; Port Pins P2.0 to P2.3 i/p pins and P2.4 to P2.7 o/p pins
MOV P1,#00H ; Port P0 output port
REL: MOV P1,#00H ; make all rows ground to check all keys
MOV A,P2 ; read port p2 to ensure that all keys released
Prof. Suraj R. Gaikwad MIC
ANL A,#0FH ; maks upper bits because they are not used
CJNE A,#0FH,REL ; check till all keys released
AGAIN: ACALL DELAY
MOV A,P2 ; see if any key pressed or not?
ANL A,#0FH ; mask upper bits
CJNE A,#0FH,KPRESS ; if a is not equal to 0fh then key is pressed
SJMP AGAIN ; check again if key is not pressed
KPRESS: ACALL DELAY
MOV A,P2 ;
ANL A,#0FH ; mask unused upper bits
CJNE A,#0FH,KPRESS1 ; if a is not equal to 0fh then key is pressed
SJMP AGAIN ; check again if key is not pressed
KPRESS1:
MOV P1,#0FEH ; ground row 0
MOV A,P2 ; read all columns
ANL A,#0FH ; mask unused upper bits
CJNE A,0FH,R_0 ; key is pressed in first row (row 0),check columns
MOV P1,#0FDH ; Ground ROW 1
MOV A,P2 ; read all columns
ANL A,#0FH ; mask unused upper bits
CJNE A,0FH,R_1 ;key is pressed in second row (row 1),check columns
MOV P1,#0FBH ; ground row 2
MOV A,P2 ; read all columns
ANL A,#0FH ; mask unused upper bits
CJNE A,0FH,R_2 ;key is pressed in third row (row 2),check columns
MOV P1,#0F7H ; ground row 0
MOV A,P2 ; read all columns
ANL A,#0FH ; mask unused upper bits
CJNE A,0FH,R_3 ;key is pressed in fourth row (row 3),check columns
LJMP AGAIN
R_0: MOV DPTR,#KCODE0 ;set dptr=start of row 0
SJMP CHECK_C
R_1: MOV DPTR,#KCODE1 ;set dptr=start of row 1
SJMP CHECK_C
R_2: MOV DPTR,#KCODE2 ;set dptr=start of row 2
SJMP CHECK_C
R_3: MOV DPTR,#KCODE3 ;set dptr=start of row 3
CHECK_C:
RRC A ;check whether carry occurs or not
JNC GET_CODE
Prof. Suraj R. Gaikwad MIC
INC DPTR
SJMP CHECK_C
GET_CODE: CLR A
MOVC A,@A+dptr
MOV P0,A
LJMP REL
DELAY: MOV R7,#0FFh
DLOOP: MOV R6,#0FFh
D_LOOP: DJNZ R6,D_LOOP
DJNZ R7,DLOOP
RET
Result:
KCODE0: DB '0','1','2','3' ; These codes are for LCDs
KCODE1: DB '4','5','6','7' ; Replace this code by seven
KCODE2: DB '8','9','A','B' ; segment code as per your
KCODE3: DB 'C','D','E','F' ; Circuit.

More Related Content

PPTX
Complexity Analysis of Recursive Function
PPT
Recursion.ppt
PPT
Java Presentation
PPT
Scanner class
PPTX
Recursive Function
PPT
Java Basics
PPT
Java Socket Programming
PPTX
OOP Introduction with java programming language
Complexity Analysis of Recursive Function
Recursion.ppt
Java Presentation
Scanner class
Recursive Function
Java Basics
Java Socket Programming
OOP Introduction with java programming language

What's hot (20)

PDF
file handling c++
PPT
Applet life cycle
PPTX
Register transfer and micro-operation
PPTX
Shell scripting
PDF
Constructor and Destructor
PPTX
Input & Output
PPT
14 file handling
 
PPTX
Java program structure
PPT
JAVA OOP
PPTX
polymorphism
PDF
STL in C++
PPTX
Data file handling in c++
PPTX
DOCX
Multiple choice questions for Java io,files and inheritance
PPTX
Introduction to numpy
PPT
C++ Overview
PPSX
Function in c
PPT
Introduction to C Programming
PPTX
Ch.1 oop introduction, classes and objects
DOCX
Data Structure in C (Lab Programs)
file handling c++
Applet life cycle
Register transfer and micro-operation
Shell scripting
Constructor and Destructor
Input & Output
14 file handling
 
Java program structure
JAVA OOP
polymorphism
STL in C++
Data file handling in c++
Multiple choice questions for Java io,files and inheritance
Introduction to numpy
C++ Overview
Function in c
Introduction to C Programming
Ch.1 oop introduction, classes and objects
Data Structure in C (Lab Programs)
Ad

Viewers also liked (20)

PPT
Research Process
DOCX
the amazing quran
DOCX
EngAhmed
PDF
Bonner Directors 2016 -Book of Bonner
PDF
etailment WIEN 2016 - A. Schiechl, S. Danninger, F. Wolf – Netconomy & SAP Ös...
PPTX
Participación Político Social. Peruanos Haciendo Perú. por Sara Sara
PPTX
Butterfly blizzard: millions of butterflies
PDF
20151020 Metis
PDF
Unit 4 Outcome 1B - Questions v1a
PPTX
22.6 Profitability Ratios
PDF
Task-based syllabus design and task sequencing
DOCX
uanraju inst cv 9 sep 2015
PPTX
Mga sawikain o idyuma
PDF
Portaria 260-2014-ingles
PDF
Multiple perspectives on bibliometric data
PPTX
Tutorial 6
PPTX
Slide show 208
PDF
Perfil dos alunos à saída da  Escolaridade Obrigatória 
PDF
Amc Square learning Job Tips
PDF
Viewse um006 -en-e (1)
Research Process
the amazing quran
EngAhmed
Bonner Directors 2016 -Book of Bonner
etailment WIEN 2016 - A. Schiechl, S. Danninger, F. Wolf – Netconomy & SAP Ös...
Participación Político Social. Peruanos Haciendo Perú. por Sara Sara
Butterfly blizzard: millions of butterflies
20151020 Metis
Unit 4 Outcome 1B - Questions v1a
22.6 Profitability Ratios
Task-based syllabus design and task sequencing
uanraju inst cv 9 sep 2015
Mga sawikain o idyuma
Portaria 260-2014-ingles
Multiple perspectives on bibliometric data
Tutorial 6
Slide show 208
Perfil dos alunos à saída da  Escolaridade Obrigatória 
Amc Square learning Job Tips
Viewse um006 -en-e (1)
Ad

Similar to Mic practicals (20)

PDF
micro controllers lecture notes unit 1 and 2
PPTX
Applications of microcontroller(8051)
PPTX
Basic programming of 8085
PDF
Https _doc-0o-c4-apps-viewer.googleusercontent
PDF
Stack and subroutine
PPTX
Microprocessor Week 8: Subroutine
PPT
Microcontroller 8051- soft.ppt
PPTX
Micro task1
PDF
3 jump, loop and call instructions
PDF
Solutionmanual8051microcontrollerbymazidi 131215070701-phpapp02
PDF
Solutionmanual8051microcontrollerbymazidi
DOCX
Microcontroller (8051) general and simple alp n cprograms
PPT
Chp6 assembly language programming for pic copy
PPTX
8051 microcontroller
DOCX
Embedded System Practical manual (1)
PPTX
6.pptx
PDF
Real Time Embedded System
PDF
8051-mazidi-solution
PPTX
8085 microprocessor introduction in details
PPTX
Intelligent Transportation System
micro controllers lecture notes unit 1 and 2
Applications of microcontroller(8051)
Basic programming of 8085
Https _doc-0o-c4-apps-viewer.googleusercontent
Stack and subroutine
Microprocessor Week 8: Subroutine
Microcontroller 8051- soft.ppt
Micro task1
3 jump, loop and call instructions
Solutionmanual8051microcontrollerbymazidi 131215070701-phpapp02
Solutionmanual8051microcontrollerbymazidi
Microcontroller (8051) general and simple alp n cprograms
Chp6 assembly language programming for pic copy
8051 microcontroller
Embedded System Practical manual (1)
6.pptx
Real Time Embedded System
8051-mazidi-solution
8085 microprocessor introduction in details
Intelligent Transportation System

Recently uploaded (20)

PPTX
Management Information system : MIS-e-Business Systems.pptx
PPTX
Principal presentation for NAAC (1).pptx
PPTX
Amdahl’s law is explained in the above power point presentations
PPT
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
PDF
Design of Material Handling Equipment Lecture Note
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PPTX
Feature types and data preprocessing steps
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PPTX
Measurement Uncertainty and Measurement System analysis
PPTX
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
PPTX
wireless networks, mobile computing.pptx
PPTX
ai_satellite_crop_management_20250815030350.pptx
DOC
T Pandian CV Madurai pandi kokkaf illaya
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PDF
20250617 - IR - Global Guide for HR - 51 pages.pdf
PDF
Prof. Dr. KAYIHURA A. SILAS MUNYANEZA, PhD..pdf
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
Management Information system : MIS-e-Business Systems.pptx
Principal presentation for NAAC (1).pptx
Amdahl’s law is explained in the above power point presentations
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
Design of Material Handling Equipment Lecture Note
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Feature types and data preprocessing steps
distributed database system" (DDBS) is often used to refer to both the distri...
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
Measurement Uncertainty and Measurement System analysis
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
wireless networks, mobile computing.pptx
ai_satellite_crop_management_20250815030350.pptx
T Pandian CV Madurai pandi kokkaf illaya
Exploratory_Data_Analysis_Fundamentals.pdf
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
Soil Improvement Techniques Note - Rabbi
20250617 - IR - Global Guide for HR - 51 pages.pdf
Prof. Dr. KAYIHURA A. SILAS MUNYANEZA, PhD..pdf
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT

Mic practicals

  • 2. Prof. Suraj R. Gaikwad MIC Exp: 1) To write an assembly language program for arithmetic operations. Program: 1) MOV A,#20H MOV F0,#20H ADD A,F0 RET 2) MOV A,#20H MOV F0,#10H SUB A,F0 RET 3) MOV A,#04H MOV F0,#02H MUL A,F0 RET 4) MOV A,#10H MOV F0,#02H ADD A,F0 RET Results: Addition: A = 40H Subtraction: A = 0AH Multiplication: A = 08H Division: A = 05H
  • 3. Prof. Suraj R. Gaikwad MIC Exp:2) To develop an assembly language program to transfer block of 10 bytes stored in internal data memory from location 40H to 60H. Program: ORG 0000H MOV R0,#40H MOV R1,#60H MOV R2,#0AH LOOP:MOV A,@R0 MOV @R1,A INC R0 INC R1 DJNZ R2, LOOP END
  • 4. Prof. Suraj R. Gaikwad MIC Exp:3) To develop an assembly language program to get square of numbers. Program: ORG 0000H MOV R0,#40H MOV R1,#60H MOV R2,#0AH LOOP1:MOV A,@R0 MOV B,@R0 MUL AB MOV @R1,A INC R0 INC R1 DJNZ R2,LOOP1 END Result: Input: Output: 00H = 0D 01H = 1D 04H = 4D 09H = 9D 10H = 16D 19H = 25D 24H = 36D 31H = 49D 40H = 64D 51H = 81D
  • 5. Prof. Suraj R. Gaikwad MIC Exp:4) To develop program for arranging 10 numbers in descending order. Program: ORG 00H ARR EQU 70H L0:MOV R1,#ARR MOV R0,#ARR MOV R2,#0AH MOV R3,#00H DEC R2 L1:MOV A,@R0 MOV B,A INC R1 SUBB A,@R1 JNC L2 MOV A,B XCH A,@R1 MOV @R0,A MOV R3,#01H L2:INC R0 DJNZ R2,L1 CJNE R3,#00,L0 SJMP $ END Result: Input: Output:
  • 6. Prof. Suraj R. Gaikwad MIC Exp:5) To develop a program to generate Square wave over port pins. Program: ORG 0000H :initialization MOV TMOD,#10H :move 10H into timer/counter mode control resister UP: MOV TL1,#0D2H :move 0D2H into timer 1 low byte MOV TH1,#0FFH :move offH into timer 1 high byte SETB TR1 :addressed TR1 is set, TR1=timer 1 run control bit WAIT: JNB TF1,WAIT :jump if addressed TR1 is 0, otherwise proceed with next instruction CLR TR1 :adressed TR1 is cleared CPL P1.5 : complement the addressed P1.5 CLR TF1 : adressed TF1 is cleared, TF1=timer 1 overflow flag SJMP UP :program branches unconditionally to address indicated END :end Result:
  • 7. Prof. Suraj R. Gaikwad MIC Exp:6) To generate Square wave using DAC. Circuit Diagram: C Program: #include <REG51xD2.H> #include <stdio.h> sbit Amp = P3^3; /* Port line to change amplitude */ sbit Fre = P3^2; /* Port line to change frequency */ void delay(unsigned int x) /* delay routine */ { for(;x>0;x--); } main() { unsigned char on = 0x7f,off=0x00; unsigned int fre = 100; while(1)
  • 8. Prof. Suraj R. Gaikwad MIC { if(!Amp) /* if user choice is to change amplitude */ { while(!Amp); /* wait for key release */ on+=0x08; /* Increase the amplitude */ } if(!Fre) /* if user choice is to change frequency */ { if(fre > 1000) /* if frequency exceeds 1000 reset to default */ fre = 100; while(!Fre); /* wait for key release */ fre += 50; /* Increase the frequency */ } P0=on; /* write amplitude to port */ P1=on; delay(fre); P0 = off; /* clear port */ P1 = off; delay(fre); } } Output Waveform:
  • 9. Prof. Suraj R. Gaikwad MIC Assembly Program: ORG 0000H MOV DPTR, #8000H UP:MOV DPL,#40H MOV DPH,#40H CLR A MOVC A,@A+DPTR SETB P1.5 WAIT:JNB P1.5,WAIT CLR P1.5 SJMP UP END Output Waveform:
  • 10. Prof. Suraj R. Gaikwad MIC Exp:7) To write a program to drive Stepper Motor. Theory: Driving Unipolar Stepper Motor with 8051: Unipolar stepper motors can be used in three modes namely the Wave Drive, Full Drive and Half Drive mode. Half Drive Stepping Sequence
  • 11. Prof. Suraj R. Gaikwad MIC Interfacing Using L293D: Interfacing Using ULN2003:
  • 12. Prof. Suraj R. Gaikwad MIC Programs: Keil C Code for Wave Drive:
  • 13. Prof. Suraj R. Gaikwad MIC Keil C Code for Full Drive:
  • 14. Prof. Suraj R. Gaikwad MIC Keil C Code for Half Drive:
  • 15. Prof. Suraj R. Gaikwad MIC Result: 1) Wave drive stepper sequence:
  • 16. Prof. Suraj R. Gaikwad MIC 2) Full drive stepping sequence:
  • 17. Prof. Suraj R. Gaikwad MIC 3) Half wave stepping sequence:
  • 18. Prof. Suraj R. Gaikwad MIC
  • 19. Prof. Suraj R. Gaikwad MIC
  • 20. Prof. Suraj R. Gaikwad MIC Exp:8) To write a program to drive Stepper Motor in clockwise direction and anti-clockwise direction. Program: ORG 0000H MOV R2,#12H MOV A,#88H LOOP1: MOV P2,A RR A DJNZ R2, LOOP1 MOV R2,#12H MOV A,#11H LOOP2: MOV P2,A RL A DJNZ R2, LOOP2 END Result:
  • 21. Prof. Suraj R. Gaikwad MIC
  • 22. Prof. Suraj R. Gaikwad MIC
  • 23. Prof. Suraj R. Gaikwad MIC Exp:9) To write a program to read keyboard and display code. Diagram: Program: • Program to interface matrix keyboard 4x4 • Rows are connected to the Port pins P1.0-P1.3 & Columns are connected to Port pins P2.0-P2.3 • Rows are grounded one by one and read columns Seven segment display is connected at port P0 ORG 00H AJMP START ORG 13H RETI START:MOV P0,#00H MOV P2,#0FH ; Port Pins P2.0 to P2.3 i/p pins and P2.4 to P2.7 o/p pins MOV P1,#00H ; Port P0 output port REL: MOV P1,#00H ; make all rows ground to check all keys MOV A,P2 ; read port p2 to ensure that all keys released
  • 24. Prof. Suraj R. Gaikwad MIC ANL A,#0FH ; maks upper bits because they are not used CJNE A,#0FH,REL ; check till all keys released AGAIN: ACALL DELAY MOV A,P2 ; see if any key pressed or not? ANL A,#0FH ; mask upper bits CJNE A,#0FH,KPRESS ; if a is not equal to 0fh then key is pressed SJMP AGAIN ; check again if key is not pressed KPRESS: ACALL DELAY MOV A,P2 ; ANL A,#0FH ; mask unused upper bits CJNE A,#0FH,KPRESS1 ; if a is not equal to 0fh then key is pressed SJMP AGAIN ; check again if key is not pressed KPRESS1: MOV P1,#0FEH ; ground row 0 MOV A,P2 ; read all columns ANL A,#0FH ; mask unused upper bits CJNE A,0FH,R_0 ; key is pressed in first row (row 0),check columns MOV P1,#0FDH ; Ground ROW 1 MOV A,P2 ; read all columns ANL A,#0FH ; mask unused upper bits CJNE A,0FH,R_1 ;key is pressed in second row (row 1),check columns MOV P1,#0FBH ; ground row 2 MOV A,P2 ; read all columns ANL A,#0FH ; mask unused upper bits CJNE A,0FH,R_2 ;key is pressed in third row (row 2),check columns MOV P1,#0F7H ; ground row 0 MOV A,P2 ; read all columns ANL A,#0FH ; mask unused upper bits CJNE A,0FH,R_3 ;key is pressed in fourth row (row 3),check columns LJMP AGAIN R_0: MOV DPTR,#KCODE0 ;set dptr=start of row 0 SJMP CHECK_C R_1: MOV DPTR,#KCODE1 ;set dptr=start of row 1 SJMP CHECK_C R_2: MOV DPTR,#KCODE2 ;set dptr=start of row 2 SJMP CHECK_C R_3: MOV DPTR,#KCODE3 ;set dptr=start of row 3 CHECK_C: RRC A ;check whether carry occurs or not JNC GET_CODE
  • 25. Prof. Suraj R. Gaikwad MIC INC DPTR SJMP CHECK_C GET_CODE: CLR A MOVC A,@A+dptr MOV P0,A LJMP REL DELAY: MOV R7,#0FFh DLOOP: MOV R6,#0FFh D_LOOP: DJNZ R6,D_LOOP DJNZ R7,DLOOP RET Result: KCODE0: DB '0','1','2','3' ; These codes are for LCDs KCODE1: DB '4','5','6','7' ; Replace this code by seven KCODE2: DB '8','9','A','B' ; segment code as per your KCODE3: DB 'C','D','E','F' ; Circuit.