-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUARTDriver.asm
More file actions
97 lines (90 loc) · 3.47 KB
/
UARTDriver.asm
File metadata and controls
97 lines (90 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;***************************************************************************
; PROGRAM: UARTDriver
; PURPOSE: Subroutines for a 16550 UART
; ASSEMBLER: TASM 3.2
; LICENCE: The MIT Licence
; AUTHOR : MCook
; CREATE DATE : 06 May 15
;***************************************************************************
;The eight addresses that the 16550 resides in I/O space.
;Change to suit hardware.
UART0: EQU 00h ;Data in/out
UART1: EQU 01h ;Check RX
UART2: EQU 02h ;Interrupts
UART3: EQU 03h ;Line control
UART4: EQU 04h ;Modem control
UART5: EQU 05h ;Line status
UART6: EQU 06h ;Modem status
UART7: EQU 07h ;Scratch register
;***************************************************************************
;UART_INIT
;Function: Initialize the UART to BAUD Rate 9600 (1.8432 MHz clock input)
;***************************************************************************
UART_INIT:
LD A,80h ;Mask to Set DLAB Flag
OUT (UART3),A
LD A,12 ;Divisor = 12 @ 9600bps w/ 1.8432 Mhz
OUT (UART0),A ;Set BAUD rate to 9600
LD A,00
OUT (UART1),A ;Set BAUD rate to 9600
LD A,03h
OUT (UART3),A ;Set 8-bit data, 1 stop bit, reset DLAB Flag
LD A,01h
OUT (UART1),A ;Enable receive data available interrupt only
RET
;***************************************************************************
;UART_PRNT_STR:
;Function: Print out string starting at MEM location (HL) to 16550 UART
;***************************************************************************
UART_PRNT_STR:
PUSH AF
UARTPRNTSTRLP:
LD A,(HL)
CP EOS ;Test for end byte
JP Z,UART_END_PRNT_STR ;Jump if end byte is found
CALL UART_TX
INC HL ;Increment pointer to next char
JP UARTPRNTSTRLP ;Transmit loop
UART_END_PRNT_STR:
POP AF
RET
;***************************************************************************
;UART_TX_READY
;Function: Check if UART is ready to transmit
;***************************************************************************
UART_TX_RDY:
PUSH AF
UARTTXRDY_LP:
IN A,(UART5) ;Fetch the control register
BIT 5,A ;Bit will be set if UART is ready to send
JP Z,UART_TX_RDY_LP
POP AF
RET
;***************************************************************************
;UART_TX
;Function: Transmit character in A to UART
;***************************************************************************
UART_TX:
CALL UART_TX_RDY ;Make sure UART is ready to receive
OUT (UART0),A ;Transmit character in A to UART
RET
;***************************************************************************
;UART_RX_READY
;Function: Check if UART is ready to receive
;***************************************************************************
UART_RX_RDY:
PUSH AF
UART_RXRDY_LP:
IN A,(UART5) ;Fetch the control register
BIT 0,A ;Bit will be set if UART is ready to receive
JP Z,UART_RX_RDY_LP
POP AF
RET
;***************************************************************************
;UART_RX
;Function: Receive character in UART to A
;***************************************************************************
UART_RX:
CALL UART_RX_RDY ;Make sure UART is ready to receive
IN A,(UART0) ;Receive character in UART to A
RET