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

📄 f06x_sar16data.lst

📁 // This program measures the voltage on an external ADC input and prints the // result to a termin
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   F06X_SAR16DATA                                                        02/15/2008 14:18:26 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE F06X_SAR16DATA
OBJECT MODULE PLACED IN F06x_SAR16data.OBJ
COMPILER INVOKED BY: C:\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe F06x_SAR16data.c DB OE

line level    source

   1          //------------------------------------------------------------------------------------
   2          // F06x_SAR16Data.c
   3          //------------------------------------------------------------------------------------
   4          // Copyright (C) 2005 Silicon Laboratories, Inc.
   5          //
   6          //
   7          // Data Acquisition example for 'F06x
   8          //
   9          // Target: C8051F060TB Target Board
  10          //
  11          // Description: This example illustrates the use of ADC1 and the DMA to acquire and store
  12          // data.  It is intended for use with the C8051F060TB target board in the development kit.
  13          //
  14          // This code measures a signal at the AIN0 input with the 16-bit SAR ADC0.
  15          // The data is sampled at a rate of 100kHz.  ADC output data is transferred to
  16          // XDATA memory space using the DMA.
  17          //
  18          // With the EMIF configured for off-chip XRAM access (on the upper ports),
  19          // this code moves the ADC data to the C8051F060TB target boards's SRAM device.
  20          // Once data acquisition is complete, the code then prompts the user to press the P3.7
  21          // button on the target board when ready to receive the data via the UART0 serial port.
  22          // The TB features an RS-232 transceiver and connector, so the data can be transferred
  23          // to a PC via its serial port.
  24          //
  25          // The code is set to acquire up to 32768 samples (for 64kbytes of data).  The SRAM device
  26          // can accommodate up to 128kbytes, but this requires banking (A16 signal on the SRAM).
  27          //
  28          // Target Board Configuration:  This example uses RS-232 communications, typically with
  29          // a PC.  A serial cable should be connected to the J5 RS-232 DB-9 connector on the
  30          // target board and to a serial port on a PC.  (A serial port will also be needed for
  31          // PC communications with the EC-2 serial adapter for programming and debug).
  32          // Data can be input from the PC's serial port using commonly available Hyperterminal.
  33          // The following target board jumpers must be configured (see user's guide for schematic):
  34          //
  35          //   J2: installed (voltage supply)
  36          //   J6 and J9: installed (RS-232 combs)
  37          //   J17 and J28: installed (external voltage reference for SIR)
  38          //   J11: installed (SRAM chip select)
  39          //   J14: Installed to connect to (SRAM) A16 to GND, and NOT P3.7 which will be used
  40          //        for push-button
  41          //   J1: Installed to connect P3.7 to push-button.
  42          //   J20: Installed to enable +/-5V switching power supply. Connect pin 1 (Van, +5V) to
  43          //        pin 2 (/SHIN).
  44          //
  45          // See the User's Guide for additional information and jumper connection information.
  46          //
  47          //--------------------------------------------------------------------------------------
  48          
  49          //--------------------------------------------------------------------------------------
  50          // Includes
  51          //--------------------------------------------------------------------------------------
  52          #include <c8051f060.h>                    // SFR declarations
  53          #include <stdio.h>
  54          
  55          //-----------------------------------------------------------------------------
C51 COMPILER V8.08   F06X_SAR16DATA                                                        02/15/2008 14:18:26 PAGE 2   

  56          // 16-bit SFR Definitions for 'F06x
  57          //-----------------------------------------------------------------------------
  58          
  59          sfr16 RCAP3    = 0xCA;                 // Timer3 reload value
  60          sfr16 TMR3     = 0xCC;                 // Timer3 counter
  61          
  62          sfr16 ADC0     = 0xBE;                 // ADC0 Data
  63          sfr16 ADC1     = 0xBE;                 // ADC1 Data
  64          
  65          sfr16 DMA0DS   = 0xDB;                 // DMA0 XRAM Address Pointer
  66          sfr16 DMA0CT   = 0xF9;                 // DMA0 Repeat Counter Limit
  67          sfr16 DMA0DA   = 0xD9;                 // DMA0 Address Beginning
  68          sfr16 DMA0CS   = 0xFB;                 // DMA0 Repeat Counter
  69          
  70          
  71          //------------------------------------------------------------------------------------
  72          // Global CONSTANTS
  73          //------------------------------------------------------------------------------------
  74          
  75          #define SYSCLK 22118400                   // SYSCLK frequency in Hz
  76          #define BAUDRATE 9600                   // Baud Rate for UART0
  77          
  78          // DMA INSTRUCTIONS
  79          #define DMA0_END_OF_OP     0x00           // End-of-Operation
  80          #define DMA0_END_OF_OP_C   0x80           // End-of-Operation + Continue
  81          #define DMA0_GET_ADC0      0x10           // Retrieve ADC0 Data
  82          #define DMA0_GET_ADC1      0x20           // Retrieve ADC1 Data
  83          #define DMA0_GET_ADC01     0x30           // Retrieve ADC0 and ADC1 Data
  84          #define DMA0_GET_DIFF      0x40           // Retrieve Differential Data
  85          #define DMA0_GET_DIFF1     0x60           // Retrieve Differential and ADC1 Data
  86          
  87          
  88          #define NUM_SAMPLES        8          // Number of ADC sample to acquire (each sample 2 bytes)
  89          #define XRAM_START_ADD     0x0000         // DMA0 XRAM Start address of ADC data log
  90          #define SAMP_RATE          100000         // ADC sample rate in Hz
  91          
  92          
  93          sbit LED = P0^7;                          // LED: '1' = ON; '0' = OFF
  94          sbit BUTTON = P3^7;                       // pushbutton on the target board
  95          sbit RAM_CS = P4^5;                       // chip select bit is P4^4
  96          
  97          //------------------------------------------------------------------------------------
  98          // Function PROTOTYPES
  99          //------------------------------------------------------------------------------------
 100          void SYSCLK_Init (void);
 101          void UART0_Init (void);
 102          void PORT_Init (void);
 103          void ADC0_Init (void);
 104          void ADC1_Init (void);
 105          void DMA0_Init (void);
 106          void Timer3_Init (int counts);
 107          void EMIF_Init (void);
 108          void SendData(void);
 109          
 110          //-------------------------
 111          // Global Variables
 112          //-------------------------
 113          unsigned char Conv_Complete = 0;
 114          unsigned int xdata * data read_ptr;
 115          
 116          //------------------------------------------------------------------------------------
 117          // MAIN Routine
C51 COMPILER V8.08   F06X_SAR16DATA                                                        02/15/2008 14:18:26 PAGE 3   

 118          //------------------------------------------------------------------------------------
 119          void main (void)
 120          {
 121   1         WDTCN = 0xde;                          // disable watchdog timer
 122   1         WDTCN = 0xad;
 123   1      
 124   1         SYSCLK_Init ();                        // initialize SYSCLK
 125   1      
 126   1         PORT_Init ();
 127   1      
 128   1         EMIF_Init ();                          // Storing ADC samples in SRAM on the
 129   1                                                // target board.
 130   1         SFRPAGE = CONFIG_PAGE;
 131   1      
 132   1         RAM_CS = 0;                            // assert SRAM chip select
 133   1      
 134   1         UART0_Init ();                         // initialize UART0
 135   1      
 136   1         Timer3_Init (SYSCLK/SAMP_RATE);        // Init Timer3 for 100ksps sample rate
 137   1      
 138   1         ADC0_Init ();                          // configure ADC0 and ADC1 for differential
 139   1                                                // measurement.
 140   1      
 141   1         DMA0_Init ();                          // Configure DMA to move NUM_SAMP samples.
 142   1      
 143   1      
 144   1         SFRPAGE = UART0_PAGE;
 145   1         printf ("Data Acquisition in progress...\n");
 146   1      
 147   1         SFRPAGE = DMA0_PAGE;                   // Switch to DMA0 Page
 148   1      
 149   1         while (!(DMA0CN & 0x40));              // Wait for DMA to obtain and move ADC samples
 150   1                                                // by polling DMA0INT bit.
 151   1      
 152   1         SFRPAGE = LEGACY_PAGE;
 153   1         printf ("Data Acquisition complete.\nPress P3.7 button when ready to receive file.\n");
 154   1      
 155   1         while (BUTTON != 0);                   // Wait for user to press P3.7 on the TB.
 156   1      
 157   1         SendData();                            // Send data via the UART0.
 158   1      
 159   1         while(1);                              // Done.
 160   1              
 161   1      
 162   1      }
 163          
 164          //------------------------------------------------------------------------------------
 165          // PORT_Init
 166          //------------------------------------------------------------------------------------
 167          //
 168          // Configure the Crossbar and GPIO ports
 169          //
 170          void PORT_Init (void)
 171          {
 172   1      char old_SFRPAGE = SFRPAGE;
 173   1      
 174   1         SFRPAGE = CONFIG_PAGE;              // Switch to configuration page
 175   1      
 176   1      
 177   1         XBR0    = 0x04;                     // Enable UART0 on crossbar
 178   1         XBR1    = 0x00;
 179   1         XBR2    = 0x40;                     // Enable crossbar and weak pull-ups
C51 COMPILER V8.08   F06X_SAR16DATA                                                        02/15/2008 14:18:26 PAGE 4   

 180   1         P0MDOUT |= 0xFF;                    // enable Port0 outputs as push-pull
 181   1      
 182   1         SFRPAGE = old_SFRPAGE;              // restore SFRPAGE
 183   1      }
 184          
 185          //-----------------------------------------------------------------------------
 186          // UART0_Init
 187          //-----------------------------------------------------------------------------
 188          //
 189          // Configure the UART0 using Timer1, for <baudrate> and 8-N-1.
 190          //
 191          void UART0_Init (void)

⌨️ 快捷键说明

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