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
64
Embed
SIX SEMESTER MICROPROCESSOR BASED SYSTEMS BASIC …...1. Introduction to 89S52 & led interfacing 2. Blinking LED in different formations 3. 7-segment interfacing and programming 4.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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
Lab: 1
Introduction 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
Block Diagram
LED Code
ORG 000H
Next: MOV A,#11111111B
MOV P2,A
JMP Next
end
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.
C code
#include <reg51.h> #include <stdio.h> void wait (void) { unsigned int x; for(x=0;x<10000;x++) {} } void main (void) { unsigned int i; /* Delay variable */ unsigned char j; /* LED variable */
while (1) /* Loop forever */ { for (j=0x01; j< 0x80; j<<=1) { /* Blink LEDs 0, 1, 2, 3, 4, 5, 6 */ P2 = j; /* send Output to Port 1 */ P0 = j; /* Output to LED Port */ wait (); /* call wait function */ } } } Assembly Programming Code ORG 000H MOV A,#10000000B NEXT: MOV P2,A CALL DELAY RR A JMP NEXT ;============================== ; DELAY 0.1S ;============================== DELAY: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 RET END
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.
STEPPER MOTOR
Assembly Code For single phase
ORG 000H
START:
MOV P2,#00010001B
CALL DELAY
MOV P2,#10001000B
CALL DELAY
MOV P2,#01000100B
CALL DELAY
MOV P2,#00100010B
CALL DELAY
JMP START
;==============================
; DELAY 20mS
;==============================
DELAY:
MOV R6,#40
DL1:
MOV R7,#249
DJNZ R7,$
DJNZ R6,DL1
RET
END
Assembly Code For 2‐ phase
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.
Assembly Code For Photointerrupter
Stepper motor control through photointerrupter changes the direction from CCW to CW.
ORG 000H
MOV A,#00110011B
TEST:
JB P3.4,TURNR
RL A
MOV P2,A
CALL DELAY
JMP TEST
TURNR:
RR A
MOV P2,A
CALL DELAY
JMP TEST
DELAY:
MOV R6,#20
DL1:
MOV R7,#249
DJNZ R7,$
DJNZ R6,DL1
RET
END
Control LEDs Using Photo Interrupter
Lab 7 8051 PROGRAMMING IN C
Accessing a Pin of Port #include <reg51.h> sbit MYBIT=P1^0; void main(void) { unsigned int z; for (z=0;z<=50000;z++) { MYBIT=0; MYBIT=1; } }
Accessing Pins of Multiple Ports #include <reg51.h>
sbit MYBIT=P1^7;
sbit MYBIT1=P1^5;
sbit MYBIT2=P1^3;
sbit MYBIT3=P1^1;
sbit MYBIT4=P2^1;
void main(void)
{
unsigned int z;
for (z=0;z<=50000;z++)
{
MYBIT=0;
MYBIT=1;
MYBIT1=0;
MYBIT1=1;
MYBIT2=0;
MYBIT2=1;
MYBIT3=0;
MYBIT3=1;
MYBIT4=0;
MYBIT4=1;
}
}
Getting Input From Ports
#include <reg51.h>
void main(void)
{
unsigned int mybyte;
P0=0xFF; //make P0 input port
while (1)
{
mybyte=P0; //get a byte from P0
if (mybyte<128)
P1=mybyte; //send it to P1
else
P2=mybyte; //send it to P2
}
}
Getting Input From Port’s Pin
#include <reg51.h>
sbit mybit=P1^5;
void main(void)
{
mybit=1; //make mybit an input
while (1)
{
if (mybit==1)
P0=0x55;
else
P2=0xAA;
}
}
Using Functions In C
#include <reg51.h>
void MSDelay(unsigned int);
void main(void)
{
while (1) //repeat forever
{
P1=0x55;
MSDelay(2);
P1=0xAA;
MSDelay(2);
}
}void MSDelay(unsigned int itime)
{
unsigned int i,j;
for (i=0;i<itime;i++)
for (j=0;j<1;j++);
}
Control Stepper Motor in C Single Phase
Control Stepper Motor in C Dual Phase
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 expressly cause program flow to deviate in some way. However, interrupts give us a mechanism to "put on hold" the normal program flow, execute a subroutine, and then resume normal program flow as if we had never left it. This subroutine, called an interrupt handler, is only executed when a certain event (interrupt) occurs.
We need to be able to distinguish between various interrupts and executing different code depending on what interrupt was triggered. This is accomplished by jumping to a fixed address when a given interrupt occurs.
By default at power up, all interrupts are disabled. The 8051 will not execute the interrupt. Your program must specifically tell the 8051 that it wishes to enable interrupts and specifically which interrupts it wishes to enable. Your program may enable and disable interrupts by modifying the IE.
Interrupt Overview
Assembly Code for Interrupt
ORG 000H
JMP MAIN
ORG 013H
JMP INT1
ORG 100H
MAIN:
MOV IE,#10000100B
SETB IT1
MOV A,#00110011B
NEXT:
MOV P2,A
CALL DELAY
RR A
JMP NEXT
;==============================
INT1:
CLR EA
PUSH 6
PUSH 7
MOV R0,#200
NEXT_L
MOV P2,A
CALL DELAY
RL A
DJNZ R0,NEXT_L
POP 7
POP 6
SETB EA
RETI
;==============================
; DELAY 10mS
;==============================
DELAY:
MOV R6,#20
DL1:
MOV R7,#249
DJNZ R7,$
DJNZ R6,DL1
RET
END
Write code using Interrupt 0
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 SFR gives 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 exact same functions, but for timer 0. The individual bits of TMOD have the following functions:
SIMPLE TIMER
ORG 000H
MOV TMOD,#01 ;Timer 0, mode 1(16-bit mode) HERE: MOV TL0,#0F2H ;TL0=F2H, the low byte MOV TH0,#0FFH ;TH0=FFH, the high byte CPL P1.5 ;toggle P1.5 ACALL DELAY SJMP HERE DELAY: SETB TR0 ;start the timer 0 AGAIN: JNB TF0,AGAIN ;monitor timer flag 0
;until it rolls over CLR TR0 ;stop timer 0 CLR TF0 ;clear timer 0 flag RET END
TIMER AUTO- RELOAD
ORG 000H MOV TMOD,#002H ;Timer 0, mode 1(16-bit mode) MOV TL0,#0F2H ;TL0=F2H, the low byte MOV TH0,#0FEH ;TH0=FFH, the high byte HERE: CPL P1.5 ;toggle P1.5 ACALL DELAY SJMP HERE DELAY: SETB TR0 ;start the timer 0 AGAIN: JNB TF0,AGAIN ;monitor timer flag 0 ;until it rolls over CLR TR0 ;stop timer 0 CLR TF0 ;clear timer 0 flag RET END
CALCULATING TIME ORG 000H CLR P2.3 ;Clear P2.3 MOV TMOD,#01 ;Timer 0, 16-bitmode HERE: MOV TL0,#3EH ;TL0=3Eh, the low byte MOV TH0,#0B8H ;TH0=B8H, the high byte SETB P2.3 ;SET high timer 0 SETB TR0 ;Start the timer 0 AGAIN: JNB TF0,AGAIN ;Monitor timer flag 0 CLR TR0 ;Stop the timer 0 CLR TF0 ;Clear TF0 for next round END 1/12 X 11.0529 921075 Hz T=1/F = 1.0856µs (FFFFH – B83E + 1) = 47C2H = 18370 In decimal and 18370 18370 × 1.085 us = 19.93145 ms USING TIMERS IN C #include <REGX51.H> 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 1 while(!TF1) { } TR1 = 0; // Stop Timer 1; TF1 = 0; // TF1 = Timer 1 Overflow. This bit is set by the } }
USING TIMER AS COUNTER #include <REGX51.H> 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 run when INT1 (P3.3) is high. When this bit is clear the timer will run regardless of the state of INT1. TMOD.6 C/T1 = When this bit is set the timer will count events on T1 (P3.5). When this bit is clear the timer will 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 <REGX51.H> 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 run when INT1 (P3.3) is high. When this bit is clear the timer will run regardless of the state of INT1. TMOD.6 C/T1 = When this bit is set the timer will count events on T1 (P3.5). When this bit is clear the timer will 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. } } Write Code For Largest Delay
Write Code For Shortest Delay
Convert All Assembly Codes To C
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.
Assembly Code For Pulse Counter
ORG 000H
MOV A,#0
MOV P2,#0
NEXT:
JB P3.4,$
ADD A,#1
DA A
MOV P2,A
JNB P3.4,$
JMP NEXT
END
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.
Assembly Code For Speaker ORG 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
DL1:
MOV R7,#249
DJNZ R7,$
DJNZ R6,DL1
DJNZ R5,DL2
RET
END
Lab 12 LCD Interfacing and Programming. Hardware list
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
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'
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
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
Lab: 13
INTRODUCTION TO 8086 BASED MICROPROCESSOR TRAINER (IPC-8603)
SYSTEM INTRODUCTION
• IPC-8603 is a single board MICROPROCESSOR TRAINING/DEVELOPMENT KIT configured around the INTEL’s 16 bit Microprocessor 8086. The system can operate at either 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 8279 8279 is a general purpose programmable keyboard and display I/O interface device designed for use with the 8086 microprocessor. It provides a scanned interface to 28 contact key matrix provided in IPC-8603 and scanned displays. 8255 8255 is a programmable peripheral interface (PPI) designed to use with 8086 Microprocessor. This basically acts as a general purpose I/O component to interface peripheral equipments to the system bus. 8253 This chip is a programmable interval timer/counter and can be used for the generation of accurate time delays under software control. Various other functions that can be implemented with this chip are programmable rate generator. Event Counter, Binary rate multiplier, real time clock etc. This chip has got three
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 form and then converts them into a continuous serial data stream for transmission. Simultaneously it can receive serial data stream and converts them into parallel data characters for the CPU. This chip will signal the CPU whenever it can accept a new character for transmission or whenever it has received a character for the CPU. The CPU can read the complete status of it at any time. 8251 has been utilized in IPC-8603 for Main/Aux. RS-232-C interface and 20mA current loop. INTERFACES
• KEYBOARD DESCRIPTION The IPC-8603 has 25 keys and eight seven segment displays to communicate with outside world. As the power is turned on and Reset key is pressed, a message -UP 86 is displayed on the display and all the keys are in command mode. The keyboard is shown below.
• HEXADECIMAL DISPLAY CHARACTERS
Lab: 14
COMMAND DESCRIPTION OF EXAMINE BYTE, EXAMINE WORD, EXAMINE REGISTER.
HEXADECIMAL KEYPAD LEGEND INTERPRETATION
FUNCTION KEY OPERATION
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.
Examining & Modifying Memory Word Location 10H relative to the DS Register.
EXAMINE REGISTER
Lab: 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.
Examining and Modifying a Register.
Examining a Series of Registers.
GO Function The Go (Go) command is used to transfer control of the 8086 from the keypad monitor program to a user’s program in memory.
Transferring Control to the Sample Program.
Entering and Executing a Breakpoint in the program.
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.