Title: EDUSAT SESSION FOR ADVANCED MICROPROCESSOR EC54
1EDUSAT SESSION FOR ADVANCED MICROPROCESSOR
(EC54) Date 08.11.2005 Session VII Topic
Programming Examples Faculty Anita Kanavalli
MSRIT
2Program 9
Write a program to compute factorial of a
positive number using recursive
procedure Program .MODEL SMALL .STACK
64H .DATA Num DW 04H Fact DW ?
3Program 9
.CODE MOV AX,_at_DATA MOV DS,AX MOV BX,Num CALL
FACT MOV AH,4CH INT 21H .EXIT
4Program 9
FACT PROC CMP BX,00H JE Next PUSH BX DEC BX CALL
FACT POP BX MUL BX
5Program 9
RET Next MOV AX,01H RET ENDP END
6Interfacing
- PPI or Multi Function Devices (MFD)
F0
D- BF
I/O
FN1
C P U
FN2
F1
I/O
System Bus
SW Register
F2
I/O
CW Register
7Interfacing
- D-Buf is the data buffer
- System Bus- carries ADDR,DATA,CONTROL
- FN1,FN2,FN3,F0,F1.. Are functional circuits
(MFC) - MFCs could be I/O ports, Timers, Transmitters,
Receivers etc - MFC- Independent function
- Each MFC has UNIQUE ADDRESS
- SW Register- Status register
8Interfacing
- SW register- could be absent as in 8255A
- CW register- must be present in all MFDs (
PPIs) - There could be more than one CW register
- Each SW and CW also has UNIQUE ADDRESS
- CW- defines (prepares) a functional unit in one
of the modes - SW- tells the status of various functional
devices
9Interfacing
- PROGRAMMING ?
- SEND CONTROL WORD / WORDS
- SEND/RECEIVE DATA TO/FROM each functional unit
10Interfacing
- I/O s
- Logic Controllers
- Modem
- Stepper Motor
- Key board
- Display
- One for each functional unit sometimes
11Interfacing Examples
1 Generate a square wave on PC0 pin of 8255 in
the add on card Command Word of 8255
7 6 5 4 3
2 1 0
1 MD MD PA PCU
MD PB PCL
12Interfacing Examples
- PPI or Multi Function Devices (MFD) 8255A
PA
D- BF
FN1
C P U
FN2
PB
System Bus
PC
Card
CW Register
13Interfacing Example
- Program
- .MODEL SMALL
- .DATA
- PA EQU 200H
- PB EQU 201H
- PC EQU 202H
- CW WQU 203H
14Interfacing Example
.CODE MOV AX,_at_DATA MOV DS,AX MOV AL,80H
CW MOV DX,CW the addr of CW moved to DX OUT
DX,AL CW sent to MFD Back MOV AL,00H
15Interfacing Example
MOV DX,PC move addr of port c OUT DX,AL CALL
Delay procedure call MOV AL,01H MOV DX,PC OUT
DX,AL CALL Delay JMP Back
16Interfacing Example
Delay PROC MOV CX,0FFFFH Here LOOP
Here RET ENDP END
17Interfacing Example
2 Interface a stepper motor and write program
to rotate in clock-wise direction by N-steps
To all coils of the motor
8255A
Memory
P C 0- 3
CPU
Stepper Motor
18Interfacing Example
- Program
- .MODEL SMALL
- .DATA
- PA EQU 200H
- PB EQU 201H
- PC EQU 202H
- CW WQU 203H
19Interfacing Example
.CODE MOV AX,_at_DATA MOV DS,AX MOV AL,80H
CW MOV DX,CW the addr of CW moved to DX OUT
DX,AL CW sent to MFD MOV CX,64H for the steps
of rotation
20Interfacing Example
MOV AL,88H data to be sent on PC lines MOV
DX,PC load DX with addr of PC Back OUT
DX,AL CALL Delay ROR AL,01H LOOP Back .EXIT
21Interfacing Example
Delay PROC RET ENDP END
22Interfacing Example
3 Interface a 8X3 matrix key pad and write a
program to identify the key closed
.MODEL SMALL .DATA PA EQU 200H PB EQU
201H PC EQU 202H CW WQU 203H
23Interfacing Example
.CODE MOV AX,_at_DATA MOV DS,AX MOV AL,90H
CW MOV DX,CW move addr of CW to DX OUT
DX,AL CW sent to MFD MOV AX,07H MOV DX,PC
24Interfacing Example
OUT DX,AL W1 MOV DX,PA IN AL,DX CMP
AL,00H JZ W1 L1 MOV AH,AL MOV DX,PC OUT DX,AL
25Interfacing Example
MOV DX,PA IN AL,DX CMP AL,00H JNZ C1 ADD
BL,08H MOV AL,0AH RCL AL,01H JMP L1
26Interfacing Example
C1 RCR AL,01H JC L2 INC BL JMP C1 L2 MOV
BL,AL CMP AL,0AH JB Num ADD AL,07H
27Interfacing Example
Num ADD AL,30H MOV DL,AL MOV AH,02H INT
21H MOV AH,4CH INT 21H END