Professional Documents
Culture Documents
(LAB)
LAB REPORT
MUHAMMAD SAEED TAHIR
L1F12BSEE0078
SECTION: EC1
SUBMITTED TO: DR.ALI FAISAL, ENGR.JAWAD
KHALID
Faculty of engineering
University of Central Punjab
EXPERIMENT 1
INTRODUCTION TO MICROCONTROLLER PINS,
PORTS
This is the pin configuration of 8051. The clock frequency of 8051 is 11.0592
MHz which is provided to microcontroller by the following circuit
It is 8-bit bi-directional I/O port. It is bit/ byte addressable. When logic '1'
is written into port latch then it works as input mode. It functions as
simply I/O port and it does not have any alternative function.
Port 2 (p2.0 to p2.7):
It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During
external memory access it functions as higher order address bus (A8A15).
Port 3(p3.0 to port 3.7):
It is 8-bit I/O port. In an alternating function each pins can be
used as a special function I/o pin
Pull up resistors are present inside all pins of port 1 2 3 but the
port 0 pins have no pull up resistors so they are connected
externally
EXPERIMENT 2
ABOUT ULN 2003 AND INTERNAL STRUCTURE OF
PINS
This is the internal structure of every pin of micro controller and it explains that
how value is written or readed from the controller.
EXPERIMENT 3
PROGRAMMING
COMMANDS:
Mov A,#55h
JB Jump if bit 0
JNB Jump if bit 1
CJNE reg,#data Jump if A byte
DJNZ A,byte Decrement and Jump if A 0
JNZ Jump if A 0
LAB TASKS:
1) TURN ON ODD LEDS WITH THE SWITCH IF SWITCH IS
PRESSED SECONDLY ALL LEDS TURN OFF
Org 00h
Mov p1,#00h
Mov p3,#00h
Here:
JNB P1.1, here
Here1:
JB P1.1, here
Mov p3,#55h
Here2:
JNB P1.1, here
Here3:
JB P1.1, here
Mov p3,#00h
TASK 2:
TURN ON ODD LEDS BY ONE AND 4 LEDS BY OTHER SWITCH AND
IF SWITCH PRESSED AGAIN TURN ON THE CORRESPONDING
OTHER LEDS
Org 00h
Mov p1,#00h
Mov p3,#00h
Start:
Jb p1.3,l2
Jb p1.1,l1
Sjmp start
L1:
Here:
JNB P1.1, here
Here1:
JB P1.1, here1
Mov p3,#55h
Here2:
JNB P1.1, here2
Here3:
JB P1.1, here3
Mov p3,#0AAh
L2:
Here:
JNB P1.1, here
Here1:
JB P1.1, here1
Mov p3,#oFh
Here2:
JNB P1.1, here2
Here3:
JB P1.1, here3
Mov p3,#00h
End
EXPERIMENT 4
DC MOTOR CONTROL
TASK1: SIMPLE SWITCH FOR MOTOR CONTROL
Org 00h
Start:
JB p1.1,here
Clr p1.1
Here:
Setb p1.1
Sjmp start
(switch at p1.1)(MOTOR NOT TURNS ON)
TASK2: MOTOR WITH RELAY
Org 00h
Start:
JB p1.1,here
Clr p1.1
Here:
Setb p1.1
Sjmp start
TASK3: ROTATE CLOCKWISE AND ANTI-CLOCKWISE
Org 00h
Start:
Jb p1.1,l1
Jb p1.3,l2
Sjmp start
L1:
Here:
Jb p1.1,here
Setb p2.1
L2:
Here1:
Jb p1.3,here
Setb p2.2
Sjmp start
End
CLR P3.0
SJMP NEW
End
2.
org 0h
mov p1,#00
mov p3,#00
NEW:
JB P1.5,NEW4
JNB P1.0,NEW
NEW1:
JB P1.0,NEW1
SETB P3.0
CLR P3.1
NEW2:
JNB P1.0,NEW2
NEW3:
JB P1.0,NEW3
CLR P3.0
CLR P3.1
SJMP NEW
NEW4:
JNB P1.5,NEW4
NEW5:
JB P1.5,NEW5
CLR P3.0
SETB P3.1
NEW6:
JNB P1.5,NEW6
NEW7:
JB P1.5,NEW7
CLR P3.0
CLR P3.1
SJMP NEW
End
ORG 00H
MOV DPTR,#200H // moves starting address of LUT to DPTR
MOV A,#11111111B // loads A with all 1's
MOV P3,#00000000B // initializes P3 as output port
ACALL DISPLAY
NEXT2:JB P1.6,NEXT4
MOV A,#2D
ACALL DISPLAY
NEXT4:SETB P1.0
CLR P1.1
JB P1.4,NEXT5
MOV A,#4D
ACALL DISPLAY
NEXT5:JB P1.5,NEXT6
MOV A,#5D
ACALL DISPLAY
NEXT6:JB P1.6,NEXT8
MOV A,#6D
ACALL DISPLAY
NEXT8:SETB P1.1
CLR P1.2
JB P1.4,NEXT9
MOV A,#8D
ACALL DISPLAY
NEXT9:JB P1.5,NEXT10
MOV A,#9D
ACALL DISPLAY
NEXT10:JB P1.6,NEXT12
MOV A,#10D
ACALL DISPLAY
NEXT12:SETB P1.2
CLR P1.3
JB P1.4,NEXT13
MOV A,#12D
ACALL DISPLAY
NEXT13:JB P1.5,NEXT14
MOV A,#13D
ACALL DISPLAY
NEXT14:JB P1.6,BACK
MOV A,#14D
ACALL DISPLAY
LJMP BACK
DISPLAY:MOVC A,@A+DPTR // gets digit drive pattern for the current key
from LUT
MOV P3,A
RET
ORG 200H
DB 01100000B
DB 11011010B ;
DB 11110010B ;
DB 11101110B ;
DB 01100110B ;
DB 10110110B ;
DB 10111110B ;
DB 00111110B ;
DB 11100000B ;
DB 11111110B ;
DB 11110110B ;
DB 10011100B ;
DB 10011110B ;
DB 11111100B ;
DB 10001110B ;
DB 01111010B ;
END
2.
Write a program to interface 4x3 keypad on port 1 and display numeric
keypad output on 20x4 lcd connected on port 3 of 8051 controller
ORG 00H
MOV DPTR,#200H // moves starting address of LUT to DPTR
MOV A,#11111111B // loads A with all 1's
MOV P3,#00000000B // initializes P3 as output port
mov a,#38h
acall comnwrt
mov a,#0eh
acall comnwrt
mov a,#01h
acall comnwrt
mov a,#06h
acall comnwrt
NEXT4:SETB P1.0
CLR P1.1
JB P1.4,NEXT5
MOV A,#80H
ACALL COMNWRT
MOV A,#4D
ACALL DISPLAY
NEXT5:JB P1.5,NEXT6
MOV A,#80H
ACALL COMNWRT
MOV A,#5D
ACALL DISPLAY
NEXT6:JB P1.6,NEXT8
MOV A,#80H
ACALL COMNWRT
MOV A,#6D
ACALL DISPLAY
NEXT8:SETB P1.1
CLR P1.2
MOV A,#80H
ACALL COMNWRT
JB P1.4,NEXT9
MOV A,#80H
ACALL COMNWRT
MOV A,#8D
ACALL DISPLAY
NEXT9:JB P1.5,NEXT10
MOV A,#80H
ACALL COMNWRT
MOV A,#9D
ACALL DISPLAY
NEXT10:JB P1.6,NEXT12
MOV A,#80H
ACALL COMNWRT
MOV A,#10D
ACALL DISPLAY
NEXT12:SETB P1.2
CLR P1.3
JB P1.4,NEXT13
MOV A,#80H
ACALL COMNWRT
MOV A,#12D
ACALL DISPLAY
NEXT13:JB P1.5,NEXT14
MOV A,#80H
ACALL COMNWRT
MOV A,#13D
ACALL DISPLAY
NEXT14:JB P1.6,FRONT
MOV A,#80H
ACALL COMNWRT
MOV A,#14D
ACALL DISPLAY
FRONT:
LJMP BACK
DISPLAY:MOVC A,@A+DPTR // gets digit drive pattern for the current key
from LUT
ACALL DATAWRT
RET
COMNWRT:
MOV P3,A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DATAWRT:
MOV P3,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DELAY:
MOV R3,#9
OUTER:
MOV R4,#255
INNER:
DJNZ R4,INNER
DJNZ R3,OUTER
RET
ORG 200H
mov a,#38h
acall comnwrt
mov a,#0eh
acall comnwrt
mov a,#01h
acall comnwrt
mov a,#06h
acall comnwrt
BACK:
MOV P1,#11111111B // loads P1 with all 1's
CLR P1.0 // makes row 1 low
NEXT:
JB P1.5,NEXT2 // checks whether column 2 is low and so on...
MOV A,#80H
ACALL COMNWRT
ACALL DISPLAY
NEXT2:
SETB P1.0
CLR P1.1
JB P1.5,NEXT3
MOV A,#0C0H
ACALL COMNWRT
ACALL DISPLAY1
NEXT3:
SETB P1.1
CLR P1.2
JB P1.5,NEXT4
MOV A,#094H
ACALL COMNWRT
ACALL DISPLAY2
NEXT4:
SETB P1.2
CLR P1.3
JB P1.5,FRONT
MOV A,#0D4H
ACALL COMNWRT
ACALL DISPLAY3
FRONT:
LJMP BACK
DISPLAY:
MOV DPTR,#200H
MOV R0,#5
NEW:
MOV A,#0
MOVC A,@A+DPTR // gets digit drive pattern for the current key from LUT
INC DPTR
ACALL DATAWRT
DJNZ R0,NEW
RET
DISPLAY1:
MOV DPTR,#205H
MOV R0,#4
NEW1:
MOV A,#0
MOVC A,@A+DPTR // gets digit drive pattern for the current key from LUT
INC DPTR
ACALL DATAWRT
DJNZ R0,NEW1
RET
DISPLAY2:
MOV DPTR,#209H
MOV R0,#3
NEW2:
MOV A,#0
MOVC A,@A+DPTR // gets digit drive pattern for the current key from LUT
INC DPTR
ACALL DATAWRT
DJNZ R0,NEW2
RET
DISPLAY3:
MOV DPTR,#20CH
MOV R0,#3
NEW4:
MOV A,#0
MOVC A,@A+DPTR // gets digit drive pattern for the current key from LUT
INC DPTR
ACALL DATAWRT
DJNZ R0,NEW4
RET
COMNWRT:
MOV P3,A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DATAWRT:
MOV P3,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DELAY:
MOV R3,#9
OUTER:
MOV R4,#255
INNER:
DJNZ R4,INNER
DJNZ R3,OUTER
RET
ORG 200H
DB "jAWAD0139UCPF12"
END
4.
Write a program to detect analog input using ADC0804 and display
digital output on 20*4 lcd connected on port 3 of 8051 controller
ORG 0H
MOV P1,#00
MOV P2,#00
MOV P3,#00
MOV A,#38H
ACALL LCDCMD
MOV A,#0EH
ACALL LCDCMD
MOV A,#01H
ACALL LCDCMD
MOV A,#06H
ACALL LCDCMD
AGAIN:
MOV A,#80H
ACALL LCDCMD
SETB P2.5
CLR P2.6
NOP
NOP
NOP
SETB P2.6
EOC: JB P2.7,EOC
SETB P2.7
CLR P2.5
CLR A
MOV A,P1
MOV B,#10
DIV AB
MOV R0,B
MOV B,#10
DIV AB
MOV R1,B
MOV R2,A
MOV A,R2
ADD A,#30H
ACALL LCDDATA
ACALL DELAY
MOV A,R1
ADD A,#30H
ACALL LCDDATA
ACALL DELAY
MOV A,R0
ADD A,#30H
ACALL LCDDATA
ACALL DELAY
SJMP AGAIN
LCDCMD:
MOV P3,A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
LCDDATA:
MOV P3,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DELAY:
MOV R0,#4
S0:
MOV R1,#255
S1:
DJNZ R1,S1
DJNZ R0,S0
RET
END