📄 fc_ctrl.psm
字号:
CALL LCD_cursor
INPUT sF, status_port ;select source based on switches
COMPARE sF, 00 ;test for no switches active
AND sF, 0F ;isolate switches
JUMP NZ, test_SMA
CALL disp_menu
JUMP warm_start
test_SMA: COMPARE sF, switch0
JUMP NZ, test_50M
CALL disp_SMA_input
LOAD sF, 00
JUMP select_source
test_50M: COMPARE sF, switch1
JUMP NZ, test_DCM
CALL disp_50MHz_Crystal
LOAD sF, 01
JUMP select_source
test_DCM: COMPARE sF, switch2
JUMP NZ, test_Ring
CALL disp_DCM_Oscillator
LOAD sF, 02
JUMP select_source
test_Ring: COMPARE sF, switch3
JUMP Z, Ring_select
CALL disp_menu ;more than one switch is set
JUMP warm_start
Ring_select: CALL disp_Ring_Oscillator
LOAD sF, 03
select_source: OUTPUT sF, source_control_port ;select source control
;
;Read the most recent values from display on LCD.
;
;Interrupts will be disabled during the reading of values to ensure a clean
;value is obtained when reading multi-byte values.
;
;
;Display the count value in the top right of the LCD display
;Up to 999,999,999
;
DISABLE INTERRUPT ;copy cycle count to register set [s5,s4,s3,s2]
FETCH s2, count0
FETCH s3, count1
FETCH s4, count2
FETCH s5, count3
ENABLE INTERRUPT
CALL integer_to_BCD ;convert last 32-bit value to BCD digits
LOAD s5, 10 ;Line 1 position 0
CALL LCD_cursor
LOAD s6, decimal8 ;up to 999,999,999 Hz
CALL disp_digits
JUMP warm_start
;
;
;
;**************************************************************************************
; Display frequency value on LCD display
;**************************************************************************************
;
;
;Display value on the LCD display at current position.
;The values to be displayed must be stored in scratch pad memory
;locations 'decimal0' to 'decimal9' which must be in ascending locations.
;
;The routing performs leading zero suppression and scales to Hz, KHz or MHz ranges.
;
;Registers used s0,s1,s4,s5,sE,sF
;
disp_digits: LOAD sF, FF ;set blanking flag
LOAD sE, character_space ;scaling character for MHz, KHz or Hz
FETCH s5, decimal8 ;100MHz digit
CALL zero_test
CALL disp_digit
FETCH s5, decimal7 ;10MHz digit
CALL zero_test
CALL disp_digit
FETCH s5, decimal6 ;1MHz digit
CALL zero_test
CALL disp_digit
COMPARE sF, FF ;check if any MHz were active
JUMP Z, khz_space
LOAD s5, character_stop
CALL LCD_write_data
LOAD sE, character_M
JUMP khz_digits
khz_space: LOAD s5, character_space
CALL LCD_write_data
khz_digits: FETCH s5, decimal5 ;100KHz digit
CALL zero_test
CALL disp_digit
FETCH s5, decimal4 ;10KHz digit
CALL zero_test
CALL disp_digit
FETCH s5, decimal3 ;1KHz digit
CALL zero_test
CALL disp_digit
COMPARE sE, character_M ;check if any MHz were active
JUMP Z, hz_space
COMPARE sF, FF ;check if any KHz were active
JUMP Z, hz_space
LOAD s5, character_stop
CALL LCD_write_data
LOAD sE, character_K
JUMP hz_digits
hz_space: LOAD s5, character_space
CALL LCD_write_data
hz_digits: FETCH s5, decimal2 ;100KHz digit
CALL zero_test
CALL disp_digit
FETCH s5, decimal1 ;10KHz digit
CALL zero_test
CALL disp_digit
FETCH s5, decimal0 ;1KHz digit (always displayed)
ADD s5, character_0 ;convert number to ASCII
CALL LCD_write_data
LOAD s5, character_space
CALL LCD_write_data
LOAD s5, sE
CALL LCD_write_data
LOAD s5, character_H
CALL LCD_write_data
LOAD s5, character_z
CALL LCD_write_data
LOAD s5, character_space ;ensure end of line is clear
CALL LCD_write_data
RETURN
;
;Check digit for zero. If not zero then clear
;blanking flag (sF=00)
zero_test: COMPARE s5, 00
RETURN Z
LOAD sF, 00
RETURN
;
;Display single digit at current position
;or space if blanking (sF=FF) is active
;
disp_digit: COMPARE sF, FF
JUMP Z, blank_digit
ADD s5, character_0 ;convert number to ASCII
CALL LCD_write_data
RETURN
blank_digit: LOAD s5, character_space
CALL LCD_write_data
RETURN
;
;
;
;**************************************************************************************
; 32-bit integer to BCD conversion
;**************************************************************************************
;
;Convert the 32 bit value in register set [s5,s4,s3,s2]
;into the BCD decimal equivalent located in the scratch pad memory
;locations 'decimal0' to 'decimal9' which must be in ascending locations.
;
;Each digit is formed in turn starting with the least significant.
;
;Registers used s0,s2,s3,s4,s5,s6,s7,s8,s9,sA,sB,sC,sD,sE,sF
;
integer_to_BCD: LOAD sE, 0A ;10 digits to be formed from value upto 4294967295
LOAD sF, decimal0 ;pointer for LS-Digit
int_to_BCD_loop: CALL divide_32bit_by_10
STORE s1, (sF) ;remainder becomes digit value
ADD sF, 01 ;move to next most significant digit
SUB sE, 01 ;one less digit to compute
JUMP NZ, int_to_BCD_loop
RETURN
;
;Divide 32-bit binary integer by 10
;
;The value to be divided is held in register set [s5,s4,s3,s2]
;and this is where the result is returned to.
;
;At then end of the integer division the remainder in the range 0 to 9
;will be in register s1.
;
;Registers used s0, s2,s3,s4,s5,s6,s7,s8,s9,sA,sB,sC,sD
;
divide_32bit_by_10: LOAD sA, s2 ;copy input value to set [sD,sC,sB,sA]
LOAD sB, s3
LOAD sC, s4
LOAD sD, s5
LOAD s2, 00 ;clear result
LOAD s3, 00
LOAD s4, 00
LOAD s5, 00
LOAD s9, A0 ;initialise '10' value into msb's of set [s9,s8,s7,s6]
LOAD s8, 00
LOAD s7, 00
LOAD s6, 00
LOAD s0, 1D ;29 subtract and shift iterations to be performed
div10_loop: SUB sA, s6 ;perform 32-bit subtract [sD,sC,sB,sA]-[s9,s8,s7,s6]
SUBCY sB, s7
SUBCY sC, s8
SUBCY sD, s9
JUMP C, div10_restore
SL1 s2 ;shift '1' into result
JUMP div10_shifts
div10_restore: ADD sA, s6 ;perform 32-bit addition [sD,sC,sB,sA]+[s9,s8,s7,s6]
ADDCY sB, s7
ADDCY sC, s8
ADDCY sD, s9
SL0 s2 ;shift '0' into result
div10_shifts: SLA s3 ;complete 32-bit shift left
SLA s4
SLA s5
SR0 s9 ;divide '10' value by 2 (shift right 1 place)
SRA s8
SRA s7
SRA s6
SUB s0, 01 ;count iterations
JUMP NZ, div10_loop
LOAD s1, sA ;remainder of division
RETURN
;
;
;
;
;**************************************************************************************
;LCD text messages
;**************************************************************************************
;
;
;Display 'PicoBlaze' on LCD at current cursor position
;
;
disp_PicoBlaze: LOAD s5, character_P
CALL LCD_write_data
LOAD s5, character_i
CALL LCD_write_data
LOAD s5, character_c
CALL LCD_write_data
LOAD s5, character_o
CALL LCD_write_data
LOAD s5, character_B
CALL LCD_write_data
LOAD s5, character_l
CALL LCD_write_data
LOAD s5, character_a
CALL LCD_write_data
LOAD s5, character_z
CALL LCD_write_data
LOAD s5, character_e
CALL LCD_write_data
RETURN
;
;
;Display 'Frequency' on LCD at current cursor position
;
;
disp_Frequency: LOAD s5, character_F
CALL LCD_write_data
LOAD s5, character_r
CALL LCD_write_data
LOAD s5, character_e
CALL LCD_write_data
LOAD s5, character_q
CALL LCD_write_data
LOAD s5, character_u
CALL LCD_write_data
LOAD s5, character_e
CALL LCD_write_data
LOAD s5, character_n
CALL LCD_write_data
LOAD s5, character_c
CALL LCD_write_data
LOAD s5, character_y
CALL LCD_write_data
RETURN
;
;
;Display 'Counter' on LCD at current cursor position
;
;
disp_Counter: LOAD s5, character_C
CALL LCD_write_data
LOAD s5, character_o
CALL LCD_write_data
LOAD s5, character_u
CALL LCD_write_data
LOAD s5, character_n
CALL LCD_write_data
LOAD s5, character_t
CALL LCD_write_data
LOAD s5, character_e
CALL LCD_write_data
LOAD s5, character_r
CALL LCD_write_data
RETURN
;
;Display version number on LCD at current cursor position
;
;
disp_version: LOAD s5, character_v
CALL LCD_write_data
LOAD s5, character_1
CALL LCD_write_data
LOAD s5, character_stop
CALL LCD_write_data
LOAD s5, character_0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -