1

嗨,我正在尝试在组装中制作秒表以在 Dragon 12 plus 板上运行,我已将其设置为按钮开始停止并重置时间,程序运行但速度不够快。我知道问题与延迟有关,但我不知道如何解决它。我认为我的中断例程太长,但我尝试实施的所有其他方法都不起作用,任何输入都会非常感激。好吧,这是我的代码,抱歉没有很好地注释

      XDEF      Entry       ; export 'Entry' symbol
      ABSENTRY  Entry       ; for absolute assembly: mark this as application entry point

      INCLUDE   'derivative.inc' 

      ROM       EQU     $0400
      DATA      EQU     $1000
      PROG      EQU     $2000
      RS        EQU     $01           ; Register Select pin for LCD module  
      EN        EQU     $02           ; Enable pin for LCD module


  ; Variable/Data Section

                ORG     DATA
      START     RMB     2
      DELAYC    FDB     1876
      CMD       FDB     $0000
      CNT       FDB     1000 
      CLOCKON   FCB     $00
      SECOND    FCB     $00
      TENTH     FCB     $00
      HUNDREDTH FCB     $00
      TMINUTE   FCB     $00
      THOUR     FCB     $00
      MINUTE    FCB     $00
      HOUR      FCB     $00
      TSECOND   FCB     $00

                ORG     PROG
      ; Insert your code following the label "Entry"          
      Entry:    SEI
                JSR     INIT 
      MAINLOOP: 
                WAI
                CLI
                BRA     MAINLOOP
      INTKEY:  
                SEI
                JSR     DELAY
                LDAB    PTH
                COMB
                CMPB    #$01
                BEQ     STARTCLOCK
                CMPB    #$02
                BEQ     STOPCLOCK
                CMPB    #$04
                BEQ     RESETCLOCK
                BRA     RESETIGNORE

      STARTCLOCK
                MOVB    #$80,TSCR1
                LDAA    #$01
                STAA    CLOCKON
                BRA     RESETIGNORE
      STOPCLOCK 
                MOVB    #$C0,TSCR1
                LDAA    #$00
                STAA    CLOCKON
                BRA     RESETIGNORE
      RESETCLOCK
                LDAA    CLOCKON
                CMPA    #$01
                BEQ     RESETIGNORE
                JSR     TIMERCLR
                LDAA    #$00
                STAA    HUNDREDTH    
                STAA    TENTH
                STAA    SECOND
                STAA    TSECOND
                STAA    MINUTE
                STAA    TMINUTE
                STAA    HOUR
                STAA    THOUR

      RESETIGNORE
                LDAA    #$FF
                STAA    PIFH
                CLI
                RTI             
      INCREMENTHUNDREDTH
                LDAB    CLOCKON
                CMPB    #$00
                LBEQ    RETURN
                LDAA    HUNDREDTH
                CMPA    #9
                BEQ     INCREMENTTENTH
                ADDA    #1
                STAA    HUNDREDTH
                LBRA    DISPLAYHUNDREDTH
      INCREMENTTENTH
                LDAA    #$00
                STAA    HUNDREDTH
                LDAA    TENTH
                CMPA    #9
                BEQ     INCREMENTSECOND
                ADDA    #1
                STAA    TENTH
                LBRA    DISPLAYTENTH         
      INCREMENTSECOND
                LDAA    #$00
                STAA    TENTH
                LDAA    SECOND
                CMPA    #9
                BEQ     INCREMENTTSECOND
                ADDA    #1
                STAA    SECOND         
                LBRA     DISPLAYSECOND
      INCREMENTTSECOND
                LDAA    #$00
                STAA    SECOND
                LDAA    TSECOND
                CMPA    #5
                BEQ     INCREMENTMINUTE
                ADDA    #1
                STAA    TSECOND
                LBRA     DISPLAYTSECOND  
      INCREMENTMINUTE
                LDAA    #$00
                STAA    TSECOND
                LDAA    MINUTE
                CMPA    #9
                BEQ     INCREMENTTMINUTE
                ADDA    #1
                STAA    MINUTE
                BRA     DISPLAYMINUTE
      INCREMENTTMINUTE 
                LDAA    #$00
                STAA    MINUTE
                LDAA    TMINUTE
                CMPA    #5
                BEQ     INCREMENTHOUR
                ADDA    #1
                STAA    TMINUTE
                BRA     DISPLAYTMINUTE
      INCREMENTHOUR
                LDAA    #$00
                STAA    TMINUTE
                LDAA    HOUR
                CMPA    #9
                BEQ     INCREMENTTHOUR
                ADDA    #1
                STAA    HOUR
                BRA     DISPLAYHOUR 
      INCREMENTTHOUR
                LDAA    #$00
                STAA    HOUR
                LDAA    THOUR
                ADDA    #1
                STAA    THOUR
                BRA     DISPLAYTHOUR 

      DISPLAYTHOUR
                LDAA    #$C0
                JSR     COM_WRT
                JSR     DELAY
                LDAA    THOUR
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
      DISPLAYHOUR
                LDAA    #$C1
                JSR     COM_WRT
                JSR     DELAY
                LDAA    HOUR
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
      DISPLAYTMINUTE
                LDAA    #$C3
                JSR     COM_WRT
                JSR     DELAY
                LDAA    TMINUTE
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
      DISPLAYMINUTE
                LDAA    #$C4
                JSR     COM_WRT
                JSR     DELAY
                LDAA    MINUTE
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
      DISPLAYTSECOND
                LDAA    #$C6
                JSR     COM_WRT
                JSR     DELAY
                LDAA    TSECOND
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
      DISPLAYSECOND
                LDAA    #$C7
                JSR     COM_WRT
                JSR     DELAY
                LDAA    SECOND
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
      DISPLAYTENTH
                LDAA    #$C9
                JSR     COM_WRT
                JSR     DELAY
                LDAA    TENTH
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
      DISPLAYHUNDREDTH
                LDAA    #$CA
                JSR     COM_WRT
                JSR     DELAY 
                LDAA    HUNDREDTH
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
      RETURN    
                RTI

      ; INITIALIZATION


      INIT 
                BSET    DDRB,#$FF     ; Set Port B to output
                BSET    DDRJ,#$02     ; Set Port J pin 1 to output
                BCLR    PTJ,#$02      ; Enable discrete LEDs
      ; Disable 7-Segment Display
                BSET    DDRP,#$0F     ; Set Port P pins 0-3 to output
                BSET    PTP, #$0F     ; Disable 7-Segment Display
      ; Pushbuttons/DSs
                BCLR    DDRH, #$00    ; Set Port H pins to input
                LDAA    #0          ;PTH as input   
            STAA    DDRH
            LDAA    #$FF        ;   
                STAA    PIEH   
       ; Set Port K to Output
                LDAA    #$FF
                STAA    DDRK                        
                JSR     CLEAR ; Clear LCD screen   
                BSET    TSCR2,#$0F
                BSET    TIE,#$80
                BSET    TIOS,#$80
                LDD     #$0753
                STD     TC7
                MOVB    #$CD,HPRIO
                BSR     TIMERCLR
                CLI
                RTS

      TIMERCLR
                LDAA    #$C0
                JSR     COM_WRT
                JSR     DELAY
                LDAA    THOUR
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
                LDAA    HOUR
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY 
                LDAA    #':'
                JSR     DATA_WRT
                JSR     DELAY
                LDAA    TMINUTE
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
                LDAA    MINUTE
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY 
                LDAA    #':'
                JSR     DATA_WRT
                JSR     DELAY
                LDAA    TSECOND
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
                LDAA    SECOND
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY 
                LDAA    #'.'
                JSR     DATA_WRT
                JSR     DELAY
                LDAA    TENTH
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY 
                LDAA    HUNDREDTH
                ADDA    #48
                JSR     DATA_WRT
                JSR     DELAY
                RTS
      ;---------------------------------------------------- 
      ; Clear LCD Subroutine   
      ;----------------------------------------------------
      ; This sequence of instructions initializes the LCD and
      ; sets the cursor to the beginning of the first line.
      ; It also will move the cursor to the right, one space,
      ; when writing a new character. Please note, characters
      ; don't wrap around.    
      CLEAR:    LDAA    #$33
                BSR     COM_WRT
                JSR     DELAY   
                LDAA    #$32
                BSR     COM_WRT
                JSR     DELAY
                LDAA    #$28
                BSR     COM_WRT
                JSR     DELAY
                LDAA    #$0C; WAS E, HOPEFULLY THIS HIDES CURSOR
                BSR     COM_WRT
                JSR     DELAY
                LDAA    #$01
                BSR     COM_WRT
                BSR     DELAY
                LDAA    #$06
                BSR     COM_WRT
                BSR     DELAY
                LDAA    #$80
                BSR     COM_WRT
                BSR     DELAY    
                RTS
      ;---------------------------------------------------- 
      ; Command Write Subroutine   
      ;---------------------------------------------------- 
      COM_WRT:
                STAA      CMD           ; Save curent command into CMD
                ; Write upper nibble only
                ANDA    #$F0          ; Get upper nibble only
                LSRA                  ; Shift right to align DB pins of LCD w/ Port K pins
                LSRA
                STAA    PORTK         ; Output to Port K
                BCLR    PORTK,RS      ; Set register select for an instruction <----
                BSET    PORTK,EN      ; Enable high
                NOP                   ; Delay 1 cycle
                NOP                   ; Delay 1 cycle
                NOP                   ; Delay 1 cycle
                BCLR    PORTK,EN      ; Enable low
                ; Write lower nibble only
                LDAA    CMD           ; Reload Reg A w/ CMD
                ANDA    #$0F          ; Get lower nibble only
                LSLA                  ; Shift left to align DB pins of LCD w/ Port K pins
                LSLA
                STAA    PORTK         ; Output to Port K
                BCLR    PORTK,RS      ; Set register select for an instruction <----
                BSET    PORTK,EN      ; Enable high
                NOP                   ; Delay 1 cycle
                NOP                   ; Delay 1 cycle
                NOP                   ; Delay 1 cycle
                BCLR    PORTK,EN      ; Enable low
                RTS
      ;---------------------------------------------------- 
      ; Data Write Subroutine   
      ;---------------------------------------------------- 
      DATA_WRT:
                STAA      CMD           ; Save curent command into CMD
                ; Write upper nibble only
                ANDA    #$F0          ; Get upper nibble only
                LSRA                  ; Shift right to align DB pins of LCD w/ Port K pins
                LSRA
                STAA    PORTK         ; Output to Port K
                BSET    PORTK,RS      ; Set register select for data <----
                BSET    PORTK,EN      ; Enable high
                NOP                   ; Delay 1 cycle
                NOP                   ; Delay 1 cycle
                NOP                   ; Delay 1 cycle
                BCLR    PORTK,EN      ; Enable low
                ; Write lower nibble only
                LDAA    CMD           ; Reload Reg A w/ CMD 
                ANDA    #$0F          ; Get lower nibble only
                LSLA                  ; Shift left to align DB pins of LCD w/ Port K pins
                LSLA
                STAA    PORTK         ; Output to Port K
                BSET    PORTK,RS      ; Set register select for data <----
                BSET    PORTK,EN      ; Enable high
                NOP                   ; Delay 1 cycle
                NOP                   ; Delay 1 cycle
                NOP                   ; Delay 1 cycle
                BCLR    PORTK,EN      ; Enable low
                RTS

      ; Delay Subroutine   

      DELAY:   
                LDY     #6000         ; 6000 x 4 = 24,000 cycles = 1ms
      LOOP_1MS: 
                LDX     #4           
      LOOP:     
                DEX
                BNE     LOOP             
                DEY                   ; This instruction takes 1 cycle
                BNE     LOOP_1MS      ; This instruction takes 3 cycles
                RTS
      ;INITILIZE INTERUPTS

               ORG      $3E7E
               FDB      Entry
               ORG      $3E4C
               FDB      INTKEY 
               ORG      $3E60
               FDB      INCREMENTHUNDREDTH
4

0 回答 0