C8051F系列單片機(jī)由Silicon Labs公司推出,是業(yè)內(nèi)最小封裝的微控制器 (MCU)(小至 2 mm x 2 mm),不會犧牲性能或集成性。完整的小型封裝產(chǎn)品線包括高達(dá) 100 MIPs 的 CPU、12-位 ADC、12-位 DAC 以及其他重要的模擬外圍設(shè)備,如集成精密振蕩器 (±2%) 和精密溫度傳感器 (±2 °C)。還提供成本敏感、引腳兼容的一次性可編程 (OTP) 選項(xiàng)。
C8051F系列單片機(jī)已有6種產(chǎn)品選型,高度集成的小封裝C8051F系列單片機(jī)經(jīng)過優(yōu)化,專門應(yīng)用于消費(fèi)、汽車和通訊市場中的空間有限、低功耗、低成本的應(yīng)用中。借助于經(jīng)濟(jì)高效且專業(yè)的開發(fā)工具和系統(tǒng)內(nèi)調(diào)試功能,開發(fā)變得快速簡單。
c8051f單片機(jī)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 “l(fā)cd.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毫安電流時(shí)AD采樣初值 12位AD
#define ADPRE 175 //AD轉(zhuǎn)溫度時(shí)比值放大1000倍 即:(ADC-ADC04V)*ADPRE /1000
//*************溫度標(biāo)定設(shè)置**************
#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背光關(guān),開控制量,如果沒有鍵按下超過1分鐘,關(guān)閉背光!有鍵按下立刻開背光
bit Disptime,sendc;
sbit BLK = P3^6 ; //LCD背光
uint SPEEDcount1; //計(jì)數(shù)器
uint SPEEDcount2; //計(jì)數(shù)
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通道變量四路來料溫度 環(huán)境溫度濕度 橫坡度 攤鋪厚度
uchar idata HPF,KT1F,KT2F,KT3F,KT4F,HTF,HRF; //橫坡傳感器狀態(tài)位
long a;
//*******參數(shù)設(shè)置,傳感器標(biāo)定 變量和數(shù)組************************//
uchar xdata SZL0,SZH0,SZL1,SZH1,SZL2,SZH2;
uchar xdata SZL3,SZH3,SZL4,SZH4,SZL5,SZH5,SZL6,SZH6; //0~2為施工站號,3~4,5~6分別為攤鋪,壓實(shí)輸入長度
uchar code CSSZ_c[7] _at_ 0x8000; //7k的地址左右站號設(shè)置,攤鋪碾壓計(jì)算長度輸入
uchar xdata CSSZ_x[7] _at_ 0x8000;
uchar xdata Between[7]; //0~11時(shí)間12~19存功率
////////////////////////////////////
//GPS數(shù)據(jù)存儲數(shù)組
//uchar xdata A_V[1]; // V無效 A有效
//uchar xdata JD01[4]; //經(jīng)度
//uchar xdata WD01[4]; //經(jīng)度
uchar xdata JD[12] = {0x30,0x30,0x30,0x30,
0x30,0x2e,0x30,0x30,
0x30,0x30,0x30,0x30}; //經(jīng)度 初始化送數(shù)字“0”
uchar xdata JD_a; //經(jīng)度方向
uchar xdata WD[11] = {0x30,0x30,0x30,0x30,
0x2e,0x30,0x30,0x30,
0x30,0x30,0x30}; //緯度 初始化送數(shù)字“0”
uchar xdata WD_a; //緯度方向
//uchar xdata time[6]; //時(shí)間時(shí)分秒
//uchar xdata TIMER[6]; //年月日
//uchar xdata speed[5]; //速度
//uchar xdata HIGH[6] = {0x30,0x30,0x30,0x30,
// 0x30,0x30}; //高度 初始化送數(shù)字“0”
//uchar xdata angle[5]; //方位角
//uchar xdata use_sat[2]; //使用的衛(wèi)星數(shù)
//uchar xdata total_sat[2]; //天空中總衛(wèi)星數(shù)
//uchar lock; //定位狀態(tài)
//串口中斷需要的變量
uchar xdata seg_count; //逗號計(jì)數(shù)器
uchar xdata dot_count; //小數(shù)點(diǎn)計(jì)數(shù)器
uchar xdata byte_count; //位數(shù)計(jì)數(shù)器
uchar xdata cmd_number; //命令類型
uchar xdata mode; //0:結(jié)束模式,1:命令模式,2:數(shù)據(jù)模式
uchar xdata buf_full; //1:整句接收完成,相應(yīng)數(shù)據(jù)有效。0:緩存數(shù)據(jù)無效。
uchar xdata cmd[5]; //命令類型存儲數(shù)組
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[]={“環(huán)境溫度:”};
uchar code tab6[]={“環(huán)境濕度:”};
uchar code tab7[]={“橫坡度:”};
uchar code tab8[]={“℃”};
//uchar code tab9[]={“瀝青攤鋪厚度:”};
uchar code tab10[]={“緯度:”};
uchar code tab11[]={“經(jīng)度:”};
uchar code tab12[]={“高度:”};
uchar code tab13[]={“設(shè)備ID:”};
uchar code tab14[]={“攤鋪S(mm):”};
uchar code tab15[]={“碾壓S(mm):”};
uchar code page0[]={“參數(shù)設(shè)置:”};
uchar code page1[]={“攤鋪壓實(shí)監(jiān)測裝置”};
uchar code page2[]={“實(shí)時(shí)顯示”};
uchar code page41[]={“攤鋪速度:”};
uchar code page42[]={“碾壓速度:”};
//uchar code page5[]={“傳感器標(biāo)定:”};
uchar code page5[]={“瀝青攤鋪厚度:”};
uchar code page51[]={“前探頭:”};
uchar code page52[]={“后探頭:”};
uchar code page6[]={“實(shí)時(shí)定位信息:”};
uchar code page7[]={“修改時(shí)間:”};
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};//數(shù)字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函數(shù)
//===========================================
void Flash_Erase_CSSZ() //flash擦除充電時(shí)間和功率
{
EA =0;
FLSCL |= 0x01; //
PSCTL |= 0x03; //允許擦,允許寫
CSSZ_x[0] = 0;
PSCTL &= 0xfc; //禁止寫,禁止擦
FLSCL &= 0xfe;
}
void Flash_Program_CSSZ() //flash寫入充電時(shí)間時(shí)間和功率
{
uchar j;
EA =0;
FLSCL |= 0x01; //使能FLASH單穩(wěn)態(tài)定時(shí)器,F(xiàn)LASH讀時(shí)間SYSCLK《=25MHz
PSCTL |= 0x01; //write enable
for(j =0;j《7;j++)
{
CSSZ_x[j] = Between[j];
}
PSCTL &= 0xfc; //禁止寫
FLSCL &= 0xfe;
EA = 1;
}
//================================
//中值濾波程序
//================================
void filter()
{
static uchar count,i,j;
uint xdata value_buf[N];
uint temp;
sum=0;
for(count=0;count《N;count++)
{
value_buf[count] = ADCbuffer1[count];
}
for (j=0;j《N-1;j++)
{
for (i=0;i《N-j;i++)
{
if ( value_buf[i]》value_buf[i+1] )
{
temp = value_buf[i];
value_buf[i] = value_buf[i+1];
value_buf[i+1] = temp;
}
}
}
for(count=1;count《N-1;count++)
sum += value_buf[count];
}
//===================================
//按鍵處理程序 按鍵為P6口
//===================================
void key_scan()
{
static uchar i;
//static uchar k;
uchar Mkey=P6;
if(BGset《2)
{
if((Mkey&0xFF)!= 0xFF) //有鍵按下先開啟背光
{
delayms(200);
if((Mkey&0xFF)!= 0xFF)
{
BGset++;
if(BGset》1)
{
BGset = 2;
}
}
}
}
if(BGset ==2 )
{
if(!(Mkey&0x08)) //ESC按下嗎? P63
{
delayms(200); //消抖
if(!(Mkey&0x08)) //再判斷
{
BGset =2; //開背光
//if(k《1) {Page = 0;} //頁面0:顯示版本信息狀態(tài)
//k++;
//if(k》1) {k =0;Page = 1; } //再按后退出
Page = 1;
set = 0;
}
}
if(!(Mkey&0x10)) //DATA按下嗎? P64
{
delayms(200); //消抖
if(!(Mkey&0x10)) //再判斷
{
BGset =2; //開背光
//if(k《1) {Page = 0;} //頁面0:顯示版本信息狀態(tài)
//k++;
//if(k》1) {k =0;Page = 1; } //再按后退出
Page = 0;
set = 0;
}
}
if(!set)
{
if(!(Mkey&0x80)) //---》按下嗎?下翻
{
delayms(200);
if(!(Mkey&0x80))
{
if(Page !=0)
{
Page++;
BGset =2;
if(Page》7) //如果超過7界面回到1畫面
{
Page = 1;
}
}
}
}
if(!(Mkey&0x20)) //《---按下嗎?上翻
{
delayms(200);
if(!(Mkey&0x20))
{
if(Page !=0)
{
Page--;
BGset =2;
if(Page《1) //小于1畫面后不顯示0畫面,顯示7畫面
{
Page = 7;
}
}
}
}
}
//************************************************
//設(shè)置參數(shù)
//************************************************
if(Page ==0)
{
if(!(Mkey&0x02)) //SET按下嗎?設(shè)定SET在0畫面設(shè)置參數(shù)
{
delayms(200);
if(!(Mkey&0x02))
{
BGset =2;
set = 1; //如果按下SET鍵表示開始設(shè)置時(shí)間,置設(shè)置標(biāo)志位;
}
}
if(set == 1)
{
if(!(Mkey&0x20)) //《- 按下嗎?左移《- 在0畫面修改參數(shù)
{
delayms(200);
if(!(Mkey&0x20))
{
BGset =2;
direction1++;
if(direction1 》 14)
{
direction1 = 1; //本界面14個(gè)數(shù)字要修改
}
}
}
if(!(Mkey&0x80)) //-》按下嗎?右移-》只在0畫面修改時(shí)間
{
delayms(200);
if(!(Mkey&0x80))
{
BGset =2;
direction1--;
if(direction1 《 1)
{
direction1 = 14;
}
}
}
switch(direction1)
{
case 1: //第一位修改
{
//number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);
number_disp (0x9e,1,TAB[SZH6],TAB[SZL6]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZL0++;
if(SZL0》9) //設(shè)置,不超過9
{
SZL0 = 0;
}
}
}
/*if(!(Mkey&0x10)) //-按下嗎?
{
delayms(200);
if(!(Mkey&0x10))
{
BGset =2;
if(SZL0《=0) //小于1畫面后不顯示0畫面
{
SZL0 = 9;
}
SZL0--;
}
}*/
if(Tset 《 2)
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]);
}
if(Tset》2)
{
number_disp (0x97,1,TAB[SZH0],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 2://第二位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZH0++;
if(SZH0》9) //設(shè)置,不超過9
{
SZH0 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]);
}
if(Tset》2)
{
number_disp (0x97,1,0x20,TAB[SZL0]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 3://第三位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZL1++;
if(SZL1》9) //設(shè)置,不超過9
{
SZL1 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
}
if(Tset》2)
{
number_disp (0x96,1,TAB[SZH1],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 4://第4位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZH1++;
if(SZH1》9) //設(shè)置,不超過9
{
SZH1 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
}
if(Tset》2)
{
number_disp (0x96,1,0x20,TAB[SZL1]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 5://第5位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZL2++;
if(SZL2》9) //設(shè)置,不超過9
{
SZL2 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
}
if(Tset》2)
{
number_disp (0x95,1,TAB[SZH2],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 6://第6位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZH2++;
if(SZH2》9) //設(shè)置,不超過9
{
SZH2 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
}
if(Tset》2)
{
number_disp (0x95,1,0x20,TAB[SZL2]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 7://第7位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZL3++;
if(SZL3》9) //設(shè)置,不超過9
{
SZL3 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
}
if(Tset》2)
{
number_disp (0x8f,1,TAB[SZH3],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 8://第8位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZH3++;
if(SZH3》9) //設(shè)置,不超過9
{
SZH3 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
}
if(Tset》2)
{
number_disp (0x8f,1,0x20,TAB[SZL3]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 9://第9位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZL4++;
if(SZL4》9) //設(shè)置,不超過9
{
SZL4 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
}
if(Tset》2)
{
number_disp (0x8e,1,TAB[SZH4],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 10://第10位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZH4++;
if(SZH4》9) //設(shè)置,不超過9
{
SZH4 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
}
if(Tset》2)
{
number_disp (0x8e,1,0x20,TAB[SZL4]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 11://第11位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZL5++;
if(SZL5》9) //設(shè)置,不超過9
{
SZL5 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);
}
if(Tset》2)
{
number_disp (0x9f,1,TAB[SZH5],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 12://第12位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZH5++;
if(SZH5》9) //設(shè)置,不超過9
{
SZH5 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);
}
if(Tset》2)
{
number_disp (0x9f,1,0x20,TAB[SZL5]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 13://第11位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZL6++;
if(SZL6》9) //設(shè)置,不超過9
{
SZL6 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x9e,1,TAB[SZH6],TAB[SZL6]);
}
if(Tset》2)
{
number_disp (0x9e,1,TAB[SZH6],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 14://第12位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZH6++;
if(SZH6》9) //設(shè)置,不超過9
{
SZH6 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x9e,1,TAB[SZH6],TAB[SZL6]);
}
if(Tset》2)
{
number_disp (0x9e,1,0x20,TAB[SZL6]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
default:break;
}
if(!(Mkey&0x04)) //ENT按下嗎?確認(rèn)ENT 在0畫面設(shè)定參數(shù)
{
delayms(200);
if(!(Mkey&0x04))
{
BGset =2;
Between[0] = SZH0*10 + SZL0;
Between[1] = SZH1*10 + SZL1;
Between[2] = SZH2*10 + SZL2;
Between[3] = SZH3*10 + SZL3;
Between[4] = SZH4*10 + SZL4;
Between[5] = SZH5*10 + SZL5;
Between[6] = SZH6*10 + SZL6;
Flash_Erase_CSSZ();
Flash_Program_CSSZ(); //寫入FLASH
set = 0;
Page = 1; //退出到1畫面
}
}
}
}
//***********************************************
//修改時(shí)間
//***********************************************
if(Page ==7) //修改時(shí)間界面
{
if(!(Mkey&0x02)) //SET按下嗎?設(shè)定SET只在7畫面設(shè)置時(shí)間
{
delayms(200);
if(!(Mkey&0x02))
{
BGset =2;
set = 2; //如果按下SET鍵表示開始設(shè)置時(shí)間,置設(shè)置標(biāo)志位;
}
}
if(set == 2)
{
if(!(Mkey&0x20)) //《- 按下嗎?左移《- 只在7畫面修改時(shí)間
{
delayms(200);
if(!(Mkey&0x20))
{
BGset =2;
direction--;
if(direction 《 1)
{
direction = 6;
}
}
}
if(!(Mkey&0x80)) //-》按下嗎?右移-》只在7畫面修改時(shí)間
{
delayms(200);
if(!(Mkey&0x80))
{
BGset =2;
direction++;
if(direction 》 6)
{
direction = 1;
}
}
}
switch(direction)
{
case 1:
{
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
keybuffer[0]++;
if(keybuffer[0]》99) //年設(shè)置,不超過100年
{
keybuffer[0] = 13;
}
}
}
if(!(Mkey&0x40)) //-按下嗎?
{
delayms(200);
if(!(Mkey&0x40))
{
BGset =2;
keybuffer[0]--;
if(keybuffer[0]《13) //小于1畫面后不顯示0畫面,顯示6畫面
{
keybuffer[0] = 13;
}
}
}
if(Tset 《 2)
{
TH = keybuffer[0]/10;
TL = keybuffer[0]%10;
number_disp (0x8a,1,TAB[TH],TAB[TL]);
}
if(Tset》2)
{
number_disp (0x8a,1,0x20,0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 2:
{
TH = keybuffer[0]/10;
TL = keybuffer[0]%10;
number_disp (0x8a,1,TAB[TH],TAB[TL]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
keybuffer[1]++;
if(keybuffer[1]》12) //月設(shè)置,不超過12月
{
keybuffer[1] = 1;
}
}
}
if(!(Mkey&0x40)) //-按下嗎?
{
delayms(200);
if(!(Mkey&0x40))
{
BGset =2;
keybuffer[1]--;
if(keybuffer[1]《1) //小于1 顯示12月
{
keybuffer[1] = 12;
}
}
}
if(Tset 《 2)
{
TH = keybuffer[1]/10;
TL = keybuffer[1]%10;
number_disp (0x8c,1,TAB[TH],TAB[TL]);
}
if(Tset》2)
{
number_disp (0x8c,1,0x20,0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 3:
{
TH = keybuffer[1]/10;
TL = keybuffer[1]%10;
number_disp (0x8c,1,TAB[TH],TAB[TL]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
keybuffer[2]++;
if(keybuffer[2]》31) //日設(shè)置,不超過31日
{
keybuffer[2] = 1;
}
}
}
if(!(Mkey&0x40)) //-按下嗎?
{
delayms(200);
if(!(Mkey&0x40))
{
BGset =2;
keybuffer[2]--;
if(keybuffer[2]《1) //小于1,顯示31日
{
keybuffer[2] = 31;
}
}
}
if(Tset《2)
{
TH = keybuffer[2]/10;
TL = keybuffer[2]%10;
number_disp (0x8e,1,TAB[TH],TAB[TL]);
}
if(Tset》2)
{
number_disp (0x8e,1,0x20,0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 4:
{
TH = keybuffer[2]/10;
TL = keybuffer[2]%10;
number_disp (0x8e,1,TAB[TH],TAB[TL]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
keybuffer[3]++;
if(keybuffer[3]》23) //時(shí)設(shè)置,不超過24
{
keybuffer[3] = 0;
}
}
}
if(!(Mkey&0x40)) //-按下嗎?
{
delayms(200);
if(!(Mkey&0x40))
{
BGset =2;
keybuffer[3]--;
if(keybuffer[3]《=0) //小于1,顯示23
{
keybuffer[3] = 23;
}
}
}
if(Tset 《 2)
{
TH = keybuffer[3]/10;
TL = keybuffer[3]%10;
number_disp (0x9A,1,TAB[TH],TAB[TL]);
}
if(Tset》2)
{
number_disp (0x9A,1,0x20,0x20);
}
}break;
case 5:
{
TH = keybuffer[3]/10;
TL = keybuffer[3]%10;
number_disp (0x9A,1,TAB[TH],TAB[TL]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
keybuffer[4]++;
if(keybuffer[4]》59) //分設(shè)置,不超過59
{
keybuffer[4] = 0;
}
}
}
if(!(Mkey&0x40)) //-按下嗎?
{
delayms(200);
if(!(Mkey&0x40))
{
BGset =2;
keybuffer[4]--;
if(keybuffer[4]《=0) //小于1,顯示59
{
keybuffer[4] = 59;
}
}
}
if(Tset 《 2)
{
TH = keybuffer[4]/10;
TL = keybuffer[4]%10;
number_disp (0x9C,1,TAB[TH],TAB[TL]);
}
if(Tset》2)
{
number_disp (0x9C,1,0x20,0x20);
}
}break;
case 6:
{
TH = keybuffer[4]/10;
TL = keybuffer[4]%10;
number_disp (0x9C,1,TAB[TH],TAB[TL]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset = 2;
keybuffer[5]++;
if(keybuffer[5]》59) //秒設(shè)置,不超過59
{
keybuffer[5] = 0;
}
}
}
if(!(Mkey&0x40)) //-按下嗎?
{
delayms(200);
if(!(Mkey&0x40))
{
BGset = 2;
keybuffer[5]--;
if(keybuffer[5]《=0) //小于1,顯示59
{
keybuffer[5] = 59;
}
}
}
if(Tset 《 2)
{
TH = keybuffer[5]/10;
TL = keybuffer[5]%10;
number_disp (0x9E,1,TAB[TH],TAB[TL]);
}
if(Tset》2)
{
number_disp (0x9E,1,0x20,0x20);
}
}break;
default:break;
}
if(!(Mkey&0x04)) //ENT按下嗎?確認(rèn)ENT 只在6畫面設(shè)定時(shí)間
{
delayms(200);
if(!(Mkey&0x04))
{
BGset =2;
for(i=0;i《6;i++)
{
time_buf1[i+1] = keybuffer[i];
}
Ds1302_Write_Time(); //寫DS1302
set = 0;
Page = 1; //退出到1畫面
}
}
}
}
}
}
//===================================
//串口0 串口1發(fā)送函數(shù)
//===================================
void Uart0_SendData(uchar dat0)
{
SBUF0=dat0; //寫SBUF0,開始發(fā)送
while(!TI0); //等待發(fā)送
TI0=0; //清發(fā)送標(biāo)志位
}
void Uart1_SendData(uchar dat1)
{
SBUF1=dat1; //寫SBUF1,開始發(fā)送
while(!(SCON1&0x02));
SCON1 = (SCON1&0xfd);
}
void Timer2_Init(int ct2s)
{
RCAP2H = -ct2s/0xff;
RCAP2L = -ct2s;
}
//-----------------------------------------------------------------------------
// Main 年:0xC4EA 月:0xD4C2 日:0xC8D5 時(shí):0xCAB1: 分0xB7D6: 秒:0xC3EB 的漢字內(nèi)碼
//-----------------------------------------------------------------------------
void main(void)
{
//uint TEMP1,TEMP2,TEMP3,TEMP4,HT,HR,HP; //8路AD通道變量四路來料溫度 環(huán)境溫度濕度 橫坡度
uchar i,j,Page1,BEW1,BEW2,BEW3,BEW4; //BEW1,BEW2,BEW3,BEW4; 拆分顯示的百,十,個(gè)位,小數(shù)點(diǎn)位中間變量
Init_Device();
P5 = 0xff;
delayms(200);
Ds1302_Init();
init_lcd ();
clrram ();
ADC0CF = ((SYSCLK/SAR_CLK)-1)《《3; // set SAR clock to 3MHz
ADC1CF = ((SYSCLK/SAR_CLK)-1)《《3; // set SAR clock to 3MHz
ADC1CF |= 0x01; //ADC1增益設(shè)為1
AD0EN = 1; //使能AC0啟動轉(zhuǎn)換
ADC1CN &=~(0x80); //使能AC1啟動轉(zhuǎn)換
TMR3CN = 0x04; //啟動TM3
EA = 1;
Timer2_Init(SYSCLK/12/100); //10ms
//Ds1302_Write_Time() ;
// Ds1302_Read_Time();
for(j=0;j《7;j++)
{
Between[j] = CSSZ_c[j]; //讀取FLASH
}
SZH0 = Between[0]/10;
SZL0 = Between[0]%10;
SZH1 = Between[1]/10;
SZL1 = Between[1]%10;
SZH2 = Between[2]/10;
SZL2 = Between[2]%10;
SZH3 = Between[3]/10;
SZL3 = Between[3]%10;
SZH4 = Between[4]/10;
SZL4 = Between[4]%10;
SZH5 = Between[5]/10;
SZL5 = Between[5]%10;
SZH6 = Between[6]/10;
SZL6 = Between[6]%10;
if(SZL0》9) SZL0 = 0;
if(SZH0》9) SZH0 = 0;
if(SZL1》9) SZL1 = 0;
if(SZH1》9) SZH1 = 0;
if(SZL2》9) SZL2 = 0;
if(SZH2》9) SZH2 = 0;
if(SZL3》9) SZL3 = 0;
if(SZH3》9) SZH3 = 0;
if(SZL4》9) SZL4 = 0;
if(SZH4》9) SZH4 = 0;
if(SZL5》9) SZL5 = 0;
if(SZH5》9) SZH5 = 0;
if(SZL6》9) SZL6 = 0;
if(SZH6》9) SZH6 = 0;
img_disp (tab32);
delayms(5000);
ET2 = 1;
TR2 = 1;
BLK = 0;
//Ds1302_Write_Time() ;
while(1)
{
key_scan();
Ds1302_Read_Time();
if(Page!=Page1)
{
clrram (); //如果頁面變化,需要清屏;
}
switch(Page)
{
case 1: //畫面1:顯示當(dāng)前
{
string_disp (0x80,16,page1);
number_disp (0x89,1,0x32,0x30); //數(shù)字20
number_disp (0x8b,1,0xc4,0xea); //年
number_disp (0x8d,1,0xd4,0xc2); //月
number_disp (0x8f,1,0xc8,0xd5); //日
number_disp (0x9b,1,0xca,0xb1); //時(shí)
number_disp (0x9d,1,0xb7,0xd6); //分
number_disp (0x9f,1,0xc3,0xeb); //秒
TH = time_buf1[1]/10; //年
TL = time_buf1[1]%10;
number_disp (0x8a,1,TAB[TH],TAB[TL]);
TH = time_buf1[2]/10; //月
TL = time_buf1[2]%10;
number_disp (0x8C,1,TAB[TH],TAB[TL]);
TH = time_buf1[3]/10; //日
TL = time_buf1[3]%10;
number_disp (0x8E,1,TAB[TH],TAB[TL]);
TH = time_buf1[4]/10; //時(shí)
TL = time_buf1[4]%10;
number_disp (0x9A,1,TAB[TH],TAB[TL]);
TH = time_buf1[5]/10; //分
TL = time_buf1[5]%10;
number_disp (0x9C,1,TAB[TH],TAB[TL]);
TH = time_buf1[6]/10; //秒
TL = time_buf1[6]%10;
number_disp (0x9E,1,TAB[TH],TAB[TL]);
Page1=Page; //保存當(dāng)前頁面值
}break;
case 2:
{
string_disp (0x82,8,page2); //顯示實(shí)時(shí)采集量
string_disp (0x90,10,tab5);
if(HTF)
{
string_disp (0x97,2,tab8); //顯示℃
BEW2 = HT/100; //環(huán)境溫度十位
BEW3 = (HT%100)/10; //環(huán)境溫度個(gè)位
BEW4 = (HT%100)%10; //環(huán)境溫度小數(shù)位
if(!BEW2) //滅零處理
{
BEW2 = 10;
}
number_disp (0x95,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x96,1,0x2E,TAB[BEW4]);
}
else
{
string_disp (0x95,6,run2);
}
string_disp (0x88,10,tab6);
if(HRF)
{
string_disp (0x8f,2,run3); //顯示% //顯示%
BEW2 = HR/100; //環(huán)境濕度十位
BEW3 = (HR%100)/10; //環(huán)境濕度個(gè)位
BEW4 = (HR%100)%10; //環(huán)境濕度小數(shù)位
if(!BEW2) //滅零處理
{
BEW2 = 10;
}
number_disp (0x8D,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x8E,1,0x2E,TAB[BEW4]);
}
else
{
string_disp (0x8D,6,run2);
}
string_disp (0x98,8,tab7);
BEW2 = HP/100; //橫坡度十位
BEW3 = (HP%100)/10; //橫坡度個(gè)位
BEW4 = (HP%100)%10; //橫坡度小數(shù)位
if(HPF == 0) //負(fù)度數(shù)標(biāo)志位
{
number_disp (0x9C,1,0x2d,0x20);
number_disp (0x9D,1,TAB[BEW2],0x2E);
number_disp (0x9E,1,TAB[BEW3],TAB[BEW4]);
number_disp (0x9f,1,0x20,0x20);
}
if(HPF == 1) //正度數(shù)標(biāo)志位
{
number_disp (0x9C,1,0x2b,0x20);
number_disp (0x9D,1,TAB[BEW2],0x2E);
number_disp (0x9E,1,TAB[BEW3],TAB[BEW4]);
number_disp (0x9f,1,0x20,0x20);
}
if(HPF == 2) //0度數(shù)標(biāo)志位
{
number_disp (0x9C,1,0x20,0x20);
number_disp (0x9D,1,TAB[BEW2],0x2E);
number_disp (0x9E,1,TAB[BEW3],TAB[BEW4]);
number_disp (0x9f,1,0x20,0x20);
}
if(HPF == 3) //未連接標(biāo)志位
{
string_disp (0x9d,6,run2);
number_disp (0x9C,1,0x20,0x20);
}
Page1=Page;
}break;
case 3: //顯示來料溫度 ADC04V 645
{
string_disp (0x80,6,tab1);
if(KT1F)
{
string_disp (0x86,2,tab8); //顯示℃
BEW1 = TEMP1/1000; //溫度百位
BEW2 = (TEMP1%1000)/100; //溫度十位
BEW3 = ((TEMP1%1000)%100)/10; //溫度個(gè)位
BEW4 = ((TEMP1%1000)%100)%10; //溫度小數(shù)位
if(!BEW1) //滅零處理
{
BEW1 = 10;
if(!BEW2)
{
BEW2 = 10;
}
}
number_disp (0x85,1,0x2E,TAB[BEW4]);
number_disp (0x84,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x83,1,0x20,TAB[BEW1]);
}
else
{
string_disp (0x84,6,run2); //顯示“未連接”
number_disp (0x83,1,0x20,0x20);
}
string_disp (0x90,6,tab2);
if(KT2F)
{
string_disp (0x96,2,tab8); //顯示℃
BEW1 = TEMP2/1000; //溫度百位
BEW2 = (TEMP2%1000)/100; //溫度十位
BEW3 = ((TEMP2%1000)%100)/10; //溫度個(gè)位
BEW4 = ((TEMP2%1000)%100)%10; //溫度小數(shù)位
if(!BEW1) //滅零處理
{
BEW1 = 10;
if(!BEW2)
{
BEW2 = 10;
}
}
number_disp (0x95,1,0x2E,TAB[BEW4]);
number_disp (0x94,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x93,1,0x20,TAB[BEW1]);
}
else
{
number_disp (0x93,1,0x20,0x20);
string_disp (0x94,6,run2);
}
string_disp (0x88,6,tab3);
if(KT3F)
{
string_disp (0x8E,2,tab8); //顯示℃
BEW1 = TEMP3/1000; //溫度百位
BEW2 = (TEMP3%1000)/100; //溫度十位
BEW3 = ((TEMP3%1000)%100)/10; //溫度個(gè)位
BEW4 = ((TEMP3%1000)%100)%10; //溫度小數(shù)位
if(!BEW1) //滅零處理
{
BEW1 = 10;
if(!BEW2)
{
BEW2 = 10;
}
}
number_disp (0x8D,1,0x2E,TAB[BEW4]);
number_disp (0x8C,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x8B,1,0x20,TAB[BEW1]);
}
else
{
number_disp (0x8B,1,0x20,0x20);
string_disp (0x8C,6,run2);
}
string_disp (0x98,6,tab4);
if(KT4F)
{
string_disp (0x9E,2,tab8); //顯示℃
BEW1 = TEMP4/1000; //溫度百位
BEW2 = (TEMP4%1000)/100; //溫度十位
BEW3 = ((TEMP4%1000)%100)/10; //溫度個(gè)位
BEW4 = ((TEMP4%1000)%100)%10; //溫度小數(shù)位
if(!BEW1) //滅零處理
{
BEW1 = 10;
if(!BEW2)
{
BEW2 = 10;
}
}
number_disp (0x9D,1,0x2E,TAB[BEW4]);
number_disp (0x9C,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x9B,1,0x20,TAB[BEW1]);
}
else
{
number_disp (0x9B,1,0x20,0x20);
string_disp (0x9C,6,run2);
}
Page1=Page;
}break;
case 4: //
{
string_disp (0x80,10,page41);
string_disp (0x88,10,page42);
if(SPEEDTP《9999)
{
BEW1 = SPEEDTP/1000;
BEW2 = (SPEEDTP%1000)/100; //溫度十位
BEW3 = ((SPEEDTP%1000)%100)/10; //溫度個(gè)位
BEW4 = ((SPEEDTP%1000)%100)%10;
if(!BEW1) //滅零處理
{
BEW1 = 10;
}
string_disp (0x95,6,run4);
number_disp (0x94,1,TAB[BEW3],TAB[BEW4]);
number_disp (0x93,1,TAB[BEW2],0x2E);
number_disp (0x92,1,0x20,TAB[BEW1]);
}
else
{
string_disp (0x92,8,run6);
}
if(SPEEDNY《9999)
{
BEW1 = SPEEDNY/1000;
BEW2 = (SPEEDNY%1000)/100; //溫度十位
BEW3 = ((SPEEDNY%1000)%100)/10; //溫度個(gè)位
BEW4 = ((SPEEDNY%1000)%100)%10;
if(!BEW1) //滅零處理
{
BEW1 = 10;
}
string_disp (0x9d,4,run5);
number_disp (0x9C,1,TAB[BEW3],TAB[BEW4]);
number_disp (0x9B,1,TAB[BEW2],0x2E);
number_disp (0x9A,1,0x20,TAB[BEW1]);
}
else
{
string_disp (0x9a,8,run6);
}
Page1=Page;
}break;
case 5: //顯示定位信息
{
string_disp (0x80,14,page6);
string_disp (0x98,6,tab10);
number_disp (0x9b,1,WD[0],WD[1]);
number_disp (0x9c,1,WD[2],WD[3]);
number_disp (0x9d,1,WD[4],WD[5]);
number_disp (0x9e,1,WD[6],WD[7]);
number_disp (0x9f,1,WD[8],WD[9]);
string_disp (0x88,6,tab11);
number_disp (0x8B,1,JD[0],JD[1]);
number_disp (0x8C,1,JD[2],JD[3]);
number_disp (0x8D,1,JD[4],JD[5]);
number_disp (0x8E,1,JD[6],JD[7]);
number_disp (0x8F,1,JD[8],JD[9]);
//string_disp (0x98,6,tab12);
//number_disp (0x9B,1,HIGH[0],HIGH[1]);
//number_disp (0x9C,1,HIGH[2],HIGH[3]);
//number_disp (0x9D,1,HIGH[4],HIGH[5]);
Page1=Page;
}break;
case 6: //傳感器標(biāo)定 厚度顯示
{
string_disp (0x80,8,page51);
BEW1 = TPHD1/100;
if(!BEW1) //滅零處理
{
BEW1 = 10;
}
BEW2 = (TPHD1%100)/10;
BEW3 = (TPHD1%100)%10;
number_disp (0x85,1,TAB[BEW1],TAB[BEW2]);
number_disp (0x86,1,0x2E,TAB[BEW3]);
number_disp (0x87,1,0x43,0x4d);
string_disp (0x90,9,page52);
BEW1 = TPHD2/100;
if(!BEW1) //滅零處理
{
BEW1 = 10;
}
BEW2 = (TPHD2%100)/10;
BEW3 = (TPHD2%100)%10;
number_disp (0x95,1,TAB[BEW1],TAB[BEW2]);
number_disp (0x96,1,0x2E,TAB[BEW3]);
number_disp (0x97,1,0x43,0x4d);
string_disp (0x88,13,page5);
if (TPHD1》TPHD2)
{
TPHD = TPHD1 - TPHD2;
}
else
{
TPHD = 0;
}
BEW1 = TPHD/100;
if(!BEW1) //滅零處理
{
BEW1 = 10;
}
//if(BEW1》3) //超過3,異常數(shù),則清零
//{
// BEW1 = 10;
// }
BEW2 = (TPHD%100)/10;
BEW3 = (TPHD%100)%10;
number_disp (0x9d,1,TAB[BEW1],TAB[BEW2]);
number_disp (0x9e,1,0x2E,TAB[BEW3]);
number_disp (0x9f,1,0x43,0x4d);
Page1=Page;
}break;
case 7: //修改時(shí)間
{
if(!(set==2)) //沒有按SET鍵
{
string_disp (0x80,10,page7);
number_disp (0x89,1,0x32,0x30); //數(shù)字20
number_disp (0x8b,1,0xc4,0xea); //年
number_disp (0x8d,1,0xd4,0xc2); //月
number_disp (0x8f,1,0xc8,0xd5); //日
number_disp (0x9b,1,0xca,0xb1); //時(shí)
number_disp (0x9d,1,0xb7,0xd6); //分
number_disp (0x9f,1,0xc3,0xeb); //秒
TH = time_buf1[1]/10; //年
TL = time_buf1[1]%10;
number_disp (0x8a,1,TAB[TH],TAB[TL]);
TH = time_buf1[2]/10; //月
TL = time_buf1[2]%10;
number_disp (0x8C,1,TAB[TH],TAB[TL]);
TH = time_buf1[3]/10; //日
TL = time_buf1[3]%10;
number_disp (0x8E,1,TAB[TH],TAB[TL]);
TH = time_buf1[4]/10; //時(shí)
TL = time_buf1[4]%10;
number_disp (0x9A,1,TAB[TH],TAB[TL]);
TH = time_buf1[5]/10; //分
TL = time_buf1[5]%10;
number_disp (0x9C,1,TAB[TH],TAB[TL]);
TH = time_buf1[6]/10; //秒
TL = time_buf1[6]%10;
number_disp (0x9E,1,TAB[TH],TAB[TL]);
for (j = 0;j《6;j++)
{
keybuffer[j] = time_buf1[j+1];
}
}
Page1=Page; //保存當(dāng)前頁面值
}break;
case 0: //顯示故障狀態(tài)
{
if(!(set==1)) //沒有按SET鍵
{
number_disp (0x82,1,0xb2,0xce); //參
number_disp (0x83,1,0xca,0xfd); //數(shù)
number_disp (0x84,1,0xc9,0xe8); //設(shè)
number_disp (0x85,1,0xd6,0xc3); //置
string_disp (0x90,8,tab13);
string_disp (0x88,10,tab14);
string_disp (0x98,10,tab15);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);
number_disp (0x9e,1,TAB[SZH6],TAB[SZL6]);
}
Page1=Page; //保存當(dāng)前頁面值
}break;
default:break;
}
if(sendc)
{
sendc = 0;
Uart0_SendData(0x7f); //首字符串
Uart0_SendData(0x00); //數(shù)據(jù)包長度
Uart0_SendData(0x38); //56個(gè)字節(jié)
switch(Between[2]) //協(xié)議類型,0X0a攤鋪 0X14碾壓
{
case 0x0a:
Uart0_SendData(0x0a); //攤鋪
break;
case 0x14:
Uart0_SendData(0x14); //壓實(shí)
break;
default:
Uart0_SendData(0x0a); //默認(rèn)0X0a
break;
}
Uart0_SendData(0x00); //預(yù)留字節(jié)
Uart0_SendData(0x00);
Uart0_SendData(Between[2]); //ID
Uart0_SendData(Between[1]);
Uart0_SendData(Between[0]);
Uart0_SendData(0x14);
Uart0_SendData(time_buf1[1]); //時(shí)間年月日時(shí)分秒
Uart0_SendData(time_buf1[2]);
Uart0_SendData(time_buf1[3]);
Uart0_SendData(time_buf1[4]);
Uart0_SendData(time_buf1[5]);
Uart0_SendData(time_buf1[6]);
for(i=0;i《12;i++) //經(jīng)度
{
Uart0_SendData(JD[i]);
}
for(i=0;i《11;i++) //緯度
{
Uart0_SendData(WD[i]);
}
Uart0_SendData(TPHD/100); //攤鋪厚度
Uart0_SendData(TPHD%100);
switch(Between[2])
{
case 0x10:
Uart0_SendData(SPEEDTP/100); //攤鋪速度
Uart0_SendData(SPEEDTP%100);
break;
case 0x20:
Uart0_SendData(SPEEDNY/100); //壓實(shí)速度
Uart0_SendData(SPEEDNY%100);
break;
default:
Uart0_SendData(0x00); //壓實(shí)速度
Uart0_SendData(0x00);
break;
}
Uart0_SendData(TEMP1/100); //料溫
Uart0_SendData(TEMP1%100);
Uart0_SendData(TEMP2/100);
Uart0_SendData(TEMP2%100);
Uart0_SendData(TEMP3/100);
Uart0_SendData(TEMP3%100);
Uart0_SendData(TEMP4/100);
Uart0_SendData(TEMP4%100);
Uart0_SendData(HT/100); //環(huán)境溫度濕度橫坡度
Uart0_SendData(HT%100);
Uart0_SendData(HR/100);
Uart0_SendData(HR%100);
Uart0_SendData(HP/100);
Uart0_SendData(HP%100);
Uart0_SendData(TPrange/100);
Uart0_SendData(TPrange%100);
Uart0_SendData(0xa3); //結(jié)束符
//Uart0_SendData(0xa5);
//Uart0_SendData(0xa6);
}
}
}
/*void UART0_ISR(void) interrupt 4
{
static uchar Rcv;
if(RI0)
{
Rcv = SBUF0;
RI0 =0;
}
if(Rcv == 0x7E) //
{
i = 1;
buffer[0] = Rcv;
}
else
{
if(i 《 13) //12個(gè)字節(jié)
{
buffer[i] = Rcv;
i++;
}
}
}*/
void UART1_ISR(void) interrupt 20
{
static uchar tmp;
if ((SCON1 & 0x01) == 0x01)
{
tmp = SBUF1;
SCON1 = (SCON1 & 0xFE); //RI1 = 0;
switch(tmp)
{
case ‘$’: //首字符
{
cmd_number=0; //命令類型清空
mode=1; //接收命令模式
byte_count=0; //接收位數(shù)清空
}
break;
case ‘,’:
{
seg_count++; //逗號計(jì)數(shù)加1
byte_count=0;
}
break;
case ‘*’: //數(shù)據(jù)幀結(jié)束標(biāo)志
{
switch(cmd_number)
{
case 1:
buf_full|=0x01;
break;
case 2:
buf_full|=0x02;
break;
case 3:
buf_full|=0x04;
break;
}
mode=0;
}
break;
default:
if(mode==1)
{ //命令種類判斷
cmd[byte_count]=tmp; //接收字符放入類型緩存
if(byte_count》=4)
{ //如果類型數(shù)據(jù)接收完畢,判斷類型
if(cmd[0]==‘G’)
{
if(cmd[1]==‘P’)
{
if(cmd[2]==‘G’)
{
if(cmd[3]==‘G’)
{
if(cmd[4]==‘A’)
{
cmd_number=1;
mode=2;
seg_count=0;
byte_count=0;
}
}
}
}
}
}
}
else if(mode==2)
{ //接收數(shù)據(jù)處理
//類型1數(shù)據(jù)接收。GPGGA
switch(seg_count)
{
case 2: //緯度處理
if(byte_count《10)
{
WD[byte_count]=tmp;
}
break;
case 3: //緯度方向處理
if(byte_count《1)
{
WD_a=tmp;
}
break;
case 4: //經(jīng)度處理
if(byte_count《11)
{
JD[byte_count]=tmp;
}
break;
case 5: //經(jīng)度方向處理
if(byte_count《1)
{
JD_a=tmp;
}
break;
/*case 6: //定位判斷
if(byte_count《1)
{
lock=tmp;
}
break;
case 7: //定位使用的衛(wèi)星數(shù)
if(byte_count《2)
{
use_sat[byte_count]=tmp;
}
break;*/
//case 9: //高度處理
//if(byte_count《6)
//{
// HIGH[byte_count]=tmp;
// }
//break;
default:break;
}
}
byte_count++; //接收數(shù)位加1
break;
}
//temp=0;
//byte_count++; //接收數(shù)位加1
}
}
//=======================================================
//TIMER2 10毫秒自動重裝
//=======================================================
void TIME2_ISR (void) interrupt 5 //20毫秒自動重裝
{
static uchar i,j1,j2,j3,j4,j5,j6,k,k1,m,m1,LTP1,LNY1;
static uint c1,c2,c3,c4;
TF2 = 0; //清標(biāo)志位
i++;
if(i==50)
{
P5=~(P5);
i = 0;
}
LTP1 = P7; //接近開關(guān)不遮擋輸出高電平,
LNY1 = P7;
if((LTP1&0xFF) ==0xFF) //P70=1;遮擋上了,接近開關(guān)無輸出,此時(shí)P70=1;
{
j1++;
if(j1》2) //2次以上還是原來狀態(tài)證明不是干擾脈沖
{
j1 = 0;
k = 1; //檢測到P70為0,置位K
}
c3++;
if(c3》9000) //超過1分半鐘沒變化認(rèn)為停止了
{
c3 = 0;
SPEEDcount1 = 0;
SPEEDTP = 0;
}
}
if(k) //在置位情況下等待下降沿
{
if((LTP1&0xFF) ==0xFE) //P70=0;檢測到無遮擋,接近開關(guān)輸出24V,開始一個(gè)周期此時(shí)P70 = 0;
{
j2++;
if(j2》2) //過濾脈沖干擾
{
j2 = 0;
k1 = 1;
}
c1++;
if(c1》9000) //超過1分半鐘沒變化認(rèn)為停止了
{
c1 = 0;
SPEEDcount1 = 0;
SPEEDTP = 0;
k1 = 0;
k = 0;
}
if(k1)
{
SPEEDcount1++; //發(fā)生了正跳變,開始計(jì)時(shí)
}
}
if(k1)
{
if((LTP1&0xFF) ==0xFF) //再一次檢測到有遮擋表示一次檢測周期結(jié)束,計(jì)時(shí)結(jié)束,開始計(jì)算速度
{
j3++;
if(j3》2)
{
j3 = 0;
k1 = 0;
k = 0;
//SPEEDTP = SPEEDcount1/100; //(秒)
SPEEDTP = (long)600*(Between[4]*100 + Between[3])/SPEEDcount1; //米/分;顯示部分已經(jīng)后移了兩位
SPEEDcount1 = 0;
c1 = 0;
c3 = 0;
TPcount++;
TPrange = (long)TPcount*(Between[6]*100 + Between[5])/1000;
}
}
}
}
if((LNY1&0xFF) ==0xFF) //P71=1;
{
j4++;
if(j4》2) //2次以上還是原來狀態(tài)證明不是干擾脈沖
{
j4 = 0;
m = 1; //檢測到P71為0,置位M
}
c4++;
if(c4》9000) //超過1分半鐘沒變化認(rèn)為停止了
{
c4 = 0;
SPEEDcount2 = 0;
SPEEDNY = 0;
}
}
if(m) //在置位情況下等待下降沿
{
if((LNY1&0xFF) ==0xFD) //P71=0;
{
j5++;
if(j5》2) //過濾脈沖干擾
{
j5 = 0;
m1 = 1;
}
c2++;
if(c2》9000) //等待了1分半鐘沒變化,認(rèn)為停止了
{
c2 = 0;
SPEEDcount2 = 0;
SPEEDNY = 0;
m1 = 0;
m = 0;
}
if(m1)
{
SPEEDcount2++; //發(fā)生了正跳變,開始計(jì)時(shí)
}
}
if(m1)
{
if((LNY1&0xFF) ==0xFF) //發(fā)生了負(fù)跳變,計(jì)時(shí)結(jié)束,開始計(jì)算速度
{
j6++;
if(j6》2)
{
j6 = 0;
m1 = 0;
m = 0;
SPEEDNY = (long)36*(Between[6]*100 + Between[5])/SPEEDcount2; //km/h;顯示部分已經(jīng)后移了兩位
SPEEDcount2 = 0;
c2 = 0;
c4 = 0;
}
}
}
}
}
void ADC0_ISR (void) interrupt 15
{
static uchar count0; // Loop counter
AD0INT = 0; //清中斷標(biāo)志位
switch( AMX0SL ) //通道轉(zhuǎn)換
{
case 0x00: //AIN0.0
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 1;
filter();
TPHD1= (sum/(N-2));
if(TPHD1》ADC04V)
{
TPHD1 = TPHD1 - 5; //去掉偏移量
a = (long)TPHD1*2500/4095; //放大1000倍,采集到1毫伏
a = (a*469-37500)/1000; //超聲傳感器公式150=a*0.4+b 900=a*2.0+b a=468.75 b=37.5
TPHD1 = a;
}
else {TPHD1 = 0;}
}
break;
case 0x01: //AIN0.1
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 2;
filter();
TPHD2= (sum/(N-2));
if(TPHD2》ADC04V)
{
TPHD2 = TPHD2 - 5;
a = (long)TPHD2*2500/4095; //放大1000倍,采集到1毫伏
a = (a*469-37500)/1000; //超聲傳感器公式150=a*0.4+b 900=a*2.0+b a=468.75 b=37.5
TPHD2 = a;
}
else {TPHD2 = 0;}
}
break;
case 0x04: //AIN0.4
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 3;
filter();
TEMP1= (sum/(N-2));
if(TEMP1》ADC04V)
{
KT1F = 1;
TEMP1 = TEMP1 - 5; //去掉偏移量
a = (long)TEMP1*2500/4095; //放大1000倍,采集到1毫伏
a = (long)(a*331-129000)/100; //線性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分別取313和125
TEMP1 = a; //兩點(diǎn)標(biāo)定法標(biāo)定后取a = 368 b = 157
}
else {TEMP1 = 0;KT1F = 0;}
}
break;
case 0x05: //AIN0.5
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 4;
filter();
TEMP2= (sum/(N-2));
if(TEMP2》ADC04V)
{
KT2F = 1;
TEMP2 = TEMP2 - 5; //去掉偏移量
a = (long)TEMP2*2500/4095; //放大1000倍,采集到1毫伏
a = (long)(a*331-129000)/100; //線性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分別取313和125
TEMP2 = a;
}
else {TEMP2 = 0;KT2F = 0;}
}
break;
case 0x06: //AIN0.6
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 5;
filter();
TEMP3= (sum/(N-2));
if(TEMP3》ADC04V)
{
KT3F = 1;
TEMP3 = TEMP3 - 5; //去掉偏移量
a = (long)TEMP3*2500/4095; //放大1000倍,采集到1毫伏
a = (long)(a*331-129000)/100; //線性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分別取313和125
TEMP3 = a;
}
else {TEMP3 = 0;KT3F = 0;}
}
break;
case 0x07: //AIN0.7
ADCbuffer1[count0]=ADC0;
count0++;
if (count0 》 N-1)
{
count0 = 0;
AD0EN = 0;
ADcount = 6;
filter();
TEMP4= (sum/(N-2));
if(TEMP4》ADC04V)
{
KT4F = 1;
TEMP4 = TEMP4 - 5; //去掉偏移量
a = (long)TEMP4*2500/4095; //放大1000倍,采集到1毫伏
a = (long)(a*331-129000)/100; //線性方程0=0.4a-b;500=2.0a-b 求解得a = 312.5 b=125 分別取313和125
TEMP4 = a;
}
else {TEMP4 = 0;KT4F = 0;}
}
break;
default:break;
}
}
void ADC1_ISR (void) interrupt 17
{
static uchar count1; // Loop counter
ADC1CN &=~(0x20); //清中斷標(biāo)志位
switch( AMX1SL ) //通道轉(zhuǎn)換
{
case 0x03: //AIN1.3
ADCbuffer1[count1]=ADC1;
count1++;
if (count1 》 N-1)
{
count1 = 0;
ADC1CN &=~(0x80);
ADcount = 7;
filter();
HT= (sum/(N-2));
if(HT》40)
{
HTF = 1;
HT = HT -4;
HT = (long)(HT*HTA-HTB*100)/10;
}
else {HT = 0;HTF = 0;}
}
break;
case 0x02: //AIN1.2
ADCbuffer1[count1]=ADC1;
count1++;
if (count1 》 N-1)
{
count1 = 0;
ADC1CN &=~(0x80);
ADcount = 8;
filter();
HR= (sum/(N-2));
if(HR》40)
{
HRF = 1;
HR = HR-4;
HR = (long)(HR*HRA-HRB*100)/10;
}
else {HR = 0;HRF = 0;}
}
break;
case 0x01: //AIN1.1
ADCbuffer1[count1]=ADC1;
count1++;
if (count1 》 N-1)
{
count1 = 0;
ADC1CN &=~(0x80);
ADcount = 9;
filter();
HP1= (sum/(N-2));
if((HP1》40)&&(HP1《123)) //負(fù)向傾角
{
HPF = 0;
HP = HP1-4;
HP = (long)(HPB*100-HP*HPA)/10;
}
if((HP1》127)&&(HP1《=255)) //正向傾角
{
HPF = 1;
HP = HP1-4;
HP = (long)(HP*HPA-HPB*100)/10;
}
if((HP1》=123)&&(HP1《=127))
{
HPF = 2; //只顯示0
HP = 0;
}
if(HP1《40)
{
HPF = 3; //未連接
}
}
break;
/* case 0x00: //AIN1.0
ADCbuffer1[count1]=ADC1;
count1++;
//ADC0CN |=0x10; //寫ADC1BUSY位啟動轉(zhuǎn)換
if (count1 》 N-1){
count1 = 0;
ADC1CN &=~(0x80);
ADcount = 8;
}
break;*/
default:break;
}
}
//-----------------------------------------
//TIMER3中斷 25毫秒定時(shí)
//-----------------------------------------
void Timer3_ISR(void) interrupt 14
{
static uchar j,k,count2,count3;
static uint count1;
TMR3CN &=~(0x80); //清標(biāo)志位
count1++;
count2++;
count3++;
j++;
if(count1》2000) //兩分鐘串口發(fā)送一次數(shù)據(jù)
{
count1 = 0;
sendc = 1;
}
if(count2 == 6) //200ms
{
count2 = 0;
Tset++;
if(Tset》4)
{
Tset = 0;
}
}
if(count3 == 4) //100ms
{
count3 = 0;
switch(ADcount)
{
case 1:
AMX0SL = 0x01; //指向下一個(gè)轉(zhuǎn)換通道
AD0EN = 1;
break;
case 2:
AMX0SL = 0x04; //指向下一個(gè)轉(zhuǎn)換通道
AD0EN = 1;
break;
case 3:
AMX0SL = 0x05; //指向下一個(gè)轉(zhuǎn)換通道
AD0EN = 1;
break;
case 4:
AMX0SL = 0x06; //下一個(gè)轉(zhuǎn)換通道
AD0EN = 1;
break;
case 5:
AMX0SL = 0x07; //下一個(gè)轉(zhuǎn)換通道
AD0EN = 1;
break;
case 6:
AMX1SL = 0x03; //下一個(gè)轉(zhuǎn)換通道
AD0EN = 0;
ADC1CN |= 0x80;
break;
case 7:
AMX1SL = 0x02; //下一個(gè)轉(zhuǎn)換通道
ADC1CN |= 0x80;
break;
case 8:
AMX1SL = 0x01; //下一個(gè)轉(zhuǎn)換通道
ADC1CN |= 0x80;
break;
case 9:
AMX0SL = 0x00; //下一個(gè)轉(zhuǎn)換通道
AD0EN = 1;
ADC1CN &=~(0x80);
break;
default:break;
}
}
if(j==40) //1秒誤差累積;正常是40
{
j = 0;
if(BGset)
{
k++;
BLK = 1;
if(k》120) //4分鐘關(guān)背光
{
k=0;
BGset = 0;
BLK = 0;
}
}
}
}
評論