⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fg_ctrl.psm

📁 PicoBlaze的开发压缩包,PicoBlaze的编译器.
💻 PSM
📖 第 1 页 / 共 5 页
字号:
                       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_stop, 2E
                       CONSTANT character_semi_colon, 3B
                       CONSTANT character_minus, 2D
                       CONSTANT character_divide, 2F       ;'/'
                       CONSTANT character_plus, 2B
                       CONSTANT character_comma, 2C
                       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_exclaim, 21      ;'!'
                       CONSTANT character_BS, 08           ;Back Space command character
                       ;
                       ;
                       ;
                       ;
                       ;
                       ;**************************************************************************************
                       ;Initialise the system
                       ;**************************************************************************************
                       ;
           cold_start: CALL LCD_reset                      ;initialise LCD display
                       ;
                       ;Write 'Frequency Generator' to LCD display and display for 4 seconds
                       ;
                       LOAD s5, 10                         ;Line 1 position 0
                       CALL LCD_cursor
                       CALL disp_Frequency
                       LOAD s5, 22                         ;Line 2 position 2
                       CALL LCD_cursor
                       CALL disp_Generator
                       CALL delay_1s                       ;wait 4 seconds
                       CALL delay_1s
                       CALL delay_1s
                       CALL delay_1s
                       CALL LCD_clear                      ;clear screen
                       ;
                       ;
                       ;Initial frequency of 100MHz
                       ;
                       LOAD s0, 00
                       LOAD s1, 01
                       STORE s0, BCD_digit0
                       STORE s0, BCD_digit1
                       STORE s0, BCD_digit2
                       STORE s0, BCD_digit3
                       STORE s0, BCD_digit4
                       STORE s0, BCD_digit5
                       STORE s0, BCD_digit6
                       STORE s0, BCD_digit7
                       STORE s1, BCD_digit8
                       ;
                       LOAD s0, 04                         ;Start position for editing frequency is 1MHz digit
                       STORE s0, cursor_position
                       LOAD s0, BCD_digit6
                       STORE s0, edit_digit_pointer
                       ;
                       ;
                       ENABLE INTERRUPT                    ;interrupts are used to detect rotary controller
                       CALL delay_1ms
                       LOAD s0, 00                         ;clear the status of any spurious rotary events
                       STORE s0, rotary_status             ;   as a result of system turning on.
                       ;
                       ;**************************************************************************************
                       ; Main program
                       ;**************************************************************************************
                       ;
                       ; The main program is centred on the task of editing the frequency. It waits until the
                       ; rotary control is used and then makes the appropriate changes. If the actual digit
                       ; digit value is changed then the calculation to drive the DDS is performed each time.
                       ;
                       ; The start state is that of allowing the edit cursor position to be moved. Rotary
                       ; inputs are detected by the interrupt service routine and set a flag bit which the
                       ; main program then uses to adjust the cursor position and pointer to the corresponding
                       ; BCD digit in memory.
                       ;
                       ; A press of the rotary control is detected by polling and used to change to the digit
                       ; editing mode.
                       ;
                       ;
            move_mode: CALL compute_DDS_words              ;compute DDS control values
                       CALL display_freq                   ;refresh display with cursor position shown
                       LOAD s0, LED0                       ;indicate move mode on LEDs
                       OUTPUT s0, LED_port
            move_wait: INPUT s0, rotary_port               ;read rotary encoder
                       TEST s0, rotary_press               ;test for press of button which changes mode
                       JUMP NZ, edit_mode
                       FETCH s0, rotary_status             ;check for any rotation of rotary control
                       TEST s0, rotary_event
                       JUMP Z, move_wait
                       ;
                       AND s0, 7F                          ;clear flag now that action it is being processed
                       STORE s0, rotary_status
                       FETCH sA, cursor_position           ;read current position
                       FETCH sB, edit_digit_pointer
                       TEST s0, rotary_left                ;determine direction to move cursor
                       JUMP Z, move_right
                       ;
            move_left: COMPARE sB, BCD_digit8              ;can not move left of 100MHz digit
                       JUMP Z, move_mode
                       ADD sB, 01                          ;move to next higher BCD digit
                       SUB sA, 01                          ;move cursor to match digit to be edited
                       COMPARE sA, 09                      ;must skip over space separator
                       JUMP Z, skip_left
                       COMPARE sA, 05                      ;must skip over decimal point
                       JUMP NZ, edit_point_update
            skip_left: SUB sA, 01                          ;move cursor further left
                       JUMP edit_point_update
                       ;
           move_right: COMPARE sB, BCD_digit0              ;can not move right of 1Hz digit
                       JUMP Z, move_mode
                       SUB sB, 01                          ;move to next lower BCD digit
                       ADD sA, 01                          ;move cursor to match digit to be edited
                       COMPARE sA, 09                      ;must skip over space separator
                       JUMP Z, skip_right
                       COMPARE sA, 05                      ;must skip over decimal point
                       JUMP NZ, edit_point_update
           skip_right: ADD sA, 01                          ;move cursor further right
                       ;
    edit_point_update: STORE sA, cursor_position           ;update edit value in memory
                       STORE sB, edit_digit_pointer
                       JUMP move_mode
                       ;
                       ;
                       ; The edit mode is reached by pressing the rotary control. Since this is a simple switch
                       ; a software de-bounce delay is used to wait for the knob to be released fully before
                       ; entering the digit editing mode fully.
                       ;
                       ; In this mode rotations of the detected by the interrupt service routine are used to
                       ; increment or decrement the digit value at the cursor position with carry/borrow to
                       ; the left.
                       ;
                       ; A new press of the rotary control is detected by polling and used to change back to the
                       ; cursor moving mode.
                       ;
                       ;
            edit_mode: CALL wait_switch_release            ;wait for switch press to end
         edit_display: CALL compute_DDS_words              ;compute DDS control values
                       CALL display_freq                   ;refresh display with new values
                       LOAD s0, LED1                       ;indicate edit mode on LEDs
                       OUTPUT s0, LED_port
            edit_wait: INPUT s0, rotary_port               ;read rotary encoder
                       TEST s0, rotary_press               ;test for press of button which changes mode
                       JUMP NZ, end_edit_mode
                       FETCH s0, rotary_status             ;check for any rotation of rotary control
                       TEST s0, rotary_event
                       JUMP Z, edit_wait
                       ;
                       AND s0, 7F                          ;clear flag now that action it is being processed
                       STORE s0, rotary_status
                       FETCH sB, edit_digit_pointer        ;read pointer to BCD digit for initial change
                       TEST s0, rotary_left                ;determine direction to increment or decrement
                       JUMP Z, inc_digit
                       ;
                       ; Decrement the value starting at the current position and borrowing from the left.
                       ; However the value needs to bottom out at all 0's from the editing position.
                       ;
                       ;
            dec_digit: FETCH sA, (sB)                      ;read digit value at pointer position
                       SUB sA, 01                          ;decrement digit
                       COMPARE sA, FF                      ;test for borrow from next digit
                       JUMP Z, dec_borrow
                       STORE sA, (sB)                      ;store decremented digit value
                       JUMP edit_display                   ;decrement task complete
           dec_borrow: LOAD sA, 09                         ;current digit rolls over to nine
                       STORE sA, (sB)                      ;store '9' digit value
                       COMPARE sB, BCD_digit8              ;check if working on 100MHz digit
                       JUMP Z, set_min_value
                       ADD sB, 01                          ;increment pointer to next most significant digit
                       JUMP dec_digit                      ;decrement next digit up.
                       ;
        set_min_value: FETCH sB, edit_digit_pointer        ;Must fill digits from insert to MS-Digit with 000...
                       LOAD sA, 00
             fill_min: STORE sA, (sB)
                       COMPARE sB, BCD_digit8              ;check if filled to 100MHz digit
                       JUMP Z, edit_display
                       ADD sB, 01                          ;fill next higher digit
                       JUMP fill_min
                       ;
                       ; Increment the value starting at the current position and carrying to the left.
                       ; However the value needs to saturate to all 9's from the editing position.
                       ;
            inc_digit: FETCH sA, (sB)                      ;read digit value at pointer position
                       ADD sA, 01                          ;increment digit
                       COMPARE sA, 0A                      ;test for carry to next digit

⌨️ 快捷键说明

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