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

📄 key05r2.asm

📁 使用68HC705J1A写的一个键盘的代码,包括资料说明,一份难得的资料,本人开发键盘时好不容易才找到的资料
💻 ASM
📖 第 1 页 / 共 3 页
字号:

releas8 cmp     #$7E     ;Scroll Lock Released
        bne     releas9
        bclr    pscrlck,status

releas9 cmp     #$77     ;Num Lock Released
        bne     relea10
        bclr    pnumlck,status

relea10 jmp     main     ;Return to Main

*****************************************************
*                                                   *
* rel_ext - An Extended Key has been Released       *
*                                                   *
*****************************************************

rel_ext jsr     Receive  ;Get Next byte
        lda     byte

        cmp     #$11    ;Right Alt Released
        bne     rel_ex2
        bclr    ralt,status
        jmp     alt_rel

rel_ex2 cmp     #$14    ;Right Ctrl Released
        bne     rel_ex3
        bclr    rctrl,status
        jmp     ctrl_re

rel_ex3 jmp     main    ;Return to main

*****************************************************
*                                                   *
* LEDshow - Copies the 3 LSB of the LED register to *
*           keyboard for the keyboards Status LED's *
*           E.g. Num Lock, Caps Lock, Scroll Lock   *
*           Also makes their status present on      *
*           PORTB                                   *
*                                                   *
*****************************************************

LEDshow lda     LED
        ora     #$20    ;Set TXD High
        and     #$27
        sta     PORTB   ;Made Status Avalible at PORTB
        lda     #$ED
        sta     byte
        jsr     transmit
        jsr     Receive
        lda     LED
        and     #$07
        sta     byte
        jsr     transmit
        jmp     main

*****************************************************
*                                                   *
* Transmit - Send Data stored at Byte to the        *
*            Keyboard. Result                       *
*                                                   *
*****************************************************

transmit
        ldx     #$08                    ;8 Data Bits
        bset    clk,DDRA                ;Set Clock Low
        lda     #$13                    ;Delay 64uS
        jsr     delay
        clra                            ;Clear Parity Register
        bset    data,DDRA               ;Set Data Low
        bclr    clk,DDRA                ;Release Clock Line
        jsr     highlow

loop    ror     byte
        bcs     mark

space   bset    data,DDRA               ;Clear Bit
        jmp     next

mark    bclr    data,DDRA               ;Clear Bit
        inca                            ;Parity Calculation

next    jsr     highlow                 ;Wait for high to low transition

        decx
        bne     loop

        and     #$01
        bne     clr_par
set_par bclr    data,DDRA
        jmp     tr_ackn
clr_par bset    data,DDRA
tr_ackn jsr     highlow

        bclr    data,DDRA               ;Release Data Line
        jsr     highlow
        brset   data,PORTA,error        ;Check for Ack
        brclr   clk,PORTA,*             ;Wait for idle line

        bset    clk,DDRA                ;Prevent Keyboard from sending data
                                        ;(Clear to Send)
        rts

error   lda     #$FF      ;Reset
        sta     byte
        jsr     transmit
        rts

*****************************************************
*                                                   *
* Receive - Get a Byte from the Keyboard. Result    *
*           stored in byte.                         *
*                                                   *
*****************************************************

Receive ldx     #08                     ;Number of Bits
        clr     PAR                     ;Clear Parity Register
        bclr    clk,DDRA                ;Clear to Send

        brset   clk,PORTA,*             ;wait for idle Clock
        brset   data,PORTA,Receive      ;False Start Bit, Restart

Recdata ror     byte
        jsr     highlow                 ;Wait for high to low Transision
        brset   data,PORTA,Recset

        bclr    7,byte
        jmp     Recnext

Recset  bset    7,byte
        inc     PAR

Recnext decx
        bne     Recdata                 ;Loop until 8 bits been received

        jsr     highlow

        lda     PORTA                   ;Read Parity Bit
        rola                            ;Place in LSbit
        rola
        eor     PAR                     ;Parity Bit Detection
        and     #$01
        beq     r_error

        jsr     highlow
        brclr   data,PORTA,r_error      ;Stop Bit Detection

        bset    clk,DDRA                ;Prevent Keyboard from sending data
                                        ;(Clear to Send)
        rts

r_error lda     #$FE                    ;Resend
        sta     byte
        jsr     Transmit
        jmp     Receive                 ;Try again

*****************************************************
*                                                   *
* highlow - Waits for next High to Low Transistion  *
*           on the Clock Line                       *
*                                                   *
*****************************************************


highlow brclr   clk,PORTA,*         ;Loop until Clk High
        brset   clk,PORTA,*         ;Loop until Clk Low
        rts

*****************************************************
*                                                   *
* ctrlhex & althex - Make sure keys pressed are     *
* valid. If not, don't store them. Also converts    *
* ASCII to binary and stores them in the ASCII      *
* Storage Location                                  *
*                                                   *
*****************************************************

ctrlhex cmp     #'a'            ;Convert 'a' - 'f' to binary
        blo     he1_ran
        cmp     #'f'
        bhi     outrang
        sub     #$57
        jmp     store

he1_ran cmp     #'A'            ;Convert 'A' - 'F' to binary
        blo     altdec
        cmp     #'F'
        bhi     outrang
        sub     #$37
        jmp     store

altdec  cmp     #'0'            ;Convert '0' - '9' to binary
        blo     outrang
        cmp     #'9'
        bhi     outrang
        sub     #$30

store   ldx     asc+1           ;Shift Bytes Left
        stx     asc+0
        ldx     asc+2
        stx     asc+1
        sta     asc+2           ;Store as Binary
outrang jmp     main

*****************************************************
*                                                   *
* alt_rel Alt Released. (Decimal Enter Routine)     *
*         Once both the ALT keys have been released *
*         a calculation must be made to convert the *
*         bytes found in ASCII Storage to binary    *
*         for transmission.                         *
*                                                   *
*****************************************************

alt_rel lda     status          ;Decimal Calculation
        and     #$30
        bne     complet         ;One of the Alt Keys Still Pressed

        lda     asc
        ldx     #$64    ;x 100
        mul
        sta     byte

        lda     asc+1
        ldx     #$0A    ;x 10
        mul
        add     asc+2   ;Add Units
        add     byte    ;Add hundreds
        sta     byte

        jsr     RS232T  ;Transmit number

        jmp     main    ;Return to Main.

*****************************************************
*                                                   *
* ctrl_re Ctrl Released.(Hexadecimal Enter Routine) *
*         Once both the CTRL keys have been released*
*         a calculation must be made to convert the *
*         bytes found in ASCII Storage to binary    *
*         for transmission.                         *
*                                                   *
*****************************************************

ctrl_re lda     status
        and     #$C0
        bne     complet         ;One of the Ctrl Keys Still Pressed

        lda     asc+1
        lsla
        lsla
        lsla
        lsla
        add     asc+2
        sta     byte

        jsr     RS232T          ;Transmit Number

complet jmp     main            ;Return to Main

*****************************************************
*                                                   *
* clrasc - Clear ASCII Storage Locations (3 Bytes)  *
*        - These storage bytes are used for the     *
*          ALTDEC & CTRLHEX Routines.               *
*                                                   *
*****************************************************

clrasc  clr     asc+0
        clr     asc+1
        clr     asc+2
        jmp     main

*****************************************************
*                                                   *
* RS-232 NRZ 8N1 Transmit Routine.                  *
*                                                   *
* Uses a 4.00 Mhz Crystal (2 Mhz Bus Speed)         *
* to obtain a transmission speed of 9600 BPS        *
*                                                   *
*****************************************************

RS232T  ldx     #8        ; Number of Bits (8)
        bclr    TXD,PORTB ; Start Bit (0)
        lda     #$1D      ; 29 Cycles 6[29] + 6
        jsr     delay
        brn     *
        nop
        nop
nextbit ror     byte
        bcs     rsmark
        bclr    TXD,PORTB ; Space (Logic 0)
        jmp     rsnext
rsmark  bset    TXD,PORTB ; Mark (Logic 1)
        brn     *
rsnext  lda     #$1C      ; 28 Cycles 6[28] + 6
        jsr     delay
        nop
        nop
        decx
        bne     nextbit
        brn     *
        brn     *
        nop
        bset    TXD,PORTB ; Stop Bit (Logic 1)
        lda     #$1F      ; 31 Cycles 6[31] + 6
        jsr     delay
        rts

delay   deca              ; Delay = 6[A] + 6
        bne     delay
        rts

*****************************************************
*                                                   *
*   No-Shift - Lookup Table when Shift not Pressed  *
*                                                   *
*****************************************************

⌨️ 快捷键说明

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