?? uclock.psm
字號:
STORE int_counter_lsb, us_time_stamp_lsb ;counter. Interrupts are disabled to ensure that both bytes relate
STORE int_counter_msb, us_time_stamp_msb ;to the same count value.
ENABLE INTERRUPT
FETCH s4, us_time_stamp_lsb ;read the new 'us' time stamp in [s5,s4]
FETCH s5, us_time_stamp_msb ;
SUB s4, s2 ;calculate 'us' time difference [s5,s4] = [s5,s4] - [s3,s2]
SUBCY s5, s3 ; (This works correctly even if counter has rolled over)
FETCH s2, us_time_lsb ;read current 'us' time into [s3,s2]
FETCH s3, us_time_msb
ADD s2, s4 ;add on the elapsed 'us' value [s3,s2] = [s3,s2] + [s5,s4]
ADDCY s3, s5
;determine how many 1000us (1ms) units there are (if any) in current 'us' time
LOAD s0, 00 ;reset 'ms' counter
test_1000us: SUB s2, count_1000_lsb ;subtract 1000 from [s3,s2]
SUBCY s3, count_1000_msb
JUMP C, store_us_time ;Carry indicates [s3,s2] was less than 1000us
ADD s0, 01 ;increment 'ms' elapsed because [s3,s2] was more or equal to 1000us
JUMP test_1000us ;repeat to see if more than 1ms has elapsed
store_us_time: ADD s2, count_1000_lsb ;add 1000 to restore 'us' value
ADDCY s3, count_1000_msb
STORE s2, us_time_lsb ;store the current value of 'us'
STORE s3, us_time_msb
;s0 holds the number of 'ms' elapsed since last update (if any).
FETCH s2, ms_time_lsb ;read current 'ms' time into [s3,s2]
FETCH s3, ms_time_msb
ADD s2, s0 ;add on the elapsed 'ms' value [s3,s2] = [s3,s2] + s0
ADDCY s3, 00
;determine if there are now more than 1000ms to form 1 second.
LOAD s0, 00 ;reset 'second' counter
SUB s2, count_1000_lsb ;subtract 1000 from [s3,s2]
SUBCY s3, count_1000_msb
JUMP C, restore_ms_time ;Carry indicates [s3,s2] was less than 1000ms
ADD s0, 01 ;increment 'second' elapsed because [s3,s2] was more or equal to 1000ms
JUMP store_ms_time ;new value of 'ms' is remainder of subtraction
restore_ms_time: ADD s2, count_1000_lsb ;add 1000 to restore 'ms' value
ADDCY s3, count_1000_msb
store_ms_time: STORE s2, ms_time_lsb ;store the current value of 'ms'
STORE s3, ms_time_msb
;s0 currently determines if one second needs to be added to the hh:mm:ss clock time
FETCH s1, real_time_seconds ;read seconds
ADD s1, s0 ;add one second if required by s0
COMPARE s1, seconds_in_a_minute ;test for 1 minute
JUMP Z, inc_minutes
STORE s1, real_time_seconds ;store updated seconds
JUMP time_update_complete
inc_minutes: LOAD s1, 00 ;seconds become zero
STORE s1, real_time_seconds
FETCH s1, real_time_minutes ;read minutes
ADD s1, 01 ;increment minutes
COMPARE s1, minutes_in_an_hour ;test for 1 hour
JUMP Z, inc_hours
STORE s1, real_time_minutes ;store updated minutes
JUMP time_update_complete
inc_hours: LOAD s1, 00 ;minutes become zero
STORE s1, real_time_minutes
FETCH s1, real_time_hours ;read hours
ADD s1, 01 ;increment hours
COMPARE s1, hours_in_a_day ;test for 24 hours
JUMP Z, reset_hours
STORE s1, real_time_hours ;store updated hours
JUMP time_update_complete
reset_hours: LOAD s1, 00 ;hours become zero
STORE s1, real_time_hours
;
;With the time updated, there is then a test for time=alarm time
;
time_update_complete: FETCH s0, real_time_hours
FETCH s1, alarm_time_hours ;compare hours
COMPARE s0, s1
JUMP NZ, finish_update
FETCH s0, real_time_minutes ;compare minutes
FETCH s1, alarm_time_minutes
COMPARE s0, s1
JUMP NZ, finish_update
FETCH s0, real_time_seconds ;compare seconds
FETCH s1, alarm_time_seconds
COMPARE s0, s1
JUMP NZ, finish_update
FETCH s0, alarm_status ;test if alarm is turned on
TEST s0, alarm_armed
JUMP Z, finish_update ;alarm was off
OR s0, alarm_active ;activate alarm
STORE s0, alarm_status
CALL alarm_drive
finish_update: FETCH s0, time_preserve0 ;restore the register contents
FETCH s1, time_preserve1
FETCH s2, time_preserve2
FETCH s3, time_preserve3
FETCH s4, time_preserve4
FETCH s5, time_preserve5
RETURN
;
;Convert character to upper case
;
;The character supplied in register s0.
;If the character is in the range 'a' to 'z', it is converted
;to the equivalent upper case character in the range 'A' to 'Z'.
;All other characters remain unchanged.
;
;Registers used s0.
;
upper_case: COMPARE s0, 61 ;eliminate character codes below 'a' (61 hex)
RETURN C
COMPARE s0, 7B ;eliminate character codes above 'z' (7A hex)
RETURN NC
AND s0, DF ;mask bit5 to convert to upper case
RETURN
;
;
;Convert character '0' to '9' to numerical value in range 0 to 9
;
;The character supplied in register s0. If the character is in the
;range '0' to '9', it is converted to the equivalent decimal value.
;Characters not in the range '0' to '9' are signified by the return
;with the CARRY flag set.
;
;Registers used s0.
;
1char_to_value: ADD s0, C6 ;reject character codes above '9' (39 hex)
RETURN C ;carry flag is set
SUB s0, F6 ;reject character codes below '0' (30 hex)
RETURN ;carry is set if value not in range
;
;
;Determine the numerical value of a two character decimal string held in
;scratch pad memory such the result is in the range 0 to 99 (00 to 63 hex).
;
;The string must be stored as in two consecutive memory locations and the
;location of the first (tens) character supplied in the s1 register.
;The result is provided in register s2. Strings not using characters in the
;range '0' to '9' are signified by the return with the CARRY flag set.
;
;Registers used s0, s1 and s2.
;
2char_to_value: FETCH s0, (s1) ;read 'tens' character
CALL 1char_to_value ;convert to numerical value
RETURN C ;bad character - CARRY set
LOAD s2, s0
SL0 s2 ;multiply 'tens' value by 10 (0A hex)
SL0 s2
ADD s2, s0
SL0 s2
ADD s1, 01 ;read 'units' character
FETCH s0, (s1)
CALL 1char_to_value ;convert to numerical value
RETURN C ;bad character - CARRY set
ADD s2, s0 ;add units to result and clear CARRY flag
RETURN
;
;
;Interrupt service routine (ISR)
;
;The interrupt is used to increment a 16-bit counter formed with two registers
;called [int_counter_msb,int_counter_lsb]. This provides a count of the number
;of micro-seconds elapsed. The counter is 'free running' in that it will count
;up to 65,535 and then roll over to zero. The count value is then used in other
;parts of the program as required and where it is less time critical.
;
;The ISR only uses the specified counter registers
;
ADDRESS 3FC
ISR: ADD int_counter_lsb, 01 ;add 1us to 16-bit counter
ADDCY int_counter_msb, 00
RETURNI ENABLE
;
;Interrupt vector
;
ADDRESS 3FF
JUMP ISR
;
;
;Useful constants
;
;
;ASCII table
;
CONSTANT character_a, 61
CONSTANT character_b, 62
CONSTANT character_c, 63
CONSTANT character_d, 64
CONSTANT character_e, 65
CONSTANT character_f, 66
CONSTANT character_g, 67
CONSTANT character_h, 68
CONSTANT character_i, 69
CONSTANT character_j, 6A
CONSTANT character_k, 6B
CONSTANT character_l, 6C
CONSTANT character_m, 6D
CONSTANT character_n, 6E
CONSTANT character_o, 6F
CONSTANT character_p, 70
CONSTANT character_q, 71
CONSTANT character_r, 72
CONSTANT character_s, 73
CONSTANT character_t, 74
CONSTANT character_u, 75
CONSTANT character_v, 76
CONSTANT character_w, 77
CONSTANT character_x, 78
CONSTANT character_y, 79
CONSTANT character_z, 7A
CONSTANT character_A, 41
CONSTANT character_B, 42
CONSTANT character_C, 43
CONSTANT character_D, 44
CONSTANT character_E, 45
CONSTANT character_F, 46
CONSTANT character_G, 47
CONSTANT character_H, 48
CONSTANT character_I, 49
CONSTANT character_J, 4A
CONSTANT character_K, 4B
CONSTANT character_L, 4C
CONSTANT character_M, 4D
CONSTANT character_N, 4E
CONSTANT character_O, 4F
CONSTANT character_P, 50
CONSTANT character_Q, 51
CONSTANT character_R, 52
CONSTANT character_S, 53
CONSTANT character_T, 54
CONSTANT character_U, 55
CONSTANT character_V, 56
CONSTANT character_W, 57
CONSTANT character_X, 58
CONSTANT character_Y, 59
CONSTANT character_Z, 5A
CONSTANT character_0, 30
CONSTANT character_1, 31
CONSTANT character_2, 32
CONSTANT character_3, 33
CONSTANT character_4, 34
CONSTANT character_5, 35
CONSTANT character_6, 36
CONSTANT character_7, 37
CONSTANT character_8, 38
CONSTANT character_9, 39
CONSTANT character_colon, 3A
CONSTANT character_semi_colon, 3B
CONSTANT character_less_than, 3C
CONSTANT character_greater_than, 3E
CONSTANT character_equals, 3D
CONSTANT character_space, 20
CONSTANT character_CR, 0D ;carriage return
CONSTANT character_question, 3F ;'?'
CONSTANT character_dollar, 24
CONSTANT character_BS, 08 ;Back Space command character
;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -