微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 基于飞思卡尔DZ60的AD 1302 KEY 485 CAN FLASH LCD程序

基于飞思卡尔DZ60的AD 1302 KEY 485 CAN FLASH LCD程序

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

#define DI1 PTGD_PTGD2 //外触发1----->

#define DI2 PTED_PTED5 //外触发2----->

#define DI3 PTED_PTED4 //外触发3----->

#define DI4 PTED_PTED3 //外触发4----->

#define JDQ1 PTCD_PTCD4 //继电器1----->

#define JDQ2 PTAD_PTAD5 //继电器2----->

#define JDQ3 PTBD_PTBD5 //继电器3----->

#define JDQ4 PTAD_PTAD6 //继电器4----->

#define JDQ5 PTBD_PTBD6 //继电器5----->

#define DE485 PTED_PTED2 //485 T R切换----->

if ( value_buf[i]>

if(MonthC1>

minutes=((ReadValue&0x70)>>

day=((ReadValue&0x70)>>

year=((ReadValue&0x70)>>

if(MonthC2>

nian=((temp&0x70)>>

if(nian>

if(MonthC3>

(ADcount == 1)

{

filter();

ADC1= (sum/(N-2));

if(ADC1<7){ ADC1 = 0; //屏蔽掉待机状态时的不干净的初值

}

if (ADC1>163)

{

Failure = Failure|0x01; //置过压标志

}

else Failure = Failure&0xfe; //清过压标志

//b = 750*50;

//b = b/255;

b = (long)7500*ADC1; //放大10倍,为了送显示

//ADC1 = b*ADC1;

//ADC1 = ADC1/5;

ADC1 = b>>10; //除以1024

ADC1H = ADC1>>8;

ADC1L = ADC1&255;

ADch_s = 11;

ADCSC1=0x6b;

}

if(ADcount == 2)

{

filter();

ADC2= (sum/(N-2));

if(ADC2<7) { ADC2 = 0;

}

if (ADC2>191) //过流

{

Failure = Failure|0x02; //置过流标志

}

else Failure = Failure&0xfd; //清过流标志

//a= 400*50;

//a= a/255;

a = (long)4000*ADC2;

//ADC2 = a*ADC2; //转换成电压值 ,取小数点后一位,所以先扩大50倍

//ADC2 = ADC2/5; //10倍电流送显示,用于显示小数点

ADC2 = a>>10;

ADC2H = ADC2>>8;

ADC2L = ADC2&255;

ADC1 = ADC1/10;

ADC2 = ADC2/10;

P =(long)ADC1*ADC2;

PH = P>>16;

PL = P&0xffff;

P1H = PH>>8;

P1L = PH&255;

P0H = PL>>8;

P0L = PL&255;

if(Pchange==0x02) //如果放电

{

PdownCount++; //秒累加

P2 = P2+P; //一直累积的放电电量

Psum=(long)(P2/3600/1000);

BetweenH = Psum>>16;

BetweenL = Psum&0xffff;

MW9H = BetweenH>>8;

MW9L = BetweenH&255;

MW8H = BetweenL>>8;

MW8L = BetweenL&255;

P1 = P1+P; //秒功率累加

Pdown = (long)P1/3600; //实际放电功率,按小时计算

BetweenH = Pdown>>16;

BetweenL = Pdown&0xffff;

MW7H = BetweenH>>8;

MW7L = BetweenH&255;

MW6H = BetweenL>>8;

MW6L = BetweenL&255;

if(PdownCount > T) //超过半个小时开始写入EEPROM

{

PdownCount = 0;

p=( unsigned char *)(0x1600); //指定地址

*p=0x01;

FCMD=0x40; //擦除命令

FSTAT_FCBEF=1; //启动命令

Delay(1);

while(FSTAT_FCCF==0); //等待完成

if(FSTAT_FACCERR==1)

FSTAT_FACCERR=1;

p=(byte *)(0x1600); //指定地址

*p = 0x01;

WEEP();

p=(byte *)(0x1601); //总放电量写入EEPROM

*p = MW8L;

WEEP();

p=(byte *)(0x1602);

*p = MW8H;

WEEP();

p=(byte *)(0x1603);

*p = MW9L;

WEEP();

p=(byte *)(0x1604);

*p = MW9H;

WEEP();

asm(nop);

if((time_buf1[2] == MonthF3)&& (time_buf1[3] == DateF3)) //当前时间等于缓存时间,继续写入缓存

{

MonthF3 = time_buf1[2];

DateF3 = time_buf1[3];

FBETW0L = MW6L;

FBETW0H = MW6H;

FBETW1L = MW7L;

FBETW1H = MW7H;

p=( unsigned char *)(0x1520); //指定地址

*p=0x01;

FCMD=0x40; //擦除命令

FSTAT_FCBEF=1; //启动命令

Delay(1);

while(FSTAT_FCCF==0); //等待完成

if(FSTAT_FACCERR==1)

FSTAT_FACCERR=1;

p=(byte *)(0x1520); //指定地址

*p = 0x01;

WEEP();

p=(byte *)(0x1521);

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

网站地图

Top