//------------------------------------------------------------------------------------ // 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通道變量四路來料溫度 環(huán)境溫度濕度 橫坡度 攤鋪厚度 uchar idata HPF,KT1F,KT2F,KT3F,KT4F,HTF,HRF; //橫坡傳感器狀態(tài)位 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]; //使用的衛(wèi)星數 //uchar xdata total_sat[2]; //天空中總衛(wèi)星數 //uchar lock; //定位狀態(tài) //串口中斷需要的變量 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[]={"環(huán)境溫度:"}; uchar code tab6[]={"環(huán)境濕度:"}; 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[]={"攤鋪壓實監(jiān)測裝置"}; 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單穩(wěn)態(tài)定時器,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:顯示版本信息狀態(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; } } } } } //************************************************ //設置參數 //************************************************ 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); //定時送滅狀態(tài),實現閃爍 } }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]); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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]); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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]); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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]); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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]); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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]); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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]); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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); //定時送滅狀態(tài),實現閃爍 } }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發(fā)送函數 //=================================== void Uart0_SendData(uchar dat0) { SBUF0=dat0; //寫SBUF0,開始發(fā)送 while(!TI0); //等待發(fā)送 TI0=0; //清發(fā)送標志位 } 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 時:0xCAB1: 分0xB7D6: 秒:0xC3EB 的漢字內碼 //----------------------------------------------------------------------------- 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; 拆分顯示的百,十,個位,小數點位中間變量 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; //環(huán)境溫度十位 BEW3 = (HT%100)/10; //環(huán)境溫度個位 BEW4 = (HT%100)%10; //環(huán)境溫度小數位 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)境濕度個位 BEW4 = (HR%100)%10; //環(huán)境濕度小數位 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: //顯示故障狀態(tài) { 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個字節(jié) switch(Between[2]) //協(xié)議類型,0X0a攤鋪 0X14碾壓 { case 0x0a: Uart0_SendData(0x0a); //攤鋪 break; case 0x14: Uart0_SendData(0x14); //壓實 break; default: Uart0_SendData(0x0a); //默認0X0a break; } Uart0_SendData(0x00); //預留字節(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]); //時間年月日時分秒 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); //環(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); //結束符 //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個字節(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; //接收位數清空 } 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: //定位使用的衛(wèi)星數 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次以上還是原來狀態(tài)證明不是干擾脈沖 { 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++; //發(fā)生了正跳變,開始計時 } } 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次以上還是原來狀態(tài)證明不是干擾脈沖 { 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++; //發(fā)生了正跳變,開始計時 } } if(m1) { if((LNY1&0xFF) ==0xFF) //發(fā)生了負跳變,計時結束,開始計算速度 { 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) //兩分鐘串口發(fā)送一次數據 { 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; } } } }