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;
}
評論
查看更多