A Design Example

advertisement
A Design Example
A Programmable Calculator
Programmable Calculator
•
•
•
•
•
•
Working in Exact Mode
Receiving Program from RS232 Port
Saving Programs using RS232 Port
Memory Fill/View/Edit/Search
Switch to floating point calculator
Using DMA for Large Data Transfer
Hardware Specifications
•
•
•
•
•
•
•
•
Keyboard with 64 (8x8) Keys
8 Seven-Segment Display
Timer Options: hh – mm – ss
8087 Coprocessor  Maximum Mode
DMA 8237 for Fast Data Transfer
UART 8250 for RS232 Port
RAM (00000-7FFFF) – EPROM (80000-FFFFF)
Clock = 115200*16*4=7372800 Hz
=7.3728MHz
CPU Pins in Maximum Mode
GND
AD14
AD13
AD12
AD11
AD10
AD9
AD8
AD7
AD6
AD5
AD4
AD3
AD2
AD1
AD0
NMI
INTR
CLK
GND
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
8086
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
Max Mode
VCC
AD15
A16/S3
A17/S4
A18/S5
A19/S6
BHE/S7
MN/MX
RD
RQ/GT0
RQ/GT1
LOCK
S2
S1
S0
QS0
QS1
TEST
READY
RESET
GND
S0, S1 and S2 Signals
S2
S1
S0
0
0
0
0
0
1
Characteristics
Interrupt
acknowledge
Read I/O port
0
1
0
Write I/O port
0
1
1
Halt
1
0
0
Code access
1
0
1
Read memory
1
1
0
Write memory
1
1
1
Passive State
8086 System Maximum Mode
+5V
Clock
generator
READY
Gnd
CLK
S1
S2
DEN
DT/R
Wait-State
Generator
MRDC
S0
RESET
MWTC
AMWC
IORC
IOWC
AIOWC
ALE
8086 CPU
RES
MN/MX
S0
S1
S2
8288
Bus Controller
CLK
STB
INTA
A0 - A19
OE
AD0-AD15
A16-A19
8282
Latch
Address Bus
BHE
T
OE
8286
Transceiver
DATA
8284 Clock Generator for 8086
an 18-pin chip
• specially designed to be used with 8088/86 microprocessors,
• It provides the clock and synchronization for the microprocessor,
• also provides the READY signal for the insertion of wait states into the CPU
bus cycle.
7.3728MHz
22.1184MHz
Bank Write and Bank Read Control Logic
2 EPROMs Each 256KB = 256Kx8 = Eight 27512 or 28512
2 SRAMs Each 256KB = 256Kx8 = Eight 62512 or 61512
Total 1M
A0
Bank Write Control Logic
A0
Bank Read Control Logic
D0 - D7
SRAMs
A1-A16
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDL
WE WRL
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDL
WRL
WE
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDL
WE WRL
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDU
WRL
WE
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Y7
A0
A1
A2
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Y7
A0
A1
A2
A17
A18
A19
G1 A0
DEN
G2
D8 - D15
A1-A16
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDU
WE WRU
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDU
WRU
WE
CS
OE RDU
WE WRU
CS
OE RDU
WE WRU
A17
A18
A19
G1 BHE
DEN
G2
D0 - D7
EPROMs
A1-A16
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDL
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE
RDL
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE
RDL
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE
RDL
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Y7
A0
A1
A2
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Y7
A0
A1
A2
A17
A18
A19
G1 A0
DEN
G2
D8 - D15
A1-A16
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDU
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
D0
D1
D2
D3
D4
D5
D6
D7
CS
OE RDU
CS
OE
RDU
CS
OE RDU
A17
A18
A19
G1 BHE
DEN
G2
Peripherals
•
•
•
•
•
•
•
8255 (Keyboard)
8255 (Display)
Timer 8254
8259 Interrupt Controller
DMA 8237
Coprocessor 8087
UART 8250
Address Decoding for the Peripherals
Buffer
D0-D7
8255A
PPI
8086
AD0-AD7
ALE
Latch (‘373) A0
A1
A2
A3
A4
A5
A6
A7
Keyboard Y0
Y1
X0 Timer Y2
Display Y3
X1
Y4
X2
UART Y5
8259 Y6
DMA Y7
Keyboard Address: 000XXPP0
Timer
Address: 010XXPP0
Display Address: 011XXPP0
UART
Address: 101XPPP0
8259
Address: 110XXXP0
DMA
Address: 111PPPP0
A0
A1
CS
8259
A0
CS
IR0
IR1
Address Definition
•
•
•
•
•
•
Keyboard_BASE
Display_BASE
Timer_BASE
UART_BASE
DMA_BASE
8259_BASE
EQU
EQU
EQU
EQU
EQU
EQU
0
60H
40H
0A0H
0E0H
0C0H
Connecting 8087 to Processor
8250/16450/16550 UART Connection
A0
A2
A4
A6
A8
AA
AC
AD
A0
A2
A3 A2 A1 (System) A2 A1 A0 (UART)
Y5 (Decoder)  CS
101XPPP0
Line Drivers  RS232 io
Registers
• Transmitter holding register
• Receiver buffer register
• Interrupt enable register
00001111  A2
Registers
• Interrupt identification register
00000PPP  A4
Line Control
00011111  A6
Even Parity, 2 Stop bits, 8 Data bits
Modem Registers
Modem Control Register
00000001  A8 DTR Active
Modem Status Register
status  AD
Line Status
Status  AA
Divisor Register
Baud Rate
Divisor(Decimal)
Divisor(hex)
460,800
1
1
115,200
4
4
57,600
8
8
28,800
16
10
38400
12
C
19200
24
18
9600
48
30
Input Clock : 7.3728MHz  Required Baud Rate: 9600 bps
10000000  A6 DLAB Set
0011 0000  A0
0  A2
Intel Hex Data Format
• : No – Address – Data – Check Sum
• :0A 00400 56 78 F6 00 80 80 6C 40 03 02 75
• 56 + 78 + F6 + 80 + 80 + 6C + 40 + 3 + 2 = 375
Commands From RS232
•
•
•
•
•
•
•
•
Upload Data
Download Data
Dump Memory
Fill Memory
Go To Address
Breakpoint
Trace
Register …
Definitions
• DISPLAY_SEGMENTS
• DISPLAY_GND
• DISPLAY_CTRL
EQU
EQU
EQU
Display_BASE
Display_BASE +2
Display_BASE+ 6
• KEYBOARD_ROW
• KEYBOARD_COL
• KEYBOARD_CTRL
EQU
EQU
EQU
Keyboard_BASE
Keyboard_BASE+2
Keyboard_BASE+6
•
•
•
•
EQU
EQU
EQU
EQU
Timer_BASE
Timer_BASE+2
Timer_BASE+4
Timer_BASE+6
EQU
EQU
8259_BASE
8259_BASE+2
TIMER_CH0
TIMER_CH1
TIMER_CH2
TIMER_CTRL
• IC8259_0
• IC8259_1
Main Program
ORG 0FFF0H ;Address FFFF0
•
•
•
•
•
•
XOR
AX,AX
MOV DS,AX
MOV AH,70H
MOV SS,AX
MOV SP,0FFFFH
JMP 0F000H:100
;AX=0
;DS=0
;AX=7000H
;STACK From 7FFFFH
; SS*10H+SP=7FFFFH
Initialize & Main LOOP
ORG
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
CLI
CALL
CALL
CALL
CALL
CALL
CALL
STI
Main_LOOP:
CALL
JZ
CALL
CALL
RS232:
CALL
JZ
CALL
JMP
100H ;Address F0100
INIT_KEYBOARD
INIT_DISPLAY
INIT_TIMER
INIT_8259
INIT_DMA
INIT_RS232
Keyboard_hit
RS232
GETCH
;Scan Code Available in AL
Process_Key
RX_AVAILABLE
Main_LOOP
Process_RX
Main_LOOP
INIT_KEYBOARD
• INIT_KEYBOARD:
• MOV AL,00001011B ;Mode0 output for A &
•
;Mode 0 input for B input for C
• OUT KEYBOARD_CTRL,AL
• MOV AL,0FFH
;OFF All Rows
• OUT KEYBOARD_ROW,AL
• XOR AL,AL
;Reset FIFO
• MOV [Key_head],AL
• MOV [Key_tail],AL
• RET
INIT_DISPLAY
• INIT_DISPLAY:
•
MOV AL,00001001B ;Mode 0 and out for both A & B. C input
•
OUT DISPLAY_CTRL,AL
•
MOV AL,0FFH
•
OUT DISPLAY_GND,AL ;All 7-Segments off
•
XOR AX,AX
;Clear ALL Ms of Calc(X,Y,M0-M7)
•
MOV ES,AX
•
MOV DI,offset X_SIZE
•
CLD
•
MOV CX,10
•
REP:STOSW
;X_SIZE=Y_SIZE=M_SIZE0-7=0
•
CALL REFRESH_DISPLAY
•
RET
REFRESH_DISPLAY
• REFRESH_DISPLAY: ; Shows the content of X register
•
MOV
DI,offset DISPLAY_DATA
•
MOV
AX,[X_SIZE]
•
CMP
AX,0
•
JNE
X_NOT_ZERO
•
XOR
AX,AX
•
MOV
WORD PTR [DI],AX
•
MOV
WORD PTR [DI+2],AX
•
MOV
WORD PTR [DI+4],AX
•
MOV
BYTE PTR [DI+6],AL
•
MOV
BYTE PTR [DI+7],10111111B
•
RET
INIT_TIMER
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
INIT_TIMER:
MOV AL,00110110B
OUT TIMER_CTRL,AL
MOV AX,36864
OUT TIMER_CH0,AL
MOV AL,AH
OUT TIMER_CH0,AL
MOV AL,01110111B
OUT TIMER_CTRL,AL
MOV AX,200H
OUT TIMER_CH1,AL
MOV AL,AH
OUT TIMER_CH1,AL
RET
;Counter 0, 2 Bytes, Mode 3, Binary
;7.3728M/36864=200Hz; Refreshing Rate
;Counter 1, 2 Bytes, Mode 3, BCD
;200Hz/200=1Hz; Time Refresh Rate
INIT_8259
• INIT_8259:
• MOV AL,00010011B
;ICW1: Edge - Single - ICW4
•
•
•
•
•
OUT IC8259_0,AL
MOV AL,80H
; ICW2=Interupt Type
OUT IC8259_1,AL
MOV AL,00000001B ;ICW4: 8086 Processor
RET
INIT_RS232
• INIT_RS232:
Download