Professional Documents
Culture Documents
Prepared By:
Checked By:
Approved By:
Dr.Noman Jafri
Dean, FUUAST-Islamabad
S NO.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.
TOPIC OF EXPERIMENT
Introduction to 89S52 & led interfacing Blinking LED in different formations 7-segment interfacing and programming Dot matrix led control Single phase stepper motor control Photo interrupter control 8051 programming in c 8051 interrupt programming Timer mode programming Pulse counter Speaker control LCD interfacing and programming Introduction to 8086 based microprocessor trainer (ipc-8603) Command description of examine byte, examine word, examine register. 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
Pin Configurations
Block Diagram
LEDCode
ORG 000H Next: MOV A,#11111111B MOV P2,A JMP Next end
LAB 2:
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; unsigned char j;
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 */ } } }
ORG 000H MOV A,#10000000B NEXT: MOV CALL RR JMP P2,A DELAY A NEXT
;============================== ; DELAY 0.1S ;============================== DELAY: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 RET END
Assembly Programming Code ORG MOV NEXT_R: RR MOV CALL CJNE NEXT_L: RL MOV CALL CJNE 000H A,#00000001B A P2,A DELAY A,#01H,NEXT_R A P2,A DELAY A,#80H,NEXT_L
JMP NEXT_R ;============================== ; DELAY 0.1S ;============================== DELAY: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 RET END
WRITE CODE
LAB 3
DELAY: MOV DL2: MOV DL1: MOV DJNZ DJNZ DJNZ RET END R7,#249 R7,$ R6,DL 1 R5,DL 2 R6,#200 R5,#5
DownCounter
ORG 000H NEXT: MOV P2,A CALL DELAY ADD A,#99H DA JMP A NEXT ORG 000H MOV A,#99H
DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 DJNZ R5,DL2 RET END
MAKEUPDOWNCOUNTER
Lab 4
Dot Matrix LED Control.
DOTMATRIX DOTMATRIX
NEXT_COL: MOV R0,#64 MOV P0,#FFH MOV A,#10000000B MOV P0,A CALL RR DJNZ DELAY A R0,NEXT_COL
NEXT_ROW: ;============================== ;DELAY0.1S ;============================== JMP START MOV P2,A CALL RR DJNZ DELAY A R0,NEXT_ROW
DELAY: DL1: MOV R7,#249 DJNZ DJNZ RET END R7,$ R6,DL1 MOV R6,#200
CJNE
R1,#5,NEXT
JMP
START
;============================== ;DELAY5mS ;============================== DELAY: DL1: ;============================== TABLE: DB END 3EH,48H,88H,48H,3EH MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 RET MOV R6,#10
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
AssemblyCodeForsinglephase
START: MOV 2,#00010001B P CALLDELAY MOV 2,#10001000B P CALLDELAY MOV 2,#01000100B P CALLDELAY MOV 2,#00100010B P CALLDELAY JMP START ORG000H
;============================== ;DELAY20mS ;============================== DELAY: DL1: MOV 7,#249 R DJNZR7,$ DJNZR6,DL1 RET END MOV 6,#40 R
AssemblyCodeFor2 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.
AccessingPinsofMultiplePorts
#include<reg51.h> sbitMYBIT=P1^7; sbitMYBIT1=P1^5; sbitMYBIT2=P1^3; sbitMYBIT3=P1^1; sbitMYBIT4=P2^1; voidmain(void) { unsignedintz; 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; } } GettingInputFromPorts #include<reg51.h> voidmain(void) { unsignedintmybyte; P0=0xFF;//makeP0inputport while(1) { mybyte=P0;//getabytefromP0 if(mybyte<128) P1=mybyte;//sendittoP1 else P2=mybyte;//sendittoP2
} } GettingInputFromPortsPin #include<reg51.h> sbitmybit=P1^5; voidmain(void) { mybit=1;//makemybitaninput while(1) { if(mybit==1) P0=0x55; else P2=0xAA; } }
UsingFunctionsInC #include<reg51.h> voidMSDelay(unsignedint); voidmain(void) { while(1)//repeatforever { P1=0x55; MSDelay(2); P1=0xAA; MSDelay(2); } }voidMSDelay(unsignedintitime) { unsignedinti,j; for(i=0;i<itime;i++) for(j=0;j<1;j++); }
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.
InterruptOverview
MOV A,#00110011B
PUSH 6 PUSH 7
MOV R0,#200
;============================== ;DELAY10mS ;============================== DELAY: DL1: END MOV R7,#249 DJNZ DJNZ RET R7,$ R6,DL1 MOV R6,#20 SETB RETI EA POP POP 7 6
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 MOV TL0,#0F2H MOV TH0,#0FEH HERE: CPL P1.5 ACALL DELAY SJMP HERE DELAY: SETB TR0 AGAIN: JNB TF0,AGAIN ;until it rolls over CLR TR0 CLR TF0 RET END
;Timer 0, mode 1(16-bit mode) ;TL0=F2H, the low byte ;TH0=FFH, the high byte ;toggle P1.5
;start the timer 0 ;monitor timer flag 0 ;stop timer 0 ;clear timer 0 flag
CALCULATING TIME ORG 000H CLR P2.3 MOV TMOD,#01 HERE: MOV TL0,#3EH MOV TH0,#0B8H SETB P2.3 SETB TR0 AGAIN: JNB TF0,AGAIN CLR TR0 CLR TF0 END
;Clear P2.3 ;Timer 0, 16-bitmode ;TL0=3Eh, the low byte ;TH0=B8H, the high byte ;SET high timer 0 ;Start the timer 0 ;Monitor timer flag 0 ;Stop the timer 0 ;Clear TF0 for next round
1/12 X 11.0529 921075 Hz T=1/F = 1.0856s (FFFFH B83E + 1) = 47C2H = 18370 In decimal and 18370 18370 1.085 us = 19.93145 ms
USING TIMERS IN
#include <REGX51.H> sbit SPEAKER = P1^7; void main(void) { TMOD = 0x10; while(1) { TL1 = 0x1A; TH1 = 0xFF; TR1 = 1; while(!TF1) { } TR1 = 0; TF1 = 0; } }
/* initial values */
// Start Timer 1
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. } }
/* 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; TH1 = 0x00; while(1){ TR1 = 1; while(!TF1){ P0=TL1; } TR1 = 0; TF1 = 0; } } /* initial values */
// Start Timer 1; // 0XDF = 1101 1111 // Stop Timer 1; // TF1 = Timer 1 Overflow. This bit is set by the // microcontroller when Timer 1 overflows.
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.
MOV P2,A
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.
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
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' ACALL DATAWRT ;DATA TO WRITE ON LCD ;ROUTINE FOR WRITING DATA ON LCD
ACALL
DATAWRT
ACALL DELAY
SJMP
COMNWRT: MOV CLR NOP CLR P3.6 ;PIN READ/WRITE=0 ;PIN ENABLE=1 P1,A P3.7 ;PIN RS=0
SETB P3.5 NOP CLR NOP RET DATAWRT: MOV P1,A P3.5
;PIN ENABLE=0
;PIN RS=1
SETB P3.5 NOP CLR NOP RET DELAY: MOV DJNZ RET END P3.5
;PIN ENABLE=0
R0,#255 R0,$
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 INTELs 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 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
INPUT/OUTPUT
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
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.
Lab: 14
COMMAND DESCRIPTION OF EXAMINE BYTE, EXAMINE WORD, EXAMINE REGISTER.
HEXADECIMAL KEYPAD LEGEND INTERPRETATION
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
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.
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.
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.
Lab 16
Project Proposal