uclock.psm
来自「PacoBlaze is a from-scratch synthesizabl」· PSM 代码 · 共 1,009 行 · 第 1/4 页
PSM
1,009 行
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 + =
减小字号Ctrl + -
显示快捷键?