微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 基于C8051F的AD UART0 KEY FLASH TIME3程序

基于C8051F的AD UART0 KEY FLASH TIME3程序

时间:12-01 来源:互联网 点击:
//------------------------------------------------------------------------------------

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

sfr16 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[count] = ADCbuffer1[count];;

}

for (j=0;j

{

for (i=0;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

sum += value_buf[count];

}

void Uart0_SendData(uchar dat0)

{

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

while(TI0==0); //等待发送

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

}

void Flash_Erase_CTP() //flash擦除充电时间和功率

{

EA =0;

VDM0CN = 0x80; // 使能VDD监视器

RSTSRC =

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top