C8051F系列单片机由Silicon Labs公司推出,是业内最小封装的微控制器 (MCU)(小至 2 mm x 2 mm),不会牺牲性能或集成性。完整的小型封装产品线包括高达 100 MIPs 的 CPU、12-位 ADC、12-位 DAC 以及其他重要的模拟外围设备,如集成精密振荡器 (±2%) 和精密温度传感器 (±2 °C)。还提供成本敏感、引脚兼容的一次性可编程 (OTP) 选项。
C8051F系列单片机已有6种产品选型,高度集成的小封装C8051F系列单片机经过优化,专门应用于消费、汽车和通讯市场中的空间有限、低功耗、低成本的应用中。借助于经济高效且专业的开发工具和系统内调试功能,开发变得快速简单。
c8051f单片机ad采样程序
//------------------------------------------------------------------------------------
// Main.c
//------------------------------------------------------------------------------------
// Copyright (C) 2013 SINYD.
// BY Wbr
// Tool chain: KEIL Full ‘c’
//
//#pragma CD OE DB SB // Compilation directives
//------------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------------
#ifndef C8051REG
#include “c8051f020.h” // SFR declarations
#define C8051REG
#endif
#include “1302.h”
#include “lcd.h”
#include 《INTRINS.H》
#define SYSCLK 22118400 //SYSCLK frequency in Hz
#define BAUDRATE 115200 //Baud rate of UART in bps
#define SAR_CLK 2500000 //ADC conversion clock = 2.5MHz
#define ADC04V 645 //4毫安电流时AD采样初值 12位AD
#define ADPRE 175 //AD转温度时比值放大1000倍 即:(ADC-ADC04V)*ADPRE /1000
//*************温度标定设置**************
#define HTA 32 //线性方程0=0.4a-b;50=2.0a-b 求解得a = 31.25 b=12.5 分别取32和13
#define HTB 13
#define HRA 63 //线性方程0=0.4a-b;100=2.0a-b 求解得a = 62.5 b=25 分别取63和25
#define HRB 25
#define TEA 313 //线性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分别取313和125
#define TEB 125
#define HPA 63 //线性方程-5=0.4a-b;5=2.0a-b 求解得a = 6.25 b=7.5 分别取63和75 放大10倍
#define HPB 75
//------------------------------------------------------------------------------------
// Global CONSTANTS
//------------------------------------------------------------------------------------
extern void Init_Device(void);
#define N 11
sfr16 TMR2 = 0xCC; //定义成16位地址
sfr16 ADC0 = 0xBE;
uint idata ADCbuffer1[N];
uint sum = 0;
uchar ADcount = 0;
uchar Page = 1,direction = 1,direction1 = 1;
uchar set = 0,ent = 0,Tset;
uchar TH,TL,TT1,TT2,TT3; //用来拆分送显示的变量
uchar keybuffer[6];
uchar BGset=0; //BGset背光关,开控制量,如果没有键按下超过1分钟,关闭背光!有键按下立刻开背光
bit Disptime,sendc;
sbit BLK = P3^6 ; //LCD背光
uint SPEEDcount1; //计数器
uint SPEEDcount2; //计数
uint SPEEDTP; //测试距离 V=SPEEDrange/SPEEDtime;
uint SPEEDNY;
uint TPrange = 0;
uint TPcount = 0;
uint idata TEMP1 = 0;
uint idata TEMP2 = 0;
uint idata TEMP3 = 0;
uint idata TEMP4 = 0;
uint idata HT = 0;
uint idata HR = 0;
uint idata HP = 0;
uint idata HP1= 0;
uint idata TPHD= 0;
uint idata TPHD1= 0;
uint idata TPHD2= 0; //8路AD通道变量四路来料温度 环境温度湿度 横坡度 摊铺厚度
uchar idata HPF,KT1F,KT2F,KT3F,KT4F,HTF,HRF; //横坡传感器状态位
long a;
//*******参数设置,传感器标定 变量和数组************************//
uchar xdata SZL0,SZH0,SZL1,SZH1,SZL2,SZH2;
uchar xdata SZL3,SZH3,SZL4,SZH4,SZL5,SZH5,SZL6,SZH6; //0~2为施工站号,3~4,5~6分别为摊铺,压实输入长度
uchar code CSSZ_c[7] _at_ 0x8000; //7k的地址左右站号设置,摊铺碾压计算长度输入
uchar xdata CSSZ_x[7] _at_ 0x8000;
uchar xdata Between[7]; //0~11时间12~19存功率
////////////////////////////////////
//GPS数据存储数组
//uchar xdata A_V[1]; // V无效 A有效
//uchar xdata JD01[4]; //经度
//uchar xdata WD01[4]; //经度
uchar xdata JD[12] = {0x30,0x30,0x30,0x30,
0x30,0x2e,0x30,0x30,
0x30,0x30,0x30,0x30}; //经度 初始化送数字“0”
uchar xdata JD_a; //经度方向
uchar xdata WD[11] = {0x30,0x30,0x30,0x30,
0x2e,0x30,0x30,0x30,
0x30,0x30,0x30}; //纬度 初始化送数字“0”
uchar xdata WD_a; //纬度方向
//uchar xdata time[6]; //时间时分秒
//uchar xdata TIMER[6]; //年月日
//uchar xdata speed[5]; //速度
//uchar xdata HIGH[6] = {0x30,0x30,0x30,0x30,
// 0x30,0x30}; //高度 初始化送数字“0”
//uchar xdata angle[5]; //方位角
//uchar xdata use_sat[2]; //使用的卫星数
//uchar xdata total_sat[2]; //天空中总卫星数
//uchar lock; //定位状态
//串口中断需要的变量
uchar xdata seg_count; //逗号计数器
uchar xdata dot_count; //小数点计数器
uchar xdata byte_count; //位数计数器
uchar xdata cmd_number; //命令类型
uchar xdata mode; //0:结束模式,1:命令模式,2:数据模式
uchar xdata buf_full; //1:整句接收完成,相应数据有效。0:缓存数据无效。
uchar xdata cmd[5]; //命令类型存储数组
extern uchar time_buf1[8] ;
uchar code tab0[]={“料温:”};
uchar code tab1[]={“料温1:”};
uchar code tab2[]={“料温2:”};
uchar code tab3[]={“料温3:”};
uchar code tab4[]={“料温4:”};
uchar code tab5[]={“环境温度:”};
uchar code tab6[]={“环境湿度:”};
uchar code tab7[]={“横坡度:”};
uchar code tab8[]={“℃”};
//uchar code tab9[]={“沥青摊铺厚度:”};
uchar code tab10[]={“纬度:”};
uchar code tab11[]={“经度:”};
uchar code tab12[]={“高度:”};
uchar code tab13[]={“设备ID:”};
uchar code tab14[]={“摊铺S(mm):”};
uchar code tab15[]={“碾压S(mm):”};
uchar code page0[]={“参数设置:”};
uchar code page1[]={“摊铺压实监测装置”};
uchar code page2[]={“实时显示”};
uchar code page41[]={“摊铺速度:”};
uchar code page42[]={“碾压速度:”};
//uchar code page5[]={“传感器标定:”};
uchar code page5[]={“沥青摊铺厚度:”};
uchar code page51[]={“前探头:”};
uchar code page52[]={“后探头:”};
uchar code page6[]={“实时定位信息:”};
uchar code page7[]={“修改时间:”};
uchar code run1[]={“先按:SET再按:ENT”};
uchar code run2[]={“未连接”};
uchar code run3[]={“%”};
uchar code run4[]={“M/MIN”};
uchar code run5[]={“KM/H”};
uchar code run6[]={“线路故障”};
uchar xdata TAB[11]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x20};//数字0~9及显示空白0x20*/
uchar code tab32[] ={
/*-- 宽度x高度=128x64 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xE0,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0xF8,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xF8,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0x00,0x1F,0xFE,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7E,0x00,0x7F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xF8,0x00,0xFC,0x00,0x1E,0x3E,0x01,0xFE,0x01,0xFF,0xFF,0x80,0x00,
0x00,0x00,0x03,0xF0,0x01,0xF8,0x00,0x1E,0x3E,0x01,0xEF,0x03,0xFF,0xFF,0xC0,0x00,
0x00,0x00,0x0F,0xC0,0x01,0xF0,0x00,0x3C,0x7F,0x03,0xCF,0x07,0x9F,0xFF,0xC0,0x00,
0x00,0x00,0x1F,0x80,0x01,0xF0,0x00,0x3C,0x7F,0x03,0xC7,0x8F,0x1C,0x07,0xC0,0x00,
0x00,0x00,0x3F,0x00,0x01,0xE0,0x00,0x7C,0x7F,0x83,0xC7,0x9E,0x38,0x07,0x80,0x00,
0x00,0x00,0x3F,0x00,0x01,0xE1,0xE0,0x78,0xFF,0x87,0x83,0xFC,0x38,0x07,0x80,0x00,
0x00,0x00,0x7E,0x00,0x00,0xF0,0xF8,0x78,0xF3,0xC7,0x83,0xF8,0x78,0x07,0x80,0x00,
0x00,0x00,0xFC,0x00,0x00,0x00,0xF8,0xF8,0xF3,0xC7,0x81,0xF0,0x70,0x0F,0x00,0x00,
0x00,0x00,0xFC,0x00,0x00,0x00,0xFC,0xF1,0xE1,0xEF,0x01,0xE0,0x70,0x0F,0x00,0x00,
0x00,0x00,0xFC,0x00,0x00,0x01,0xF8,0xF1,0xE1,0xFF,0x03,0xE0,0x70,0x0F,0x00,0x00,
0x00,0x01,0xFC,0x00,0x00,0x03,0xF9,0xF1,0xE0,0xFF,0x03,0xC0,0xE0,0x1E,0x00,0x00,
0x00,0x01,0xFC,0x00,0x00,0x07,0xF1,0xE3,0xC0,0xFE,0x03,0xC0,0xFF,0xFE,0x00,0x00,
0x00,0x01,0xFC,0x00,0x00,0x3F,0xE1,0xE3,0xC0,0x7E,0x07,0xC0,0xFF,0xFE,0x00,0x00,
0x00,0x00,0xFE,0x00,0x1F,0xFF,0x83,0xE7,0xC0,0x7E,0x07,0x81,0xFF,0xFC,0x00,0x00,
0x00,0x00,0xFC,0x00,0x03,0xF8,0x00,0x80,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x06,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x22,0x10,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x19,0x81,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x22,0x18,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0x67,0xF0,0x00,0x0F,0xE3,0x8E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x73,0xCE,0x00,0x00,0x07,0x83,0x8E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x71,0x8C,0x00,0x00,0x07,0x83,0x86,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x63,0x1E,0x00,0x00,0x07,0x1F,0xCE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xDF,0xC0,0x00,0x07,0x3F,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0xC0,0x00,0x0F,0x03,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x38,0xCF,0xFF,0xCE,0x03,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xB9,0xCF,0xFF,0xCE,0x03,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x78,0x39,0x80,0x00,0x0E,0x03,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFE,0x31,0x80,0x00,0x1E,0x03,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0xFE,0x73,0x80,0x00,0x1C,0x03,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0x76,0x73,0x00,0x00,0x1C,0x01,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x06,0x76,0x63,0x00,0x00,0x3C,0x01,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x04,0xE6,0xE7,0x00,0x00,0x38,0x01,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0D,0xE6,0xE6,0x00,0x00,0x38,0x01,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
//----------------------------------------
// Function PROTOTYPES
//----------------------------------------
void delayms(uint ms)
{
uint Temp;
while(ms--)
{
Temp=2000;
while(Temp--);
{
//PCA0CPH2 = 1;
}
}
}
//===========================================
//写FLASH函数
//===========================================
void Flash_Erase_CSSZ() //flash擦除充电时间和功率
{
EA =0;
FLSCL |= 0x01; //
PSCTL |= 0x03; //允许擦,允许写
CSSZ_x[0] = 0;
PSCTL &= 0xfc; //禁止写,禁止擦
FLSCL &= 0xfe;
}
void Flash_Program_CSSZ() //flash写入充电时间时间和功率
{
uchar j;
EA =0;
FLSCL |= 0x01; //使能FLASH单稳态定时器,FLASH读时间SYSCLK《=25MHz
PSCTL |= 0x01; //write enable
for(j =0;j《7;j++)
{
CSSZ_x[j] = Between[j];
}
PSCTL &= 0xfc; //禁止写
FLSCL &= 0xfe;
EA = 1;
}
评论
查看更多