📄 control.psm
字号:
; LS-byte first. Then reads must continue until address 0097 has been read for the
; command to complete naturally (otherwise a master reset is required).
;
;
;
read_memory_command: LOAD s3, F0 ;read memory Command
CALL write_byte_slow ;transmit command
LOAD s5, 00 ;initial address in [s5,s4]=0000
LOAD s4, 00
LOAD s3, s4 ;transmit address
CALL write_byte_slow
LOAD s3, s5
CALL write_byte_slow
rmc_line_loop: CALL send_CR
LOAD s0, s5 ;display 16-bit address
CALL send_hex_byte
LOAD s0, s4
CALL send_hex_byte
CALL send_space
CALL send_space
rmc_data_loop: CALL send_space
CALL read_byte_slow ;read data into s3
LOAD s0, s3 ;display byte
CALL send_hex_byte
ADD s4, 01 ;increment address
ADDCY s5, 00
TEST s4, 07 ;test for 8-byte boundary
JUMP NZ, rmc_data_loop
COMPARE s4, 98 ;test for last address
JUMP NZ, rmc_line_loop
CALL send_OK
JUMP reset_menu ;needs master reset next
;
;
;**************************************************************************************
; DS2432 Write Scratchpad Memory Command.
;**************************************************************************************
;
; The write scratchpad memory command (0F hex) allows 8-bytes of data to be written
; together with a target address for final storage in the main memory map.
;
; The DS2432 provides an initial confirmation of the write by returning a 16-bit CRC
; value which KCPSM3 tests. The CRC is computed based on the command, address and
; data transmitted (11 bytes). To achieve this, all bytes transmitted to the DS2432
; are recorded in KCPSM3 scratch pad memory in ascending locations starting at
; the location defined by constant 'command_start'.
;
; This routine prompts the user to enter the 16-bit target address is to be loaded
; into the target address registers TA2 and TA1 in the DS2432 device. Note that only
; address values below 0090 hex are valid. If the address is too high, then the
; DS2432 aborts the command and this routine will too.
;
; Also note that the address will be forced internally to the DS2432 to match an
; 8-byte boundary address in which the least significant 3-bits are reset to '000'
; regardless of the address provided. The CRC still reflects the transmitted address.
;
; After providing a valid address, the routine then prompts the user to enter
; 8 bytes of data which are written to the DS2432.
;
;
;
write_scratchpad_command: LOAD sE, command_start ;pointer to memory
LOAD s3, 0F ;write scratchpad memory Command
STORE s3, (sE) ;record command sequence
ADD sE, 01 ;increment pointer
CALL write_byte_slow ;transmit command
wsc_addr_loop: CALL send_address ;obtain 16-bit address 0000 to FFFF in [s5,s4]
CALL obtain_8bits
JUMP C, wsc_addr_loop ;bad input address
LOAD s5, s0
CALL obtain_8bits
JUMP C, wsc_addr_loop ;bad input address
LOAD s4, s0
LOAD s3, s4 ;transmit target address TA1 (LS-Byte)
STORE s3, (sE) ;record command sequence
ADD sE, 01 ;increment pointer
CALL write_byte_slow
LOAD s3, s5 ;transmit target address TA2 (MS-Byte)
STORE s3, (sE) ;record command sequence
ADD sE, 01 ;increment pointer
CALL write_byte_slow
COMPARE s5, 00 ;check address less than 0090 hex
JUMP NZ, end_write_scratchpad ;DS2432 aborts command and so
COMPARE s4, 90 ;no need to read data bytes.
JUMP NC, end_write_scratchpad
LOAD s4, 00 ;initialise byte counter
wsc_data_loop: CALL send_data ;obtain a byte of data
LOAD UART_data, s4 ;display which byte requested
ADD UART_data, character_0 ;convert to ASCII
CALL send_to_UART
CALL send_equals
CALL obtain_8bits
JUMP C, wsc_data_loop ;bad input data
LOAD s3, s0 ;transmit byte
STORE s3, (sE) ;record command sequence
ADD sE, 01 ;increment pointer
CALL write_byte_slow
ADD s4, 01 ;count bytes
COMPARE s4, 08
JUMP NZ, wsc_data_loop
CALL read_byte_slow ;read back the 16-bit CRC into [s5,s4]
LOAD s4, s3
CALL read_byte_slow
LOAD s5, s3
STORE s4, (sE) ;record command sequence
ADD sE, 01 ;increment pointer
STORE s5, (sE) ;record command sequence
CALL send_CR
CALL send_CRC ;'CRC=' to display CRC value
LOAD s0, s5
CALL send_hex_byte
LOAD s0, s4
CALL send_hex_byte
CALL send_CR
LOAD s2, 0B ;11 (0B hex) bytes transmitted in this command
CALL compute_CRC16 ;compute CRC value in [s1,s0]
FETCH s5, (sE) ;compare with received value
SUB sE, 01
FETCH s4, (sE) ;compare with received value
COMPARE s5, s1
JUMP NZ, wsc_crc16_fail
COMPARE s4, s0
JUMP NZ, wsc_crc16_fail
CALL send_Pass
JUMP reset_menu ;needs master reset next
wsc_crc16_fail: CALL send_Fail
end_write_scratchpad: JUMP reset_menu ;needs master reset next
;
;
;
;**************************************************************************************
; Write Byte Command.
;**************************************************************************************
;
; This routine simply allows you to specify any byte and write it to the DS2432 device.
; Apart from checking that the value is in the range 00 to FF hex, there is no checking
; of the meaning of the value to the DS2432 device and all attempts to track the
; state machine will be lost.
;
;
write_byte_command: CALL send_CR
CALL send_Byte ;obtain a byte of data
CALL send_equals
CALL obtain_8bits
JUMP C, write_byte_command ;bad input data
LOAD s3, s0 ;transmit byte
CALL write_byte_slow ;transmit byte
CALL send_OK
JUMP DS2432_menu ;remain in memory and function menu
;
;
;
;**************************************************************************************
; Read Byte Command.
;**************************************************************************************
;
; This routine will attempt to read a single byte from the DS2432 device.
; The results will be displayed on the terminal. There is no checking of the meaning
; of the value received from the DS2432 device and all attempts to track the
; state machine will be lost.
;
;
read_byte_command: CALL send_CR
CALL send_Byte ;obtain a byte of data
CALL send_equals
CALL read_byte_slow ;receive byte
LOAD s0, s3 ;display value
CALL send_hex_byte
CALL send_OK
JUMP DS2432_menu ;remain in memory and function menu
;
;
;
;
;**************************************************************************************
; DS2432 Read Scratchpad Memory Command.
;**************************************************************************************
;
; The read scratchpad memory command (AA hex) allows the 8-bytes of data previously
; to be written into the scratchpad memory to be read back for verification together with
; the target address, a transfer status register and a 16-bit CRC value.
;
; The 16-bit CRC is formed of the command byte, address TA1 and TA2, E/S byte and 8 data
; bytes as transmitted (12 bytes). These may not be the same as the values provided
; during a previous write to scratchpad memory. All these bytes are recorded in KCPSM3
; scratch pad memory in ascending locations starting at the location defined by
; constant 'command_start'.
;
;
read_scratchpad_command: LOAD sE, command_start ;pointer to memory
LOAD s3, AA ;read scratchpad memory Command
STORE s3, (sE) ;record command sequence
ADD sE, 01 ;increment pointer
CALL write_byte_slow ;transmit command
CALL send_address ;display 'Address='
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -