微波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]>

seconds=((ReadValue&0x70)>>

minutes=((ReadValue&0x70)>>

hours=((ReadValue&0x70)>>

day=((ReadValue&0x70)>>

month=((ReadValue&0x70)>>

year=((ReadValue&0x70)>>

nian=((temp&0x70)>>

if(nian>

yue=((temp&0x70)>>

if(yue>

ri=((temp&0x70)>>

if(ri>

zhou=((temp&0x70)>>

if(zhou>

shi=((temp&0x70)>>

if(shi>

fen=((temp&0x70)>>

部时钟

MCGC2=0x40; //时钟源二分频

MCGTRM=0xa8;//内部时钟微调

}

//===================================

//函数名: IO_INIT

//作用: 初始化IO 输入输出

//====================================

void IO_INIT(void)

{

PTADD = 0xe6; //数据方向 1为输出,0为输入

PTBDD = 0x76;

PTCDD = 0xb0;

//PTDDD = 0xff;

PTEDD = 0x45;

PTFDD = 0xff;

PTGDD = 0x38;

PTAD = 0 ; //初始状态IO全为0

PTBD = 0;

PTCD = 0;

PTDD = 0;

PTED = 0;

PTFD = 0;

PTGD = 0;

}

//===================================

//函数名: ADC_INIT

//作用: 初始化ADC 总线时钟8M

//===================================

void ADC_INIT(void)

{

ADCCFG = 0xf9; //低功耗模式,10位精度,ADCK=总线频率/8/2=500K

ADCSC2 = 0x00; //0x00:软件触发,比较功能禁止

APCTL1 = 0x14; //通道引脚使能: 使用通道为AD19 AD11 AD3 AD4

APCTL2 = 0x08;

APCTL3 = 0x08;

ADch_s = 19; //选择19通道开始

ADCSC1 = 0x73; //0x53:中断使能,单次转换,选择19通道启动转换.

}

//===================================

//函数名:SCI_INIT

//作用: 初始化SCI1

//====================================

void SCI_INIT(void)

{

SCI1BD = 8000000/16/Baud;

SCI1C1 = 0x00;

SCI1C2 = 0x2c; //使能接受中断

}

//===================================

//串口发送

//===================================

void SCI1send (byte x)

{

while(SCI1S1_TDRE==0);

SCI1D = x;

}

//===================================

//定时器1初始化

//===================================

void TPM1_Init(void) //定时器1初始化

{

TPM1MODH=0x3d; //

TPM1MODL=0x09; //250MS

TPM1SC=0x4F; //TPM1时钟源为总线时钟;分频系数为128;溢出中断使能

}

//===================================

//延时

//===================================

void Delay(Word time)

{

Word i,j;

for(i=0;i

__RESET_WATCHDOG();

for(j=0;j<500;j++);

}

}

void WEEP()

{

FCMD=0x20;

FSTAT_FCBEF=1;

asm{

NOP

NOP

NOP

NOP

}

while(FSTAT_FCCF==0);

if(FSTAT_FACCERR==1)

FSTAT_FACCERR=1;

}

/*********************主函数************************************/

void main(void)

{

static byte MonthF1,DateF1,MonthF2,DateF2,MonthF3,DateF3,MonthC1,DateC1,MonthC2,DateC2,MonthC3,DateC3; //充电放电历史记录的两次时间变量及缓存变量

static byte FBETW0L,FBETW0H,FBETW1L,FBETW1H,CBETW0L,CBETW0H,CBETW1L,CBETW1H;

static word PupCount,PdownCount;

byte Pchange = 0 ; //充电0XFF 放电0X00转换标志

byte Failure; //故障信息指示MW17.0 = 1过压 MW17.1 = 1过流

word BetweenH,BetweenL;

long a,b;

byte SendSum;

MCU_INIT();

IO_INIT();

Ds1302_Init();

ADC_INIT();

TPM1_Init();

SCI_INIT();

DE485 = 1; //485发送使能;

PTED_PTED6 = 1;

Ds1302_Read_Time(); //先读取一次时间用于判断历史时间

if(!DI1) //DI1 = 0

{

Pchange = 0x01; //充电

}

if(!DI2) //DI2 = 0

{ //放电

Pchange = 0x02;

}

if(DI1&&DI2) //DI1,DI2都 为高电平

{

Pchange = 0;

}

FCdiv = 39; //设置FLASH分频 8M总线时钟分频数39;FLASH读写200KH

asm(nop);

//**************读取记录的充电的历史记录************************

//************前1次的前1次得充电记录

p=(byte *)(0x1401); //

MonthC1= *p;

p=(byte *)(0x1402); //时间

DateC1= *p;

p=(byte *)(0x1403); //电量的最低位

MW21L= *p;

p=(byte *)(0x1404); //

MW21H= *p;

p=(byte *)(0x1405); //

MW22L= *p;

p=(byte *)(0x1406); //

MW22H= *p;

if(MonthC1>12)

{

MonthC1 = 0;

DateC1= 0;

MW21L = 0;

MW21H = 0;

MW22L = 0;

MW22H = 0;

}

//*************前1次的充电记录*********************************

p=(byte *)(0x1411); //

MonthC2= *p;

p=(byte *)(

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

网站地图

Top