You are on page 1of 40

1 Interfacing Stepper Motor to 8086 using 8255

1.1 1.2 Using ULN2003 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the preassembled kit . . . . . . . . . . . . . . . . . . . . . . . .

Contents

3
3 7

2 Interfacing LED displays to 8086


2.1 2.2 Using 8255 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using 8279 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11
11 13

3 Interfacing 8255 & 8253 to 8086


3.1 3.2 Using 8255 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using 8253 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15
15 17

4 Interfacing ADC & DAC to 8086


4.1 4.2 ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . DAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

21
21 22

5 8051 Programming
5.1 5.2 Wave generation Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

25
25 27

6 7 8 9

Interfacing Hex Keyboard with 8086 Timers in Interrupt Mode 8051 timers: Stack Check Mode 8051 timers: Interrupt Mode
29

30 32 35 38
2009

th October,

Introduction
Set Baud Rate
Type BU and press enter Type 5 to set baud rate as 9600

Setup serial input


Type SI and press enter Kit displays SERIAL INPUT and now kit is ready for serial input

Burning program onto 8086 kit


Open command window Type the program, save, assemble and link the *.asm le Then debug lename.exe and press enter

 n filename.bin  wcs:1000  q
Then type datacom and press enter

 set parameters and then transmit lename.bin  wait till transmission is complete

Execute the program


Type GO 1000 and press enter

1 Interfacing Stepper Motor to 8086 using 8255


Experiment 1 6th August, 2009

1.1 Using ULN2003


1) A program to rotate a stepper motor continuously in the anticlockwise direction, for three dierent speeds
CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H CR EQU 0C6H PB EQU 0C2H MOV AL, 80H OUT CR, AL MOV AL, 66H BACK: OUT PB, AL ROL AL, 1H CALL DELAY JMP BACK DELAY PROC NEAR MOV CX, 0FFFFH AGN: LOOP AGN RET DELAY ENDP HLT CODE ENDS END

;address of the control register ;address of Port B ;control word for Port B as output ;send it to the control register ;load sequence in AL ;send it to Port B ;rotate left once ;call a delay ;repeat the sequence ;delay procedure

;end of delay procedure

2) A program to nd the step angle of the given stepper motor


CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H CR EQU 0C6H PB EQU 0C2H MOV AL, 80H OUT CR, AL MOV CX, 200 MOV AL, 66H BAC: OUT PB, AL ROR AL, 1H CALL DELAY LOOP BAC DELAY PROC NEAR BACK: MOV DX, 3H AGN: MOV BX, 0FFFFH DEC BX JNZ AGN DEC DX JNZ BACK RET DELAY ENDP HLT CODE ENDS END

;address ;address ;control ;send it

of control register of Port B word for Port B as output to control register

;load sequence in AL ;send it to Port B ;rotate right once ;call a delay ;repeat until CX=0 ;delay procedure

;end of delay procedure

3) A program to rotate a stepper motor 90 degrees in the clockwise direction and 180 degrees in the anticlockwise direction four times

CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H CR EQU 0C6H PB EQU 0C2H MOV DX, 4 MOV AL, 80H OUT CR, AL ABC: MOV CX, 50 ;CX=50 MOV AL, 66H BACK: OUT PB, AL ROR AL, 1H CALL DELAY LOOP BACK MOV CX, 100 MOV AL, 66H BACK1: OUT PB, AL ROL AL, 1H CALL DELAY LOOP BACK1 DEC DX JNZ ABC DELAY PROC NEAR MOV BX, 0FFFH AGN: DEC BX JNZ AGN RET DELAY ENDP HLT CODE ENDS END

;address of control register ;address of Port B ;control word for Port B as output ;send it to control register ;load sequence in AL ;send it to Port B ;rotate right once ;call a delay ;repeat until CX=0 ;load sequence in AL ;rotate it once, to the left ;call a delay ;repeat until CX=0 ;delay procedure

;end of delay procedure

Procedure: ULN2003 driver IC circuit is setup on breadboard. The input is given using the 26

pin at cable from 8255 board. We are using Port B of 8255 to give input of the driver IC. Pin 9, 10, 11, 12 of the 26 pin connector is found to be Port B using CRO. These pins are connected to pin numbers 1, 2, 3 and 4 of ULN2003. Output is taken from 13, 14, 15 and 16 of ULN2003. Stepper motor have ve input leads and a VCC lead. All 24 permututations are tried to get the anticlockwise rotation of the stepper motor.

Result: Stepper motor was driven as per the requirement and step angle = 7.2o

1.2 Using the preassembled kit


1) A program to rotate a stepper motor continuously in the anticlockwise direction, for three dierent speeds

CODE SEGMENT ASSUME CS:CODE, DS:CODE PORT1 EQU 0C0H START: MOV DI, OFFSET TABLE MOV CL, 04 LOOP1: MOV AL, [DI] OUT PORT1, AL MOV DX, 1010H DELAY: DEC DX JNZ DELAY INC DI LOOP LOOP1 JMP START TABLE: DB 0AH, 6, 5, 9 HLT CODE ENDS END

;port address ORG 1000H ;load address of table to DI

;output values ;introduce delay

;rotate motor continuously

2) A program to nd the step angle of the given stepper motor

CODE SEGMENT ASSUME CS:CODE, DS:CODE PORT1 EQU 0C0H ORG 1000H MOV BX, 50 START: MOV DI, OFFSET TABLE MOV CL, 04 LOOP1: MOV AL, [DI] OUT PORT1, AL MOV DX, 1010H DELAY: DEC DX JNZ DELAY INC DI LOOP LOOP1 DEC BX JNZ START HLT TABLE: DB 9, 5, 6, 0AH HLT CODE ENDS END

;port address

;load address of table to DI ;to get 200 steps ;output values ;introduce delay

;rotates motor till BX = 0

3) A program to rotate a stepper motor 90 degrees in the clockwise direction and 180 degrees in the anticlockwise direction four times
CODE SEGMENT ASSUME CS:CODE, DS:CODE PORT1 EQU 0C0H ORG 1000H MOV AH,4 START: MOV BL, 12 FORWD: MOV DI, OFFSET FORW CALL ROTATE DEC BL JNZ FORWD CALL DELAY MOV BL, 25 REVER: MOV DI, OFFSET REV CALL ROTATE DEC BL JNZ REVER CALL DELAY DEC AH JNZ START ROTATE: MOV CL, 4 REPT: MOV AL, [DI] OUT PORT1, AL MOV DX, 1010H LOOP1: DEC DX JNZ LOOP1 INC DI LOOP REPT RET MOV DX, 0FFFFH DELAY: DEC DX JNZ DELAY RET HLT FORW: DB 9, 5, 6, 0AH REV: DB 0AH, 6, 5, 9 CODE ENDS END

;port address

;procedure for rotating values ;loop for 48 steps ;delay

;procedure for rotating values ;loop for 100 steps ;delay ;loop for repeating 4 times ;procedure to output to port

;delay after each step

;delay procedure

Procedure: The 8255 board is given with power transistors already assembled. The output from
8086 trainer kit is taken using a at cable to 8255 board and output is given to motor.

Result: Stepper motor was driven as per the requirement and step angle = 7.2o

10

2 Interfacing LED displays to 8086


Experiment 2 13th August, 2009

2.1 Using 8255


1) A program to display an eight character word on the display
CODE SEGMENT ASSUME CS:CODE, DS:CODE TABLE EQU 1200H DATA EQU 00C8H CON EQU 00C0H ORG 1000H CON: MOV SI, TABLE MOV BL, 08H L1: DEC BL MOV AL, BL OUT CONTL, AL MOV AL, [SI] OUT DATA, AL CALL DELAY INC SI CMP BL, 00H JNZ L1 JMP CON DELAY: MOV CL, 02H L2: MOV AL, 0FFH L3: DEC AL JNZ L3 DEC CL JNZ L2 RET ORG 1200H DB 77H, 78H, 78H, 04H DB 78H, 3EH, 5EH, 79H CODE ENDS END

;display RAM pointer ;number of digits to scan

;select digit position ;give display information ;delay of 2mS ;data pointer incremented ;check if 8 digits are displayed ;if not, repeat ;repeat from first digit ;delay of 2mS

11

2) A program to display a word rolling on the LED display


CODE SEGMENT ASSUME CS:CODE, DS:CODE TABLE EQU 1200H DATA EQU 00C8H CONT EQU 00C0H ORG 1000H REP: MOV CH, 0FH MOV DX, 0000H COM: MOV SI, TABLE ADD SI, DX MOV BL, 08H LO1: DEC BL MOV AL, BL OUT CONT, AL MOV AL, [SI] OUT DATA, AL CALL DELAY INC SI CMP BL, 00H JNZ LO1 DEC CH JNZ COM SUB SI, 0007H CMP SI, 120FH JZ REP INC DX JMP COM DELAY: MOV CL, 02 L1: MOV AL, 0FFH L2: DEC AL JNZ L2 DEC CL JNZ L1 RET ORG 1200H DB 77H, 78H, 78H, 04H DB 78H, 3EH, 5EH, 79H DB 00H, 00H, 00H, 00H DB 00H, 00H, 00H, 00H DB 77H, 78H, 78H, 04H DB 78H, 3EH, 5EH, 79H CODE ENDS END

;delay for rolling display

;select digit position ;give display information ;call delay procedure ;increment data pointer

;check for first 16 digits

;delay procedure

12

2.2 Using 8279


1) A program to display a key pressed on a LED display
CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H DATR EQU 0C0H CNTR EQU 0C2H TABLE DB 0CH, 9FH, 4AH, 0BH, 99H, 29H, 28H, 8FH DB 08H, 09H, 88H, 38H, 6CH, 1AH, 68H, 0E8H LEA SI, TABLE ;pointer to the seven segment codes MOV CX, 08 ;counter MOV AL, 0 ;word for display RAM ,right entry OUT CNTR, AL ;send it to control register MOV AL, 3EH ;word to divide clock frequency by 30 OUT CNTR, AL ;send it to control register MOV AL, 3EH ;word to divide clock frequency by 30 OUT CNTR, AL ;send it to control register MOV AL, 0CCH ;word to clear display OUT CNTR, AL ;send it to control register MOV AL, 90H ;word to write display RAM OUT CNTR, AL ;send it to control register MOV AL, 0FFH ;data to blank out the display AGN: OUT DATR, AL ;send it to the data register LOOP AGN ;repeat for 8 digits GO: LEA SI, TABLE NEXT: IN AL,CNTR ;read in the status register TEST AL, 07 ;test if D0=1 JZ NEXT ;if not continue testing MOV AL, 40H ;otherwise write CW to read FIFO OUT CNTR, AL ;send it to control register IN AL, DATR ;read in the FIFO AND AL, 0FH ;mask upper nibble of key code MOV BL, AL ;copy it to BL MOV BH, 0 ADD SI, BX ;add BX to SI MOV AL, [SI] ;take corresponding display code OUT DATR, AL ;send it to data register JMP GO ;continue for more keys CODE ENDS END

13

2) A program to display a word rolling on the LED display


CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H START: MOV SI, 1200H MOV CX, 0FH MOV AL, 10H OUT 0C2H, AL MOV AL, 0CCH OUT 0C2H, AL MOV AL, 90H OUT 0C2H, AL NEXT: MOV AL, [SI] OUT 0C0H, AL CALL DELAY INC SI LOOP NEXT JMP START DELAY: MOV DX, 0A0FFH LOOP1: DEC DX JNZ LOOP1 RET ORG 1200H DB 0FFH, 0FFH, 0FFH, 0FFH DB 0FFH, 0FFH, 0FFH, 0FFH DB 98H, 68H, 7CH, 0C8H DB 0FFH, 1CH, 29H, 0FFH CODE ENDS END

;pointer to the seven segment codes ;send ;word ;send ;word ;send it to it to it to control register clear display to control register write display RAM to control register

;take corresponding display code ;send it to data register ;call delay procedure

;delay procedure

Procedure: 8279 chip has two portions  one for providing scanned display interface for LED and the other for interfacing with keyboards or an array of sensors. In the absence of this chip, the processor is fully involved in the detecting of key press and displaying of words. But with 8279, the processor has to just give the commands and the 8279 takes care of all the activities. In case of a valid key press, the code of the key enters into the FIFO RAM. At the same time, the count in the status register increments. While programming, the key press is detected by checking whether the count in the status register is incremented or not.

14

3 Interfacing 8255 & 8253 to 8086


Experiment 3 20th August, 2009

3.1 Using 8255


1) A program to generate a square wave of frequency at 6kHz at PB7
CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H MOV AL,80H OUT 0C6H,AL BACK: MOV AL, 00H OUT 0C2H, AL CALL DELAY MOV AL, 0FFH OUT 0C2H, AL CALL DELAY JMP BACK DELAY PROC NEAR MOV CX, 20 HERE: NOP LOOP HERE RET DELAY ENDP HLT CODE ENDS END

;value to be passed to control register

;set port B = 0H ;call delay procedure ;set port B = 0FFH ;call delay procedure ;delay procedure

Procedure: 6kHz square wave has a time period of 166.66s. So a delay of 83s is called for each ON time and OFF time. For getting square wave at PB7, port B is made output port and output is taken from PB7. Others pins are don't cares. Waveform: Observed frequency = 4.23 kHz; Ton = 118S; Tof f = 118S

15

2) A program to generate a asymmetrical wave of 20% duty cycle at PC7 using BSR mode of 8255
CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H MOV AL, 90H OUT 0C6, AL MOV AL, 90H OUT 0C6H, AL BACK: MOV AL, 0FH OUT 0C6H, AL CALL DELAY MOV AL, 0EH OUT 0C6H, AL CALL DELAY CALL DELAY CALL DELAY CALL DELAY JMP BACK DELAY PROC NEAR MOV CX, 20H HERE: NOP LOOP HERE RET DELAY ENDP HLT CODE ENDS END

;value to be passed to control register

;set port C = 0FFH ;call delay procedure ;set port C = 0H ;call delay procedure

;delay procedure

Procedure: A square wave of 20% duty cycle means the square wave is ON for

the time period. A delay of some value is created. The delay is called once when the output port is ON and the delay is called four times when the port is OFF. PC7 is set/reset using the BSR mode.

1 th 5 of

Waveform: Observed frequency = 4.23 kHz; Ton = 47S; Tof f = 188S

16

3.2 Using 8253


1) A program to generate three simultaneous square waveforms of frequencies 13kHz, 60kHz and 1kHz at OUT1, OUT2 & OUT3 respectively using same clock frequency of 1.5MHz.
DATA SEGMENT CR EQU 0CEH CNT0 EQU 0C8H CNT1 EQU 0CAH CNT2 EQU 0CCH DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA ORG 1000H MOV AL, 36H OUT CR, AL MOV AX, 180 OUT CNT0, AL MOV AL, AH OUT CNT0, AL MOV AL, 76H OUT CR, AL MOV AX, 39 OUT CNT1, AL MOV AL, AH OUT CNT1, AL MOV AL, 0B6H OUT CR, AL MOV AX, 180 OUT CNT2, AL MOV AL, AH OUT CNT2, AL HLT CODE ENDS END

;address ;address ;address ;address

of of of of

the control register counter 0 counter 1 counter 2

;select counter 0 in mode 3 ;value to be passed to control register ;load count = 115 in AX ;send lower byte of count to counter 0 ;move higher byte of count to AL ;send higher byte of count to counter 0 ;select counter 1 in mode 3 ;value to be passed to control register ;load count = 25 in AX ;send lower byte of count to counter 1 ;move higher byte of count to AL ;send higher byte of count to counter 1 ;select counter 2 in mode 3 ;value to be passed to control register ;load count = 1500 in AX ;send lower byte of count to counter 2 ;move higher byte of count to AL ;send higher byte of count to counter 2

Procedure: For 8253, a delay procedure is not required. It produces hardware delay which is made use to create the waveforms. Mode 3 of counters 0, 1 & 2 is made use in this program. Counter 0 divides input frequency by 115 to produce a square wave of 13kHz. Similarly, counter 1 and counter 2 divides the input frequency by 25 and 1500 to produce 60kHz and 1kHz respectively. Waveforms: Observed frequency = 17.8 kHz; Ton = 28S; Tof f = 28S

17

Observed frequency = 92.5 kHz; Ton = 5.4S; Tof f = 5.4S

Observed frequency = 1.5 kHz; Ton = 333S; Tof f = 333S

18

2) A program to generate an asymmetric square wave at the output of counter 2 using any two modes of the 8253 chip. Use the modes which do not require an L to H transition at the gate. Using Mode 2
DAT SEGMENT CR EQU 0CEH CNT2 EQU 0CCH DAT ENDS COD SEGMENT ASSUME CS: COD, DS: DAT ORG 1000H MOV AL, 0B4H OUT CR, AL MOV AX, 3 OUT CNT2, AL MOV AL, AH OUT CNT2, AL HLT COD ENDS END ;address of control register ;address of counter 2

;control word for counter 2 in mode 2 ;send it to control register ;load count = 3 in AX ;lower byte of count to counter 2 ;move higher byte of count to AL ;send higher byte of count to counter 2

Using Mode 4
DAT SEGMENT CR EQU 0CEH CNT2 EQU 0CCH DAT ENDS COD SEGMENT ASSUME CS: COD, DS: DAT ORG 1000H AGA: MOV AL, 0B8H OUT CR, AL MOV AX, 3 OUT CNT2, AL MOV AL, AH OUT CNT2, AL JUMP AGA HLT COD ENDS END ;address of control register ;address of counter 2

;control word for counter 2 in mode 4 ;send it to control register ;load count = 3 in AX ;send lower byte of count to counter 2 ;move higher byte of count to AL ;send higher byte of count to counter 2

Procedure: The control word is selected such as to set counter 2 in mode 2 or mode 4. In mode 2, the counter reloads after one cycle. In mode 4, the counter has to be reloaded by the user. The pulse will be high for N cycles and low for one cycle where N = count.

19

Waveforms:

Ton = 5 ; Tof f =

Ton = 7 ; Tof f =

20

4 Interfacing ADC & DAC to 8086


Experiment 4 10th September, 2009

4.1 ADC
1) A program to measure the DC voltage at ADC pin and get digital readout.
CODE SEGMENT ASSUME CS:CODE,DS:CODE ORG 1000H MOV AL, 10H OUT 0C8H, AL MOV AL, 18H OUT 0C8H, AL MOV AL, 01 OUT 0D0H, AL MOV AL, 00 MOV AL, 00 MOV AL, 00 MOV AL, 00 OUT 0D0H LOOP: IN AL, 0D8H AND AL, 01 CMP AL, 01 JNZ LOOP IN AL, 0C0H MOV BX, 1100H MOV [BX], AL HLT CODE ENDS END

;make ALE low ;enable ALE ;make SC high ;create delay

;make ALE & SC low ;check for EOC ;if EOC port is low, jump ;move data to the memory location

Procedure: ADC creates a digital output depending on the analog input given. Analog signal
is given to the ADC through one of the inut pins. Then ALE and SC are enabled to latch address and to start conversion. After giving a delay ALE and SC are lowered. EOC port is monitored. If it is low then data is taken in and send to memory.

21

4.2 DAC
1) A program to generate a triangular waveform of T = 10ms.
CODE SEGMENT ASSUME CS:CODE,DS:DAT ORG 1000H MOV AL, 0 REPEA: OUT 0C8H, AL CALL DELAY INC AL CMP AL, 45 JNZ REPEA AGN: OUT 0C8H, AL CALL DELAY DEC AL CMP AL, 0 JNZ AGN JMP REPEA DELAY PROC NEAR MOV CX, 26 HERE: LOOP HERE RET DELAY ENDP HLT CODE ENDS END

;AL=0 ;send AL to port A ;call delay ;compare AL with 45H ;if not equal, repeat ;if AL=45H, decrement loop ;call delay ;comapare AL with 0 ;if not 0, continue decrementing ;if AL=0, increment ;delay procedure ;value of N for a small delay

Procedure: DAC converts digital signals into analog form. Depending on the digital input given, a current is generated which is converted into voltage by the DAC. To create a triangular waveform rst the count is incremented by giving a delay after each increment. After a particular value the count is decremented in a similar manner. Time period is calculated depending on the clock. Waveform: T = 9.8ms

22

2) A program to generate a ramp waveform of T = 1ms.


CODE SEGMENT ASSUME CS:CODE,DS:DAT ORG 1000H AGN: MOV AL,0 REPEA: OUT 0C8H,AL CALL DELAY INC AL CMP AL,24 JNZ REPEA JMP AGN DELAY PROC NEAR MOV CX,10 HERE: LOOP HERE RET DELAY ENDP HLT CODE ENDS END

;AL=0 ;send AL to port A ;call a delay ;compare AL with 24H ;if not equal, repeat ;if AL=0, increment ;delay procedure ;value of N for a small delay

Procedure: DAC converts digital signals into analog form. Depending on the digital input given,

a current is generated which is converted into voltage by the DAC. To create a ramp waveform the count is incremented by giving a delay after each increment. Then this is repeated. Time period is calculated depending on the clock.

Waveform: T = 1.1ms

23

3) A program to generate a staircase waveform with each step 1ms delay.


CODE SEGMENT ASSUME CS:CODE, DS:DAT ORG 1000H STRT: MOV AL, 0 OUT 0C8H, AL CALL DELAY REPEA: ADD AL, 31 OUT 0C8H, AL CALL DELAY CMP AL, 248 JNZ REPEA JMP STRT DELAY PROC NEAR MOV CX, 240 AGN: LOOP AGN RET DELAY ENDP HLT CODE ENDS END

;AL=0 ;send AL to Port A ;call a delay ;add 31 to AL ;send AL to Port A ;call delay ;check whether AL=248 ;if not, repeat addition ;if AL=248, go to START ;delay procedure ;value of N for Delay

Procedure: DAC converts digital signals into analog form. Depending on the digital input given, a current is generated which is converted into voltage by the DAC. To create 8 steps total count is divided by 8. So count is to be incremented by 32 after the delay to get a staircase waveform. Waveform: T = 8.2ms each step of approx. 1ms

24

5 8051 Programming
Experiment 5 17th September, 2009

5.1 Wave generation


1) A Program to generate a square wave of 10 kHz frequency at any output pin.
MAIN: HERE: ORG 0000H CPL P1.3 ACALL DELAY SJMP HERE MOV R2,#45 DJNZ R2,AGAIN RET ;complement ;call delay procedure ;infinite loop for square wave generation ;delay loop for 0.1msec

DELAY: AGAIN: END

25

2) A program to generate a asymmetric wave with ON time 1 ms and OFF time 0.3 ms.
MAIN: HERE: ORG 0000H SETB P1.3 ACALL DELAY ACALL DELAY ACALL DELAY CLR P1.3 ACALL DELAY SJMP HERE MOV R2,#2 MOV R3,#153 DJNZ R3,AGAIN DJNZ R2,THERE RET ;make P1.3 = 1 ;call delay ;call delay ;call delay ;make P1.3 = 0 ;call delay ;infinite loop ;delay loop for 0.3 msec

DELAY: THERE: AGAIN:

END

26

5.2 Miscellaneous
1) A program to add two 64 bit numbers which are in consecutive locations in RAM and store it in RAM.
MAIN: ORG 0000H

MOV R0,#31H MOV R1,#8H MOV DPTR,#40H REPEAT1: CLR A ;loop for moving the 1st number into RAM MOVC A,@A+DPTR MOV @R0,A INC DPTR INC R0 DJNZ R1,REPEAT1 MOV R0,#51H MOV R1,#8H MOV DPTR,#60H REPEAT2: CLR A ;loop for moving the 2nd number into RAM MOVC A,@A+DPTR MOV @R0,A INC DPTR INC R0 DJNZ R1,REPEAT2 CLR C MOV R2,#08 MOV R0,#31H MOV R1,#51H SETB PSW.3 ;select register bank 1 MOV R0,#61H CLR PSW.3 ;select register bank 0 AGAIN: MOV A,@R0 ADDC A,@R1 ;adding the 2 numbers INC R0 INC R1 SETB PSW.3 MOV @R0,A ;sum is moved into RAM and stored INC R0 CLR PSW.3 DJNZ R2,AGAIN ORG 40H DATA1: DB 24H,0AEH,32H,38H,0C0H,32H,0DEH,32H ORG 60H DATA2: DB 54H,0EH,0FCH,81H,2AH,93H,93H,88H END
27

2) A program to store a word `INDIAN' in ROM. Read it from ROM and display it at Port 0. Display one character at a time with a delay between successive displays.
MAIN: BACK: ORG 0000H MOV DPTR,#500H MOV R2,#06 CLR A MOVC A,@A+DPTR MOV P0,A ACALL DELAY INC DPTR DJNZ R2,BACK SJMP HERE MOV R2,#45 DJNZ R2,AGAIN RET ORG 50H DB `I',`N',`D',`I',`A',`N' ;delay procedure ;loop for moving each character to P0 ;DPTR points to the character being displayed

HERE: DELAY: AGAIN:

DAT: END

28

3) Write a look up table in ROM for the cubes of decimal numbers. In another ROM location, store the squares. Depending on the status of pin P0.0, get the squares/cubes displayed at Port 1 LEDs.
MAIN: START: ORG 0000H SETB P0.0 JNB P0.0,Square JB P0.0,Cube MOV DPTR,#500H MOV R2,#10 CLR A MOVC A,@A+DPTR MOV P1,A ACALL DELAY INC DPTR DJNZ R2,BACK11 SJMP START MOV DPTR,#700H MOV R2,#08 CLR A MOVC A,@A+DPTR MOV P1,A ACALL DELAY INC DPTR DJNZ R2,BACK SJMP START MOV R2,#60 MOV R3,#255 MOV R4,#255 DJNZ R4,HERE DJNZ R3,AGAIN DJNZ R2,THERE RET ORG 500H DB 0,1,4,9,16,25,36,49,64,81 ORG 700H DB 0,1,8,27,64,125,216,243 ;loop for displaying the contents of DAT2 ;loop for displaying the contents of DAT1 ;setting P0.0 as input port ;if P0.0=0 jump to square ;if P0.0=1 jump to cube

SQUARE: BACK11:

CUBE: BACK:

DELAY: THERE: AGAIN: HERE:

;procedure for delay

END DAT1: DAT2:

29

6 Interfacing Hex Keyboard with 8086


Experiment 6 27th September, 2009

A program to identify a key pressed on hex keyboard interfaced through 8255 to 8086.
CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H ROW_0 DB 0,1,2,3 ROW_1 DB 4,5,6,7 ROW_2 DB 8,9,0AH,0BH ROW_3 DB 0CH,0DH,0EH,0FH CR EQU 0C6H PA EQU 0C0H PB EQU 0C2H MOV AL, 82H OUT CR, AL MOV AL, 0 OUT PA, AL KEYP: IN AL, PB AND AL, 0FH CMP AL, 0FH JZ KEYP CALL DELAY IN AL, PB AND AL, 0FH CMP AL, 0FH JZ KEYP ROW0: MOV AL, 0FEH OUT PA, AL IN AL, PB AND AL, 0FH CMP AL, 0FH JZ ROW1 LEA SI, ROW_0 JMP COL_ID ROW1: MOV AL, 0FDH OUT PA, AL IN AL, PB AND AL, 0FH CMP AL, 0FH JZ ROW2 LEA SI, ROW_1

;address of the control register ;address of Port A ;address of Port B ;8255 control word ;send to control register ;send zeros to all the rows ;read in the columns ;mask the upper nibble ;compare with 0FH ;if equal, no key pressed ;if key press ,wait for debounce time ;after the delay, confirm the key press ;read in the columns ;mask the upper nibble ;compare with 0FH ;if equal, no key pressed ;send `0' to Row0 alone ;read in the columns ;mask the upper nibble ;compare with 0FH ;no key press in Row0, so check Row1 ;not equal, SI to point to Row0 data ;go to finding the column ;send `0' to Row1 alone and repeat steps

30

JMP COL_ID ROW2: MOV AL, 0FBH OUT PA, AL IN AL, PB AND AL, 0FH CMP AL, 0FH JZ ROW3 LEA SI, ROW_2 JMP COL_ID ROW3: MOV AL, 0F7H OUT PA, AL IN AL, PB AND AL, 0FH CMP AL, 0FH JZ KEYP LEA SI, ROW_3 COL_ID: SHR AL, 1 JNC FOUND INC SI JMP COL_ID FOUND: MOV BX, 1500H MOV AL, [SI] MOV [BX], AL DELAY PROC NEAR MOV CX, 6000 AGN: LOOP AGN RET DELAY ENDP CODE ENDS END

;send `0' to Row2 alone and repeat steps

;send `0' to Row3 alone and repeat steps

;to identify the column ,shift right ;if no carry, column is found ;otherwise point SI to next data of row ;go back to finding the column ;get the data pointed by SI into AL ;this is the pressed key, store in KEY ;delay for key debounce

Procedure: The rows and columns are connected to lower four bits of Port A and Port B

respectively. The key press is detected by rst sending zero to all rows and the columns are read. If no key is pressed we get 1111 from PB3 to PB0 else we get a zero corresponding to the column which contains the key pressed. Now to recongnise the row containing the key, the rows are grounded one by one. The columns are read. When the value read is less than 1111, then the row grounded gives the required row. To ensure the a key press detected is valid, key debounce time is given and checked again. If even then the key press is detected the key press is a valid one.

31

7 Timers in Interrupt Mode


Experiment 7 1st October, 2009

1) A program to generate two square waves of frequency 5kHz and 13kHz simultaneously using timers in interrupt mode.
ORG 0000H LJMP NEXT ORG 000BH CPL P1.3 RETI ORG 001BH CPL P2.3 RETI ORG 0030H MOV TMOD,#22H MOV IE,#8AH MOV TH0,#048H MOV TH1,#0B9H SETB TCON.4 SETB TCON.6 SJMP WAIT ;interrupt vector for timer 0 ;toggle P1.3 ;interrupt vector for timer 1 ;toggle P2.3

MAIN:

NEXT:

WAIT: END

;set both the timers in mode 2 ;enable timer0 and timer1 overflow interrupt ;load TH0 value ;load TH1 value ;start timer 0 ;start timer 1

32

2) A program to generate the half the input frequency using timers.


ORG 0000H LJMP MAIN ORG 0003H CPL P0.3 RETI ORG 0030H SETB TCON.0 MOV IE,#81H SJMP HERE

;interrupt vector for interrupt 0 ;toggle P0.3

MAIN: HERE: END

;make INT0 an edge-triggered interrupt ;enable external interrupt 0

33

3) A program to nd the frequency of the input square wave.


ORG 0000H MOV TMOD,#15H SETB P3.4 MOV TL0,#00H MOV TH0,#00H SETB TCON.4 MOV R0,#28 MOV TL1,#00H MOV TH1,#00H SETB TCON.6 JNB TCON.7,BACK CLR TCON.7 CLR TCON.6 DJNZ R0,AGAIN MOV A,TL0 MOV P2,A MOV A,TH0 MOV P1,A SJMP RPT ;timer1 as timer and timer0 as counter ;set P3.4 as input port ;clear TL0 ;clear TH0 ;start counter 0 ;to time 1 sec ;load count value in TL1 ;load count value in TH1 ;start timer 1 ;test timer 1 flag ;clear timer 1 flag ;stop timer 1 ;repeat the loop until R0=0 ;move the count value to port2 ;move the count value to port1

MAIN: RPT:

AGAIN:

BACK:

END

34

8 8051 timers: Stack Check Mode


Experiment 8 15th October, 2009

1) A program to generate a symmetric square wave of 11 kHz on any port pin using timer 0 in mode 1.

MAIN: HERE:

ORG 0000H MOV TMOD,#01H MOV TH0,#0FFH MOV TL0,#0ADH CPL P1.3 ACALL DELAY SJMP HERE SETB TCON.4 JNB TCON.5,AGAIN CLR TCON.4 CLR TCON.5 RET ;start timer 0 ;set when rolling over from 0FFFFH to 0000H ;stop timer 0 ;timer 0 in mode 1

DELAY: AGAIN:

END

35

2) A program to generate an asymmetrical square wave with ON time 15 ms and OFF time of 3 ms on pin P0.5 using timer 1 in mode 2.
ORG 0000H MOV TMOD,#20H MOV TH1,#00H SETB P0.5 MOV R2,#5 ACALL DELAY DJNZ R2,HERE CLR P0.5 ACALL DELAY SJMP REP MOV R0,#22 SETB TCON.6 JNB TCON.7,BAK CLR TCON.6 CLR TCON.7 DJNZ R0,AGAIN RET ;start timer 1 ;timer 1 mode 2

MAIN: REP: HERE:

DELAY: AGAIN: BAK:

END

36

3) A program to a square wave whose one cycle consists of one square wave of period 30 ms followed by three square waves of 10 ms each.
ORG 0000H MOV TMOD,#01H SETB P0.2 ACALL DELAY ACALL DELAY ACALL DELAY CLR P0.2 ACALL DELAY ACALL DELAY ACALL DELAY MOV R0,#3 SETB P0.2 ACALL DELAY CLR P0.2 ACALL DELAY DJNZ R0,BACK SJMP HERE MOV TH0,#0DCH MOV TL0,#03AH SETB TCON.4 JNB TCON.5,AGAIN CLR TCON.4 CLR TCON.5 RET ;timer 0 mode 1

MAIN: HERE:

BACK:

DELAY:

AGAIN:

;start timer 0 ;set when rolling over from 0FFFFH to 0000H ;stop timer 0

END

37

9 8051 timers: Interrupt Mode


Experiment 9 22nd October, 2009

1) A program to generate a symmetric square wave of 25 KHz at any port pin using timer 1 in mode 1.
ORG 0000H LJMP START ORG 001BH CPL P1.0 MOV TH1,#0FFH MOV TL1,#0E3H RETI ORG 0030H MOV TMOD,#10H MOV IE,#88H MOV TH1,#0FFH MOV TL1,#0E3H SETB TCON.6 SJMP HERE ;goto label START ;ISR corresponding to timer 1 ;compliment P0.0 ;load timer

MAIN:

START:

;timer 1 in mod 1 ;enable timer 1 interrupt ;load the timer ;start timer ;wait for interrupt

HERE: END

38

2) A program to generate a square wave with ON time of 2 ms and OFF time of 0.5 ms using timer 0 in mode 1.
ORG 0000H LJMP START ORG 000BH JB P1.7,ONE SETB P1.7 CLR P1.0 MOV TH0,#0F1H MOV TL0,#0ACH RETI CLR P1.7 SETB P1.0 MOV TH0,#0FCH MOV TL0,#06AH RETI ORG 0050H CLR P1.7 MOV TMOD,#01H MOV IE,#82H MOV TH0,#0FCH MOV TL0,#6AH SETB TCON.4 SJMP HERE ;ISR corresponding to timer 0 ;jump if P1.7 = 1 ;set P1.7 ;clear P1.0 ;delay for 2 ms

MAIN:

ONE:

;clear P1.7 ;set P1.0 ;delay for 0.5 ms

START:

;clear P1.7 ;timer 0 in mod 1 ;enable timer 0 interrupt ;load timer ;start timer 0 ;wait for interrupt

HERE: END

39

3) A program to blink LEDs of port 1 with a delay of 1s.


ORG 0000H LJMP START ORG 001BH DJNZ R0,SKIP MOV R0,10 MOV A,#0FFH XRL P1,A MOV TH1,#00H MOV TL1,#00H RETI ORG 0030H MOV TMOD,#10H MOV IE,#88H MOV R0,#28 MOV TL1,#00H MOV TH1,#00H SETB TCON.6 SJMP HERE ;timer 1, mod 1 ;enable timer 1 interrupt ;R0= 28 ;load timer ;start timer 1 ;wait for interrupt ;ISR corresponding to timer 1 ;if R0!=0 go to label SKIP ;reload R0 ;compliment the bits of P1 ;load timer

MAIN:

SKIP: START:

HERE: END

40

You might also like