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

📄 clock.psm

📁 PicoBlaze_Real_Time_Clock
💻 PSM
📖 第 1 页 / 共 5 页
字号:
                 LOAD s5, character_t
                 CALL LCD_write_data
                 LOAD s5, character_o
                 CALL LCD_write_data
                 CALL disp_space
                 LOAD s5, character_S
                 CALL LCD_write_data
                 LOAD s5, character_e
                 CALL LCD_write_data
                 LOAD s5, character_t
                 CALL LCD_write_data
                 CALL disp_space
                 RETURN
      disp_msg7: LOAD s5, character_H
                 CALL LCD_write_data
                 LOAD s5, character_a
                 CALL LCD_write_data
                 LOAD s5, character_p
                 CALL LCD_write_data
                 LOAD s5, character_p
                 CALL LCD_write_data
                 LOAD s5, character_y
                 CALL LCD_write_data
                 CALL disp_space
                 LOAD s5, character_B
                 CALL LCD_write_data
                 LOAD s5, character_i
                 CALL LCD_write_data
                 LOAD s5, character_r
                 CALL LCD_write_data
                 LOAD s5, character_t
                 CALL LCD_write_data
                 LOAD s5, character_h
                 CALL LCD_write_data
                 LOAD s5, character_d
                 CALL LCD_write_data
                 LOAD s5, character_a
                 CALL LCD_write_data
                 LOAD s5, character_y
                 CALL LCD_write_data
                 LOAD s5, 21
                 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
                 ;a different section (see above in this case).
                 ;
                 ;
                 ;Pulse LCD enable signal 'E' high for greater than 230ns (1us is used).
                 ;
                 ;Register s4 should define the current state of the LCD output port.
                 ;
                 ;Registers used s0, s4
                 ;
    LCD_pulse_E: XOR s4, LCD_E                       ;E=1
                 OUTPUT s4, LCD_output_port
                 CALL delay_1us
                 XOR s4, LCD_E                       ;E=0
                 OUTPUT s4, LCD_output_port
                 RETURN
                 ;
                 ;Write 4-bit instruction to LCD display.
                 ;
                 ;The 4-bit instruction should be provided in the upper 4-bits of register s4.
                 ;Note that this routine does not release the master enable but as it is only
                 ;used during initialisation and as part of the 8-bit instruction write it
                 ;should be acceptable.
                 ;
                 ;Registers used s4
                 ;
LCD_write_inst4: AND s4, F8                          ;Enable=1 RS=0 Instruction, RW=0 Write, E=0
                 OUTPUT s4, LCD_output_port          ;set up RS and RW >40ns before enable pulse
                 CALL LCD_pulse_E
                 RETURN
                 ;
                 ;
                 ;Write 8-bit instruction to LCD display.
                 ;
                 ;The 8-bit instruction should be provided in register s5.
                 ;Instructions are written using the following sequence
                 ; Upper nibble
                 ; wait >1us
                 ; Lower nibble
                 ; wait >40us
                 ;
                 ;Registers used s0, s1, s4, s5
                 ;
LCD_write_inst8: LOAD s4, s5
                 AND s4, F0                          ;Enable=0 RS=0 Instruction, RW=0 Write, E=0
                 OR s4, LCD_drive                    ;Enable=1
                 CALL LCD_write_inst4                ;write upper nibble
                 CALL delay_1us                      ;wait >1us
                 LOAD s4, s5                         ;select lower nibble with
                 SL1 s4                              ;Enable=1
                 SL0 s4                              ;RS=0 Instruction
                 SL0 s4                              ;RW=0 Write
                 SL0 s4                              ;E=0
                 CALL LCD_write_inst4                ;write lower nibble
                 CALL delay_40us                     ;wait >40us
                 LOAD s4, F0                         ;Enable=0 RS=0 Instruction, RW=0 Write, E=0
                 OUTPUT s4, LCD_output_port          ;Release master enable
                 RETURN
                 ;
                 ;
                 ;
                 ;Write 8-bit data to LCD display.
                 ;
                 ;The 8-bit data should be provided in register s5.
                 ;Data bytes are written using the following sequence
                 ; Upper nibble
                 ; wait >1us
                 ; Lower nibble
                 ; wait >40us
                 ;
                 ;Registers used s0, s1, s4, s5
                 ;
 LCD_write_data: LOAD s4, s5
                 AND s4, F0                          ;Enable=0 RS=0 Instruction, RW=0 Write, E=0
                 OR s4, 0C                           ;Enable=1 RS=1 Data, RW=0 Write, E=0
                 OUTPUT s4, LCD_output_port          ;set up RS and RW >40ns before enable pulse
                 CALL LCD_pulse_E                    ;write upper nibble
                 CALL delay_1us                      ;wait >1us
                 LOAD s4, s5                         ;select lower nibble with
                 SL1 s4                              ;Enable=1
                 SL1 s4                              ;RS=1 Data
                 SL0 s4                              ;RW=0 Write
                 SL0 s4                              ;E=0
                 OUTPUT s4, LCD_output_port          ;set up RS and RW >40ns before enable pulse
                 CALL LCD_pulse_E                    ;write lower nibble
                 CALL delay_40us                     ;wait >40us
                 LOAD s4, F0                         ;Enable=0 RS=0 Instruction, RW=0 Write, E=0
                 OUTPUT s4, LCD_output_port          ;Release master enable
                 RETURN
                 ;
                 ;
                 ;
                 ;
                 ;Read 8-bit data from LCD display.
                 ;
                 ;The 8-bit data will be read from the current LCD memory address
                 ;and will be returned in register s5.
                 ;It is advisable to set the LCD address (cursor position) before
                 ;using the data read for the first time otherwise the display may
                 ;generate invalid data on the first read.
                 ;
                 ;Data bytes are read using the following sequence
                 ; Upper nibble
                 ; wait >1us
                 ; Lower nibble
                 ; wait >40us
                 ;
                 ;Registers used s0, s1, s4, s5
                 ;
                 ;LCD_read_data8: LOAD s4, 0E                         ;Enable=1 RS=1 Data, RW=1 Read, E=0
                 ;                OUTPUT s4, LCD_output_port          ;set up RS and RW >40ns before enable pulse
                 ;                XOR s4, LCD_E                       ;E=1
                 ;                OUTPUT s4, LCD_output_port
                 ;                CALL delay_1us                      ;wait >260ns to access data
                 ;                INPUT s5, LCD_input_port            ;read upper nibble
                 ;                XOR s4, LCD_E                       ;E=0
                 ;                OUTPUT s4, LCD_output_port
                 ;                CALL delay_1us                      ;wait >1us
                 ;                XOR s4, LCD_E                       ;E=1
                 ;                OUTPUT s4, LCD_output_port
                 ;                CALL delay_1us                      ;wait >260ns to access data
                 ;                INPUT s0, LCD_input_port            ;read lower nibble
                 ;                XOR s4, LCD_E                       ;E=0
                 ;                OUTPUT s4, LCD_output_port
                 ;                AND s5, F0                          ;merge upper and lower nibbles
                 ;                SR0 s0
                 ;                SR0 s0
                 ;                SR0 s0
                 ;                SR0 s0
                 ;                OR s5, s0
                 ;                LOAD s4, 04                         ;Enable=0 RS=1 Data, RW=0 Write, E=0
                 ;                OUTPUT s4, LCD_output_port          ;Stop reading 5V device and release master enable
                 ;                CALL delay_40us                     ;wait >40us
                 ;                RETURN
                 ;
                 ;
                 ;Reset and initialise display to communicate using 4-bit data mode
                 ;Includes routine to clear the display.
                 ;
                 ;Requires the 4-bit instructions 3,3,3,2 to be sent with suitable delays
                 ;following by the 8-bit instructions to set up the display.
                 ;
                 ;  28 = '001' Function set, '0' 4-bit mode, '1' 2-line, '0' 5x7 dot matrix, 'xx'
                 ;  06 = '000001' Entry mode, '1' increment, '0' no display shift
                 ;  0C = '00001' Display control, '1' display on, '0' cursor off, '0' cursor blink off
                 ;  01 = '00000001' Display clear
                 ;
                 ;Registers used s0, s1, s2, s3, s4
                 ;
      LCD_reset: CALL delay_20ms                     ;wait more that 15ms for display to be ready
                 LOAD s4, 30
                 CALL LCD_write_inst4                ;send '3'
                 CALL delay_20ms                     ;wait >4.1ms
                 CALL LCD_write_inst4                ;send '3'
                 CALL delay_1ms                      ;wait >100us
                 CALL LCD_write_inst4                ;send '3'
                 CALL delay_40us                     ;wait >40us
                 LOAD s4, 20
                 CALL LCD_write_inst4                ;send '2'
                 CALL delay_40us                     ;wait >40us
                 LOAD s5, 28                         ;Function set
                 CALL LCD_write_inst8
                 LOAD s5, 06                         ;Entry mode
                 CALL LCD_write_inst8
                 LOAD s5, 0C                         ;Display control
                 CALL LCD_write_inst8
      LCD_clear: LOAD s5, 01                         ;Display clear
                 CALL LCD_write_inst8
                 CALL delay_1ms                      ;wait >1.64ms for display to clear
                 CALL delay_1ms
                 LOAD s5, 13
                 CALL LCD_cursor
                 LOAD s5, 3A                         ;;;;;;;;;;;;;;;;;;;;;;;    :
                 CALL LCD_write_data
                 LOAD s5, 16
                 CALL LCD_cursor
                 LOAD s5, 2D                         ;;;;;;;;;;;;;;;;;;;;;;     -
                 CALL LCD_write_data
                 LOAD s5, 20
                 CALL LCD_cursor

⌨️ 快捷键说明

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