c8051f单片机ad采样程序.docx
《c8051f单片机ad采样程序.docx》由会员分享,可在线阅读,更多相关《c8051f单片机ad采样程序.docx(35页珍藏版)》请在冰豆网上搜索。
![c8051f单片机ad采样程序.docx](https://file1.bdocx.com/fileroot1/2023-1/30/811533c9-c391-4a96-a544-d154a5148e6b/811533c9-c391-4a96-a544-d154a5148e6b1.gif)
c8051f单片机ad采样程序
c8051f单片机ad采样程序
////Main.c
////Copyright(C)2013SINYD.
//BYWbr
//Toolchain:
KEILFull'c'
//
//#pragmaCDOEDBSB//Compilationdirectives
////Includes
//#ifndefC8051REG
#include"c8051f020.h"//SFRdeclarations
#defineC8051REG
#endif
1000倍即:
(ADC-ADC04V)*ADPRE/1000
#defineHTB13
#defineHRA63//线性方程
0=0.4a-b;100=2.0a-b求解得a=62.5b=25分别取63和
0=0.4a-b;500=2.0a-b求解得a=312.5b=125分别取313和125#defineTEB125
#defineHPA63
//线性方程-5=0.4a-b;5=2.0a-b
#defineHPB75
////GlobalCONSTANTS
//externvoidInit_Device(void);
#defineN11
sfr16TMR2=0xCC;//定义成16位地址
sfr16ADC0=0xBE;
uintidataADCbuffer1[N];
uintsum=0;
ucharADcount=0;
ucharPage=1,direction=1,direction1=1;
ucharset=0,ent=0,Tset;
ucharkeybuffer[6];
ucharBGset=0;
//BGset背光关,开控制量,
如果没有键按下超过
1分钟,关闭背光!
有键按下立刻开背
光
bitDisptime,sendc;
sbitBLK=P3A6;
//LCD背光
uint
SPEEDcount1;
//计数器
uint
SPEEDcount2;
//计数
uint
SPEEDTP;
//测试距离
V=SPEEDrange/SPEEDtime;
uint
SPEEDNY;
uint
TPrange=0;
uint
TPcount=0;
uint
idataTEMP1=0;
uint
idataTEMP2=0;
uint
idataTEMP3=0;
uint
idataTEMP4=0;
uintidataHT=0;
uintidataHR=0;uintidataHP=0;
uintidataHP1=0;
ucharidataHPF,KT1F,KT2F,KT3F,KT4F,HTF,HRF;//横坡传感器状态位
longa;
//*******参数设置,传感器标定变量和数组************************//
ucharxdataSZL0,SZH0,SZL1,SZH1,SZL2,SZH2;
ucharxdata
SZL3,SZH3,SZL4,SZH4,SZL5,SZH5,SZL6,SZH6;//0~2
为施工站号,3~4,5~6分别为摊铺,压实输入长度
ucharcodeCSSZ_c[7]_at_0x8000;//7k的
地址左右站号设置,摊铺碾压计算长度输入
ucharxdataCSSZ_x[7]_at_0x8000;
ucharxdataWD[11]={0x30,0x30,0x30,0x30,
//0x30,0x30};
//ucharxdataangle[5];//ucharxdatause_sat[2];//ucharxdatatotal_sat[2];
//ucharlock;//串口中断需要的变量ucharxdataseg_count;ucharxdatadot_count;ucharxdatabyte_count;
//ucharxdataHIGH[6]={0x30,0x30,0x30,0x30,
//高度初始化送数字“0”//方位角
//使用的卫星数//天空中总卫星数
//定位状态
//逗号计数器//小数点计数器
//位数计数器
ucharxdatacmd_number;
//命令类型
ucharxdatamode;
//0:
结束模式,1:
命令模式,2:
数据模式
ucharxdatabuf_full;
//1:
整句接收完成,
相应数据有效。
0:
缓存数据无效。
ucharxdatacmd[5];
//命令类型存储数组
extern
uchartime_buf1[8];
uchar
codetab0[]={"料温:
"};
uchar
codetab1[]={"料温1:
"};
uchar
codetab2[]={"料温2:
"};
uchar
codetab3[]={"料温3:
"};
uchar
codetab4[]={"料温4:
"};
uchar
codetab5[]={"环境温度:
"};
uchar
codetab6[]={"环境湿度:
"};
uchar
codetab7[]={"横坡度:
"};
uchar
codetab8[]={"C"};
//uchar
codetab9[]={"沥青摊铺厚度
:
"};
uchar
codetab10[]={"纬度:
"};
uchar
codetab11[]={"经度:
"};
uchar
codetab12[]={"高度:
"};
uchar
codetab13[]={"设备ID:
"};
uchar
codetab14[]={"摊铺S(mm):
"}
ucharcodetab15[]={"碾压S(mm):
"};
ucharcodepage0[]={"参数设置:
"};
ucharcodepage1[]={"摊铺压实监测装置"};
ucharcodepage2[]={"实时显示"};
ucharcodepage41[]={"摊铺速度:
"};
ucharcodepage42[]={"碾压速度:
"};
//ucharcodepage5[]={"传感器标定:
"};
ucharcodepage5[]={"沥青摊铺厚度:
"};
ucharcodepage51[]={"前探头:
"};
ucharcodepage52[]={"后探头:
"};
ucharcodepage6[]={"实时定位信息:
"};
ucharcodepage7[]={"修改时间:
"};
ucharcoderun1[]={"先按:
SET再按:
ENT"};
ucharcoderun2[]={"未连接"};
ucharcoderun3[]={"%"};
ucharcoderun4[]={"M/MIN"};
ucharcoderun5[]={"KM/H"};
ucharcoderun6[]={"线路故障"};
ucharxdata
TAB[11]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x3
8,0x39,0x20};//数字0~9及显示空白0x20*/ucharcodetab32[]={
/*--宽度x高度=128x64--*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF0,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xE0,0x1F,0x
C0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x
3C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0xF8,0x00,0x00,0x00,0x
07,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x00,0x00,0x00,0x
01,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xF8,0x00,0x00,0x00,0x00,0x
00,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x
00,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x
00,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xF8,0x00,0x00,0x00,0x00,0x00,0x
00,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x
00,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0x00,0x1F,0xFE,0x00,0x00,0x00,0x
00,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7E,0x00,0x7F,0x80,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xF8,0x00,0xFC,0x00,0x1E,0x3E,0x01,0
xFE,0x01,0xFF,0xFF,0x80,0x00,
0x00,0x00,0x03,0xF0,0x01,0xF8,0x00,0x1E,0x3E,0x01,0x
EF,0x03,0xFF,0xFF,0xC0,0x00,
0x00,0x00,0x0F,0xC0,0x01,0xF0,0x00,0x3C,0x7F,0x03,0
xCF,0x07,0x9F,0xFF,0xC0,0x00,
0x00,0x00,0x1F,0x80,0x01,0xF0,0x00,0x3C,0x7F,0x03,0x
C7,0x8F,0x1C,0x07,0xC0,0x00,
0x00,0x00,0x3F,0x00,0x01,0xE0,0x00,0x7C,0x7F,0x83,0x
C7,0x9E,0x38,0x07,0x80,0x00,
0x00,0x00,0x3F,0x00,0x01,0xE1,0xE0,0x78,0xFF,0x87,0x
83,0xFC,0x38,0x07,0x80,0x00,
0x00,0x00,0x7E,0x00,0x00,0xF0,0xF8,0x78,0xF3,0xC7,0
x83,0xF8,0x78,0x07,0x80,0x00,
0x00,0x00,0xFC,0x00,0x00,0x00,0xF8,0xF8,0xF3,0xC7,0
x81,0xF0,0x70,0x0F,0x00,0x00,
0x00,0x00,0xFC,0x00,0x00,0x00,0xFC,0xF1,0xE1,0xEF,0
x01,0xE0,0x70,0x0F,0x00,0x00,
0x00,0x00,0xFC,0x00,0x00,0x01,0xF8,0xF1,0xE1,0xFF,0
x03,0xE0,0x70,0x0F,0x00,0x00,
0x00,0x01,0xFC,0x00,0x00,0x03,0xF9,0xF1,0xE0,0xFF,0
x03,0xC0,0xE0,0x1E,0x00,0x00,
0x00,0x01,0xFC,0x00,0x00,0x07,0xF1,0xE3,0xC0,0xFE,0
x03,0xC0,0xFF,0xFE,0x00,0x00,
0x00,0x01,0xFC,0x00,0x00,0x3F,0xE1,0xE3,0xC0,0x7E,0
x07,0xC0,0xFF,0xFE,0x00,0x00,
0x00,0x00,0xFE,0x00,0x1F,0xFF,0x83,0xE7,0xC0,0x7E,0
x07,0x81,0xFF,0xFC,0x00,0x00,
0x00,0x00,0xFC,0x00,0x03,0xF8,0x00,0x80,0x00,0x00,0x
00,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x06,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x22,0x10,0x00,0x02,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x19,0x81,0x02,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x22,0x18,0x40,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x08,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x
03,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0x67,0xF0,0x00,0x0F,0x
E3,0x8E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x73,0xCE,0x00,0x00,0x07,0x
83,0x8E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x71,0x8C,0x00,0x00,0x07,0x
83,0x86,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x63,0x1E,0x00,0x00,0x07,0x
1F,0xCE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xDF,0xC0,0x00,0x07,0
x3F,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0xC0,0x00,0x0F,0x
03,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x38,0xCF,0xFF,0xCE,0
x03,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xB9,0xCF,0xFF,0xCE,0
x03,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x78,0x39,0x80,0x00,0x0E,0x
03,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFE,0x31,0x80,0x00,0x1E,0x
03,0xC0,0x00,0x00,0x00,0x00,
01,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x04,0xE6,0xE7,0x00,0x00,0x38,0x
01,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0D,0xE6,0xE6,0x00,0x00,0x38,0x
01,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
00,0x00,0x00,0x00,0x00,0x00,
};
//
//FunctionPROTOTYPES
//
voiddelayms(uintms)
{
uintTemp;while(ms--)
{
Temp=2000;while(Temp--);
{//PCA0CPH2=1;
}
}
}//===========================================//写FLASH函数
//===========================================voidFlash_Erase_CSSZ()//flash擦除充电时间和功率
{
EA=0;
FLSCL|=0x01;//
PSCTL|=0x03;
//允许擦,允许
CSSZ_x[0]=0;
PSCTL&=0xfc;
擦
FLSCL&=0xfe;
}
voidFlash_Program_CSSZ()
电时间时间和功率
{
ucharj;
EA=0;
FLSCL|=0x01;
//禁止写,禁止
//flash写入充
//使能
//writeenable
//禁止写
FLASH单稳态定时器,FLASH读时间SYSCLK<=25MHz
PSCTL|=0x01;
for(j=0;j<7;j++)
{
CSSZ_x[j]=Between[j];
}
PSCTL&=0xfc;
FLSCL&=0xfe;
EA=1;
//================================
//中值滤波程序
//================================voidfilter()
{
staticucharcount,i,j;
uintxdatavalue_buf[N];
uinttemp;
sum=0;
for(count=0;countvalue_buf[i+1])
{
temp=value_buf[i];
value_buf[i]=value_buf[i+1];value_buf[i+1]=temp;
}
}
}
for(count=1;countsum+=value_buf[count];
}
//===================================
//voidkey_scan()
{
staticuchari;//staticuchark;ucharMkey=P6;if(BGset1)
{
BGset=2;}
}
}
}if(BGset==2){if(!
(Mkey&0x08))
{
delayms(200);if(!
(Mkey&0x08))
{
BGset=2;
Page=1;set=0;
}
if(!
(Mkey&0x10))
//DATA按下