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

📄 macro.inc

📁 用cy7c66113开发的HUB
💻 INC
📖 第 1 页 / 共 2 页
字号:
 MACRO  disable_128us_timer
    IORD    REG_GLOBAL_INT_ENABLE
    AND     A, ~MASK_128US
    IOWR    REG_GLOBAL_INT_ENABLE
 ENDM
;------------------------------------------------------------------------
; enable_GPIO_int
;------------------------------------------------------------------------
 MACRO  enable_GPIO_int
    IORD    REG_GLOBAL_INT_ENABLE
    OR      A, MASK_GPIO
    IOWR    REG_GLOBAL_INT_ENABLE
 ENDM
;------------------------------------------------------------------------
; disable_GPIO_int
;------------------------------------------------------------------------
 MACRO  disable_GPIO_int
    IORD    REG_GLOBAL_INT_ENABLE
    AND     A, ~MASK_GPIO
    IOWR    REG_GLOBAL_INT_ENABLE
 ENDM

 ; GPIO Macros
;------------------------------------------------------------------------
; set_port0_bit
;------------------------------------------------------------------------
 MACRO set_port3_bit mask               ; set Port 0 bit to 1
 ;   PUSH    A
 ; IORD    REG_PORT_3
 ;OR      A, mask
 ; IOWR    REG_PORT_3
 ; POP     A
 ENDM
;------------------------------------------------------------------------
; clr_port0_bit
;------------------------------------------------------------------------
 MACRO clr_port3_bit mask               ; clear Port 0 bit to 0
 ;  PUSH    A
 ;  IORD    REG_PORT_3
  ;AND     A, ~mask
  ; IOWR    REG_PORT_3
  ; POP     A
 ENDM
;------------------------------------------------------------------------
; toggle_port0_bit
;------------------------------------------------------------------------
 MACRO toggle_port0_bit mask               ; clear Port 0 bit to 0
;    PUSH    A
;    IORD    REG_PORT_2
;    OR      A, mask
;    IOWR    REG_PORT_2
;    NOP
;   AND     A, ~mask
;    write_A REG_PORT_2
;    POP     A
 ENDM


;************************************************************************
; Keyboard MACRO's
;************************************************************************
;------------------------------------------------------------------------
; enable_kb_address
; Enables USB address for SIE's response to this address
;------------------------------------------------------------------------
 MACRO enable_kb_address
    MOV     A, ~MASK_ADDRESS
    write_A REG_A_ADDRESS               ; clear device address, enable SIE
 ENDM
;------------------------------------------------------------------------
; enable_kb_ep0_int
;------------------------------------------------------------------------
 MACRO  enable_kb_ep0_int
    IORD    REG_EP_INT_ENABLE           ; enable the HUB EP0 interrupt
    OR      A, MASK_EPA0
    IOWR    REG_EP_INT_ENABLE
 ENDM
;------------------------------------------------------------------------
; disable_kb_ep0_int
;------------------------------------------------------------------------
 MACRO  disable_kb_ep0_int
    IORD    REG_EP_INT_ENABLE
    AND     A, ~MASK_EPA0
    IOWR    REG_EP_INT_ENABLE
 ENDM
;------------------------------------------------------------------------
; enable_kb_ep1_int
;------------------------------------------------------------------------
 MACRO  enable_kb_ep1_int
    IORD    REG_EP_INT_ENABLE           ; enable the HUB EP1 interrupt
    OR      A, MASK_EPA1
    IOWR    REG_EP_INT_ENABLE
 ENDM
;------------------------------------------------------------------------
; disable_kb_ep1_int
;------------------------------------------------------------------------
 MACRO  disable_kb_ep1_int
    IORD    REG_EP_INT_ENABLE
    AND     A, ~MASK_EPA1
    IOWR    REG_EP_INT_ENABLE
 ENDM
;------------------------------------------------------------------------
; enable_kb_ep2_int
;------------------------------------------------------------------------
 MACRO  enable_kb_ep2_int
    IORD    REG_EP_INT_ENABLE           ; enable the HUB EP1 interrupt
    OR      A, MASK_EPA2
    IOWR    REG_EP_INT_ENABLE
 ENDM
;------------------------------------------------------------------------
; disable_kb_ep1_int
;------------------------------------------------------------------------
 MACRO  disable_kb_ep2_int
    IORD    REG_EP_INT_ENABLE
    AND     A, ~MASK_EPA2
    IOWR    REG_EP_INT_ENABLE
 ENDM

;------------------------------------------------------------------------
; RAM CLEAR
;------------------------------------------------------------------------
; macro for clearing blocks of RAM
; destroys X and A
    MACRO   CLEARRAM base,length
    mov     X,length - 1
    mov     A,0
lp:
    mov     [X + base],A
    dec     X
    jnc     lp
    ENDM

;------------------------------------------------------------------------
; BIT Operation
;------------------------------------------------------------------------
;clear bit(s) in a RAM location
MACRO CLRBIT BIT REG
    mov A,~BIT
    and [REG],A
ENDM

;set bit(s) in a RAM location
MACRO SETBIT BIT REG
    mov A,BIT
    or  [REG],A
ENDM
  
;test bit(s) in a RAM location
MACRO TSTBIT BIT REG
    mov A,BIT
    and A,[REG]
ENDM

;clear carry
MACRO CLEARC
    or      A,0
ENDM
    
MACRO CLRC
    add     A,0
ENDM

;set carry
MACRO SETC
    cpl   A
    cpl   A
ENDM
   
;macro for packing 4 2-bit fields into a byte
MACRO TYPE a,b,c,d
    db  (a + b*4 + c*16 + d*64)
ENDM

;------------------------------------------------------------------------
; DELAY
;------------------------------------------------------------------------
; delay macro is the front-end for a call to the delay subroutine
; The fixed overhead of the macro plus the subroutine is 3 us,
; so this technique is good for delays of 4us or greater.
;

MACRO DELAY US
    push    A
    mov     A,(US-3)
    call    delay
ENDM

;===========================================================================
; This file defines a few custom-macros that are invoked from the generic
; code, to implement keyboard-specific functions
;===========================================================================
 
;kb_1ms_service is the code fragment that is inserted in-line in the 1-msec
;interrupt routine.  Use it to increment the keyboard time-based variables.

MACRO kb_1ms_service
    inc [1ms_counter]				;increment 1msec timer
    mov A,[1ms_counter]
    and A,3                         
    
    jnz .exit		                ;every 4 msec, do the following:

    mov A,[background_flags]		; set the flag to scan the keyboard
    or  A,SCAN_FLAG
    mov [background_flags],A
.exit:
    ENDM


;kb_enable_vsw is the code fragment that is inserted in-line in the code
;that powers on a port.  We only want to set the vsw bit in port 3 at this time

MACRO kb_enable_vsw
    MOV     A,[ksc_p3out]
    AND     A,~VSW_ENBL_BIT
    MOV     [ksc_p3out],A
    write_A REG_PORT_3
ENDM

;------------------------------------------------------------------------
;kb_suspend is the code fragment that gets executed just before the hub suspends.
;------------------------------------------------------------------------
MACRO kb_suspend
    clr_flag FLAG_GPIO              ;clear the GPIO flag
    mov     A, 0                    ; pull down the column lines
    iowr    REG_PORT_0
    iowr    REG_PORT_1
    mov     A,[ksc_p3out]           ;turn off the keyboard leds
    or      A,P3_LED_MASK
    iowr    REG_PORT_3
	mov A, FFh
	iowr Port2_Interrupt		    ; enable port 2 GPIO interrupt for keyboard
    enable_GPIO_int                 ; enable GPIO interrupt (for KB wakeup)
ENDM
;(KEYBOARD)
;------------------------------------------------------------------------
;kb_resume is the custom keyboard resume code
;------------------------------------------------------------------------
;
MACRO   kb_resume
    disable_GPIO_int                     ; disable this INT
    mov     A,0
    iowr    Port2_Interrupt
    mov     A, [ksc_p3out]              ;restore the leds
    iowr    REG_PORT_3
ENDM

 ;(KEYBOARD)

⌨️ 快捷键说明

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