//------------------------------------------------------------------------------------// Main.c//------------------------------------------------------------------------------------// Copyright (C) 2011 Shenyang 213.// Wbr// Tool chain: KEIL Full 'c'////#pragma CD OE DB SB // Compilation directives//------------------------------------------------------------------------------------// Includes//------------------------------------------------------------------------------------#include "C8051F340.h"#include "1302.h"#include "lcd.h"#include#define SYSCLK 12000000 // SYSCLK frequency in Hz//------------------------------------------------------------------------------------// Global CONSTANTS//------------------------------------------------------------------------------------#define uint unsigned int#define uchar unsigned char#define T 1800 //运算电量的时间单位1800是半个小时(1800秒)#define N 11sfr16 TMR2 = 0xCC; //定义成16位地址sfr16 ADC0 = 0xBD; uint xdata ADCbuffer1[N];uint count;uint sum = 0; uchar ADcount = 0;uchar ADsend;uchar Page = 1,direction = 1;uchar set = 0,ent = 0,Tset;uchar TH,TL,TT1,TT2,TT3; //用来拆分送显示的变量uchar keybuffer[6];uchar BGset=0; //BGset背光关,开控制量,如果没有键按下超过1分钟,关闭背光!有键按下立刻开背光bit Disptime,PDD;sbit DI1 = P0^0 ;sbit DI2 = P0^1 ;sbit DE = P0^6 ;sbit BLK = P0^7 ; //LCD背光sbit JC1 = P2^7 ; sbit JC2 = P3^1 ;sbit JC3 = P3^2 ;sbit JC4 = P3^3 ;sbit DI3 = P3^6 ;sbit DI4 = P3^7 ;uchar code CPT_c[20] _at_ 0x8000; //7k的地址左右//充电时间要存入的FLASH地址,保存3天的时间和功率uchar xdata CPT_x[20] _at_ 0x8000;uchar code FPT_c[20] _at_ 0x8200; //7k的地址左右//放电时间要存入的FLASH地址,保存3天的时间和功率uchar xdata FPT_x[20] _at_ 0x8200; uchar xdata Between[20]; //0~11时间12~19存功率////////////////////////////////////extern void Init_Device(void);extern uchar time_buf1[8] ;uchar code tab1[]={"实时电压:"};uchar code tab2[]={"实时电流:"};uchar code tab3[]={"实时功率:"};uchar code tab4[]={"运行状态:"};uchar code tab5[]={"历史充电记录"};uchar code tab6[]={"历史放电记录"};uchar code tab7[]={"当前时间"};uchar code tab8[]={"修改时间"};uchar code tab9[]={"暂无记录"};uchar code run1[]={"停机"};uchar code run2[]={"充电"};uchar code run3[]={"放电"};uchar code run4[]={"故障"};//uchar code run5[]={//"系统故障信息"//};uchar code run5[]={"感谢您的使用"};uchar code run6[]={"本日累计充电"};uchar code run7[]={"本日累计放电"};uchar code run8[]={"版本号:V1.0"};uchar xdata TAB[11]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x20};//数字0~9及显示空白0x20//---------------------------------------- // Function PROTOTYPES//----------------------------------------void delayms(uint ms){ uint Temp; while(ms--) { Temp=1000; while(Temp--); { //PCA0CPH2 = 1; } }}/*void Timer2_Init(int count2s){ TMR2CN = 0x00; TMR2L = -count2s; TMR2 = 0xffff; ET2 = 1; TR2 = 1; }*///================================//中值滤波程序//================================void filter(){ static uchar count,i,j; uint value_buf[N]; uint temp; sum=0; for(count=0;count value_buf[i+1] ) { temp = value_buf[i]; value_buf[i] = value_buf[i+1]; value_buf[i+1] = temp; } } } for(count=1;count 1) { BGset = 2; } } } } if(BGset ==2 ){ if(!(Mkey&0x80)) //SW1按下吗?ALM { delayms(200); //消抖 if(!(Mkey&0x80)) //再判断 { BGset =2; //开背光 if(k<1) {Page = 0;} //页面0:显示故障状态} k++; if(k>1) {k =0;Page = 1; } //再按后退出 set = 0; } } if(!set) { if(!(Mkey&0x40)) //SW2按下吗?下翻 { delayms(200); if(!(Mkey&0x40)) { if(Page !=0) { Page++; BGset =2; if(Page>6) //如果超过5界面回到1画面 { Page = 1; } } } } if(!(Mkey&0x20)) //SW3按下吗?上翻 { delayms(200); if(!(Mkey&0x20)) { if(Page !=0) { Page--; BGset =2; if(Page<1) //小于1画面后不显示0画面,显示6画面 { Page = 6; } } } } } if(Page ==6) //修改时间界面 { if(!(Mkey&0x04)) //SW6按下吗?设定SET只在6画面设置时间 { delayms(200); if(!(Mkey&0x04)) { BGset =2; set = 1; //如果按下SET键表示开始设置时间,置设置标志位; } } if(set) { if(!(Mkey&0x10)) //SW4按下吗?左移<- 只在6画面修改时间 { delayms(200); if(!(Mkey&0x10)) { BGset =2; direction--; if(direction < 1) { direction = 6; } } } if(!(Mkey&0x08)) //SW5按下吗?右移->只在6画面修改时间 { delayms(200); if(!(Mkey&0x08)) { BGset =2; direction++; if(direction > 6) { direction = 1; } } } switch(direction) { case 1: { if(!(P4&am
基于C8051F的AD UART0 KEY FLASH TIME3程序
时间:2024-05-09 01:07:10