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

📄 csr_1.asm

📁 Button 一个国外大学生毕业设计,用的是AVR单片机
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 CSR_1_EnableSwitch:
_CSR_1_EnableSwitch:

	RAM_PROLOGUE RAM_USE_CLASS_4
    RAM_SETPAGE_CUR >CSR_1_bBitMask
                                                 ; Setup Mux for switch
    mov  [CSR_1_bBitMask],A                      ; Store bit mask in temp location
   	M8C_SetBank1
    mov  A,reg[X+MUX_OFFSET]
    or   A,[CSR_1_bBitMask]
    mov  reg[X+MUX_OFFSET],A
	M8C_SetBank0

	and reg[CSR_1_ACE_CONTROL1_REG], ~0x40          ; turn off comparator output
    CSR_1_Start_CMP_M                            ; Enable power of comparator
   
    mov  A,X                                     ; Multiply port number by four for registor addresses
    asl  A
    asl  A
    mov  X,A                                     ; Restore Port address in X

                                                 ; Set mode do 110  (Hi-Z Analog)
    mov  A,reg[X+DM2_OFFSET]                     ; Set DM2 to 1
    or   A,[CSR_1_bBitMask]
    mov  reg[X+DM2_OFFSET],A

   	M8C_SetBank1
    mov  A,reg[X+DM1_OFFSET]                     ; Set DM1 to 1
    or   A,[CSR_1_bBitMask]
    mov  reg[X+DM1_OFFSET],A

	or reg[CSR_1_ACE_CONTROL1_REG], 0x40            ; turn on comparator output

    xor  [CSR_1_bBitMask],0xFF                   ; Invert bitmask
    mov  A,reg[X+DM0_OFFSET]                     ; Clear DM0 bit to 0
    and  A,[CSR_1_bBitMask]
    mov  reg[X+DM0_OFFSET],A
	M8C_SetBank0

	RAM_EPILOGUE RAM_USE_CLASS_4
    ret

.ENDSECTION



.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSR_1_DisableSwitch(BYTE bMask, BYTE bPort)
;
;  DESCRIPTION:
;    Configures switch not to be an input.  The Drive mode is changed to strong
;    and set to zero (001).  The mux is also turned off.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    
;          X =>  Port Number for given key
;          A =>  Bit mask for given switch
;
;  RETURNS:      none    
;
;  SIDE EFFECTS: 
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 CSR_1_DisableSwitch:
_CSR_1_DisableSwitch:

	RAM_PROLOGUE RAM_USE_CLASS_4
    RAM_SETPAGE_CUR >CSR_1_bBitMask
                                                 ; Disconnect switch from mux
    cpl  A                                       ; Invert bitmask
    mov  [CSR_1_bBitMask],A                      ; Store bit mask in temp location
   	M8C_SetBank1
    mov  A,reg[X+MUX_OFFSET]
    and  A,[CSR_1_bBitMask]
    mov  reg[X+MUX_OFFSET],A
   	M8C_SetBank0
    
    mov  A,X                                     ; Multiply port number by for for registor addresses
    asl  A
    asl  A
    mov  X,A                                     ; Restore Port address in X

                                                 ; Write a 0 to the bit
    mov  A,reg[X+DR_OFFSET]        
    and  A,[CSR_1_bBitMask]
    mov  reg[X+DR_OFFSET],A
                                                 ; Set mode do 001  (Digital Strong)
    mov  A,reg[X+DM2_OFFSET]                     ; Set DM2 to 0
    and  A,[CSR_1_bBitMask]
    mov  reg[X+DM2_OFFSET],A

   	M8C_SetBank1
    mov  A,reg[X+DM1_OFFSET]                     ; Set DM1 to 0
    and  A,[CSR_1_bBitMask]
    mov  reg[X+DM1_OFFSET],A

    xor  [CSR_1_bBitMask],0xFF                   ; Invert bitmask back to normal
    mov  A,reg[X+DM0_OFFSET]                     ; Set DM0 bit to 1
    or   A,[CSR_1_bBitMask]
    mov  reg[X+DM0_OFFSET],A
	M8C_SetBank0

	RAM_EPILOGUE RAM_USE_CLASS_4
    ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSR_1_StartScan(BYTE bStrtIdx, BYTE bSwCnt, BYTE bMode)
;
;  DESCRIPTION:
;  This function starts scanning of a switch or set of switches. The three
;  parameters allow scanning to start at any location in the switch array
;  and scan n keys, either once or continuously.  this function assumes
;  that the start function was executed prior to it's execution. 
; 
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    
;      bStrtIdx [SP-3]  => Starting Switch Index
;      bSwCnt   [SP-4]  => Switch count to scan
;      bMode    [SP-5]  => Scan mode
;           0x00  => Scan key/s just one time.
;           0x01  => Scan continuous
;
;  RETURNS:      None
;  SIDE EFFECTS: 
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
; Stack offset constants
SSC_STRT_IDX:    equ  -3
SSC_SW_CNT:      equ  -4
SSC_MODE:        equ  -5

 CSR_1_StartScan:
_CSR_1_StartScan:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >CSR_1_bfStatus 

   CSR_1_DisableInt_M                            ; Disable Interrupts 
   CSR_1_Stop_M                                  ; Stop counter and scan pwm
   mov   X, SP                                   ; Get pointer to parameters
   mov   A, [X+SSC_STRT_IDX]                     ; Move Start Index parameter to static variable.
   mov   [CSR_1_bScanStart],A

   add   A, [X+SSC_SW_CNT]                       ; Add Switch count to Index to get last switch + 1
   dec   A                                       ; Make Last switch, not last siwtch + 1
   mov   [CSR_1_bScanEnd],A                      ; Store End scan in static variable

   mov   A, [X+SSC_MODE]                         ; Move mode into static status variable
   and   A,0x01                                  ; Mask off only the flag
   mov   [CSR_1_bfStatus],A

  ; Reset counter
   mov   reg[CSR_1_CTR_PERIOD_LSB_REG],0xFF
   mov   reg[CSR_1_CTR_PERIOD_MSB_REG],0xFF
   
   mov   A, [CSR_1_bPWMPeriod]
   mov   reg[CSR_1_PWM_PERIOD_REG], A            ; Set PWM period

   or   [CSR_1_bfStatus],CSR_1_SCAN_ACTIVE       ; Set scan active flag

   CSR_1_Start_M                                 ; Start counter and scan pwm
   CSR_1_EnableInt_M                             ; Enable the scan pwm IRQ

   mov   A,[CSR_1_bScanStart]
   mov   [CSR_1_bSwitchNum],A                    ; Set up for first switch
   lcall CSR_1_iGetPortPin                       ; Get switch port and mask
   lcall CSR_1_EnableSwitch                      ; Enable first switch

   RAM_EPILOGUE RAM_USE_CLASS_4
   ret

.ENDSECTION



.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSR_1_StopScan(void)
;
;  DESCRIPTION:
;   This functions stops the switch scanning process in an orderly method.
;    
; 
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    None
;   
;  RETURNS:      None
;  SIDE EFFECTS: 
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 CSR_1_StopScan:
_CSR_1_StopScan:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >CSR_1_bfStatus 
   and   [CSR_1_bfStatus],~CSR_1_SCAN_CONTINUOUS 
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret

.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSR_1_GetScanStatus(void)
;
;  DESCRIPTION:
;   This function returns the scan status and resets the SCAN_SET_COMPLETE
;   bit.
;    
; 
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    None
;   
;  RETURNS:      
;     A => Scan status
;
;  SIDE EFFECTS: 
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 CSR_1_GetScanStatus:
_CSR_1_GetScanStatus:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_IDX >CSR_1_bfStatus 

   CSR_1_DisableInt_M
   mov   A,[CSR_1_bfStatus] 
   and   [CSR_1_bfStatus],~CSR_1_SCAN_SET_COMPLETE             ; Clear scan complete flag
   tst   [CSR_1_bfStatus],CSR_1_SCAN_ACTIVE                    ; Check if scanning is active
   jz    .NoReEnable                                           ; Don't re-enable if not running 
   CSR_1_EnableInt_M
.NoReEnable:

   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSR_1_iReadSwitch(BYTE bSwitch)
;
;  DESCRIPTION:
;     Returns the key scan value in A (LSB) and X (MSB)      
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:   
;    A = Switch number
;  RETURNS:     
;    Scan value of switch LSB in A and MSB in X
;  SIDE EFFECTS: 
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 CSR_1_iReadSwitch:
_CSR_1_iReadSwitch:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_IDX >CSR_1_iaSwResult 
   asl   A                                       ; Multiply by two since results are INTs
   mov   X,A
   CSR_1_DisableInt_M
   mov   A,[X+(CSR_1_iaSwResult+LSB)]
   mov   X,[X+(CSR_1_iaSwResult+MSB)]
   CSR_1_EnableInt_M
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSR_1_SetDacCurrent(BYTE bValue, BYTE bRange)
;
;  DESCRIPTION:
;      This function sets the DAC current for the oscillator.  
;     
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    
;        A => Dac Value 0 to 255
;        A => Dac Range 0 => low range, 1 => High range
;  RETURNS:    
;        none
;
;  SIDE EFFECTS: 
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 CSR_1_SetDacCurrent:
_CSR_1_SetDacCurrent:

  RAM_PROLOGUE RAM_USE_CLASS_1
   mov    reg[DAC_D], A                          ; Set Dac at medium level
   mov    A,X                                    ; Put Dac range in A

   M8C_SetBank1
   and    A,0x01                                 ; Check for high range
   jz     .SET_LOW_RANGE
   or     reg[DAC_CR],0x08                       ; Set high range
   jmp    .SDC_DONE

.SET_LOW_RANGE:
   and    reg[DAC_CR],~0x08                      ; Set low range

.SDC_DONE:
   M8C_SetBank0
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSR_1_setScanSpeed(BYTE bDivider)
;
;  DESCRIPTION:
;      This function sets the speed of the button scan.
;      In frequency mode, this value sets the period of the PWM signal that
;      gates the frequency measurement of the cap sense oscillator.  A larger
;      value for bDivider allows the counter to accumulate more oscillator
;      counts for more resolution.
;      In period mode, bDivider sets the prescaller for the cap sense oscillator.
;      The larger this value the more periods that the 24 MHz clock is counted.
;     
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    
;        A => PWM period,  PWM compare = period - 6
;  RETURNS:    
;       none
;
;  SIDE EFFECTS: 
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 CSR_1_SetScanSpeed:
_CSR_1_SetScanSpeed:

  RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >CSR_1_bPWMPeriod 
   mov    [CSR_1_bPWMPeriod], A
   mov    reg[CSR_1_PWM_PERIOD_REG], A           ; Set PWM period
   sub    A,2                                        ; Allow enough time to enter the interrupt and shutoff the PWM
   mov    reg[CSR_1_PWM_COMPARE_REG], A          ; Set PWM compare time         
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

⌨️ 快捷键说明

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