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

📄 spi.lst

📁 AT25320-AT251024的SPI控制程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
ARM COMPILER V2.53,  spi                                                                   19/12/07  10:53:13  PAGE 1   


ARM COMPILER V2.53, COMPILATION OF MODULE spi
OBJECT MODULE PLACED IN .\Obj\spi.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe spi.c THUMB INCDIR(..\Common\inc) DEBUG PRINT(.\LST\SPI.LST) TABS(4) OBJECT(
                    -.\Obj\spi.obj) 

stmt  level    source

    1          /*****************************************************************************
    2           *   spi.c:  SPI C file for Philips LPC214x Family Microprocessors
    3           *
    4           *   Copyright(C) 2006, Philips Semiconductor
    5           *   All rights reserved.
    6           *
    7           *   History 如果是25320以上的要写入三个字节的地址.......
    8           *   2005.10.01  ver 1.00    Prelimnary version, first Release
    9           *
   10          *****************************************************************************/
   11          #include "LPC214x.h"            /* LPC21XX Peripheral Registers */
   12          #include "type.h"
   13          #include "irq.h"
   14          #include "spi.h"
   15          
   16          volatile DWORD SPI0Status = 0;
   17          volatile DWORD TxCounter = 0;
   18          
   19          /*****************************************************************************
   20          ** Function name:       SPI0Handler
   21          **
   22          ** Descriptions:        SPI0 interrupt handler
   23          **
   24          ** parameters:          None
   25          ** Returned value:      None
   26          ** 
   27          *****************************************************************************/
   28          void SPI0Handler (void) __irq 
   29          {
   30   1          DWORD regValue;
   31   1        
   32   1          S0SPINT = SPI0_INT_FLAG;        /* clear interrupt flag */
   33   1          IENABLE;                /* handles nested interrupt */
   34   1      
   35   1          regValue = S0SPSR;
   36   1          if ( regValue & WCOL )
   37   1          {
   38   2          SPI0Status |= SPI0_COL;
   39   2          }
   40   1          if ( regValue & SPIF )
   41   1          {
   42   2          SPI0Status |= SPI0_TX_DONE;
   43   2          TxCounter++;
   44   2          }
   45   1          IDISABLE;
   46   1          VICVectAddr = 0;        /* Acknowledge Interrupt */
   47   1      }
   48          
   49          /*****************************************************************************
   50          ** Function name:       SPIInit
   51          **
   52          ** Descriptions:        SPI port initialization routine
   53          **              
   54          ** parameters:          None
   55          ** Returned value:      true or false, if the interrupt handler
   56          **              can't be installed correctly, return false.
   57          ** 
   58          *****************************************************************************/
ARM COMPILER V2.53,  spi                                                                   19/12/07  10:53:13  PAGE 2   

   59          DWORD SPIInit( void )
   60          {
   61   1          TxCounter = 0;
   62   1      
   63   1          S0SPCR = 0x00;
   64   1          PINSEL0 &= 0xFFFF00FF;
   65   1          PINSEL0 |= 0x00001500;
   66   1          IODIR0 = SPI0_SEL;
   67   1          IOSET0 = SPI0_SEL;
   68   1      
   69   1          /* Setting SPI0 clock, for Atmel SEEPROM, SPI clock should be no more 
   70   1          than 3Mhz on 4.5V~5.5V, no more than 2.1Mhz on 2.7V~5.5V */
   71   1          S0SPCCR = 0x8;
   72   1      #if INTERRUPT_MODE
                 if ( install_irq( SPI0_INT, (void *)SPI0Handler ) == FALSE )
                   {
                   return (FALSE);
                   }
                   /* 8 bit, CPOL=CPHA=0, master mode, MSB first, interrupt enabled */
                   S0SPCR = SPI0_SPIE | SPI0_MSTR;
               #else
   80   1          S0SPCR = SPI0_MSTR;
   81   1      #endif
   82   1          return( TRUE );
   83   1      }
   84          
   85          /*****************************************************************************
   86          ** Function name:       SPISend
   87          **
   88          ** Descriptions:        Send a block of data to the SPI port, the first
   89          **              parameter is the buffer pointer, the 2nd 
   90          **              parameter is the block length.
   91          **
   92          ** parameters:          buffer pointer, and the block length
   93          ** Returned value:      None
   94          ** 
   95          *****************************************************************************/
   96          void SPISend( BYTE *buf, DWORD Length )
   97          {
   98   1          DWORD i;
   99   1          BYTE Dummy;
  100   1      
  101   1          if ( Length == 0 )
  102   1          return;
  103   1          for ( i = 0; i < Length; i++ )
  104   1          {
  105   2          S0SPDR = *buf;
  106   2      #if INTERRUPT_MODE
                   /* In the interrupt, there is nothing to be done if TX_DONE, SPI transfer 
                   complete bit, is not set, so it's polling if the flag is set or not which 
                   is being handled inside the ISR. Not an ideal example but show how the 
                   interrupt is being set and handled. */ 
                   while ( (SPI0Status & SPI0_TX_DONE) != SPI0_TX_DONE );
                   SPI0Status &= ~SPI0_TX_DONE;
               #else
  114   2          while ( !(S0SPSR & SPIF) );
  115   2      #endif
  116   2          Dummy = S0SPDR;     /* Flush the RxFIFO */
  117   2          buf++;
  118   2          }
  119   1          return; 
  120   1      }
  121          
  122          /*****************************************************************************
  123          ** Function name:       SPIReceive
  124          ** Descriptions:        the module will receive a block of data from 
ARM COMPILER V2.53,  spi                                                                   19/12/07  10:53:13  PAGE 3   

  125          **              the SPI, the 2nd parameter is the block length.
  126          ** parameters:          buffer pointer, and block length
  127          ** Returned value:      None
  128          ** 
  129          *****************************************************************************/
  130          void SPIReceive( BYTE *buf, DWORD Length )
  131          {
  132   1          DWORD i;
  133   1      
  134   1          for ( i = 0; i < Length; i++ )
  135   1          {
  136   2          *buf = SPIReceiveByte();
  137   2          buf++;
  138   2          }
  139   1          return; 
  140   1      }
  141          
  142          /*****************************************************************************
  143          ** Function name:       SPIReceiveByte
  144          **
  145          ** Descriptions:        Receive one byte of data from the SPI port
  146          **              Write a dummy byte, wait until SPI transfer
  147          **              complete, then, read the data register to
  148          **              get the SPI data.
  149          **
  150          ** parameters:          None
  151          ** Returned value:      the data byte received
  152          ** 
  153          *****************************************************************************/
  154          BYTE SPIReceiveByte( void )
  155          {
  156   1          BYTE data;
  157   1      
  158   1          /* wrtie dummy byte out to generate clock, then read data from MISO */
  159   1          S0SPDR = 0xFF;
  160   1          /* Wait for transfer complete, SPIF bit set */
  161   1      #if INTERRUPT_MODE
                   /* In the receive routine, there is nothing to be done if TX_DONE, or
                   SPI transfer complete bit, is not set, so it's polling if the flag is set 
                   or not which is being handled inside the ISR. Not an ideal example but 
                   show how the interrupt is being set and handled. */ 
                   while ( (SPI0Status & SPI0_TX_DONE) != SPI0_TX_DONE );
                   SPI0Status &= ~SPI0_TX_DONE;
               #else
  169   1          while ( !(S0SPSR & SPIF) );
  170   1      #endif
  171   1          data = S0SPDR;
  172   1          return ( data ); 
  173   1      }
  174          
  175          /******************************************************************************
  176          **                            End Of File
  177          ******************************************************************************/
  178          
ARM COMPILER V2.53,  spi                                                                   19/12/07  10:53:13  PAGE 4   

ASSEMBLY LISTING OF GENERATED OBJECT CODE



*** PUBLICS:
 PUBLIC         SPI0Handler?A
 PUBLIC         SPIInit?T
 PUBLIC         SPISend?T
 PUBLIC         SPIReceive?T
 PUBLIC         SPIReceiveByte?T
 PUBLIC         SPI0Status
 PUBLIC         TxCounter



*** DATA SEGMENT '?DT0?spi':
 00000000          SPI0Status:
 00000000           BEGIN_INIT
 00000000  00000000  DD          0x0
 00000004           END_INIT
 00000004          TxCounter:
 00000004           BEGIN_INIT
 00000004  00000000  DD          0x0
 00000008           END_INIT



*** CODE SEGMENT '?PR?SPI0Handler?A?spi':
   28: void SPI0Handler (void) __irq 
 00000000  E92D4007  STMDB       R13!,{R0-R2,LR}
   29: {
 00000004            ; SCOPE-START
   32:     S0SPINT = SPI0_INT_FLAG;        /* clear interrupt flag */
 00000004  E3A01001  MOV         R1,#0x1
 00000008  E5100000  LDR         R0,=0xE002001C
 0000000C  E5801000  STR         R1,[R0,#0x0]

⌨️ 快捷键说明

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