C8051F35x_中文数据手册.pdf : https://download.csdn.net/download/sudaroot/10933707

官方例程C8051xxx Examples.rar :https://download.csdn.net/download/sudaroot/12496814

不方便下载(无积分)可私聊发。

//-----------------------------------------------------------------------------
// F35x_ADC0_Buffered.c
//-----------------------------------------------------------------------------
// Copyright 2004 Silicon Laboratories, Inc.
//
// AUTH: BD / PC / BW
// LMOD: BW 15 JUL 2004
// DATE: 06 APR 2004
//
// This program demonstrates taking measurements using the 24-bit ADC on the
// C8051F350/51 devices.
//
// Input pin configuration shown in ADC0_Init().
//
// For a Noise measurement, connect AIN0 and AIN1 to AGND at the terminal
// block.  Set "USE_FLOAT" to '1', "PRINT_STATISTICS" to '1',
// "PRINT_SAMPLES" to '0', and "PRINT_VOLTAGES" to '0'.
//
// This software configures the ADC to use an external VREF.  Therefore,
// on the 'F350 target board, J13 and J14 should have their shorting blocks
// installed.
//
// The standard deviation (Sigma) of a sample set is equivalent to the
// effective RMS noise of the conversion system.  "Sigma", when converted
// to Volts, is equivalent to the input-referred noise floor of the
// sampling system.
//
// Typical values of Sigma from the C8051F350 rev B target board with
// AIN0 and AIN1 grounded at the terminal block are around 9 to 11 LSBs
// in bipolar mode.  For a DC measurement, this is equivalent to a Signal-
// to-Noise ratio of about 117dB, or about 20 bits of effective dynamic
// range.
//
// 117dB = 20 log10 ( 11 / 2^23)
// 20 bits = 117dB / 6dB/bit
//
// Another parameter of note for integrating converters is the number of
// Noise-Free bits.  For a Gaussian-distributed noise floor, this number
// can be obtained by multiplying Sigma by 6, evaluating the number of
// bits required to contain the result, and subtracting this number of
// bits from the 24 available bits, as follows:
//
// 10 LSBs * 6 = 60 LSBs, which can be contained in 6 bits.  Noise-free
// resolution is 24bits - 6 bits = 18 bits.
//
// Refer to 'F350 datasheet tables "ADC0 Electrical Characteristics" and
// "Absolute Maximum Ratings" for the MIN/MAX voltage range on input pins.
//
// If using the eval version of the Keil compiler, set "USE_FLOAT" to '0'
// and calculate the standard deviation by taking the square root
// of "variance".
//
// Target: C8051F35x
//
// Tool chain: KEIL C51
//
// v1.0 PC 26 MAY 2004
// Initial Revision (Adapted from 'F350 Temp Sensor Demo)
//// set USE_FLOAT to '0' to use EVAL version of Keil compiler#define USE_FLOAT 1
#define PRINT_STATISTICS 1
#define PRINT_SAMPLES 0
#define PRINT_VOLTAGES 0//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f350.h>                    // SFR declarations
#include <stdio.h>                        // Standard I/O Library
#include <math.h>//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F35x
//-----------------------------------------------------------------------------sfr16 DP       = 0x82;                    // data pointer
sfr16 TMR3RL   = 0x92;                    // Timer3 reload value
sfr16 TMR3     = 0x94;                    // Timer3 counter
sfr16 ADC0DEC  = 0x9a;
sfr16 TMR2RL   = 0xca;                    // Timer2 reload value
sfr16 TMR2     = 0xcc;                    // Timer2 counter
sfr16 PCA0CP0  = 0xe9;                    // PCA0 Module 1 Capture/Compare
sfr16 PCA0CP1  = 0xeb;                    // PCA0 Module 2 Capture/Compare
sfr16 PCA0CP2  = 0xed;                    // PCA0 Module 2 Capture/Compare
sfr16 PCA0     = 0xf9;                    // PCA0 counter//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------#define SYSCLK       49000000             // SYSCLK frequency (Hz)
#define BAUDRATE     115200               // UART0 Baudrate (bps)#define MDCLK        2457600              // Modulator Clock (Hz)
#define OWR          10                   // desired Output Word Rate in Hz#define VREF         250L                 // External VREF (x 10^-2 V)
/*
#define VREF         243UL                // Internal VREF (x 10^-2 V)
*/sbit LED0 = P0^6;                         // LED0='1' means ON
sbit LED1 = P0^7;                         // LED1='1' means ON
sbit SW2  = P1^0;                         // SW2='0' means switch pressed//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void SYSCLK_Init (void);
void PORT_Init (void);
void ADC0_Init (void);
void IDA0_Init (void);
void UART0_Init (void);//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
void main (void) {volatile long ADC_OutputVal=0;         // Concatenated ADC output valuelong xdata sample_array[128];unsigned i;long min;long max;long l_temp;long l_average;long l_variance;long l_owr;#if (USE_FLOAT == 1)float temp;float average;float variance;float stdev;float owr;
#endif // USE_FLOAT// disable watchdog timerPCA0MD &= ~0x40;                       // WDTE = 0 (clear watchdog timer// enable)SYSCLK_Init();                         // Initialize system clock to 49 MHzPORT_Init();                           // Initialize crossbar and GPIOLED0 = 0;LED1 = 0;ADC0_Init();                           // Initialize ADC0UART0_Init();                          // Initialize UART0EA = 1;                                // enable global interruptsprintf("\nMeasurements using the 24-bit ADC in C8051F350\n");printf("\nCalibrating ...\n");EIE1 &= ~0x08;                         // Disable ADC0 interruptsADC0MD |= 0x01;                        // Init Internal Full calwhile (!AD0CALC);                      // Wait for calibration completeADC0MD &= ~0x07;                       // clear bits (put ADC0 in IDLE// mode)printf("Calibration complete\n\n");AD0INT = 0;                            // clear pending sample indicationADC0MD = 0x83;                         // Start continuous conversionswhile(1){// capture 128 samplesprintf ("Collecting 128 samples...\n");LED0 = 1;for (i = 0; i < 128; i++){while(!AD0INT);                     // wait till conversion completeAD0INT = 0;                         // clear AD0 interrupt flag// concatenate ADC0 data bytes to form the 24-bit valueADC_OutputVal = (char)ADC0H;ADC_OutputVal <<= 16;ADC_OutputVal += (long)ADC0L + ((long)ADC0M << 8);sample_array[i] = ADC_OutputVal;}LED0 = 0;// calculate mean, min, and max#if (USE_FLOAT == 1)average = 0;
#endif // USE_FLOATl_average = 0L;min = 0x7fffffffL;max = 0x80000000L;for (i = 0; i < 128; i++){ADC_OutputVal = sample_array[i];l_average = l_average + ADC_OutputVal;if (ADC_OutputVal < min)min = ADC_OutputVal;if (ADC_OutputVal > max)max = ADC_OutputVal;#if (USE_FLOAT == 1)average = average + (float) ADC_OutputVal;
#endif // USE_FLOAT}l_average = l_average / 128;#if (USE_FLOAT == 1)average = average / 128;
#endif // USE_FLOAT// calculate variancel_variance = 0L;#if (USE_FLOAT == 1)variance = 0;
#endif // USE_FLOATfor (i = 0; i < 128; i++){ADC_OutputVal = sample_array[i];l_temp = ADC_OutputVal;l_temp = l_temp - l_average;l_temp = l_temp * l_temp;l_variance = l_variance + l_temp;#if (USE_FLOAT == 1)temp = (float) ADC_OutputVal;temp = temp - average;temp = temp * temp;variance = variance + temp;
#endif // USE_FLOAT}l_variance = l_variance / 127;   // unbiased variancel_owr = (long) SYSCLK / (long)(ADC0CLK + 1);l_owr = (long) l_owr / (long)(ADC0DEC + 1);l_owr = (long) l_owr / (long)128;#if (USE_FLOAT == 1)variance = variance / 127;       // unbiased variancestdev = sqrt (variance);owr = SYSCLK /(ADC0CLK + 1);owr = owr / (ADC0DEC + 1);owr = owr / 128;
#endif // USE_FLOAT// print statistics
#if (PRINT_STATISTICS == 1)LED1 = 1;printf ("SYSCLK = %lu\n", (unsigned long) SYSCLK);printf ("ADC0CLK = 0x%02x\n", (unsigned) ADC0CLK);printf ("ADC0DEC = 0x%02x%02x\n", (unsigned) ADC0DECH,(unsigned) ADC0DECL);printf ("min = %ld\n", min);printf ("max = %ld\n", max);#if (USE_FLOAT == 1)printf ("average = %.2f\n", average);printf ("stdev = %.2f\n", stdev);printf ("variance = %.2f\n", variance);printf ("OWR = %.2f Hz\n", owr);
#elseprintf ("average = %ld\n", l_average);printf ("variance = %ld\n", l_variance);printf ("OWR = %ld Hz\n", l_owr);
#endif // USE_FLOATprintf ("\n");LED1 = 0;
#endif // PRINT_STATISTICS// print samples
#if (PRINT_SAMPLES == 1)for (i = 0; i < 128; i++){ADC_OutputVal = sample_array[i];printf ("%6ld\n", ADC_OutputVal);
//      printf ("0x%06lx\n", ADC_OutputVal);}
#endif // PRINT_SAMPLES// print voltages
#if (PRINT_VOLTAGES == 1)for (i = 0; i < 128; i++){long Calculated_uV;              // Measured voltage in uVADC_OutputVal = sample_array[i];// Caculate measured voltage in uV:// V (in uV) = ADCcode * VREF * 10 / 2^24// Note1: Multiplying by 10 because VREF is in 10^-2 V// Note2: Shifting by 4 before multiplying 10 to prevent overflow//        of unsigned long variable (32 bits)Calculated_uV = ((((((ADC_OutputVal*2*VREF)/16)*10)/1024)*1000)/1024);// Output result:printf("ADC Output Code = %6ld [Calculated voltage = %+07ld uV]\n",ADC_OutputVal, Calculated_uV);}
#endif // PRINT_VOLTAGES}// end while(1)
}//-----------------------------------------------------------------------------
// SYSCLK_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use the internal 24.5MHz
// oscillator as its clock source, with x 2 multiply for
// 49 MHz operation. Also enables missing clock detector reset.
//
void SYSCLK_Init (void)
{unsigned i;OSCICN = 0x80;                         // enable intoscCLKSEL = 0x00;                         // select intosc as sysclk source// INTOSC configureOSCICN = 0x83;// PLL configureCLKMUL = 0x00;                         // Reset Clock MultiplierCLKMUL &= ~0x03;                       // select INTOSC / 2 as PLL sourceCLKMUL |= 0x80;                        // Enable 4x Multipler (MULEN = 1)for (i = 0; i < 125; i++);             // Delay for at least 5usCLKMUL |= 0xC0;                        // Initialize Multiplierwhile (!(CLKMUL & 0x20));              // Poll for Multiply Ready// SYSCLK configureVDM0CN = 0x80;                         // enable VDD monitorRSTSRC = 0x06;                         // enable missing clock detector// and VDD monitor reset sourcesCLKSEL = 0x02;                         // select PLL as clock source
}//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports.
// P0.4 - TX0 (push-pull)
// P0.5 - RX0
// P0.6 - LED1 (push-pull)
// P0.7 - LED2 (push-pull)
//
void PORT_Init (void)
{XBR0     = 0x01;                       // UART0 SelectedXBR1     = 0x40;                       // Enable crossbar and weak pull-upsP0MDOUT |= 0xD0;                       // TX, LEDs = Push-pull
}//-----------------------------------------------------------------------------
// ADC0_Init extVREF Bipolar AIN0.1-AIN0.0
//-----------------------------------------------------------------------------
//
// This function initializes the ADC to measure across AIN0.1 and AIN0.0
// on the Target Board (Differential measurements, Bipolar codes)
//
void ADC0_Init (void)
{unsigned ADC0_decimation;REF0CN &= ~0x01;                       // disable internal vref
/*REF0CN |= 0x01;                        // (enable if using internal vref)
*/ADC0CN = 0x10;                         // Bipolar output codes, GAIN=1/*ADC0CF = 0x00;                         // interrupts upon SINC3 filter output// and uses internal VREF
*/ADC0CF = 0x04;                         // interrupts upon SINC3 filter output// and uses external VREF// Generate MDCLK for modulator.// Ideally MDCLK = 2.4576ADC0CLK = (SYSCLK/MDCLK)-1;// Ideally, MDCLK = 2.4576 MHz
//   ADC0DEC = 0x7FF;                     // set slowest OWR// program decimation rate for desired OWRADC0_decimation = (unsigned long) SYSCLK/ (unsigned long) OWR /(unsigned long) (ADC0CLK+1)/(unsigned long)128;ADC0_decimation--;ADC0DEC = ADC0_decimation;ADC0BUF = 0x00;                        // Turn off Input Buffers// Select Mux inputs//   ADC0MUX = 0x08;                        // Input pin selection:// Setup for differential measurements// AIN+ => AIN0.0// AIN- => AGND//   ADC0MUX = 0x00;                        // Input pin selection:// Setup for differential measurements// AIN+ => AIN0.0// AIN- => AIN0.0ADC0MUX = 0x01;                        // Input pin selection:// Setup for differential measurements// AIN+ => AIN0.0// AIN- => AIN0.1//   ADC0MUX = 0x10;                        // Input pin selection:// Setup for differential measurements// AIN+ => AIN0.1// AIN- => AIN0.0//   ADC0MUX = 0x32;                        // Input pin selection:// Setup for differential measurements// AIN+ => AIN0.3// AIN- => AIN0.2//   ADC0MUX = 0x54;                        // Input pin selection:// Setup for differential measurements// AIN+ => AIN0.5// AIN- => AIN0.4//   ADC0MUX = 0x76;                        // Input pin selection:// Setup for differential measurements// AIN+ => AIN0.7// AIN- => AIN0.6//   ADC0MUX = 0xff;                        // Input pin selection:// Setup for differential measurements// AIN+ => Temp+// AIN- => Temp-//   ADC0MUX = 0x88;                        // Input pin selection:// Setup for differential measurements// AIN+ => AGND// AIN- => AGNDADC0MD = 0x80;                         // Enable the ADC0 (IDLE Mode)
}//-----------------------------------------------------------------------------
// UART0_Init
//-----------------------------------------------------------------------------
//
// Configure the UART0 using Timer1, for <BAUDRATE> and 8-N-1.
//
void UART0_Init (void)
{SCON0 = 0x10;                          // 8-bit variable bit rate// level of STOP bit is ignored// RX enabled// ninth bits are zeros// clear RI0 and TI0 bitsif (SYSCLK/BAUDRATE/2/256 < 1) {TH1 = -(SYSCLK/BAUDRATE/2);CKCON |=  0x08;                     // T1M = 1; SCA1:0 = xx} else if (SYSCLK/BAUDRATE/2/256 < 4) {TH1 = -(SYSCLK/BAUDRATE/2/4);CKCON &= ~0x0B;                     // T1M = 0; SCA1:0 = 01CKCON |=  0x01;} else if (SYSCLK/BAUDRATE/2/256 < 12) {TH1 = -(SYSCLK/BAUDRATE/2/12);CKCON &= ~0x0B;                     // T1M = 0; SCA1:0 = 00} else {TH1 = -(SYSCLK/BAUDRATE/2/48);CKCON &= ~0x0B;                     // T1M = 0; SCA1:0 = 10CKCON |=  0x02;}TL1 = TH1;                             // init Timer1TMOD &= ~0xf0;                         // TMOD: timer 1 in 8-bit autoreloadTMOD |=  0x20;TR1 = 1;                               // START Timer1TI0 = 1;                               // Indicate TX0 ready
}

全篇完。

本人是一个嵌入式未入门小白,博客仅仅代表我个人主观见解方便记录成长笔记。 若有与大神大大见解有冲突,我坚信大神大大见解是对的,我的是错的。 感谢~!

Silicon C8051系列 官方例程源码相关推荐

  1. 迅为iTOP6818开发板QtE5.7应用例程源码

    应用源码请参考网盘"iTOP6818 开发板资料汇总(不含光盘内容)\08_iTOP-6818 开发板 QtE 应用开发环境以及源码\03_QtE5.7 应用例程"中的压缩包. 请 ...

  2. 易语言进程通信c语言,易语言进程通信模块和例程源码

    易语言进程通信模块和例程源码系统结构:收到信息,收到信息,接收端_开始监听,接收端_读数据,接收端_取出数据,发送端_发送数据,取得窗口句柄,SetWindowLong,CallWindowProc2 ...

  3. 正点原子Linux移植Qt,正点原子I.MX6U Qt综合例程源码

    I.MX6U Qt综合例程源码 介绍 正点原子I.MX6U Qt综合例程源码 使用说明 1.Windows下编译,安装Qt 5.12.9,可以在Windows编译,打开工程,编译完成后把src文件夹放 ...

  4. php获取优酷剧集方法,优酷获取剧集例程源码

    .版本 2 .支持库 iext .支持库 eAPI .程序集 窗口程序集1 .子程序 _按钮_获取剧集_被单击 .局部变量 网页源码, 文本型 .局部变量 正则, 正则表达式类 .局部变量 计次, 整 ...

  5. 易语言exe读写游戏例程源码_中文编程易语言的学习方法是什么

    学习中文编程易语言的可以看我的视频啊.进入我的主页.请点下关注谢谢. ----------------------------------------------------------------- ...

  6. iTOP-IMX6Q开发板QtE4.7例程源码-音频和视频

    1.QtE 音频和视频 本小节用到的源码全称是迅为"iTOP-IMX6-QtE4.7-视频音频_V1.0.rar". Phonon 最初是一个源于 KDE 的项目,为使用音频和视频 ...

  7. 图解Janusgraph系列-查询图数据过程源码分析

    图解Janusgraph系列-查询图数据过程源码分析 大家好,我是洋仔,JanusGraph图解系列文章,实时更新~ 图数据库文章总目录: 整理所有图相关文章,请移步(超链):图数据库系列-文章总目录 ...

  8. Zynq UltraScale系列使用MIPI CSI-2 RX Subsystem 解码MIPI视频PD输出 提供2套工程源码和技术支持

    目录 1.前言 2.设计思路和架构 3.vivado工程详解 4.上板调试验证 5.福利:工程代码的获取 1.前言 本设计采用OV5640摄像头MIPI模式作为输入,分辨率为1280x720@60Hz ...

  9. 单片机MCU51系列RTOS多任务超微操作系统精髓 简单实现 汇编及C语言混合 keil9.0工程源码

    系统设计核心意图:使用定时器,在延时过程中运行其它的任务. 工程源码:链接: https://pan.baidu.com/s/1LEV9qYmUn6SdemGz7TH6dw 提取码: iua5 切换任 ...

最新文章

  1. OpenJDK官方正式宣布AWT、2D、Swing等项目解散
  2. 深度学习(主要是CNN)用于图片的分类和检测总结
  3. 在R.java中新建自定义的新类
  4. STM32开发 -- 系统架构
  5. Centos下MySQL的安装及常见问题
  6. 常用JavaScript函数 31 - 46(自我总结)
  7. html + css + js 实现简易计算器
  8. log4net 使用手记
  9. java基础案例教程试题,Java基础案例教程-中国大学mooc-试题题目及答案
  10. RSA加密算法理解(整理自网络)
  11. 集合python_Python 集合
  12. 前缀无歧义编码(PFC)
  13. 按键精灵打怪学习-窗口绑定技能
  14. firebase_crashlytics缺失dSYM unity ios
  15. SDIO接口(4)——SDIO通信
  16. 《计算广告学之内容匹配广告展示广告原理、技术和实践》学习笔记
  17. xcode-instrument
  18. js/vue:video 视频播放器
  19. wordpress批量导入html文章,wordpress文章采集发布批量上传教程(火车头)
  20. Android 蓝牙 -- 还原网络设置 删除蓝牙所有存储配对信息流程分析---全网唯一

热门文章

  1. Pytorch深度学习实战教程(一):语义分割基础与环境搭建
  2. 关于kriging算法的结构分析
  3. 颜色进制转换表(全)
  4. 电竞游戏电脑推荐,外星人R14带来超凡游戏感
  5. 绝地求生FGS决赛 韩国战队成最大赢家 4AM位列第七_GoLink
  6. 【运筹学】匈牙利法 ( 匈牙利法步骤 | 第二步 : 试指派操作示例 )
  7. QQ个人信息保护 | 攻的对面叫防
  8. 《多核与GPU编程:工具、方法及实践》----1.3 现代计算机概览
  9. 2019年工程造价表_2019年全国各省市公布工程造价咨询收费标准盘点
  10. 关于速营社,我也是偶遇