c8051f单片机ad采样程序(附详细注释)

编程实验

72人已加入

描述

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;

}

//================================

//中值滤波程序

//================================

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:显示版本信息状态

//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:显示版本信息状态

//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;

}

}

}

}

}

//************************************************

//设置参数

//************************************************

if(Page ==0)

{

if(!(Mkey&0x02)) //SET按下吗?设定SET在0画面设置参数

{

delayms(200);

if(!(Mkey&0x02))

{

BGset =2;

set = 1; //如果按下SET键表示开始设置时间,置设置标志位;

}

}

if(set == 1)

{

if(!(Mkey&0x20)) //《- 按下吗?左移《- 在0画面修改参数

{

delayms(200);

if(!(Mkey&0x20))

{

BGset =2;

direction1++;

if(direction1 》 14)

{

direction1 = 1; //本界面14个数字要修改

}

}

}

if(!(Mkey&0x80)) //-》按下吗?右移-》只在0画面修改时间

{

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) //设置,不超过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); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZH0 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x97,1,TAB[SZH0],TAB[SZL0]);

}

if(Tset》2)

{

number_disp (0x97,1,0x20,TAB[SZL0]); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZL1 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);

}

if(Tset》2)

{

number_disp (0x96,1,TAB[SZH1],0x20); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZH1 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);

}

if(Tset》2)

{

number_disp (0x96,1,0x20,TAB[SZL1]); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZL2 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);

}

if(Tset》2)

{

number_disp (0x95,1,TAB[SZH2],0x20); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZH2 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);

}

if(Tset》2)

{

number_disp (0x95,1,0x20,TAB[SZL2]); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZL3 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);

}

if(Tset》2)

{

number_disp (0x8f,1,TAB[SZH3],0x20); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZH3 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);

}

if(Tset》2)

{

number_disp (0x8f,1,0x20,TAB[SZL3]); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZL4 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);

}

if(Tset》2)

{

number_disp (0x8e,1,TAB[SZH4],0x20); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZH4 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);

}

if(Tset》2)

{

number_disp (0x8e,1,0x20,TAB[SZL4]); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZL5 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);

}

if(Tset》2)

{

number_disp (0x9f,1,TAB[SZH5],0x20); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZH5 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);

}

if(Tset》2)

{

number_disp (0x9f,1,0x20,TAB[SZL5]); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZL6 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x9e,1,TAB[SZH6],TAB[SZL6]);

}

if(Tset》2)

{

number_disp (0x9e,1,TAB[SZH6],0x20); //定时送灭状态,实现闪烁

}

}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) //设置,不超过9

{

SZH6 = 0;

}

}

}

if(Tset 《 2)

{

number_disp (0x9e,1,TAB[SZH6],TAB[SZL6]);

}

if(Tset》2)

{

number_disp (0x9e,1,0x20,TAB[SZL6]); //定时送灭状态,实现闪烁

}

}break;

default:break;

}

if(!(Mkey&0x04)) //ENT按下吗?确认ENT 在0画面设定参数

{

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画面

}

}

}

}

//***********************************************

//修改时间

//***********************************************

if(Page ==7) //修改时间界面

{

if(!(Mkey&0x02)) //SET按下吗?设定SET只在7画面设置时间

{

delayms(200);

if(!(Mkey&0x02))

{

BGset =2;

set = 2; //如果按下SET键表示开始设置时间,置设置标志位;

}

}

if(set == 2)

{

if(!(Mkey&0x20)) //《- 按下吗?左移《- 只在7画面修改时间

{

delayms(200);

if(!(Mkey&0x20))

{

BGset =2;

direction--;

if(direction 《 1)

{

direction = 6;

}

}

}

if(!(Mkey&0x80)) //-》按下吗?右移-》只在7画面修改时间

{

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) //年设置,不超过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); //定时送灭状态,实现闪烁

}

}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) //月设置,不超过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); //定时送灭状态,实现闪烁

}

}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) //日设置,不超过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); //定时送灭状态,实现闪烁

}

}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) //时设置,不超过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) //分设置,不超过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) //秒设置,不超过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按下吗?确认ENT 只在6画面设定时间

{

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发送函数

//===================================

void Uart0_SendData(uchar dat0)

{

SBUF0=dat0; //写SBUF0,开始发送

while(!TI0); //等待发送

TI0=0; //清发送标志位

}

void Uart1_SendData(uchar dat1)

{

SBUF1=dat1; //写SBUF1,开始发送

while(!(SCON1&0x02));

SCON1 = (SCON1&0xfd);

}

void Timer2_Init(int ct2s)

{

RCAP2H = -ct2s/0xff;

RCAP2L = -ct2s;

}

//-----------------------------------------------------------------------------

// Main 年:0xC4EA 月:0xD4C2 日:0xC8D5 时:0xCAB1: 分0xB7D6: 秒:0xC3EB 的汉字内码

//-----------------------------------------------------------------------------

void main(void)

{

//uint TEMP1,TEMP2,TEMP3,TEMP4,HT,HR,HP; //8路AD通道变量四路来料温度 环境温度湿度 横坡度

uchar i,j,Page1,BEW1,BEW2,BEW3,BEW4; //BEW1,BEW2,BEW3,BEW4; 拆分显示的百,十,个位,小数点位中间变量

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增益设为1

AD0EN = 1; //使能AC0启动转换

ADC1CN &=~(0x80); //使能AC1启动转换

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:显示当前

{

string_disp (0x80,16,page1);

number_disp (0x89,1,0x32,0x30); //数字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); //时

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; //时

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; //保存当前页面值

}break;

case 2:

{

string_disp (0x82,8,page2); //显示实时采集量

string_disp (0x90,10,tab5);

if(HTF)

{

string_disp (0x97,2,tab8); //显示℃

BEW2 = HT/100; //环境温度十位

BEW3 = (HT%100)/10; //环境温度个位

BEW4 = (HT%100)%10; //环境温度小数位

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; //环境湿度十位

BEW3 = (HR%100)/10; //环境湿度个位

BEW4 = (HR%100)%10; //环境湿度小数位

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; //横坡度个位

BEW4 = (HP%100)%10; //横坡度小数位

if(HPF == 0) //负度数标志位

{

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) //正度数标志位

{

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度数标志位

{

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) //未连接标志位

{

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; //温度个位

BEW4 = ((TEMP1%1000)%100)%10; //温度小数位

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; //温度个位

BEW4 = ((TEMP2%1000)%100)%10; //温度小数位

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; //温度个位

BEW4 = ((TEMP3%1000)%100)%10; //温度小数位

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; //温度个位

BEW4 = ((TEMP4%1000)%100)%10; //温度小数位

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; //温度个位

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; //温度个位

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: //传感器标定 厚度显示

{

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,异常数,则清零

//{

// 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: //修改时间

{

if(!(set==2)) //没有按SET键

{

string_disp (0x80,10,page7);

number_disp (0x89,1,0x32,0x30); //数字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); //时

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; //时

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; //保存当前页面值

}break;

case 0: //显示故障状态

{

if(!(set==1)) //没有按SET键

{

number_disp (0x82,1,0xb2,0xce); //参

number_disp (0x83,1,0xca,0xfd); //数

number_disp (0x84,1,0xc9,0xe8); //设

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; //保存当前页面值

}break;

default:break;

}

if(sendc)

{

sendc = 0;

Uart0_SendData(0x7f); //首字符串

Uart0_SendData(0x00); //数据包长度

Uart0_SendData(0x38); //56个字节

switch(Between[2]) //协议类型,0X0a摊铺 0X14碾压

{

case 0x0a:

Uart0_SendData(0x0a); //摊铺

break;

case 0x14:

Uart0_SendData(0x14); //压实

break;

default:

Uart0_SendData(0x0a); //默认0X0a

break;

}

Uart0_SendData(0x00); //预留字节

Uart0_SendData(0x00);

Uart0_SendData(Between[2]); //ID

Uart0_SendData(Between[1]);

Uart0_SendData(Between[0]);

Uart0_SendData(0x14);

Uart0_SendData(time_buf1[1]); //时间年月日时分秒

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++) //经度

{

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); //压实速度

Uart0_SendData(SPEEDNY%100);

break;

default:

Uart0_SendData(0x00); //压实速度

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); //环境温度湿度横坡度

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); //结束符

//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个字节

{

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; //接收位数清空

}

break;

case ‘,’:

{

seg_count++; //逗号计数加1

byte_count=0;

}

break;

case ‘*’: //数据帧结束标志

{

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)

{ //如果类型数据接收完毕,判断类型

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)

{ //接收数据处理

//类型1数据接收。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: //经度处理

if(byte_count《11)

{

JD[byte_count]=tmp;

}

break;

case 5: //经度方向处理

if(byte_count《1)

{

JD_a=tmp;

}

break;

/*case 6: //定位判断

if(byte_count《1)

{

lock=tmp;

}

break;

case 7: //定位使用的卫星数

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++; //接收数位加1

break;

}

//temp=0;

//byte_count++; //接收数位加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; //清标志位

i++;

if(i==50)

{

P5=~(P5);

i = 0;

}

LTP1 = P7; //接近开关不遮挡输出高电平,

LNY1 = P7;

if((LTP1&0xFF) ==0xFF) //P70=1;遮挡上了,接近开关无输出,此时P70=1;

{

j1++;

if(j1》2) //2次以上还是原来状态证明不是干扰脉冲

{

j1 = 0;

k = 1; //检测到P70为0,置位K

}

c3++;

if(c3》9000) //超过1分半钟没变化认为停止了

{

c3 = 0;

SPEEDcount1 = 0;

SPEEDTP = 0;

}

}

if(k) //在置位情况下等待下降沿

{

if((LTP1&0xFF) ==0xFE) //P70=0;检测到无遮挡,接近开关输出24V,开始一个周期此时P70 = 0;

{

j2++;

if(j2》2) //过滤脉冲干扰

{

j2 = 0;

k1 = 1;

}

c1++;

if(c1》9000) //超过1分半钟没变化认为停止了

{

c1 = 0;

SPEEDcount1 = 0;

SPEEDTP = 0;

k1 = 0;

k = 0;

}

if(k1)

{

SPEEDcount1++; //发生了正跳变,开始计时

}

}

if(k1)

{

if((LTP1&0xFF) ==0xFF) //再一次检测到有遮挡表示一次检测周期结束,计时结束,开始计算速度

{

j3++;

if(j3》2)

{

j3 = 0;

k1 = 0;

k = 0;

//SPEEDTP = SPEEDcount1/100; //(秒)

SPEEDTP = (long)600*(Between[4]*100 + Between[3])/SPEEDcount1; //米/分;显示部分已经后移了两位

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次以上还是原来状态证明不是干扰脉冲

{

j4 = 0;

m = 1; //检测到P71为0,置位M

}

c4++;

if(c4》9000) //超过1分半钟没变化认为停止了

{

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分半钟没变化,认为停止了

{

c2 = 0;

SPEEDcount2 = 0;

SPEEDNY = 0;

m1 = 0;

m = 0;

}

if(m1)

{

SPEEDcount2++; //发生了正跳变,开始计时

}

}

if(m1)

{

if((LNY1&0xFF) ==0xFF) //发生了负跳变,计时结束,开始计算速度

{

j6++;

if(j6》2)

{

j6 = 0;

m1 = 0;

m = 0;

SPEEDNY = (long)36*(Between[6]*100 + Between[5])/SPEEDcount2; //km/h;显示部分已经后移了两位

SPEEDcount2 = 0;

c2 = 0;

c4 = 0;

}

}

}

}

}

void ADC0_ISR (void) interrupt 15

{

static uchar count0; // Loop counter

AD0INT = 0; //清中断标志位

switch( AMX0SL ) //通道转换

{

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; //两点标定法标定后取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); //清中断标志位

switch( AMX1SL ) //通道转换

{

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)) //负向倾角

{

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位启动转换

if (count1 》 N-1){

count1 = 0;

ADC1CN &=~(0x80);

ADcount = 8;

}

break;*/

default:break;

}

}

//-----------------------------------------

//TIMER3中断 25毫秒定时

//-----------------------------------------

void Timer3_ISR(void) interrupt 14

{

static uchar j,k,count2,count3;

static uint count1;

TMR3CN &=~(0x80); //清标志位

count1++;

count2++;

count3++;

j++;

if(count1》2000) //两分钟串口发送一次数据

{

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; //指向下一个转换通道

AD0EN = 1;

break;

case 2:

AMX0SL = 0x04; //指向下一个转换通道

AD0EN = 1;

break;

case 3:

AMX0SL = 0x05; //指向下一个转换通道

AD0EN = 1;

break;

case 4:

AMX0SL = 0x06; //下一个转换通道

AD0EN = 1;

break;

case 5:

AMX0SL = 0x07; //下一个转换通道

AD0EN = 1;

break;

case 6:

AMX1SL = 0x03; //下一个转换通道

AD0EN = 0;

ADC1CN |= 0x80;

break;

case 7:

AMX1SL = 0x02; //下一个转换通道

ADC1CN |= 0x80;

break;

case 8:

AMX1SL = 0x01; //下一个转换通道

ADC1CN |= 0x80;

break;

case 9:

AMX0SL = 0x00; //下一个转换通道

AD0EN = 1;

ADC1CN &=~(0x80);

break;

default:break;

}

}

if(j==40) //1秒误差累积;正常是40

{

j = 0;

if(BGset)

{

k++;

BLK = 1;

if(k》120) //4分钟关背光

{

k=0;

BGset = 0;

BLK = 0;

}

}

}

}

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分