?? uclock.psm
字號:
COMPARE s4, seconds_in_a_minute
JUMP NC, invalid_time
LOAD s0, 00
SR0 s0 ;reset CARRY flag (with s0=0)
RETURN ;time string was OK
invalid_time: CALL send_Invalid
CALL send_space
CALL send_Time
LOAD s0, 01
SR0 s0 ;set CARRY flag
RETURN ;time string was bad
;
;
;Fetch character from memory, convert to upper case
;and increment memory pointer.
;
;The memory pointer is provided in register s1.
;The character obtained is returned in register s0.
;
;Registers used s0 and s1.
;
fetch_char_from_memory: FETCH s0, (s1) ;read character
CALL upper_case ;convert to upper case
ADD s1, 01 ;increment memory pointer
RETURN
;
;
;
;Read one character from the UART
;
;Character read will be returned in a register called 'UART_data' and will be
;echoed to the UART transmitter.
;
;The routine first tests the receiver FIFO buffer to see if data is present.
;If the FIFO is empty, the routine waits until there is a character to read.
;As this could take any amount of time the wait loop includes a call to the
;subroutine which updates the real time clock.
;
;Registers used s0 and UART_data
;
read_from_UART: INPUT s0, UART_status_port ;test Rx_FIFO buffer
TEST s0, rx_data_present
JUMP NZ, read_character
CALL update_time ;Perform useful operation whilst waiting
JUMP read_from_UART
read_character: INPUT UART_data, UART_read_port ;read from FIFO
CALL send_to_UART ;echo received character
RETURN
;
;
;
;Transmit one character to the UART
;
;Character supplied in register called 'UART_data'.
;
;The routine first tests the transmit FIFO buffer to see if it is full.
;If the FIFO is full, the routine waits until there is space which could
;be as long as it takes to transmit one complete character.
;
; Baud Rate Time per Character (10 bits)
; 9600 1,024us
; 19200 521us
; 38400 260us
; 57600 174us
; 115200 87us
;
;Since this is a relatively long duration, the wait loop includes a
;call to the subroutine which updates the real time clock.
;
;Registers used s0
;
send_to_UART: INPUT s0, UART_status_port ;test Tx_FIFO buffer
TEST s0, tx_full
JUMP Z, UART_write
CALL update_time ;Perform useful operation whilst waiting
JUMP send_to_UART
UART_write: OUTPUT UART_data, UART_write_port
RETURN
;
;
;
;
;Alarm output
;
;Uses the alarm status scratch pad memory to set or reset the alarm
;control bit on the alarm output port.
;
;Registers used s0
;
alarm_drive: FETCH s0, alarm_status ;read status
AND s0, alarm_active ;isolate bit0
OUTPUT s0, alarm_port
RETURN
;
;
;
;
;
;Transmit the time to the UART port in the format hh:mm:ss and end
;with a carriage return.
;
;The time to converted must be stored in 3 scratch pad memory locations as
;defined below. A register named 'store_pointer' must provide the address of
;first location.
;
; Address Data
;
; store_pointer ----> hours
; store_pointer + 1 ----> minutes
; store_pointer + 1 ----> seconds
;
;The routine first converts the time into an ASCII string stored in scratch
;pad memory starting at a location specified by a constant named 'string_start'.
;The string will then be transmitted.
;
;Registers used s0, s1, s2, 'store_pointer' and 'UART_data'.
;
transmit_time: LOAD store_pointer, real_time_hours ;locate current time in memory
CALL time_to_ASCII
CALL transmit_string
RETURN
;
;
;Transmit the alarm time and status to the UART port in the format hh:mm:ss and
;ending with carriage return.
;
;The alarm time to converted must be stored in 3 scratch pad memory locations as
;defined below. A register named 'store_pointer' must provide the address of
;first location.
;
; Address Data
;
; store_pointer ----> hours
; store_pointer + 1 ----> minutes
; store_pointer + 1 ----> seconds
;
;The routine first converts the time into an ASCII string stored in scratch
;pad memory starting at a location specified by a constant named 'string_start'.
;The string will then be transmitted.
;
;Registers used s0, s1, s2, 'store_pointer' and 'UART_data'.
;
transmit_alarm_time: LOAD store_pointer, alarm_time_hours ;locate alarm time in memory
CALL time_to_ASCII
CALL transmit_string
CALL send_Alarm
CALL send_space
FETCH s0, alarm_status ;read alarm status
TEST s0, alarm_active ;test for active
JUMP Z, test_armed
CALL send_Active
RETURN
test_armed: TEST s0, alarm_armed ;test for on
JUMP Z, alarm_is_off
CALL send_ON
RETURN
alarm_is_off: CALL send_OFF
RETURN
;
;
;Transmit ASCII string to UART
;
;An ASCII string must be provided in scratch pad memory commencing at the
;location specified by a constant named 'string_start'. The string must
;end with a carriage return (0D).
;
;Registers used s1 and 'UART_data'.
; s0 is then used in subroutine 'send_to_UART'
;
transmit_string: LOAD s1, string_start ;locate start of string
next_char_tx: FETCH UART_data, (s1) ;read character from memory
CALL send_to_UART ;transmit character
COMPARE UART_data, character_CR ;test for last character
RETURN Z
ADD s1, 01 ;move to next character
JUMP next_char_tx
;
;
;Receive ASCII string from UART
;
;An ASCII string will be read from the UART and stored in scratch pad memory
;commencing at the location specified by a constant named 'string_start'.
;The string will will have a maximum length of 16 characters including a
;carriage return (0D) denoting the end of the string.
;
;As each character is read, it is echoed to the UART transmitter.
;Some minor editing is supported using backspace (BS=08) which is used
;to adjust what is stored in scratch pad memory and adjust the display
;on the terminal screen using characters sent to the UART transmitter.
;
;A test is made for the receiver FIFO becoming full. A full status is treated as
;a potential error situation and will result in a 'Overflow Error' message being
;transmitted to the UART, the receiver FIFO being purged of all data and an
;empty string being stored (carriage return at first location).
;
;Registers used s0, s1, s2 and 'UART_data'.
;
receive_string: LOAD s1, string_start ;locate start of string
LOAD s2, s1 ;compute 16 character address
ADD s2, 10
receive_full_test: INPUT s0, UART_status_port ;test Rx_FIFO buffer for full
TEST s0, rx_full
JUMP NZ, read_error
CALL read_from_UART ;obtain and echo character
STORE UART_data, (s1) ;write to memory
COMPARE UART_data, character_CR ;test for end of string
RETURN Z
COMPARE UART_data, character_BS ;test for back space
JUMP Z, BS_edit
ADD s1, 01 ;increment memory pointer
COMPARE s1, s2 ;test for pointer exceeding 16 characters
JUMP NZ, receive_full_test ;next character
CALL send_backspace ;hold end of string position on terminal display
BS_edit: SUB s1, 01 ;memory pointer back one
COMPARE s1, string_start ;test for under flow
JUMP C, string_start_again
CALL send_space ;clear character at current position
CALL send_backspace ;position cursor
JUMP receive_full_test ;next character
string_start_again: CALL send_greater_than ;restore '>' at prompt
JUMP receive_string ;begin again
;Receiver buffer overflow condition
read_error: CALL send_CR ;Transmit error message
STORE UART_data, string_start ;empty string in memory (start with CR)
CALL send_Overflow_Error
CALL send_CR
clear_UART_Rx_loop: INPUT s0, UART_status_port ;test Rx_FIFO buffer for data
TEST s0, rx_data_present
RETURN Z ;finish when buffer is empty
INPUT UART_data, UART_read_port ;read from FIFO and ignore
JUMP clear_UART_Rx_loop
;
;
;
;Send Carriage Return to the UART
;
send_CR: LOAD UART_data, character_CR
CALL send_to_UART
RETURN
;
;
;
;Send a space to the UART
;
send_space: LOAD UART_data, character_space
CALL send_to_UART
RETURN
;
;
;Send a back space to the UART
;
send_backspace: LOAD UART_data, character_BS
CALL send_to_UART
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -