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

📄 spi_master.lst

📁 DDS之AD9910驱动源码
💻 LST
📖 第 1 页 / 共 3 页
字号:
ARM COMPILER V2.53,  SPI_Master                                                            25/11/08  15:54:12  PAGE 1   


ARM COMPILER V2.53, COMPILATION OF MODULE SPI_Master
OBJECT MODULE PLACED IN SPI_Master.OBJ
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe SPI_Master.c THUMB BROWSE DEBUG TABS(4) 

stmt  level    source

    1          /***************************************************************************
    2          
    3           Author        : Neil Zhao - CAST
    4          
    5           Date          : Nov 20th, 2008
    6          
    7           File          : SPI_Master.c
    8          
    9           Hardware      : ADuC7026 and AD9910
   10          
   11           Description   : Use the GPIO to simulate the SPI communication of AD9910
   12          
   13                  
   14          ***************************************************************************/
   15          
   16          #include<ADuC7026.h>    
   17          #include<Common.h>  
   18          
   19          void delay (signed int length)
   20          {
   21   1          while (length >0)
   22   1              length--;
   23   1      }
   24          
   25          //---------------------------------
   26          //WriteToAD9910ViaSpi();
   27          //---------------------------------
   28          //Function that writes to the AD9910 via the SPI port. It sends first the control
   29          //word that includes the start address and then the data to write.
   30          //--------------------------------------------------------------------------------
   31          void WriteToAD9910ViaSpi(unsigned char RegisterAddress, unsigned char NumberofRegisters, unsigned int *Re
             -gisterData)
   32          {
   33   1          unsigned    char    ControlValue = 0;
   34   1          unsigned    int     ValueToWrite = 0;
   35   1          signed      char    RegisterIndex = 0;
   36   1          unsigned    char    i = 0;
   37   1      
   38   1          //Create the 8-bit header
   39   1          ControlValue = RegisterAddress;
   40   1      
   41   1          CLR_SCL();
   42   1          delay(1);
   43   1          SET_CS();
   44   1          delay(1);
   45   1          CLR_CS();    //bring CS low
   46   1          delay(1);
   47   1      
   48   1          //Write out the control word
   49   1          for(i=0; i<8; i++)
   50   1          {
   51   2              CLR_SCL();
   52   2              if(0x80 == (ControlValue & 0x80))
   53   2              {
   54   3                  SET_SDIO();   //Send one to SDIO pin
   55   3              }
   56   2              else
   57   2              {
   58   3                  CLR_SDIO();   //Send zero to SDIO pin
ARM COMPILER V2.53,  SPI_Master                                                            25/11/08  15:54:12  PAGE 2   

   59   3              }
   60   2              delay(1);
   61   2              SET_SCL();
   62   2              delay(1);
   63   2              ControlValue <<= 1; //Rotate data
   64   2          }
   65   1          CLR_SCL();
   66   1          delay(2);
   67   1      
   68   1          //And then the data
   69   1          for (RegisterIndex=NumberofRegisters; RegisterIndex>0; RegisterIndex--)
   70   1          {
   71   2              ValueToWrite = *(RegisterData + RegisterIndex - 1);
   72   2              for (i=0; i<32; i++)
   73   2              {
   74   3                  CLR_SCL();
   75   3                  if(0x80000000 == (ValueToWrite & 0x80000000))
   76   3                  {
   77   4                      SET_SDIO();   //Send one to SDIO pin
   78   4                  }
   79   3                  else
   80   3                  {
   81   4                      CLR_SDIO();   //Send zero to SDIO pin
   82   4                  }
   83   3                  delay(1);
   84   3                  SET_SCL();
   85   3                  delay(1);
   86   3                  ValueToWrite <<= 1; //Rotate data
   87   3              }
   88   2          }
   89   1          CLR_SCL();
   90   1          delay(1);
   91   1          SET_CS();   //bring CS high again
   92   1          IO_Update();
   93   1      }
   94          
   95          //---------------------------------
   96          //ReadFromAD9910ViaSpi();
   97          //---------------------------------
   98          //Function that reads from the AD9910 via the SPI port. It first send the control word
   99          //that includes the start address and then 32 clocks for each register to read.
  100          //--------------------------------------------------------------------------------
  101          void ReadFromAD9910ViaSpi(unsigned char RegisterAddress, unsigned char NumberofRegisters, unsigned int *R
             -egisterData)
  102          {
  103   1          unsigned    char    ControlValue = 0;
  104   1          signed      char    RegisterIndex = 0;
  105   1          unsigned    int     ReceiveData = 0;
  106   1          unsigned    char    i = 0;
  107   1          unsigned    int     iTemp = 0;
  108   1      
  109   1          //Create the 8-bit header
  110   1          ControlValue = RegisterAddress;
  111   1      
  112   1          CLR_SCL();
  113   1          delay(1);   
  114   1          SET_CS();
  115   1          delay(1);
  116   1          CLR_CS();    //bring CS low
  117   1          delay(1);
  118   1      
  119   1          //Write out the control word
  120   1          for(i=0; i<8; i++)
  121   1          {
  122   2              CLR_SCL();
  123   2              if(0x80 == (ControlValue & 0x80))
ARM COMPILER V2.53,  SPI_Master                                                            25/11/08  15:54:12  PAGE 3   

  124   2              {
  125   3                  SET_SDIO();   //Send one to SDIO pin
  126   3              }
  127   2              else
  128   2              {
  129   3                  CLR_SDIO();   //Send zero to SDIO pin
  130   3              }
  131   2              delay(1);
  132   2              SET_SCL();
  133   2              delay(1);
  134   2              ControlValue <<= 1; //Rotate data
  135   2          }
  136   1          CLR_SCL();
  137   1          delay(2);
  138   1      
  139   1          //Read data in
  140   1          for (RegisterIndex=NumberofRegisters; RegisterIndex>0; RegisterIndex--)
  141   1          {
  142   2              for(i=0; i<32; i++)
  143   2              {
  144   3                  CLR_SCL();
  145   3                  delay(1);
  146   3                  SET_SCL();
  147   3                  ReceiveData <<= 1;      //Rotate data
  148   3                  iTemp = GP4DAT;         //Read SDO of AD9910
  149   3                  if(0x00000010 == (iTemp & 0x00000010))
  150   3                  {
  151   4                      ReceiveData |= 1;   
  152   4                  }
  153   3                  delay(1);
  154   3              }
  155   2              *(RegisterData + RegisterIndex - 1) = ReceiveData;
  156   2          }
  157   1          CLR_SCL();
  158   1          delay(1);
  159   1          SET_CS();   //bring CS high again
  160   1      } 
ARM COMPILER V2.53,  SPI_Master                                                            25/11/08  15:54:12  PAGE 4   

ASSEMBLY LISTING OF GENERATED OBJECT CODE



*** EXTERNALS:
 EXTERN CODE16 (IO_Update?T)



*** PUBLICS:
 PUBLIC         delay?T
 PUBLIC         WriteToAD9910ViaSpi?T
 PUBLIC         ReadFromAD9910ViaSpi?T



*** CODE SEGMENT '?PR?delay?T?SPI_Master':
   19: void delay (signed int length)
 00000000  ---- Variable 'length' assigned to Register 'R0' ----
   21:     while (length >0)
 00000000  E000      B           L_1  ; T=0x00000004
 00000002          L_3:
 00000002  3801      SUB         R0,#0x1
 00000004          L_1:
 00000004  1C01      MOV         R1,R0 ; length
 00000006  2900      CMP         R1,#0x0 ; length
 00000008  DCFB      BGT         L_3  ; T=0x00000002
   23: }
 0000000A  4770      BX          R14
 0000000C          ENDP ; 'delay?T'


*** CODE SEGMENT '?PR?WriteToAD9910ViaSpi?T?SPI_Master':
   31: void WriteToAD9910ViaSpi(unsigned char RegisterAddress, unsigned char NumberofRegisters, unsigned int *RegisterDa
             -ta)
 00000000  B5F0      PUSH        {R4-R7,LR}
 00000002  ---- Variable 'RegisterData' assigned to Register 'R2' ----
 00000002  1C0E      MOV         R6,R1 ; NumberofRegisters
 00000004  ---- Variable 'NumberofRegisters' assigned to Register 'R6' ----
 00000004  1C07      MOV         R7,R0 ; RegisterAddress
 00000006  ---- Variable 'RegisterAddress' assigned to Register 'R7' ----
 00000006  B081      SUB         R13,#0x4
   32: {
 00000008            ; SCOPE-START
   33:     unsigned    char    ControlValue = 0;
 00000008  2100      MOV         R1,#0x0
 0000000A  A800      ADD         R0,R13,#0x0
 0000000C  7001      STRB        R1,[R0,#0x0] ; ControlValue
   34:     unsigned    int     ValueToWrite = 0;
 0000000E  2500      MOV         R5,#0x0
 00000010  ---- Variable 'ValueToWrite' assigned to Register 'R5' ----
   35:     signed      char    RegisterIndex = 0;
 00000010  2400      MOV         R4,#0x0
 00000012  ---- Variable 'RegisterIndex' assigned to Register 'R4' ----
   36:     unsigned    char    i = 0;
 00000012  2300      MOV         R3,#0x0
 00000014  ---- Variable 'i' assigned to Register 'R3' ----
   39:     ControlValue = RegisterAddress;
 00000014  1C39      MOV         R1,R7 ; RegisterAddress
 00000016  A800      ADD         R0,R13,#0x0
 00000018  7001      STRB        R1,[R0,#0x0] ; ControlValue
   41:     CLR_SCL();
 0000001A  4800      LDR         R0,=0xFFFFF430
 0000001C  6801      LDR         R1,[R0,#0x0]
 0000001E  4800      LDR         R0,=0x40000
 00000020  4381      BIC         R1,R0
 00000022  4800      LDR         R0,=0xFFFFF430
 00000024  6001      STR         R1,[R0,#0x0]
   42:     delay(1);
 00000026  2001      MOV         R0,#0x1

⌨️ 快捷键说明

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