📄 control.psm
字号:
CALL Z, rotate_mode
CALL delay_1ms ;1ms delay
SUB sE, 01 ;decrement delay counter
SUBCY sF, 00
JUMP NC, LCD_delay_loop
CALL LCD_shift_left ;shift LCD display
JUMP LCD_shift_delay
;
mode_switch: XOR sD, FF ;toggle mode
STORE sD, mode
wait_mode_switch: CALL delay_1ms ;keep shifting LCD display while waiting
SUB sE, 01
SUBCY sF, 00
JUMP NC, wait_no_shift
CALL LCD_shift_left ;shift LCD display
LOAD sF, shift_delay_msb ; [sF,sE]=loop delay in ms
LOAD sE, shift_delay_lsb
wait_no_shift: INPUT s0, rotary_port ;wait for release of press button
TEST s0, rotary_press
JUMP NZ, wait_mode_switch
JUMP LCD_delay_loop
;
;This procedure will copy the condition of the slide switches and press
;buttons to the LEDs.
;
;
normal_mode: INPUT s0, switch_port ;Read switches and buttons and directly drive LEDs
OUTPUT s0, LED_port
RETURN
;
;
;
;This procedure will poll the status of the rotary encoder.
;If rotation occurs, then the LED pattern will adjust appropriately.
;
rotate_mode: FETCH sA, LED_pattern ;last known position
FETCH s0, rotary_status ;check status of rotation
TEST s0, 80 ;test flag
JUMP Z, update_pattern
AND s0, 7F ;clear flag
STORE s0, rotary_status
TEST s0, rotary_left ;event occurred so update pattern
JUMP Z, move_right
RL sA
JUMP update_pattern
move_right: RR sA
update_pattern: STORE sA, LED_pattern
OUTPUT sA, LED_port ;drive LEDs with current pattern
RETURN
;
;
;
;
;**************************************************************************************
;LCD text messages
;**************************************************************************************
;
;
;Display 'SPARTAN-3E STARTER KIT' on LCD at current cursor position
;
;
disp_SPARTAN: LOAD s5, character_S
CALL LCD_write_data
LOAD s5, character_P
CALL LCD_write_data
LOAD s5, character_A
CALL LCD_write_data
LOAD s5, character_R
CALL LCD_write_data
LOAD s5, character_T
CALL LCD_write_data
LOAD s5, character_A
CALL LCD_write_data
LOAD s5, character_N
CALL LCD_write_data
LOAD s5, character_minus
CALL LCD_write_data
LOAD s5, character_3
CALL LCD_write_data
LOAD s5, character_E
CALL LCD_write_data
CALL disp_space
LOAD s5, character_S
CALL LCD_write_data
LOAD s5, character_T
CALL LCD_write_data
LOAD s5, character_A
CALL LCD_write_data
LOAD s5, character_R
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
CALL disp_space
LOAD s5, character_K
CALL LCD_write_data
LOAD s5, character_I
CALL LCD_write_data
LOAD s5, character_T
CALL LCD_write_data
RETURN
;
;
;Display 'www.xilinx.com/s3estarter' on LCD at current cursor position
;
;
disp_www: LOAD s5, character_w
CALL LCD_write_data
LOAD s5, character_w
CALL LCD_write_data
LOAD s5, character_w
CALL LCD_write_data
LOAD s5, character_stop
CALL LCD_write_data
LOAD s5, character_x
CALL LCD_write_data
LOAD s5, character_i
CALL LCD_write_data
LOAD s5, character_l
CALL LCD_write_data
LOAD s5, character_i
CALL LCD_write_data
LOAD s5, character_n
CALL LCD_write_data
LOAD s5, character_x
CALL LCD_write_data
LOAD s5, character_stop
CALL LCD_write_data
LOAD s5, character_c
CALL LCD_write_data
LOAD s5, character_o
CALL LCD_write_data
LOAD s5, character_m
CALL LCD_write_data
LOAD s5, character_divide
CALL LCD_write_data
LOAD s5, character_s
CALL LCD_write_data
LOAD s5, character_3
CALL LCD_write_data
LOAD s5, character_e
CALL LCD_write_data
LOAD s5, character_s
CALL LCD_write_data
LOAD s5, character_t
CALL LCD_write_data
LOAD s5, character_a
CALL LCD_write_data
LOAD s5, character_r
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 a space on LCD at current cursor position
;
;
disp_space: LOAD s5, character_space
CALL LCD_write_data
RETURN
;
;
;
;
;**************************************************************************************
;Software delay routines
;**************************************************************************************
;
;
;
;Delay of 1us.
;
;Constant value defines reflects the clock applied to KCPSM3. Every instruction
;executes in 2 clock cycles making the calculation highly predictable. The '6' in
;the following equation even allows for 'CALL delay_1us' instruction in the initiating code.
;
; delay_1us_constant = (clock_rate - 6)/4 Where 'clock_rate' is in MHz
;
;Registers used s0
;
delay_1us: LOAD s0, delay_1us_constant
wait_1us: SUB s0, 01
JUMP NZ, wait_1us
RETURN
;
;Delay of 40us.
;
;Registers used s0, s1
;
delay_40us: LOAD s1, 28 ;40 x 1us = 40us
wait_40us: CALL delay_1us
SUB s1, 01
JUMP NZ, wait_40us
RETURN
;
;
;Delay of 1ms.
;
;Registers used s0, s1, s2
;
delay_1ms: LOAD s2, 19 ;25 x 40us = 1ms
wait_1ms: CALL delay_40us
SUB s2, 01
JUMP NZ, wait_1ms
RETURN
;
;Delay of 20ms.
;
;Delay of 20ms used during initialisation.
;
;Registers used s0, s1, s2, s3
;
delay_20ms: LOAD s3, 14 ;20 x 1ms = 20ms
wait_20ms: CALL delay_1ms
SUB s3, 01
JUMP NZ, wait_20ms
RETURN
;
;Delay of approximately 1 second.
;
;Registers used s0, s1, s2, s3, s4
;
delay_1s: LOAD s4, 32 ;50 x 20ms = 1000ms
wait_1s: CALL delay_20ms
SUB s4, 01
JUMP NZ, wait_1s
RETURN
;
;
;
;**************************************************************************************
;LCD Character Module Routines
;**************************************************************************************
;
;LCD module is a 16 character by 2 line display but all displays are very similar
;The 4-wire data interface will be used (DB4 to DB7).
;
;The LCD modules are relatively slow and software delay loops are used to slow down
;KCPSM3 adequately for the LCD to communicate. The delay routines are provided in
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -