您的位置 首页 主动

根据C8051F的AD UART0 KEY FLASH TIME3程序

————————————————————————————Mainc———–

//————————————————————————————

// 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 = 0x02; // 上电复位VDD监视器复位标志
FLSCL=0X80; // 使能FLASH单稳态定时器,FLASH读时刻SYSCLK<=25MHz
FLKEY = 0xA5; // 写入关键字
FLKEY = 0xF1; // 写入关键字
PSCTL |= 0x03; //答应擦,答应写
CPT_x[0] = 0;
PSCTL &= ~0x03; //制止写,制止擦
//EA = 1;
}
void Flash_Program_CTP() //flash写入充电时刻时刻和功率
{
uchar j;
EA =0;
//Flash_Erase_CTP();
VDM0CN = 0x80; //使能VDD监视器
RSTSRC = 0x02; //上电复位/VDD监视器复位标志
FLSCL=0X80; //使能FLASH单稳态定时器,FLASH读时刻SYSCLK<=25MHz
PSCTL |= 0x01; //write enable
for(j =0;j<20;j++)
{
FLKEY = 0xa5;
FLKEY = 0xf1;
CPT_x[j] = Between[j];
//delayms(30);
}
PSCTL &= ~0x01; //制止写
EA = 1;
}
//***********************************
void Flash_Erase_FTP() //flash擦除放电时刻和功率
{
EA =0;
VDM0CN = 0x80; // 使能VDD监视器
RSTSRC = 0x02; // 上电复位VDD监视器复位标志
FLSCL=0X80; // 使能FLASH单稳态定时器,FLASH读时刻SYSCLK<=25MHz
FLKEY = 0xA5; // 写入关键字
FLKEY = 0xF1; // 写入关键字
PSCTL |= 0x03; //答应擦,答应写
FPT_x[0] = 0;
PSCTL &= ~0x03; //制止写,制止擦
//EA = 1;
}
void Flash_Program_FTP() //flash写入放电时刻和功率
{
uchar j;
//Flash_Erase_FTP();
EA = 0;
VDM0CN = 0x80; //使能VDD监视器
RSTSRC = 0x02; //上电复位/VDD监视器复位标志
FLSCL=0X80; //使能FLASH单稳态定时器,FLASH读时刻SYSCLK<=25MHz
PSCTL|=0x01; //write enable
for(j =0;j<20;j++)
{
FLKEY = 0xa5;
FLKEY = 0xf1;
FPT_x[j] = Between[j];
}
PSCTL &= ~0x01; //制止写
EA = 1;
}
/*void Flash_Read()
{
static uchar j;
for(j=0;j<3;j++)
{
timer[j]=Ftime_c[j];
}
}*/

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/zhudong/255159.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部