Upload
muhammad-humza
View
226
Download
0
Embed Size (px)
Citation preview
8/6/2019 MP NEW PEC
1/64
SIX SEMESTER
MICROPROCESSOR BASED SYSTEMS
BASIC ELECTRICAL LAB
DEPARTMENT OF ELECTRICAL ENGINEERING
Prepared By: Checked By: Approved By:
Engr. Zubair Khalid Engr. M.Nasim Khan Dr.Noman Jafri
Lecturer (Lab) Electrical, Senior Lab Engineer Electrical, Dean,
FUUAST-Islamabad FUUAST-Islamabad FUUAST-Islamabad
8/6/2019 MP NEW PEC
2/64
List of Experiments Microprocessor Based Systems
S
NO.
TOPIC OF EXPERIMENT
1. Introduction to 89S52 & led interfacing
2. Blinking LED in different formations
3. 7-segment interfacing and programming
4. Dot matrix led control5. Single phase stepper motor control
6. Photo interrupter control
7. 8051 programming in c
8. 8051 interrupt programming
9. Timer mode programming
10. Pulse counter
11. Speaker control
12. LCD interfacing and programming
13. Introduction to 8086 based microprocessor trainer (ipc-8603)
14. Command description of examine byte, examine word, examine register.
15. Examining and modifying a register, examining a series of registers, the go
(go) command, transferring control to the sample program, entering and
executing a breakpoint in the program
16. Semester project
8/6/2019 MP NEW PEC
3/64
Lab: 1Introduction to 89S52 & LED Interfacing
Features
4.0V to 5.5V Operating Range Fully Static Operation: 0 Hz to 33 MHz
256 x 8-bit Internal RAM
Three 16-bit Timer/Counters Fast Programming Time
Flexible ISP Programming
Pin Configurations
8/6/2019 MP NEW PEC
4/64
Block Diagram
LEDCode
ORG 000H
Next: MOV A,#11111111B
MOV P2,A
JMP Next
end
8/6/2019 MP NEW PEC
5/64
LAB 2:
Blinking LEDs In Different Formations
Objective:
1. Make basic circuitry to run a microcontroller.
2. Interfacing LEDs with 89S51 microcontroller.
3. Microcontroller programming in C.
4. Writing hex code to the microcontroller.
5. Running a simple program to blink set of LEDs.
6. Interfacing Microcontroller trainer.
8/6/2019 MP NEW PEC
6/64
C code
#include #include void wait (void){unsigned int x;
for(x=0;x
8/6/2019 MP NEW PEC
7/64
while (1) /* Loop forever */{for (j=0x01; j< 0x80; j
8/6/2019 MP NEW PEC
8/64
Assembly Programming Code
ORG 000HMOV A,#00000001B
NEXT_R:RR AMOV P2,ACALL DELAYCJNE A,#01H,NEXT_R
NEXT_L:RL AMOV P2,ACALL DELAYCJNE A,#80H,NEXT_L
JMP NEXT_R;==============================; DELAY 0.1S;==============================DELAY:
MOV R6,#200DL1:
MOV R7,#249DJNZ R7,$DJNZ R6,DL1RETEND
8/6/2019 MP NEW PEC
9/64
8/6/2019 MP NEW PEC
10/64
BLINK TWO LEDs MOVE IN WORD FROM RIGHT AND LEFT
8/6/2019 MP NEW PEC
11/64
LAB 3
7-Segment Interfacing and Programming
8/6/2019 MP NEW PEC
12/64
Seven Segment Display in assembly
UPCounter
ORG 000H
MOV A,#00H
NEXT:
MOV P2,A
CALL DELAY
ADD A,#1
DA A
JMP NEXT
;==============================
; DELAY 0.5S
;==============================
8/6/2019 MP NEW PEC
13/64
8/6/2019 MP NEW PEC
14/64
DL1:
MOV R7,#249
DJNZ R7,$
DJNZ R6,DL1
DJNZ R5,DL2
RET
END
MAKEUPDOWNCOUNTER
8/6/2019 MP NEW PEC
15/64
8/6/2019 MP NEW PEC
16/64
8/6/2019 MP NEW PEC
17/64
DELAY:MOV R6,#200
DL1:MOV
R7,#249
DJNZ R7,$DJNZ R6,DL1RETEND
Assembly code for Static word A.
ORG 000H
CLR P1.7
START:
MOV DPTR,#TABLE
MOV R2,#10000000B
MOV R1,#0
NEXT:
MOV A,R1
MOVC A,@A+DPTR
MOV P2,A
MOV A,R2
MOV P0,A
CALL DELAY
RR A
MOV R2,A
INC R1
8/6/2019 MP NEW PEC
18/64
CJNE R1,#5,NEXT
JMP START
;==============================
;DELAY5mS
;==============================
DELAY:
MOV R6,#10
DL1:
MOV R7,#249
DJNZ R7,$
DJNZ R6,DL1
RET
;==============================
TABLE:
DB
3EH,48H,88H,48H,3EH
END
8/6/2019 MP NEW PEC
19/64
Write Assembly code for X.
8/6/2019 MP NEW PEC
20/64
Lab 5
SINGLE PHASE STEPPER MOTOR CONTROL.
A stepper motor is a motor controlled by a series of electromagnetic coils. The center shaft has a series of
magnets mounted on it, and the coils surrounding the shaft are alternately given current or not, creating
magnetic fields which repulse or attract the magnets on the shaft, causing the motor to rotate.
This design allows for very precise control of the motor: by proper pulsing, it can be turned in very
accurate steps of set degree increments (for example, two-degree increments, half-degree increments,
etc.). They are used in printers, disk drives, and other devices where precise positioning of the motor is
necessary.
STEPPERMOTOR
8/6/2019 MP NEW PEC
21/64
8/6/2019 MP NEW PEC
22/64
AssemblyCodeFor2 phase
8/6/2019 MP NEW PEC
23/64
Lab 6
PHOTO INTERRUPTER CONTROL.
Photointerrupters are transmission type sensors incorporating an infrared LED and a
photosensor in the same package. Photointerrupters detect an object when it interrupts the
light beam emitted from the LED. Phototransistors, or digital output photo ICs, can be
selected as the photosensor.
8/6/2019 MP NEW PEC
24/64
Assembly Code For Photointerrupter
Stepper motor control through photointerrupter changes the direction from CCW to CW.
ORG 000HMOV A,#00110011B
TEST:JBP3.4,TURNRRL AMOV P2,ACALL DELAYJMP TEST
TURNR:RR AMOV P2,ACALL DELAYJMP TEST
DELAY:MOV R6,#20
DL1:MOV R7,#249DJNZ R7,$DJNZ R6,DL1RETEND
8/6/2019 MP NEW PEC
25/64
Control LEDs Using Photo Interrupter
8/6/2019 MP NEW PEC
26/64
Lab 7
8051 PROGRAMMING IN C
AccessingaPinofPort#includesbitMYBIT=P1^0;voidmain(void){unsignedintz;for(z=0;z
8/6/2019 MP NEW PEC
27/64
8/6/2019 MP NEW PEC
28/64
}}GettingInputFromPortsPin
#includesbitmybit=P1^5;voidmain(void){mybit=1;//makemybitaninputwhile(1){if(mybit==1)P0=0x55;elseP2=0xAA;}}
8/6/2019 MP NEW PEC
29/64
UsingFunctionsInC
#includevoidMSDelay(unsignedint);voidmain(void){while(1)//repeatforever{P1=0x55;MSDelay(2);P1=0xAA;MSDelay(2);}}voidMSDelay(unsignedintitime){unsignedinti,j;for(i=0;i
8/6/2019 MP NEW PEC
30/64
Control Stepper Motor in C Single Phase
8/6/2019 MP NEW PEC
31/64
Control Stepper Motor in C Dual Phase
8/6/2019 MP NEW PEC
32/64
Lab 8
8051 INTERRUPT PROGRAMMING
Interrupt is some event which interrupts normal program execution.
Program flow is always sequential, being altered only by those instructions which expresslycause program flow to deviate in some way. However, interrupts give us a mechanism to "put onhold" the normal program flow, execute a subroutine, and then resume normal program flow as ifwe had never left it. This subroutine, called an interrupt handler, is only executed when a certainevent (interrupt) occurs.
We need to be able to distinguish between various interrupts and executing different codedepending on what interrupt was triggered. This is accomplished by jumping to a fixed addresswhen a given interrupt occurs.
By default at power up, all interrupts are disabled. The 8051 will not execute the interrupt. Yourprogram must specifically tell the 8051 that it wishes to enable interrupts and specifically whichinterrupts it wishes to enable. Your program may enable and disable interrupts by modifying theIE.
8/6/2019 MP NEW PEC
33/64
8/6/2019 MP NEW PEC
34/64
Assembly Code for Interrupt
ORG 000HJMP MAINORG 013HJMP INT1ORG 100H
MAIN:MOV IE,#10000100BSETB IT1MOV A,#00110011B
NEXT:MOV P2,ACALL DELAYRR AJMP NEXT
;============================== INT1:
CLR EAPUSH 6PUSH 7MOV R0,#200
NEXT_LMOV P2,ACALL DELAYRL ADJNZ R0,NEXT_L
8/6/2019 MP NEW PEC
35/64
POP 7POP 6
SETB EARETI
;============================== ;DELAY10mS;============================== DELAY:
MOV R6,#20DL1:
MOV R7,#249DJNZ R7,$DJNZ R6,DL1RET
END
8/6/2019 MP NEW PEC
36/64
Write code using Interrupt 0
8/6/2019 MP NEW PEC
37/64
Lab 9
Timer Mode Programming
TMOD(Timer Mode)The TMOD SFR is used to control the mode of operation of both timers. Each bit of the SFRgives the microcontroller specific information concerning how to run a timer. The high four bits(bits 4 through 7) relate to Timer 1 whereas the low four bits (bits 0 through 3) perform the exactsame functions, but for timer 0. The individual bits of TMOD have the following functions:
8/6/2019 MP NEW PEC
38/64
SIMPLE TIMER
ORG 000H
MOV TMOD,#01 ;Timer 0, mode 1(16-bit mode)HERE:MOV TL0,#0F2H ;TL0=F2H, the low byteMOV TH0,#0FFH ;TH0=FFH, the high byteCPL P1.5 ;toggle P1.5ACALL DELAYSJMP HEREDELAY:SETB TR0 ;start the timer 0AGAIN: JNB TF0,AGAIN ;monitor timer flag 0
;until it rolls over
CLR TR0 ;stop timer 0CLR TF0 ;clear timer 0 flagRETEND
TIMER AUTO- RELOAD
ORG 000HMOV TMOD,#002H ;Timer 0, mode 1(16-bit mode)
MOV TL0,#0F2H ;TL0=F2H, the low byteMOV TH0,#0FEH ;TH0=FFH, the high byteHERE:CPL P1.5 ;toggle P1.5ACALL DELAYSJMP HERE
DELAY:SETB TR0 ;start the timer 0AGAIN: JNB TF0,AGAIN ;monitor timer flag 0;until it rolls overCLR TR0 ;stop timer 0
CLR TF0 ;clear timer 0 flagRETEND
8/6/2019 MP NEW PEC
39/64
CALCULATING TIME
ORG 000HCLR P2.3 ;Clear P2.3
MOV TMOD,#01 ;Timer 0, 16-bitmodeHERE: MOV TL0,#3EH ;TL0=3Eh, the low byteMOV TH0,#0B8H ;TH0=B8H, the high byteSETB P2.3 ;SET high timer 0SETB TR0 ;Start the timer 0AGAIN: JNB TF0,AGAIN ;Monitor timer flag 0CLR TR0 ;Stop the timer 0CLR TF0 ;Clear TF0 for next roundEND
1/12 X 11.0529921075 HzT=1/F = 1.0856s
(FFFFH B83E + 1) = 47C2H = 18370In decimal and 18370
18370 1.085 us = 19.93145 ms
USING TIMERS IN C
#include sbit SPEAKER = P1^7;void main(void){TMOD = 0x10; /* Timer 1, mode 1 (16 BIT )counter */while(1){TL1 = 0x1A; /* initial values */TH1 = 0xFF;TR1 = 1;
// Start Timer 1while(!TF1){}TR1 = 0; // Stop Timer 1;TF1 = 0; // TF1 = Timer 1 Overflow. This bit is set by the}}
8/6/2019 MP NEW PEC
40/64
USING TIMER AS COUNTER
#include void main(void)
{TMOD = 0x50; /* Timer 1, mode 1 (16 BIT )counter *//* GATE1=0; C/T1 =1; M10=0; M00=1; *//* TMOD.7 = GATE1 = When this bit is set the timer will only runwhen INT1 (P3.3) is high. When this bit isclear the timer will run regardless of the state of INT1.TMOD.6 C/T1 = When this bit is set the timer will count eventson T1 (P3.5). When this bit is clear the timerwill be incremented every machine cycle.So An Event Occures when we connect P3.5 to ground
*/
//P3^5=1;TL1 = 0x00; /* initial values */TH1 = 0x00;while(1){TR1 = 1; // Start Timer 1;while(!TF1){P0=TL1; // 0XDF = 1101 1111}TR1 = 0; // Stop Timer 1;TF1 = 0; // TF1 = Timer 1 Overflow. This bit is set by the
// microcontroller when Timer 1 overflows.}}
INTERRUPT CONTROLLED COUNTER
#include void main(void){TMOD = 0xD0; /* Timer 1, mode 1 (16 BIT )counter */
/* GATE1=0; C/T1 =1; M10=0; M00=1; *//* TMOD.7 = GATE1 = When this bit is set the timer will only runwhen INT1 (P3.3) is high. When this bit isclear the timer will run regardless of the state of INT1.TMOD.6 C/T1 = When this bit is set the timer will count eventson T1 (P3.5). When this bit is clear the timerwill be incremented every machine cycle.So An Event Occures when we connect P3.5 to ground
8/6/2019 MP NEW PEC
41/64
8/6/2019 MP NEW PEC
42/64
Write Code For Shortest Delay
8/6/2019 MP NEW PEC
43/64
Convert All Assembly Codes To C
8/6/2019 MP NEW PEC
44/64
Lab 10
PULSE COUNTER.
A pulse counter could be divided in three parts. The first part is a pulses source. The
second unit is microcontroller which counts, memorizes states and prepares results.
Finally, the third part is a converter of electrical states into states available to our senses
i.e. seven segment display .
Photointerrupters are transmission type sensors incorporating an infrared LED and a
photosensor in the same package. Photointerrupters detect an object when it interrupts the
light beam emitted from the LED. Phototransistors, or digital output photo ICs, can be
selected as the photosensor. And this sensor is widely used as a counter. The control
mechanism is designed to count the number of times the path is broken.
8/6/2019 MP NEW PEC
45/64
Assembly Code For Pulse Counter
ORG 000HMOV A,#0MOV P2,#0
NEXT:JB P3.4,$
ADD A,#1DA AMOV P2,A
JNB P3.4,$
JMP NEXT
END
8/6/2019 MP NEW PEC
46/64
Lab 11
SPEAKER CONTROL.
The most common type of speaker is the MOVING COIL speaker, where a coil of wire is
suspended in the magnetic field of a circular magnet. When a speech current is passed through
the coil a varying magnetic field is generated by the coil.
The two magnetic fields interact causing movement of the coil. The movement of the coil causes
a cone, which is attached to the coil, to move back and forth. This compresses and decompresses
the air thereby generating sound waves.
8/6/2019 MP NEW PEC
47/64
Assembly Code For SpeakerORG 000H
START:
MOV R0,#5
NEXT2:
MOV R1,#100
NEXT1:
SETB P3.7
CALL DELAY
CLR P3.7
CALL DELAY
DJNZ R1,NEXT1
DJNZ R0,NEXT2
CALL DL05S
JMP START
; DELAY 0.5mS
DELAY:
MOV R7,#249
DJNZ R7,$
RET
; DELAY 0.5S
DL05S:
MOV R5,#5
DL2:
MOV R6,#200
8/6/2019 MP NEW PEC
48/64
DL1:
MOV R7,#249
DJNZ R7,$
DJNZ R6,DL1
DJNZ R5,DL2
RET
END
8/6/2019 MP NEW PEC
49/64
8/6/2019 MP NEW PEC
50/64
LCD Types Character Locations
Assembly Programming Code
ORG 00
MOV A,#38H ;COMMAND FOR LCD
ACALL COMNWRT ;ROUTINE FOR SENDING COMMANDS TO LCD
ACALL DELAY ;DELAY TIME ROUTINE
MOV A,#38H
ACALL COMNWRT
8/6/2019 MP NEW PEC
51/64
ACALL DELAY
MOV A,#0EH ;COMMAND FOR DISPLAY ON & CURSOR BLINKING
ACALL COMNWRT
ACALL DELAY
MOV A,#01H ;COMMAND FOR CLEAR DISPLAY SCREEN
ACALL COMNWRT
ACALL DELAY
MOV A,#06H ;COMMAND FOR SHIFT CURSOR TO RIGHT
ACALL COMNWRT
ACALL DELAY
MOV A,#83H ;FORCE CURSOR TO BEGINNING OF IST LINE
ACALL COMNWRT
ACALL DELAY
MOV A,#'W' ;DATA TO WRITE ON LCD
ACALL DATAWRT ;ROUTINE FOR WRITING DATA ON LCD
ACALL DELAY
MOV A,#'E'
ACALL DATAWRT
ACALL DELAY
MOV A,#'L'
ACALL DATAWRT
ACALL DELAY
MOV A,#'L'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'C'
8/6/2019 MP NEW PEC
52/64
ACALL DATAWRT
ACALL DELAY
MOV A,#'O'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
MOV A,#'E'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'I'
ACALL DATAWRT
ACALL DELAY
MOV A,#'.'
ACALL DATAWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
MOV A,#'.'
ACALL DATAWRT
ACALL DELAY
MOV A,#'C'
ACALL DATAWRT
ACALL DELAY
8/6/2019 MP NEW PEC
53/64
SJMP $
COMNWRT:
MOV P1,A
CLR P3.7 ;PIN RS=0
NOP
CLR P3.6 ;PIN READ/WRITE=0
SETB P3.5 ;PIN ENABLE=1
NOP
CLR P3.5 ;PIN ENABLE=0
NOP
RET
DATAWRT:
MOV P1,A
SETB P3.7 ;PIN RS=1
NOP
CLR P3.6 ;PIN READ,WRITE=0
SETB P3.5 ;PIN ENABLE=1
NOP
CLR P3.5 ;PIN ENABLE=0
NOP
RET
DELAY:
MOV R0,#255
DJNZ R0,$
RET
END
8/6/2019 MP NEW PEC
54/64
Lab: 13
INTRODUCTION TO 8086 BASED MICROPROCESSOR TRAINER(IPC-8603)
SYSTEM INTRODUCTION
IPC-8603 is a single board MICROPROCESSOR TRAINING/DEVELOPMENT KITconfigured around the INTELs 16 bit Microprocessor 8086. The system can operate ateither 4.9 MHz or 2.45 MHz .
MEMORY IPC-8603 provides 16K Bytes of EPROM loaded with monitor and 16K bytes of
CMOS RAM.
EPROM : 32K RAM : 32K
Total Memory = 64K
INPUT/OUTPUT Parallel : 72 I/O lines using 3 nos. of 8255 Serial : RS-232-C (Main). TIMER/COUNTER : Three 16 bit Timer/Counter through 8253.
Keyboard & Display : 25 keys and 8 Seven Segment display.
BUS : All address, data and control signals (TTL Compatible) Interrupt : 8259A , 8 user Interrupt.
Physical Size : 299mm x 180mm.
Power Supply : 5V, 1.2 Amps for kit, 12V.
Operating Temp. : 0 to 50
IC 82798279 is a general purpose programmable keyboard and display I/O interfacedevice designed for use with the 8086 microprocessor. It provides a scannedinterface to 28 contact key matrix provided in IPC-8603 and scanned displays.
82558255 is a programmable peripheral interface (PPI) designed to use with 8086
Microprocessor. This basically acts as a general purpose I/O component tointerface peripheral equipments to the system bus.
8253This chip is a programmable interval timer/counter and can be used for thegeneration of accurate time delays under software control. Various other functionsthat can be implemented with this chip are programmable rate generator.Event Counter, Binary rate multiplier, real time clock etc. This chip has got three
8/6/2019 MP NEW PEC
55/64
independent 16 bit counters each having a count rate of up to 2 MHz.
8251
This chip is a programmable communication interface and is used as a peripheral
device. This device accepts data characters from the CPU in parallel formand then converts them into a continuous serial data stream for transmission.Simultaneously it can receive serial data stream and converts them into paralleldata characters for the CPU. This chip will signal the CPU whenever it canaccept a new character for transmission or whenever it has received a characterfor the CPU. The CPU can read the complete status of it at any time. 8251 hasbeen utilized in IPC-8603 for Main/Aux. RS-232-C interface and 20mA currentloop.
INTERFACES
KEYBOARD DESCRIPTIONThe IPC-8603 has 25 keys and eight seven segment displays to communicatewith outside world. As the power is turned on and Reset key is pressed, amessage -UP 86 is displayed on the display and all the keys are in commandmode. The keyboard is shown below.
HEXADECIMAL DISPLAY CHARACTERS
8/6/2019 MP NEW PEC
56/64
8/6/2019 MP NEW PEC
57/64
8/6/2019 MP NEW PEC
58/64
FUNCTION KEY OPERATION
8/6/2019 MP NEW PEC
59/64
COMMAND DESCRIPTION
The various commands that can be executed by the monitor are listed below
EXAMINE BYTE EXAMINE WORD
EXAMINE REGISTER INPUT BYTE INPUT WORD
OUTPUT BYTE
OUTPUT WORD GO
MOVE
STEP
INSERT
DELETE
FILL
BLANK CHECK
VERIFY
LIST
PROGRAM/DUPLICATE
EXAMINE BYTE
EXAMINE WORD
Examine a Series of Memory Byte Locations Relative to the CS Register.
8/6/2019 MP NEW PEC
60/64
8/6/2019 MP NEW PEC
61/64
Lab: 15
EXAMINING AND MODIFYING A REGISTER, EXAMINING A SERIES OFREGISTERS, THE GO (GO) COMMAND, TRANSFERRING CONTROL TO
THE SAMPLE PROGRAM, ENTERING AND EXECUTING A BREAKPOINTIN THE PROGRAM.
Examining and Modifying a Register.
Examining a Series of Registers.
8/6/2019 MP NEW PEC
62/64
GO
Function
The Go (Go) command is used to transfer control of the 8086 from the keypad
monitor program to a users program in memory.
Transferring Control to the Sample Program.
Entering and Executing a Breakpoint in the program.
8/6/2019 MP NEW PEC
63/64
EPROM PROGRAMMER
IPC-8603 provides onboard EPROM PROGRAMMER for the 2764/27128/27256 EPROMS.
BLANK CHECK
Blank check command is used to check the EPROM placed in the ZIF (Zero Insertion Force)socket for blank.
1) The starting address of the EPROM from where the blank check should start.
2) The End address of the EPROM till where the system should check for blank.
8/6/2019 MP NEW PEC
64/64
Lab 16
Project Proposal