📄 fg_ctrl.psm
字号:
; Display frequency on top line of the LCD and DDS data on the lower line
;**************************************************************************************
;
; The BCD value should be stored in scratch pad memory in 9 ascending locations
; called BCD_digit0 to BCD_digit8.
;
; The value is displayed in the format xxx.xxx xxxMHz
;
; However, the most significant 2 digits will be blanked if zero.
;
; registers used s0,s1,s2,s3,s4,s5,s6,s7
;
;
display_freq: CALL display_DDS_data ;display DDS information on lower line
LOAD s5, 12 ;Line 1 position 2
CALL LCD_cursor
FETCH s5, BCD_digit8 ;read 100MHz digit
COMPARE s5, 00 ;test for blanking
JUMP Z, blank_100M_digit
CALL display_digit ;display non zero digit
FETCH s5, BCD_digit7 ;read 10MHz digit and display
CALL display_digit
JUMP disp_1M_digit
;
blank_100M_digit: CALL display_space ;blank 100MHz digit
FETCH s5, BCD_digit7 ;read 10MHz digit
COMPARE s5, 00 ;test for blanking
JUMP Z, blank_10M_digit
CALL display_digit ;display non zero digit
JUMP disp_1M_digit
;
blank_10M_digit: CALL display_space ;blank 10MHz digit
;
disp_1M_digit: FETCH s5, BCD_digit6 ;read 1MHz digit and display
CALL display_digit
LOAD s5, character_stop ;display decimal point
CALL LCD_write_data
;
LOAD s2, BCD_digit5 ;set pointer to 100KHz digit
CALL display_3_digits
CALL display_space
LOAD s2, BCD_digit2 ;set pointer to 100Hz digit
CALL display_3_digits
LOAD s5, character_M ;display 'MHz'
CALL LCD_write_data
LOAD s5, character_H
CALL LCD_write_data
LOAD s5, character_z
CALL LCD_write_data
;
FETCH s5, cursor_position ;reposition edit cursor on display
ADD s5, 10 ;on line 1
CALL LCD_cursor
RETURN
;
display_3_digits: LOAD s3, 03 ;3 digits to display
3digit_loop: FETCH s5, (s2)
CALL display_digit
SUB s2, 01 ;decrement digit pointer
SUB s3, 01 ;count digits displayed
JUMP NZ, 3digit_loop
RETURN
;
display_digit: ADD s5, 30 ;convert BCD to ASCII character
CALL LCD_write_data
RETURN
;
display_space: LOAD s5, character_space
CALL LCD_write_data
RETURN
;
;
;**************************************************************************************
; Convert 9 digit BCD frequency into 32-bit binary integer
;**************************************************************************************
;
;Both values are stored in scratch pad memory
; BCD values in ascending locations BCD_digit0 to BCD_digit8
; Binary frequency in ascending locations frequency0 to frequency3
;
;Each digit is read in turn and its value is determined by repeated
;decrement until reaching zero. Each decrement causes a value to be added
;to the memory locations forming the frequency value as binary integer.
;The process requires approximately 1600 instructions to convert the highest
;value 999,999,999 which is approximately 64us at 50MHz clock rate.
;
;Registers used s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sA,sB
;
BCD_to_integer: LOAD s2, 09 ;9 digits to convert
LOAD s0, 00 ;clear frequency value ready to accumulate result
STORE s0, frequency0
STORE s0, frequency1
STORE s0, frequency2
STORE s0, frequency3
LOAD sB, 00 ;initialise BCD digit weighting [sB,sA,s9,s8] to 1
LOAD sA, 00
LOAD s9, 00
LOAD s8, 01
LOAD s3, BCD_digit0 ;locate LS-digit
next_BCD_to_int_digit: FETCH s1, (s3)
BCD_digit_convert: COMPARE s1, 00 ;test for zero
JUMP Z, next_digit_value
FETCH s0, frequency0 ;add 32-bit digit weighting to memory value
ADD s0, s8
STORE s0, frequency0
FETCH s0, frequency1
ADDCY s0, s9
STORE s0, frequency1
FETCH s0, frequency2
ADDCY s0, sA
STORE s0, frequency2
FETCH s0, frequency3
ADDCY s0, sB
STORE s0, frequency3
SUB s1, 01 ;decrement digit value
JUMP BCD_digit_convert
;Increase weighting by 10x
next_digit_value: LOAD s7, sB ;copy existing weighting
LOAD s6, sA
LOAD s5, s9
LOAD s4, s8
SL0 s8 ;multiply weight by 4x (shift left 2 places)
SLA s9
SLA sA
SLA sB
SL0 s8
SLA s9
SLA sA
SLA sB
ADD s8, s4 ;add previous weight to form 5x multiplication
ADDCY s9, s5
ADDCY sA, s6
ADDCY sB, s7
SL0 s8 ;multiply weight by 2x (shift left 1 places)
SLA s9
SLA sA
SLA sB ;weight value is now 10x previous value
ADD s3, 01 ;move to next digit for conversion
SUB s2, 01
JUMP NZ, next_BCD_to_int_digit
RETURN
;
;
;**************************************************************************************
; 32-bit x 48-bit multiply to scale the integer frequency
;**************************************************************************************
;
;Multiply the 32-bit frequency binary integer by the 48-bit scaling factor
;to form a full precision 80-bit product.
;
;The frequency binary integer is stored in scratch pad memory using ascending
;locations frequency0 to frequency3
;
;The product will be stored in scratch pad memory using ascending
;locations product0 to product9
;
;The scaling factor is provided directly as constants
; scale_constant0 to scale_constant5
;
;The multiplication is performed as a 32-bit 'shift and add' process in which the
;integer frequency is examined LSB first using a register set [sB,sA,s9,s8] and
;a scaling accumulator is formed directly in the 'product' memory locations.
;
;The process requires up to 1772 instructions which is 3544 clock cycle or
;approximately 71us at 50MHz clock rate.
;
;Registers used s0,s1,s8,s9,sA,sB (s1,s8,s9,sA,sB clear on return)
;
scale_frequency: LOAD s0, 00 ;clear accumulator section of 'product'
STORE s0, product9
STORE s0, product8
STORE s0, product7
STORE s0, product6
STORE s0, product5
STORE s0, product4
FETCH sB, frequency3 ;read frequency integer value
FETCH sA, frequency2
FETCH s9, frequency1
FETCH s8, frequency0
LOAD s1, 20 ;32-bit multiply
scale_mult_bit: SR0 sB ;shift right frequency integer
SRA sA
SRA s9
SRA s8
JUMP NC, product_shift ;no add if bit is zero (note carry is zero)
FETCH s0, product4 ;addition of scaling factor to most significant bits of product
ADD s0, scale_constant0
STORE s0, product4
FETCH s0, product5
ADDCY s0, scale_constant1
STORE s0, product5
FETCH s0, product6
ADDCY s0, scale_constant2
STORE s0, product6
FETCH s0, product7
ADDCY s0, scale_constant3
STORE s0, product7
FETCH s0, product8
ADDCY s0, scale_constant4
STORE s0, product8
FETCH s0, product9
ADDCY s0, scale_constant5
STORE s0, product9 ;carry holds any overflow of addition
product_shift: FETCH s0, product9
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -