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

📄 readadc0.s

📁 dspic30f6010a的学习事例程序
💻 S
字号:
 /**********************************************************************
 *                                                                     *
 *                        Software License Agreement                   *
 *                                                                     *
 *    The software supplied herewith by Microchip Technology           *
 *    Incorporated (the "Company") for its dsPIC controller            *
 *    is intended and supplied to you, the Company's customer,         *
 *    for use solely and exclusively on Microchip dsPIC                *
 *    products. The software is owned by the Company and/or its        *
 *    supplier, and is protected under applicable copyright laws. All  *
 *    rights are reserved. Any use in violation of the foregoing       *
 *    restrictions may subject the user to criminal sanctions under    *
 *    applicable laws, as well as to civil liability for the breach of *
 *    the terms and conditions of this license.                        *
 *                                                                     *
 *    THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION.  NO           *
 *    WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING,    *
 *    BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND    *
 *    FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE     *
 *    COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,  *
 *    INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.  *
 *                                                                     *
  **********************************************************************/
;*******************************************************************
; ReadADC0 and ReadSignedADC0
;  
;Description:        
;  Read Channel 0 of ADC, scale it using qK and put results in qADValue.
;  Do not call this routine until conversion is completed.
;
;  ReadADC0 range is qK*(0.0 ->0.9999).
;  ReadSignedADC0 range is qK*(-1.0 ->0.9999).
;
;  Scaling constant, qK, must be set elsewhere such that
;         iResult = 2 * qK * ADCBUF0
;  The factor of 2 is designed to allow qK to be given in 1.15.
;
;
;Functional prototype:
; 
; void ReadADC0( tReadADCParm* pParm )       : Calculates unsigned value 0 -> 2*qK
; void ReadSignedADC0( tReadADCParm* pParm ) : Calculates signed value -2*qK -> 2*qK
;
;On Entry:   ReadADCParm structure must contain qK. ADC channel 0
;            must contain signed fractional value.
;
;On Exit:    ReadADCParm will contain qADValue
;
;Parameters: 
; Input arguments: None
;
; Return:
;   Void
;
; SFR Settings required:
;         CORCON.SATA  = 0
;     If there is any chance that Accumulator will overflow must set
;         CORCON.SATDW = 1  
;
; Support routines required: None
;
; Local Stack usage: None
;
; Registers modified: w0,w4,w5
;
; Timing: 13 cycles
;
;*******************************************************************
;
          .include "general.inc"

; External references
          .include "ReadADC.inc"

; Register usage
          .equ ParmBaseW,w0  ; Base of parm structure
          .equ Work0W,   w4
          .equ Work1W,   w5



;=================== CODE =====================

          .section  .text
          .global   _ReadADC0
          .global   ReadADC0

_ReadADC0:
ReadADC0:

     ;; iResult = 2 * qK * ADCBUF0

          mov.w     [ParmBaseW+ADC_qK],Work0W
          mov.w     _ADCBUF0,Work1W

     ;; change from signed fractional to fractional, i.e. convert
     ;; from -1->.9999 to 0 -> 0.9999
          btg       Work1W,#15
          lsr.w     Work1W,Work1W

          mpy       Work0W*Work1W,A
          sac       A,#-1,Work0W
          mov.w     Work0W,[ParmBaseW+ADC_qADValue]
          return


          .global   _ReadSignedADC0
          .global   ReadSignedADC0

_ReadSignedADC0:
ReadSignedADC0:

     ;; iResult = 2 * qK * ADCBUF0

          mov.w     [ParmBaseW+ADC_qK],Work0W
          mov.w     _ADCBUF0,Work1W

          mpy       Work0W*Work1W,A
          sac       A,#-1,Work0W
          mov.w     Work0W,[ParmBaseW+ADC_qADValue]
          return

          .end

⌨️ 快捷键说明

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