?? uclock.psm
字號:
;KCPSM3 Program - Real Time Clock with UART communication.
;
;Ken Chapman - Xilinx Ltd - October 2003
;
;
;Port definitions
;
CONSTANT UART_status_port, 00 ;UART status input
CONSTANT tx_half_full, 01 ; Transmitter half full - bit0
CONSTANT tx_full, 02 ; FIFO full - bit1
CONSTANT rx_half_full, 04 ; Receiver half full - bit2
CONSTANT rx_full, 08 ; FIFO full - bit3
CONSTANT rx_data_present, 10 ; data present - bit4
;
CONSTANT UART_read_port, 01 ;UART Rx data input
;
CONSTANT UART_write_port, 01 ;UART Tx data output
;
CONSTANT alarm_port, 00 ;Alarm output
CONSTANT alarm_control, 01 ; bit0
;
;Special Register usage
;
NAMEREG sF, UART_data ;used to pass data to and from the UART
;
NAMEREG sE, store_pointer ;used to pass location of data in scratch pad memory
;
;Two registers to form a 16-bit counter used to count
;interrupt pulses generated at 1us intervals.
;
NAMEREG sD, int_counter_lsb ;lower 8-bits
NAMEREG sC, int_counter_msb ;upper 8-bits
;
;
;Scratch Pad Memory Locations
;
;
CONSTANT us_time_stamp_lsb, 00 ;16-bit micro-second time stamp
CONSTANT us_time_stamp_msb, 01
;
CONSTANT us_time_lsb, 02 ;16-bit micro-second real time value
CONSTANT us_time_msb, 03
;
CONSTANT ms_time_lsb, 04 ;16-bit milli-second real time value
CONSTANT ms_time_msb, 05
;
CONSTANT real_time_hours, 06 ;Current clock time
CONSTANT real_time_minutes, 07
CONSTANT real_time_seconds, 08
;
CONSTANT alarm_time_hours, 09 ;Alarm time
CONSTANT alarm_time_minutes, 0A
CONSTANT alarm_time_seconds, 0B
;
CONSTANT alarm_status, 0C ;Alarm status
CONSTANT alarm_active, 01 ; bit0 - Alarm is active
CONSTANT alarm_armed, 02 ; bit1 - Alarm is armed
;
CONSTANT time_preserve0, 10 ;storage for protection of registers
CONSTANT time_preserve1, 11 ;used by the real time clock routine.
CONSTANT time_preserve2, 12
CONSTANT time_preserve3, 13
CONSTANT time_preserve4, 14
CONSTANT time_preserve5, 15
;
;UART character strings will be stored in scratch pad memory ending in carriage return.
;A string can be up to 16 characters with the start location defined by this constant.
;
CONSTANT string_start, 20
;
;
;Initialise the system
;
;
cold_start: LOAD s0, 00 ;clear all time values
STORE s0, us_time_stamp_lsb
STORE s0, us_time_stamp_msb
STORE s0, us_time_lsb
STORE s0, us_time_msb
STORE s0, ms_time_lsb
STORE s0, ms_time_msb
STORE s0, real_time_hours
STORE s0, real_time_minutes
STORE s0, real_time_seconds
STORE s0, alarm_time_hours
STORE s0, alarm_time_minutes
STORE s0, alarm_time_seconds
STORE s0, alarm_status ;clear and disable alarm
CALL alarm_drive ;turn off alarm control output port
LOAD int_counter_lsb, 00 ;clear 'us' interrupt counter
LOAD int_counter_msb, 00
ENABLE INTERRUPT ;enable the 1us interrupts
;
;
;Start of the main program loop.
;
;A prompt is transmitted to the UART transmitter and then
;a command can be entered and interpreted.
;
;
prompt_input: CALL send_prompt ;Prompt 'KCPSM3>'
CALL receive_string ;obtain input string and maintain the time
;
;
;Parse the string and perform actions as required
;
;
;
LOAD s1, string_start
CALL fetch_char_from_memory
COMPARE s0, character_CR ;carriage return does nothing
JUMP Z, prompt_input
COMPARE s0, character_T ;start of 'TIME' command?
JUMP Z, test_for_TIME
COMPARE s0, character_A ;start of 'ALARM' command?
JUMP Z, test_for_ALARM
;
;trap other command starts here
;
bad_input_command: CALL send_Syntax_Error ;no valid command
JUMP Z, prompt_input
;
;
test_for_TIME: CALL fetch_char_from_memory
COMPARE s0, character_I ;test for rest of 'TIME'
JUMP NZ, bad_input_command
CALL fetch_char_from_memory
COMPARE s0, character_M
JUMP NZ, bad_input_command
CALL fetch_char_from_memory
COMPARE s0, character_E
JUMP NZ, bad_input_command
;now have a valid TIME command to process
CALL fetch_char_from_memory
COMPARE s0, character_CR ;carriage return means display time
JUMP NZ, set_time_command
CALL transmit_time ;transmit time to UART
JUMP prompt_input
set_time_command: COMPARE s0, character_space
JUMP NZ, bad_input_command
CALL test_time_string ;interpret 'hh:mm:ss' string
JUMP C, prompt_input ;test for invalid input
STORE s6, real_time_hours ;set new time into clock
STORE s5, real_time_minutes
STORE s4, real_time_seconds
STORE s0, ms_time_lsb ;clear 'ms' counter (s0=00)
STORE s0, ms_time_msb
CALL transmit_time ;transmit new time to UART
JUMP prompt_input
;
;
test_for_ALARM: CALL fetch_char_from_memory
COMPARE s0, character_L ;test for rest of 'ALARM'
JUMP NZ, bad_input_command
CALL fetch_char_from_memory
COMPARE s0, character_A
JUMP NZ, bad_input_command
CALL fetch_char_from_memory
COMPARE s0, character_R
JUMP NZ, bad_input_command
CALL fetch_char_from_memory
COMPARE s0, character_M
JUMP NZ, bad_input_command
;now have a valid ALARM command to process
CALL fetch_char_from_memory
COMPARE s0, character_CR ;carriage return means display alarm time
JUMP NZ, set_alarm_command
CALL transmit_alarm_time ;transmit time to UART
JUMP prompt_input
set_alarm_command: COMPARE s0, character_space ;test for ON or OFF command
JUMP NZ, bad_input_command
CALL fetch_char_from_memory
COMPARE s0, character_O
JUMP Z, set_alarm_on_off
SUB s1, 01 ;move memory pointer back to first character of 'hh:mm:ss' string
CALL test_time_string ;interpret 'hh:mm:ss' string
JUMP C, prompt_input ;test for invalid input
STORE s6, alarm_time_hours ;set new time into clock
STORE s5, alarm_time_minutes
STORE s4, alarm_time_seconds
CALL transmit_alarm_time ;transmit new alarm time and status
JUMP prompt_input
set_alarm_on_off: CALL fetch_char_from_memory
COMPARE s0, character_N ;test for 'ON'
JUMP NZ, test_OFF
CALL fetch_char_from_memory
COMPARE s0, character_CR
JUMP NZ, bad_input_command
FETCH s0, alarm_status ;turn alarm on
OR s0, alarm_armed
STORE s0, alarm_status
CALL transmit_alarm_time ;transmit alarm time and status
JUMP prompt_input
test_OFF: COMPARE s0, character_F ;test for for 'OFF'
JUMP NZ, bad_input_command
CALL fetch_char_from_memory
COMPARE s0, character_F
JUMP NZ, bad_input_command
CALL fetch_char_from_memory
COMPARE s0, character_CR
JUMP NZ, bad_input_command
LOAD s0, 00 ;turn alarm off and stop an active alarm
STORE s0, alarm_status
CALL alarm_drive ;turn off alarm
CALL transmit_alarm_time ;transmit alarm time and status
JUMP prompt_input
;
;
;
;
;Read an 'hh:mm:ss' time string and provide new values.
;
;The string must be provided in successive scratch pad memory locations
;with the s1 register containing the location of the first character.
;
;A correct time specification will result in the return of new values
;as follows:-
;
; s6 = hours
; s5 = minutes
; s4 = seconds
;
;If the syntax is incorrect or values are not in the correct ranges an
;'Invalid Time' message will be transmitted and the CARRY flag will be set
;
;Registers used s0, s1, s6, s5 and s4
;
test_time_string: CALL 2char_to_value ;obtain hours value
JUMP C, invalid_time ;test for non-decimal characters
LOAD s6, s2 ;remember hours
ADD s1, 01 ;increment memory pointer past hours
CALL fetch_char_from_memory
COMPARE s0, character_colon ;test for colon
JUMP NZ, invalid_time
CALL 2char_to_value ;obtain minutes value
JUMP C, invalid_time ;test for non-decimal characters
LOAD s5, s2 ;remember minutes
ADD s1, 01 ;increment memory pointer past minutes
CALL fetch_char_from_memory
COMPARE s0, character_colon ;test for colon
JUMP NZ, invalid_time
CALL 2char_to_value ;obtain seconds value
JUMP C, invalid_time ;test for non-decimal characters
LOAD s4, s2 ;remember minutes
ADD s1, 01 ;increment memory pointer past seconds
CALL fetch_char_from_memory
COMPARE s0, character_CR ;finish with carriage return
JUMP NZ, invalid_time
;Have values for hh:mm:ss but need to test if each is valid range.
COMPARE s6, hours_in_a_day
JUMP NC, invalid_time
COMPARE s5, minutes_in_an_hour
JUMP NC, invalid_time
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -