uclock.psm

来自「PacoBlaze is a from-scratch synthesizabl」· PSM 代码 · 共 1,009 行 · 第 1/4 页

PSM
1,009
字号
                        return
                        ;
                        ;Send 'Syntax Error' to the UART
                        ;
     send_Syntax_Error: load UART_data, character_S
                        call send_to_UART
                        load UART_data, character_y
                        call send_to_UART
                        load UART_data, character_n
                        call send_to_UART
                        load UART_data, character_t
                        call send_to_UART
                        load UART_data, character_a
                        call send_to_UART
                        load UART_data, character_x
                        call send_to_UART
                        jump send_space_Error
                        ;
                        ;Send 'Overflow Error' to the UART
                        ;
   send_Overflow_Error: load UART_data, character_O
                        call send_to_UART
                        load UART_data, character_v
                        call send_to_UART
                        load UART_data, character_e
                        call send_to_UART
                        load UART_data, character_r
                        call send_to_UART
                        load UART_data, character_f
                        call send_to_UART
                        load UART_data, character_l
                        call send_to_UART
                        load UART_data, character_o
                        call send_to_UART
                        load UART_data, character_w
                        call send_to_UART
      send_space_Error: call send_space
                        ;
                        ;Send 'Error' to the UART
                        ;
            send_Error: load UART_data, character_E
                        call send_to_UART
                        load UART_data, character_r
                        call send_to_UART
                        call send_to_UART
                        load UART_data, character_o
                        call send_to_UART
                        load UART_data, character_r
                        call send_to_UART
                        return
                        ;
                        ;Send 'KCPSM3>' prompt to the UART
                        ;
           send_prompt: call send_CR                             ;start new line
                        load UART_data, character_K
                        call send_to_UART
                        load UART_data, character_C
                        call send_to_UART
                        load UART_data, character_P
                        call send_to_UART
                        load UART_data, character_S
                        call send_to_UART
                        load UART_data, character_M
                        call send_to_UART
                        load UART_data, character_3
                        call send_to_UART
                        ;
                        ;Send '>' character to the UART
                        ;
     send_greater_than: load UART_data, character_greater_than
                        call send_to_UART
                        return
                        ;
                        ;Send 'Invalid' string to the UART
                        ;
          send_Invalid: load UART_data, character_I
                        call send_to_UART
                        load UART_data, character_n
                        call send_to_UART
                        load UART_data, character_v
                        call send_to_UART
                        load UART_data, character_a
                        call send_to_UART
                        load UART_data, character_l
                        call send_to_UART
                        load UART_data, character_i
                        call send_to_UART
                        load UART_data, character_d
                        call send_to_UART
                        return
                        ;
                        ;Send 'Time' string to the UART
                        ;
             send_Time: load UART_data, character_T
                        call send_to_UART
                        load UART_data, character_i
                        call send_to_UART
                        load UART_data, character_m
                        call send_to_UART
                        load UART_data, character_e
                        call send_to_UART
                        return
                        ;
                        ;Send 'Alarm' string to the UART
                        ;
            send_Alarm: load UART_data, character_A
                        call send_to_UART
                        load UART_data, character_l
                        call send_to_UART
                        load UART_data, character_a
                        call send_to_UART
                        load UART_data, character_r
                        call send_to_UART
                        load UART_data, character_m
                        call send_to_UART
                        return
                        ;
                        ;Send 'OFF' string to the UART
                        ;
              send_OFF: load UART_data, character_O
                        call send_to_UART
                        load UART_data, character_F
                        call send_to_UART
                        call send_to_UART
                        return
                        ;
                        ;Send 'ON' string to the UART
                        ;
               send_ON: load UART_data, character_O
                        call send_to_UART
                        load UART_data, character_N
                        call send_to_UART
                        return
                        ;
                        ;Send 'Active' string to the UART
                        ;
           send_Active: load UART_data, character_A
                        call send_to_UART
                        load UART_data, character_c
                        call send_to_UART
                        load UART_data, character_t
                        call send_to_UART
                        load UART_data, character_i
                        call send_to_UART
                        load UART_data, character_v
                        call send_to_UART
                        load UART_data, character_e
                        call send_to_UART
                        return
                        ;
                        ;
                        ;Convert time to ASCII string in scratch pad memory.
                        ;
                        ;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 resulting ASCII string will be stored in scratch pad memory starting at
                        ;a location specified by a constant named 'string_start'. The string will
                        ;take the format hh:mm:ss and end with a carriage return.
                        ;
                        ;Registers used s0, s1, s2 and 'store_pointer'.
                        ;
         time_to_ASCII: load s2, string_start                    ;location for string
                        fetch s0, store_pointer                ;read hours value
                        call decimal_to_ASCII                    ;convert to ASCII
                        store s1, s2                           ;write hours to string
                        add s2, $01
                        store s0, s2
                        add s2, $01
                        load s0, character_colon                 ;write ':' to string
                        store s0, s2
                        add s2, $01
                        add store_pointer, $01                    ;move to minutes
                        fetch s0, store_pointer                ;read minutes value
                        call decimal_to_ASCII                    ;convert to ASCII
                        store s1, s2                           ;write minutes to string
                        add s2, $01
                        store s0, s2
                        add s2, $01
                        load s0, character_colon                 ;write ':' to string
                        store s0, s2
                        add s2, $01
                        add store_pointer, $01                    ;move to seconds
                        fetch s0, store_pointer                ;read seconds value
                        call decimal_to_ASCII                    ;convert to ASCII
                        store s1, s2                           ;write seconds to string
                        add s2, $01
                        store s0, s2
                        add s2, $01
                        load s0, character_CR                    ;finish string with carriage return
                        store s0, s2
                        return
                        ;
                        ;Convert value provided in register s0 into ASCII characters
                        ;
                        ;The value provided must in the range 0 to 99 and will be converted into
                        ;two ASCII characters.
                        ;     The number of 'tens' will be representd by an ASCII character returned in register s1.
                        ;     The number of 'units' will be representd by an ASCII character returned in register s0.
                        ;
                        ;The ASCII representations of '0' to '9' are 30 to 39 hexadecimal which is simply 30 hex added to
                        ;the actual decimal value.
                        ;
                        ;Registers used s0 and s1.
                        ;
      decimal_to_ASCII: load s1, $30                              ;load 'tens' counter with ASCII for '0'
          test_for_ten: add s1, $01                               ;increment 'tens' value
                        sub s0, $0A                               ;try to subtract 10 from the supplied value
                        jump nc, test_for_ten                    ;repeat if subtraction was possible without underflow.
                        sub s1, $01                               ;'tens' value one less ten due to underflow
                        add s0, $3A                               ;restore units value (the remainder) and convert to ASCII
                        return
                        ;
                        ;
                        ;
                        ;
                        ;Real Time Clock
                        ;
                        ;Uses the 1us interrupt counter [int_counter_msb,int_counter_lsb] to determine how many
                        ;micro-seconds have elapsed since the last update. This allows for just over 65ms between
                        ;updates. Complete multiples of 1000us are used to update a 16-bit milli-second counter held
                        ;in scratch pad memory locations [ms_time_stamp_msb,ms_time_stamp_msb] which in turn
                        ;is used to update the real time hours, minutes and seconds clock held in scratch pad
                        ;memory locations 'real_time_hours', 'real_time_minutes' and 'real_time_seconds'.
                        ;
                        ;The routine uses default register names s0,s1,s2,s3,s4,s5. These are preserved in scratch pad
                        ;memory during the routine and restored before returning.
                        ;
                        ;Useful constants for real time clock operations
                        ;
                        constant count_1000_lsb, $E8              ;lower 8-bits of 1000 count value
                        constant count_1000_msb, $03              ;upper 8-bits of 1000 count value
                        constant hours_in_a_day, $18              ;24 hours in a day
                        constant minutes_in_an_hour, $3C          ;60 minutes in an hour
                        constant seconds_in_a_minute, $3C         ;60 seconds in a minute
                        ;
           update_time: store s0, time_preserve0                 ;preserve contents of registers used during routine
                        store s1, time_preserve1
                        store s2, time_preserve2
                        store s3, time_preserve3
                        store s4, time_preserve4
                        store s5, time_preserve5
                        ;
                        fetch s2, us_time_stamp_lsb              ;read the previous 'us' time stamp into [s3,s2]
                        fetch s3, us_time_stamp_msb
                        interrupt disable                        ;Read and store current 'us' time stamp provided by the interrupt

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?