Vous êtes sur la page 1sur 40

Contents

1 Interfacing Stepper Motor to 8086 using 8255 3


1.1 Using ULN2003 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.2 Using the preassembled kit . . . . . . . . . . . . . . . . . . . . . . . . 7

2 Interfacing LED displays to 8086 11


2.1 Using 8255 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.2 Using 8279 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3 Interfacing 8255 & 8253 to 8086 15


3.1 Using 8255 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.2 Using 8253 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

4 Interfacing ADC & DAC to 8086 21


4.1 ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4.2 DAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5 8051 Programming 25
5.1 Wave generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.2 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

6 Interfacing Hex Keyboard with 8086 30


7 Timers in Interrupt Mode 32
8 8051 timers: Stack Check Mode 35
9 8051 timers: Interrupt Mode 38

29
th October, 2009

1
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

2
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 ;address of the control register
PB EQU 0C2H ;address of Port B
MOV AL, 80H ;control word for Port B as output
OUT CR, AL ;send it to the control register
MOV AL, 66H ;load sequence in AL
BACK:
OUT PB, AL ;send it to Port B
ROL AL, 1H ;rotate left once
CALL DELAY ;call a delay
JMP BACK ;repeat the sequence
DELAY PROC NEAR ;delay procedure
MOV CX, 0FFFFH
AGN:
LOOP AGN
RET
DELAY ENDP ;end of delay procedure
HLT
CODE ENDS
END

3
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 ;address of control register
PB EQU 0C2H ;address of Port B
MOV AL, 80H ;control word for Port B as output
OUT CR, AL ;send it to control register
MOV CX, 200
MOV AL, 66H ;load sequence in AL
BAC:
OUT PB, AL ;send it to Port B
ROR AL, 1H ;rotate right once
CALL DELAY ;call a delay
LOOP BAC ;repeat until CX=0
DELAY PROC NEAR ;delay procedure
BACK:
MOV DX, 3H
AGN:
MOV BX, 0FFFFH
DEC BX
JNZ AGN
DEC DX
JNZ BACK
RET
DELAY ENDP ;end of delay procedure
HLT
CODE ENDS
END

4
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 ;address of control register
PB EQU 0C2H ;address of Port B
MOV DX, 4
MOV AL, 80H ;control word for Port B as output
OUT CR, AL ;send it to control register
ABC:
MOV CX, 50 ;CX=50
MOV AL, 66H ;load sequence in AL
BACK:
OUT PB, AL ;send it to Port B
ROR AL, 1H ;rotate right once
CALL DELAY ;call a delay
LOOP BACK ;repeat until CX=0
MOV CX, 100
MOV AL, 66H ;load sequence in AL
BACK1:
OUT PB, AL
ROL AL, 1H ;rotate it once, to the left
CALL DELAY ;call a delay
LOOP BACK1 ;repeat until CX=0
DEC DX
JNZ ABC
DELAY PROC NEAR ;delay procedure
MOV BX, 0FFFH
AGN:
DEC BX
JNZ AGN
RET
DELAY ENDP ;end of delay procedure
HLT
CODE ENDS
END

5
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

6
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 ;port address ORG 1000H
START:
MOV DI, OFFSET TABLE ;load address of table to DI
MOV CL, 04
LOOP1:
MOV AL, [DI]
OUT PORT1, AL ;output values
MOV DX, 1010H
DELAY: ;introduce delay
DEC DX
JNZ DELAY
INC DI
LOOP LOOP1
JMP START ;rotate motor continuously
TABLE:
DB 0AH, 6, 5, 9
HLT
CODE ENDS
END

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

CODE SEGMENT
ASSUME CS:CODE, DS:CODE
PORT1 EQU 0C0H ;port address
ORG 1000H
MOV BX, 50
START:
MOV DI, OFFSET TABLE ;load address of table to DI
MOV CL, 04 ;to get 200 steps
LOOP1:
MOV AL, [DI]
OUT PORT1, AL ;output values
MOV DX, 1010H
DELAY: ;introduce delay
DEC DX
JNZ DELAY
INC DI
LOOP LOOP1
DEC BX
JNZ START ;rotates motor till BX = 0
HLT
TABLE:
DB 9, 5, 6, 0AH
HLT
CODE ENDS
END

8
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 ;port address
ORG 1000H
MOV AH,4
START:
MOV BL, 12
FORWD:
MOV DI, OFFSET FORW
CALL ROTATE ;procedure for rotating values
DEC BL
JNZ FORWD ;loop for 48 steps
CALL DELAY ;delay
MOV BL, 25
REVER:
MOV DI, OFFSET REV
CALL ROTATE ;procedure for rotating values
DEC BL
JNZ REVER ;loop for 100 steps
CALL DELAY ;delay
DEC AH
JNZ START ;loop for repeating 4 times
ROTATE:
MOV CL, 4 ;procedure to output to port
REPT:
MOV AL, [DI]
OUT PORT1, AL
MOV DX, 1010H
LOOP1:
DEC DX ;delay after each step
JNZ LOOP1
INC DI
LOOP REPT
RET
MOV DX, 0FFFFH
DELAY:
DEC DX ;delay procedure
JNZ DELAY
RET
HLT
FORW:
DB 9, 5, 6, 0AH
REV:
DB 0AH, 6, 5, 9
CODE ENDS
END

9
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 ;display RAM pointer
MOV BL, 08H ;number of digits to scan
L1:
DEC BL
MOV AL, BL
OUT CONTL, AL ;select digit position
MOV AL, [SI]
OUT DATA, AL ;give display information
CALL DELAY ;delay of 2mS
INC SI ;data pointer incremented
CMP BL, 00H ;check if 8 digits are displayed
JNZ L1 ;if not, repeat
JMP CON ;repeat from first digit
DELAY:
MOV CL, 02H ;delay of 2mS
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

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 ;delay for rolling display
MOV DX, 0000H
COM:
MOV SI, TABLE
ADD SI, DX
MOV BL, 08H
LO1:
DEC BL
MOV AL, BL
OUT CONT, AL ;select digit position
MOV AL, [SI]
OUT DATA, AL ;give display information
CALL DELAY ;call delay procedure
INC SI ;increment data pointer
CMP BL, 00H
JNZ LO1
DEC CH
JNZ COM
SUB SI, 0007H
CMP SI, 120FH ;check for first 16 digits
JZ REP
INC DX
JMP COM
DELAY: ;delay procedure
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

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 ;pointer to the seven segment codes
MOV CX, 0FH
MOV AL, 10H
OUT 0C2H, AL ;send it to control register
MOV AL, 0CCH ;word to clear display
OUT 0C2H, AL ;send it to control register
MOV AL, 90H ;word to write display RAM
OUT 0C2H, AL ;send it to control register
NEXT:
MOV AL, [SI] ;take corresponding display code
OUT 0C0H, AL ;send it to data register
CALL DELAY ;call delay procedure
INC SI
LOOP NEXT
JMP START
DELAY: ;delay procedure
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

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 ;value to be passed to control register
OUT 0C6H,AL
BACK:
MOV AL, 00H
OUT 0C2H, AL ;set port B = 0H
CALL DELAY ;call delay procedure
MOV AL, 0FFH
OUT 0C2H, AL ;set port B = 0FFH
CALL DELAY ;call delay procedure
JMP BACK
DELAY PROC NEAR ;delay procedure
MOV CX, 20
HERE:
NOP
LOOP HERE
RET
DELAY ENDP
HLT
CODE ENDS
END

Procedure: 6kHz square wave has a time period of 166.66µs. So a delay of 83µs 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 = 118µS; Tof f = 118µS

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 ;value to be passed to control register
OUT 0C6, AL
MOV AL, 90H
OUT 0C6H, AL
BACK:
MOV AL, 0FH
OUT 0C6H, AL ;set port C = 0FFH
CALL DELAY ;call delay procedure
MOV AL, 0EH
OUT 0C6H, AL ;set port C = 0H
CALL DELAY ;call delay procedure
CALL DELAY
CALL DELAY
CALL DELAY
JMP BACK
DELAY PROC NEAR ;delay procedure
MOV CX, 20H
HERE:
NOP
LOOP HERE
RET
DELAY ENDP
HLT
CODE ENDS
END

Procedure: A square wave of 20% duty cycle means the square wave is ON for 5 of
1 th
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.

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

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 ;address of the control register
CNT0 EQU 0C8H ;address of counter 0
CNT1 EQU 0CAH ;address of counter 1
CNT2 EQU 0CCH ;address of counter 2
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
ORG 1000H
MOV AL, 36H ;select counter 0 in mode 3
OUT CR, AL ;value to be passed to control register
MOV AX, 180 ;load count = 115 in AX
OUT CNT0, AL ;send lower byte of count to counter 0
MOV AL, AH ;move higher byte of count to AL
OUT CNT0, AL ;send higher byte of count to counter 0
MOV AL, 76H ;select counter 1 in mode 3
OUT CR, AL ;value to be passed to control register
MOV AX, 39 ;load count = 25 in AX
OUT CNT1, AL ;send lower byte of count to counter 1
MOV AL, AH ;move higher byte of count to AL
OUT CNT1, AL ;send higher byte of count to counter 1
MOV AL, 0B6H ;select counter 2 in mode 3
OUT CR, AL ;value to be passed to control register
MOV AX, 180 ;load count = 1500 in AX
OUT CNT2, AL ;send lower byte of count to counter 2
MOV AL, AH ;move higher byte of count to AL
OUT CNT2, AL ;send higher byte of count to counter 2
HLT
CODE ENDS
END

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 = 28µS; Tof f = 28µS

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

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

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 ;address of control register
CNT2 EQU 0CCH ;address of counter 2
DAT ENDS
COD SEGMENT
ASSUME CS: COD, DS: DAT
ORG 1000H
MOV AL, 0B4H ;control word for counter 2 in mode 2
OUT CR, AL ;send it to control register
MOV AX, 3 ;load count = 3 in AX
OUT CNT2, AL ;lower byte of count to counter 2
MOV AL, AH ;move higher byte of count to AL
OUT CNT2, AL ;send higher byte of count to counter 2
HLT
COD ENDS
END

Using Mode 4

DAT SEGMENT
CR EQU 0CEH ;address of control register
CNT2 EQU 0CCH ;address of counter 2
DAT ENDS
COD SEGMENT
ASSUME CS: COD, DS: DAT
ORG 1000H
AGA:
MOV AL, 0B8H ;control word for counter 2 in mode 4
OUT CR, AL ;send it to control register
MOV AX, 3 ;load count = 3 in AX
OUT CNT2, AL ;send lower byte of count to counter 2
MOV AL, AH ;move higher byte of count to AL
OUT CNT2, AL ;send higher byte of count to counter 2
JUMP AGA
HLT
COD ENDS
END

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 = τ

. 5τ τ

Ton = 7τ ; Tof f = τ

. 7τ τ

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 ;make ALE low
OUT 0C8H, AL
MOV AL, 18H ;enable ALE
OUT 0C8H, AL
MOV AL, 01 ;make SC high
OUT 0D0H, AL
MOV AL, 00 ;create delay
MOV AL, 00
MOV AL, 00
MOV AL, 00
OUT 0D0H ;make ALE & SC low
LOOP:
IN AL, 0D8H ;check for EOC
AND AL, 01
CMP AL, 01
JNZ LOOP ;if EOC port is low, jump
IN AL, 0C0H
MOV BX, 1100H
MOV [BX], AL ;move data to the memory location
HLT
CODE ENDS
END

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 ;AL=0
REPEA:
OUT 0C8H, AL ;send AL to port A
CALL DELAY ;call delay
INC AL
CMP AL, 45 ;compare AL with 45H
JNZ REPEA ;if not equal, repeat
AGN:
OUT 0C8H, AL ;if AL=45H, decrement loop
CALL DELAY ;call delay
DEC AL
CMP AL, 0 ;comapare AL with 0
JNZ AGN ;if not 0, continue decrementing
JMP REPEA ;if AL=0, increment
DELAY PROC NEAR ;delay procedure
MOV CX, 26 ;value of N for a small delay
HERE:
LOOP HERE
RET
DELAY ENDP
HLT
CODE ENDS
END

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 ;AL=0
REPEA:
OUT 0C8H,AL ;send AL to port A
CALL DELAY ;call a delay
INC AL
CMP AL,24 ;compare AL with 24H
JNZ REPEA ;if not equal, repeat
JMP AGN ;if AL=0, increment
DELAY PROC NEAR ;delay procedure
MOV CX,10 ;value of N for a small delay
HERE:
LOOP HERE
RET
DELAY ENDP
HLT
CODE ENDS
END

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 ;AL=0
OUT 0C8H, AL ;send AL to Port A
CALL DELAY ;call a delay
REPEA:
ADD AL, 31 ;add 31 to AL
OUT 0C8H, AL ;send AL to Port A
CALL DELAY ;call delay
CMP AL, 248 ;check whether AL=248
JNZ REPEA ;if not, repeat addition
JMP STRT ;if AL=248, go to START
DELAY PROC NEAR ;delay procedure
MOV CX, 240 ;value of N for Delay
AGN:
LOOP AGN
RET
DELAY ENDP
HLT
CODE ENDS
END

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.

ORG 0000H
MAIN:
HERE:
CPL P1.3 ;complement
ACALL DELAY ;call delay procedure
SJMP HERE ;infinite loop for square wave generation
DELAY:
MOV R2,#45 ;delay loop for 0.1msec
AGAIN:
DJNZ R2,AGAIN
RET
END

25
2) A program to generate a asymmetric wave with ON time 1 ms and OFF time 0.3 ms.

ORG 0000H
MAIN:
HERE:
SETB P1.3 ;make P1.3 = 1
ACALL DELAY ;call delay
ACALL DELAY ;call delay
ACALL DELAY ;call delay
CLR P1.3 ;make P1.3 = 0
ACALL DELAY ;call delay
SJMP HERE ;infinite loop
DELAY:
MOV R2,#2 ;delay loop for 0.3 msec
THERE:
MOV R3,#153
AGAIN:
DJNZ R3,AGAIN
DJNZ R2,THERE
RET
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.

ORG 0000H
MAIN:
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.

ORG 0000H
MAIN:
MOV DPTR,#500H
MOV R2,#06
BACK:
CLR A ;loop for moving each character to P0
MOVC A,@A+DPTR ;DPTR points to the character being displayed
MOV P0,A
ACALL DELAY
INC DPTR
DJNZ R2,BACK
HERE:
SJMP HERE
DELAY:
MOV R2,#45 ;delay procedure
AGAIN:
DJNZ R2,AGAIN
RET
ORG 50H
DAT:
DB `I',`N',`D',`I',`A',`N'
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.

ORG 0000H
MAIN:
START:
SETB P0.0 ;setting P0.0 as input port
JNB P0.0,Square ;if P0.0=0 jump to square
JB P0.0,Cube ;if P0.0=1 jump to cube
SQUARE:
MOV DPTR,#500H
MOV R2,#10
BACK11:
CLR A ;loop for displaying the contents of DAT1
MOVC A,@A+DPTR
MOV P1,A
ACALL DELAY
INC DPTR
DJNZ R2,BACK11
SJMP START
CUBE:
MOV DPTR,#700H
MOV R2,#08
BACK:
CLR A ;loop for displaying the contents of DAT2
MOVC A,@A+DPTR
MOV P1,A
ACALL DELAY
INC DPTR
DJNZ R2,BACK
SJMP START
DELAY: ;procedure for delay
MOV R2,#60
THERE:
MOV R3,#255
AGAIN:
MOV R4,#255
HERE:
DJNZ R4,HERE
DJNZ R3,AGAIN
DJNZ R2,THERE
RET
END
ORG 500H
DAT1:
DB 0,1,4,9,16,25,36,49,64,81
ORG 700H
DAT2:
DB 0,1,8,27,64,125,216,243

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 ;address of the control register
PA EQU 0C0H ;address of Port A
PB EQU 0C2H ;address of Port B
MOV AL, 82H ;8255 control word
OUT CR, AL ;send to control register
MOV AL, 0
OUT PA, AL ;send zeros to all the rows
KEYP:
IN AL, PB ;read in the columns
AND AL, 0FH ;mask the upper nibble
CMP AL, 0FH ;compare with 0FH
JZ KEYP ;if equal, no key pressed
CALL DELAY ;if key press ,wait for debounce time
;after the delay, confirm the key press
IN AL, PB ;read in the columns
AND AL, 0FH ;mask the upper nibble
CMP AL, 0FH ;compare with 0FH
JZ KEYP ;if equal, no key pressed
ROW0:
MOV AL, 0FEH ;send `0' to Row0 alone
OUT PA, AL
IN AL, PB ;read in the columns
AND AL, 0FH ;mask the upper nibble
CMP AL, 0FH ;compare with 0FH
JZ ROW1 ;no key press in Row0, so check Row1
LEA SI, ROW_0 ;not equal, SI to point to Row0 data
JMP COL_ID ;go to finding the column
ROW1:
MOV AL, 0FDH ;send `0' to Row1 alone and repeat steps
OUT PA, AL
IN AL, PB
AND AL, 0FH
CMP AL, 0FH
JZ ROW2
LEA SI, ROW_1

30
JMP COL_ID
ROW2:
MOV AL, 0FBH ;send `0' to Row2 alone and repeat steps
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 ;send `0' to Row3 alone and repeat steps
OUT PA, AL
IN AL, PB
AND AL, 0FH
CMP AL, 0FH
JZ KEYP
LEA SI, ROW_3
COL_ID:
SHR AL, 1 ;to identify the column ,shift right
JNC FOUND ;if no carry, column is found
INC SI ;otherwise point SI to next data of row
JMP COL_ID ;go back to finding the column
FOUND:
MOV BX, 1500H
MOV AL, [SI] ;get the data pointed by SI into AL
MOV [BX], AL ;this is the pressed key, store in KEY
DELAY PROC NEAR
MOV CX, 6000 ;delay for key debounce
AGN:
LOOP AGN
RET
DELAY ENDP
CODE ENDS
END

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 simultane-
ously using timers in interrupt mode.

ORG 0000H
MAIN:
LJMP NEXT
ORG 000BH ;interrupt vector for timer 0
CPL P1.3 ;toggle P1.3
RETI
ORG 001BH ;interrupt vector for timer 1
CPL P2.3 ;toggle P2.3
RETI
ORG 0030H
NEXT:
MOV TMOD,#22H ;set both the timers in mode 2
MOV IE,#8AH ;enable timer0 and timer1 overflow interrupt
MOV TH0,#048H ;load TH0 value
MOV TH1,#0B9H ;load TH1 value
SETB TCON.4 ;start timer 0
SETB TCON.6 ;start timer 1
WAIT:
SJMP WAIT
END

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

ORG 0000H
LJMP MAIN
ORG 0003H ;interrupt vector for interrupt 0
CPL P0.3 ;toggle P0.3
RETI
ORG 0030H
MAIN:
SETB TCON.0 ;make INT0 an edge-triggered interrupt
MOV IE,#81H ;enable external interrupt 0
HERE:
SJMP HERE
END

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

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

ORG 0000H
MAIN:
MOV TMOD,#01H ;timer 0 in mode 1
HERE:
MOV TH0,#0FFH
MOV TL0,#0ADH
CPL P1.3
ACALL DELAY
SJMP HERE
DELAY:
SETB TCON.4 ;start timer 0
AGAIN:
JNB TCON.5,AGAIN ;set when rolling over from 0FFFFH to 0000H
CLR TCON.4 ;stop timer 0
CLR TCON.5
RET
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
MAIN:
MOV TMOD,#20H
MOV TH1,#00H ;timer 1 mode 2
REP:
SETB P0.5
MOV R2,#5
HERE:
ACALL DELAY
DJNZ R2,HERE
CLR P0.5
ACALL DELAY
SJMP REP
DELAY:
MOV R0,#22
AGAIN:
SETB TCON.6 ;start timer 1
BAK:
JNB TCON.7,BAK
CLR TCON.6
CLR TCON.7
DJNZ R0,AGAIN
RET
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
MAIN:
MOV TMOD,#01H ;timer 0 mode 1
HERE:
SETB P0.2
ACALL DELAY
ACALL DELAY
ACALL DELAY
CLR P0.2
ACALL DELAY
ACALL DELAY
ACALL DELAY
MOV R0,#3
BACK:
SETB P0.2
ACALL DELAY
CLR P0.2
ACALL DELAY
DJNZ R0,BACK
SJMP HERE
DELAY:
MOV TH0,#0DCH
MOV TL0,#03AH
SETB TCON.4 ;start timer 0
AGAIN:
JNB TCON.5,AGAIN ;set when rolling over from 0FFFFH to 0000H
CLR TCON.4 ;stop timer 0
CLR TCON.5
RET
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
MAIN:
LJMP START ;goto label START
ORG 001BH ;ISR corresponding to timer 1
CPL P1.0 ;compliment P0.0
MOV TH1,#0FFH ;load timer
MOV TL1,#0E3H
RETI
ORG 0030H
START:
MOV TMOD,#10H ;timer 1 in mod 1
MOV IE,#88H ;enable timer 1 interrupt
MOV TH1,#0FFH ;load the timer
MOV TL1,#0E3H
SETB TCON.6 ;start timer
HERE:
SJMP HERE ;wait for interrupt
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
MAIN:
LJMP START
ORG 000BH ;ISR corresponding to timer 0
JB P1.7,ONE ;jump if P1.7 = 1
SETB P1.7 ;set P1.7
CLR P1.0 ;clear P1.0
MOV TH0,#0F1H ;delay for 2 ms
MOV TL0,#0ACH
RETI
ONE:
CLR P1.7 ;clear P1.7
SETB P1.0 ;set P1.0
MOV TH0,#0FCH ;delay for 0.5 ms
MOV TL0,#06AH
RETI
ORG 0050H
START:
CLR P1.7 ;clear P1.7
MOV TMOD,#01H ;timer 0 in mod 1
MOV IE,#82H ;enable timer 0 interrupt
MOV TH0,#0FCH ;load timer
MOV TL0,#6AH
SETB TCON.4 ;start timer 0
HERE:
SJMP HERE ;wait for interrupt
END

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

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

40

Vous aimerez peut-être aussi