L5 : MOV BH, 70H Count for delay
DEC BH Decrement count.
JNZ L5
DELAY 2 ENDP
(v) Staircase wave :
Explanation :
We have to generate a staircase wave using DAC interface. Fig. 7 shows a staircase wave.
Fig. 7
We have considered 8 levels for drawing the stair case wave i.e. 2, 4, 8, 16, 32, 64, 128 and 256. Their hex equivalent are 02 H, 04 H, 08 H, 10 H, 20 H, 40 H, 80 H and Hex equivalent for 255 is FFH. We will store these values in an array. You can also increase or decrease the levels, for staircase waveform. Each level will be outputted on Port A of 8255 which is configured as output port.
Algorithm :
Step I : Initialize the data section.
Step II : Initialize BX to the start of array.
Step III : Initialize port A of 8255 as output port.
Step IV : Initialize count = 08H.
Step V : Load AL with first step of staircase.
Step VI : Output the contents of AL on port A.
Step VII : Call delay.
Step VIII : Increment BX to point next step value.
Step IX : Decrement count.
Step X : Check if count = 0 ? If not, go to step V.
Step XI : Initialize count = 08H in CL.
Step XII : Decrement BX to next value.
Step XIII : Load the value, pointed by BX in AL register.
Step XIV : Output the contents of AL on port A.
Step XV : Call delay.
Step XVI : Decrement count.
Step XVII : Is count = 00 ? If not, go to step XII.
Step XVIII : Jump step IV.
Flowchart : Refer Flowchart B.2(d).
Flowchart B.2(d)
Program :
Label Instruction Comment
. model small
MOV AX, @ Data Initialize data segment.
MOV DS, AX
MOV AL, 80H Initialize 8255 Port A as output port.
MOV DX, Port A DX = address of Port A.
INC BX Increment BX to point next step
value.
DEC CL Decrement count.
JNZ L1
MOV CL, COUNT Initialize CL = count.
L2 : DEC BX Decrement BX to point next step
Program 3 : Write 8086 ALP to rotate a stepper motor for given number of steps at a given angle and in the given direction of rotation based on the user choice such as,
i) If ‘C’ key is pressed - clockwise rotation.
ii) If ‘A’ key is pressed – anticlockwise rotation.
iii) If ‘B’ is pressed – ½ clockwise and Vz anticlockwise rotation.
iv) If ‘S’ key is pressed – stop rotation.
Also write routines to accelerate and deaccelerate the motor.
Explanation :
The block diagram of a microprocessor based control scheme for a stepper motor is shown in Fig. 8. The motor has four windings A, B, C and D which are driven by a single phase excitation scheme i.e. at a time only one winding is energized. The sequence in which the windings are to be energized is stored in the memory of the microprocessor system in the form of a look up table. The 8255 is configured such that port A acts as an output port. The output of the 8255 are used to drive the four transistors. The freewheeling diodes are connected across each phase of the phase windings to protect the transistors against high forward voltage at the time of their turn off. When the look up table is output on the output port in the sequence 0AH, 09H, 05H, 06H, the motor rotates in clockwise direction. When the sequence of outputting the contents of look up table is reversed i.e. 06H, 05H, 09H, 0AH the motor starts rotating in counter clockwise or anticlockwise direction. If the sequence of rotation is 0AH, 09H, 06H, 05H the motor rotates is ½ clockwise and ½ anticlockwise rotation.
The speed of motor can be changed by changing the rate at which look up table contents are being sent out. The position control is possible by programming the processor to keep a count of the number of pulses being sent out because each pulse corresponds to rotation through a specific angle.
Fig. 8
Flowchart : Refer Flowchart B.3.
Program :
Label Instruction Comment
MESS MACRO MSG MOV AH, 09W LEA DX, MSG INT 21H
ENDM . MODEL SMALL
. DATA
Clockwise DB 0AH, 09H, 05H, 06H Anticlockwise DB 06H, 05H, 09H, 0AH Half-clk DB 0AH, 09H, 06H, 05H.
MSG 1 DB 0AH, 0DH, ‘Menu $’.
MSG 2 DB 0AH, 0DH, ‘C : clockwise rotation’
MSG 3 DB 0AH, 0DH, ‘A : Anticlockwise rotation’.
MSG 4 DB 0AH, 0DH, ‘B : ½ clockwise and ½ anticlockwise rotation’
MSG 5 DB 0A, 0DH, ‘S : Stop rotation’
MSG 6 DB 0A, 0DH, ‘Accept choice’.
MSG 7 DB 0A, 0DH, ‘Wrong choice’.
. CODE
MOV AX, @Data MOV DS, AX
L1 : MESS MSG 1 Display Menu.
MESS MSG 2 MESS MSG 3 MESS MSG 4 MESS MSG 5
MESS MSG 6 Accept choice from user.
MOV AH, 01H
INT 21H
MOV BL, AL Choice in BL
CMP BL, 41H If choice = A
Label Instruction Comment
JE clkrot
CMP BL, 42H Is choice = B. (42 is ASCII equivalent for B)
JE half
CMP BL, 43H Is choice = ‘C’.
JE antirot
CMP BL, 53H Is choice = ‘S’.
JE endd.
MESS MSG 7 display ‘wrong choice’
JMP L1 display Menu again.
clkrot : CALL clockwiserot
JMP L1
half : CALL halfclockhalfanti
JMP L1
antirot : CALL anticlockwiserot.
JMP L1
endd: MOV AH, 4CH
INT 21H.
clockwiserot PROC NEAR
MOV AL, 80H Initialize port A as output port.
MOV DX, 00 Load port address of port A in DX.
OUT DX, AL Output contents of AL on port A.
MOV SI, Offset clockwise.
MOV BL, 04H Load sequence count.
L1 : MOV AL, [SI] AL = code
OUT DX, AL Output the excitation code on port A.
CALL DELAY Wait
INC SI Increment SI to point next code.
DEC BL decrement sequence count
JNZ L1 RET
clockwiserot ENDP.
Flowchart B.3
Program 4 : Write 8086 ALP to print a text message on printer using centronix parallel printer interface.
Explanation :
Whenever data on computer is to be printed, the computer sends an INIT pulse first, in order to initialize the printer. The computer then checks for a BUSY signal, in order to know whether the printer is ready to receive data or not. If the BUSY signal is not low, then the computer checks for the PE signal. If this signal is high, then display message that the “Printer is OUT OF PAPER”. If the PE signal is low the computer checks for the ––––––ERROR signal. If this signal is low, it indicates that printer is in “Paper End”
state, “Offline” state and “Error” state. In such a case display message “PRINTER OFFLINE” and stop.
Fig. 9
Fig. 10
If the BUSY signal is low, then the computer sends an ASCII code on eight parallel data lines. The computer also sends a –––STB signal to the printer, to indicate that valid data is available on the data bus. In response, the printer sends an ––––ACK (acknowledgement) signal, to indicate that data to be printed is received. The rising edge of the ––––ACK signal, resets the BUSY signal from the printer. When the computer sees that BUSY signal is low, it sends the next character along with strobe and the sequence is repeated till the last character to be printed is transferred. Fig. 10 shows the circuit for interfacing centronix type parallel input printer to 8255 A. Port A is used as an output port, to send 8-bit data to the printer. Port B is used an input port to check the ––––––ERROR , PE and BUSY signals.
The port C signals, PC7 is used as an ––––ACK signal and PC6 is used as –––STB signal.
The PC0 is used to send ––––INIT signal to initialize the printer.
Algorithm :
Step I : Initialize the data section.
Step II : Initialize the pointer to point to the string.
Step III : Initialize the counter with number of characters in the string that are to be printed.
Step IV : Initialize the 8255, port A with output port, portB as input port.
Step V : Send ––––INIT signal to initialize the printer.
Step VI : Check for BUSY signal. If it is low go to step VII, else go to step XIII.
Step VII : Send the character to be printed.
Step VIII : Check for ––––ACK . If not received, then wait till the ––––ACK signal is received.
Step IX : Increment the string pointer, to point to the next character to be printed.
Step X : Decrement the counter.
Step XVI : Display message “Printer offline”.
Step XVII : Stop.
Flowchart : Refer flowchart B.4.
Program :
The control word for 8255 is
I/O Mode A PA PCU Mode B PB PCL
1 0 1 0 X 0 1 0 = A2H
Label Instruction Comment
. model small
MSG 1 DB 10, 13, ‘Printer Out of Printer’.
MSG 2 DB 10, 13, ‘Printer offline’.
MSG 3 DB 10, 13, ‘Printing completed’.
MSG 4 DB 10, 13, ‘This matter is to be printed’.
COUNT DB 15.
. code
MOV AX, @ Data Initialize the data segment.
MOV DS, AX
LEA BX, MSG 4 Initialize pointer to start of string.
MOV DX, CWR DX = control word register address.
Label Instruction Comment the printer for initialisation.
Back : MOV CX, 0FFFH Wait for 50 s, so that printer will get
JNZ CHECK Check for BUSY signal. If high goto CHECK.
MOV AL, [BX] Load the first character in AL.
MOV DX, Port A Load the address of Port A in DX.
OUT DX, AL Send the character to be printed.
MOV DX, Port C DX = address of Port C.
L2 : IN AL, DX
Check for ––––
ACK by checking status of INTRA.
JNZ L2
MOV CL, COUNT Load count in CL.
DEC CL Decrement count.
JNZ UP Continue till all the characters are printed.
JMP ENDD
CHECK : MOV AL, AH Load the printer status in AL.
AND AL, 02H Check for PE signal high.
MOV AL, AH Load status in AL.
JZ CHECK 1
LEA DX, MSG 1 Display Message “Printer out of Paper”.
LEA DX, MSG 2 Display Message “Printer offline”.
MOV AH, 09H INT 21H
Label Instruction Comment JMP UP
ENDD : LEA DX, MSG 3 Display Message “Printing completed”.
MOV AH, 09H
INT 21H
MOV AH, 4CH Terminate Program.
INT 21H
END.
Flowchart B.4
Programs of 8253
Program 1 : Write 8086 ALP to program 8253 in mode 0, modify the program for hardware re-triggerable monoshot mode. Generate a square wave with a pulse of 1 ms. Comment on the difference between Hardware Triggered and software triggered strobe mode. Observe the waveform at GATE and OUT pin of IC 8254 on CRO.
(i) To program 8254 in mode 0 means to initialize it.
Control word
Corel A
MOV AL, 31 H ; Counter 0, mode 0 CWR MOV DX, 5006 ; CWR address
OUT DX, AL ; Loads control word in the CWR
(ii) The modification in the above program, for mode 5 i.e. Hardware retriggerable monoshot mode is only to change the control word.
Control word
Corel B
MOV AL, 3BH ; Counter 0, mode 5 CWR MOV DX, 5006 ; CWR address
OUT DX, AL ; Loads control word in CWR.
(iii) Program to generate a square wave with a pulse of 1 ms.
Step 1 : Assume the Counter 0 is used to generate square wave and addresses of Counter 0 = 10 H and Control register = 13 H.
Step 2 : The output period required is 1 ms. The input frequency is 1 MHz, so input period = 1 s.
Count value = Required period
Input period = 1 ms
1 s = (1000)10
Step 3 : The control word format to initialize counter 0, 16 bit counter, BCD counting and square wave generator mode will be as follows :
Corel C
Step 4 : The 8253 initialisation program will be as follows :
(iv) For the difference between Hardware triggered and software triggered strobe mode please refer chapter 16.
(v) For the wave forms at GATE and OUT pin of IC 8254.
Programs of 8279
Program 1 : Write a program to initialize and operate 8279 for the following specifications. The addresses of 8279 are A2 H and B2 H
Step I : According to specification (i) the 8279 should be initialized in 16 digit right entry mode.
(a) Keyboard /display mode set command :
DD = 11; KKK should be encoded KKK = 000 ; The command word is,
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 0 0 0 0 = 18 H
Step II : Specification (ii) gives external clock frequency and display scan time.
Scan time = Display scan time
Step IV : According to specification (iii) the display is common anode type that is logic 0 corresponds to segment ‘ON’ and logic 1 corresponds to segment ‘OFF’. It also gives the connection of segments with A3 - A0 and B3 - B0 lines.
We will have look up Table B.4 as follows : Table B.4 : Look-up Table
dp g f e d c b a Data Address first entry should be displayed on rightmost digit (digit 11). After first entry, it shifts the address of digit and then displays contents of corresponding location.
i.e. first entry will be displayed on digit 12 AI = 1, A3A2A1A0 = 1100
Hence the command word is, 1001 1100 = 9C H Step VI : Now we can find address of control/status and data register.
A7 while the address of data register is A2.
Step VII : Flowchart of the program is shown in Fig.10(a)
Title INITIALIZATION OF 8279
Label Instruction Comments .model small
.code
MOV AL, 00H Keyboard/display mode OUT B2 H, AL set command
MOV CX, 000F H Character counter L1: MOV AL, [BX] Read character code
Program 1: Perform an experiment to establish communication between two 8251 systems A and B.
Program 8251 system A in asynchronous transmitter mode and 8251 system B in asynchronous receiver mode. Write an ALP to transmit the data from system A and receive the data at system B. The requirements are as follows:
Transmission :
A message is stored as ASCII characters in the memory.
A message specifies the number of characters to be transmitted as the first byte.
Reception :
Message is retrieved and stored in the memory.
Successful reception should be indicated.
(i) The interfacing schematic will be as Fig. 11.
(ii) The mode word required for asynchronous mode, 8 bit character. We assume baud rate factor 16, No parity check and 1 stop bit.
Fig. 10(a)
Fig. 11
The mode word format for transmitter and receiver will be as follows :
COREL 20
(iii) Command word format to enable Tx and Rx will be as follows :
COREL 21
(iv) Status word to check TxRDy will be 01H and RxRDy will be 02H.
(v) The flow chart for both systems will be as shown Flowchart B.5.
(vi) Program for both systems will be same.
Program :
Label Instruction Comment
MOV BX, address1 Memory pointer for Tx MOV DX, address
2 Memory pointer for Rx
Label Instruction Comment
MOV AL, 00 H Dummy 00's to 8251
OUT F3 H, AL OUT F3 H, AL OUT F3 H, AL
MOV AL, 40 H Internally reset 8251 OUT F3 H, AL
MOV AL, 4E H Mode word
OUT F3 H, AL
MOV AL, 15 H Command word
OUT F3 H, AL
UP : IN AL, F3 H Status word
AND AL, 01 H
TEST AL, 01 H Check TxRDy
CALL Tx data call subroutine 1
IN AL, F3 H status word
AND AL, 02 H
TEST AL, 02 H Check RxRDy
CALL Rx data Call subroutine 2
LOOP UP Go to up.
Subroutine 1
Tx data MOV AL, [BX] Take data from memory
OUT F2 H, AL Data 8251 Tx
INC BX memory pointer = memory pointer + 1
RET Go to main program.
Subroutine 2
Rx data IN F2 H, AL Take data from Rx
MOV [DX], AL Store data in memory
INC DX Memory pointer = Memory pointer +1
RET Go to main program
Flowchart B.5 8259 Programs
Program 1 : Write 8086 APL to interface 8259 in cascade mode (M/S) and demonstrate execution of ISR in following manner :
Main program will display two digits up counter. When slave IRQ interrupt occurs, it clears the counter and starts up counting again. When Master IR1 interrupt occurs, it resets the counter to FFH and starts down counting.
Explanation :
Fig. 12 shows the interfacing of 8259 with 8086 in cascaded mode. Eight interrupt lines IR0-IR7 are connected to the interrupt request register (IRR).A microprocessor uses
two PICs to provide 15 interrupt inputs (7 on the master PIC and 8 on the slave one). the following table lists the interrupt sources on the PC .
Input on 8259A
Priority 80x86 INT Device
IRQ 0 Highest 08h Timer Chip
IRQ 1 09h Keyboard
IRQ 2 0Ah Cascade for controller 2 (IRQ 8-15) IRQ 9/1 71h CGA vertical retrace (and other IRQ 2
devices)
IRQ 8/0 70h Real-time clock
IRQ 10/2 72h Reserved
IRQ 11/3 73h Reserved
IRQ 12/4 74h Reserved in AT, auxiliary device on PS/2 systems
IRQ 13/5 75h FPU interrupt
IRQ 14/6 76h Hard disk controller
IRQ 15/7 77h Reserved
IRQ 3 0Bh Serial Port 2
IRQ 4 0Ch Serial Port 1
IRQ 5 0Dh Parallel port 2 in AT, reserved in PS/2 systems
IRQ 6 0Eh Diskette drive
IRQ 7 Lowest 0Fh Parallel Port 1
For cascaded 8259, the INT pin of the slaves are connected to interrupt request pins (IR0 – IR7) and –––––
INTA to the –––––
INTA of master 8259. The CAS2 – CAS0 lines work as output for the master and input for the slave. The CAS2 – CAS0 lines act as select lines for addressing the slaves. Fig. 12 shows cascaded 8259 interfaced with 8086 in maximum mode.
m(12.15)Fig. 12 : Interfacing 8259 with 8086 (8259 – cascaded, 8086 – maximum mode)
Program :
Label Instruction Comment
START: MOV AX,1000H
MOV DS,AX
MOV AX,4000H
MOV SS,AX
MOV SP,0500H
MOV AX,0000H
MOV ES,AX
MOV AX,1000H
MOV [ES:0008H],AX
MOV AX,2000H
MOV [ES:0009H],AX
STI Enable interrupt
L1 : JMP L1
Interrupt service routine,
Instruction MOV AL,[08H]
INC AL DAA POP AX MOV AL,[09H]
DEC AL POP AX IRET
TSR Programs
Program 1 : Write a TSR program in 8086 ALP to implement Real Time Clock (RTC). Read the Real Time from CMOS chip by suitable INT and FUNCTION and display the RTC at the bottom right corner on the screen. Access the video RAM directly in your routine.
Program :
Label Instruction Comment
.model small
.stack 100h
.code resi:
push ax
push bx push cx push dx push es push di mov ax,0b800h mov es,ax mov di,140 mov ah,02 int 1Ah mov bx,cx mov ah,07 mov cx,0504h
cld
Label Instruction Comment
Label Instruction Comment mov al,08
lea dx,resi int 21h lea dx,init add dx,100h mov cl,4 shr dx,cl inc dx mov ah,31h mov al,00 int 21h end init
TSR Programs
Program 1 : Write a TSR program in 8086 ALP to implement Screen Saver. Screen Saver should get activated if the keyboard is idle for 7 seconds. Access the video RAM directly in your routine.
Program :
Label Instruction
.model small
.stack 500h .code resi_timer:
cmp cs:flag,1
je timer_2 dec cs:count jnz timer_quit push cx push ax push dx push es push di push si push ds mov cx,0b800h mov ds,cx mov si,00 mov cx,cs
Label Instruction
timer_quit: jmp dword ptr cs:old_ip_timer timer_2 :
Label Instruction
timer_2_quit: jmp dword ptr cs: old_ip_timer resi_kbd: mov cs:count,182
cmp cs:flag,0
Label Instruction
kbd_quit: jmp dword ptr cs:old_ip_kbd
old_ip_timer dw ?
mov word ptr old_ip_timer,bx mov word ptr old_cs_timer,es mov ah,25h
mov word ptr old_ip_kbd,bx mov word ptr old_cs_kbd,es mov ah,25h
mov al,9
Label Instruction lea dx,resi_kbd int 21h
lea dx,init add dx,100h mov cl,4 shr dx,cl inc dx mov ah,31h mov al,00 int 21h end init