📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
void LeakDeal(void);
extern void ad_ch_scal(unsigned char ch,uint8 scal);
extern void Cs7705(uint8 dat);
extern void da_5628(uint8 ch,uint8 dat);
extern void MbusDel(void);
extern void SysInit(void);
extern uint8 I2C_ReadNByte (uint8 sla, uint32 suba_type, uint32 suba, uint8 *s, uint32 num);
extern uint8 I2C_WriteNByte(uint8 sla, uint8 suba_type, uint32 suba, uint8 *s, uint32 num);
extern uint8 MSPI_SendData(uint8 dat );
extern void ReadIntAd (uint8 ch);
extern float GetVaccum(uint16 dat);
extern uint8 Hc595Dat;
extern uint8 rcv_new;
extern uint8 SavePar;
extern uint8 SysSec;
extern uint8 X4Dat[65];
extern uint16 IntAdDat[6];
uint8 AlarmBase;
uint8 AlarmExp ;
uint8 AmpRate;
uint8 AmpChgDly;
uint8 AmpDly1;
uint8 AmpDly2;
uint8 AmpDly3;
uint8 AmpDly4;
uint8 AmpSelect;
uint16 AutoZeroTm;//auto zero delay time
uint8 AutoZeroFg;
uint8 CalBase ;
uint8 CalExp ;
uint16 CalValue ;
uint8 CalTm;
uint8 DecPort;
uint8 DynIndex;
uint16 ErrTimes;
uint8 EnRel1;
uint8 EnRel2;
uint8 EnPe;
uint8 EnShowVcm;
uint8 EnBeep;
uint8 FltMod;
uint8 FPGAEn;
uint8 IntAdRdRt;
uint8 KeyReg[1];
uint8 KeyRept[1];
float LeakValue;
float LkValue;
float LkValueDown;
float LeakBase ;
uint8 LeakExp ;
float LkValueDyn[120];
uint32 LeakValueRd;
uint32 LeakValueRd1;
float LeakValueRd2;
uint32 LeakValueTmp;
float LkPtVaccum;
float LkPtVaccumMain;
uint8 MdBusBuff[8];
uint8 MustV3;
uint8 MsOk;
uint8 OverPort;
uint8 Overed;
uint16 RmTime;
uint16 RunHour;
uint8 RunMin;
float RemCal;
uint32 SysErrNum;
uint32 SysStd;
uint16 StartTm;
uint8 StartDlyed;
uint8 StartDone;
uint8 StartLkDec;
int16 SigVol;
uint8 SpKeyDel;
float TpumVaccum;
float TpumVaccumMain;
uint16 TpumSpeed;
uint8 TmpOk;
uint16 TmpHour;
uint8 Unit;
uint8 VacumUnit;
uint8 VacumUnitOld;
uint8 Volum;
uint8 VolumTmp;
uint8 VDly0;
uint8 VDly1;
uint8 VDly2;
uint8 VDly3;
uint8 VDly4;
uint8 VDly5;
uint8 VDly6;
uint8 VDly7;
uint8 VDly8;
uint8 VdFg1;
uint8 VdFg2;
uint8 VdFg3;
uint8 VdFg4;
uint8 VdFg5;
uint8 VdFg6;
uint8 VdFg7;
uint8 VdFg8;
uint8 Warning;
uint8 WriteTmp[2];
uint16 WindowsFg;
uint16 RelBase1;
uint8 RelExp1;
uint16 RelBase2;
uint8 RelExp2;
float ZeroLeakValue;
float ZeroLeakValueTp;
uint8 Zeroing;
uint8 MacFact;
//uint8 * X4Point;
void DelayNS (uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
for (i=0; i<10000; i++)
{
if ((SysStd==Error)&&KeyReg[0]!=KeyStSp)
{
V2Off;V3Off;V4Off;
break;
}
}
}
void DelayNS1 (uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
for (i=0; i<10000; i++)
{
;
}
}
void BeepAlarm(uint8 tms)
{
for (;tms>0;tms--)
{
IO0CLR = BEEP;
DelayNS1(100);
IO0SET = BEEP;
DelayNS1(100);
}
}
/********************************************************************/
// 主函数开始
/********************************************************************/
int main (void)
{
// add user source code
uint8 i;
//uint32 IoD,j;
//uint8 KeyReg[1];
uint8 TryTms;
//FPGAEn=1;
//X4Point=&X4Dat[0];
IRQDisable();
SysInit();
DelayNS(10);
I2C_ReadNByte (0xA0, 1,0x10, MdBusBuff, 8);
for (i=0;i<8;i++)
X4Dat[i]=MdBusBuff[i];
DelayNS(10);
I2C_ReadNByte (0xA0, 1,0x18, MdBusBuff, 8);
for (i=8;i<16;i++)
X4Dat[i]=MdBusBuff[i-8];
DelayNS(10);
I2C_ReadNByte (0xA0, 1,0x20, MdBusBuff, 8);
for (i=16;i<24;i++)
X4Dat[i]=MdBusBuff[i-16];
DelayNS(10);
I2C_ReadNByte (0xA0, 1,0x28, MdBusBuff, 8);
for (i=24;i<32;i++)
X4Dat[i]=MdBusBuff[i-24];
DelayNS(10);
I2C_ReadNByte (0xA0, 1,0x30, MdBusBuff, 8);
for (i=32;i<40;i++)
X4Dat[i]=MdBusBuff[i-32];
DelayNS(10);
I2C_ReadNByte (0xA0, 1,0x38, MdBusBuff, 8);
for (i=40;i<48;i++)
X4Dat[i]=MdBusBuff[i-40];
DelayNS(10);
I2C_ReadNByte (0xA0, 1,0x40, MdBusBuff, 8);
for (i=48;i<56;i++)
X4Dat[i]=MdBusBuff[i-48];
DelayNS(10) ;
I2C_ReadNByte (0xA0, 1,0xfe, WriteTmp, 2);
RemCal=WriteTmp[0]*256+WriteTmp[1];
DelayNS(10) ;
I2C_ReadNByte (0xA0, 1,0xf0, WriteTmp, 2);
RunHour=WriteTmp[0]*256+WriteTmp[1];
DelayNS(10) ;
I2C_ReadNByte (0xA0, 1,0xf2, WriteTmp, 2);
RunMin =WriteTmp[0]*256+WriteTmp[1];
DelayNS(10) ;
I2C_ReadNByte (0xA0, 1,0xf4, WriteTmp, 2);
ErrTimes =WriteTmp[0]*256+WriteTmp[1];
IRQEnable();
AlarmBase=X4Dat[0]*256+X4Dat[1];
AlarmExp =X4Dat[2]*256+X4Dat[3];
Volum =X4Dat[4]*256+X4Dat[5];
Unit =X4Dat[6]*256+X4Dat[7];
CalBase=X4Dat[8]*256+X4Dat[9];
CalExp =X4Dat[10]*256+X4Dat[11];
DecPort =256*X4Dat[12]+X4Dat[13];
VacumUnit=256*X4Dat[16]+X4Dat[17];
VacumUnitOld=VacumUnit;
FltMod =256*X4Dat[18]+X4Dat[19];
ZeroMode=X4Dat[20]*256+X4Dat[21];
ZeroLevel=X4Dat[22]*256+X4Dat[23];
ZeroDelTm=X4Dat[24]*256+X4Dat[25];
RelBase1=256*X4Dat[26]+X4Dat[27];
RelExp1= 256*X4Dat[28]+X4Dat[29];
RelBase2=256*X4Dat[30]+X4Dat[31];
RelExp2= 256*X4Dat[32]+X4Dat[33];
EnRel1= 256*X4Dat[34]+X4Dat[35];
EnRel2= 256*X4Dat[36]+X4Dat[37];
MacFact= 256*X4Dat[50]+X4Dat[51];
EnWarnRel= 256*X4Dat[54]+X4Dat[55];
SysStd=Start;
AmpRate=4;
IRQDisable();
SetAmp(AmpRate);
IRQEnable();
DelayNS(1);
KeyReg[0]=0;
StartDlyed=0;
VdFg1=0;
VdFg2=0;
VdFg3=0;
VdFg4=0;
VdFg5=0;
VdFg6=0;
VdFg7=0;
VdFg8=0;
DelayNS(2000);
//for(;;);
/********************************************************************/
// 主循环开始
/********************************************************************/
while(1)
{
//if(Cnt%2)
{
// PWM2On;
}
//else
{
// PWM2Off;
}
System();
if (IntAdRdRt>10)
{
//IRQDisable(); 07 03 12
for(i=1;i<6;i++) //读取内部AD的值
{
ReadIntAd(i);
}
IntAdRdRt=0;
}
ReadIntAd(0);
LkPtVaccum=(GetVaccum(IntAdDat[0]));
//EnShowVcm=0;
//IRQEnable(); 07 03 12
/*DisTm0;
DisTm1;
DisUart0;
DisUart1;
DisI2C0;*/
//GetLeak();//LeakDeal(); //漏率处理
/*EnTm0;
EnTm1;
EnUart0;
EnUart1;
EnI2C0; */
if ((VolumTmp!=Volum)&&(Warning!=1))
{
/*DisTm0;
DisTm1;
DisUart0;
DisUart1;
DisI2C0;*/
IRQDisable();
VolumTmp=Volum;
da_5628(0,200);
DelayNS(20);
da_5628(0,180);
DelayNS(20);
da_5628(1,Volum*7);
DelayNS(20);
da_5628(0,0);
DelayNS(10);
da_5628(1,0);
IRQEnable();
/*EnTm0;
EnTm1;
EnUart0;
EnUart1;
EnI2C0;*/
}
/********************************************************************/
/* 设定的数据储存 */
/********************************************************************/
if (SavePar==1) //储存设定的数据
{
//IRQDisable();
SavePar=0;
/*DisTm0;
DisTm1;
DisUart0;
DisUart1;*/
//DisI2C0;
for (i=0;i<8;i++)
MdBusBuff[i]=X4Dat[i];
I2C_WriteNByte (0xa0, 1,0x10, MdBusBuff, 8);
DelayNS(1);
for (i=8;i<16;i++)
MdBusBuff[i-8]=X4Dat[i];
I2C_WriteNByte (0xa0, 1,0x18,MdBusBuff, 8);
DelayNS(1);
for (i=16;i<24;i++)
MdBusBuff[i-16]=X4Dat[i];
I2C_WriteNByte (0xa0, 1,0x20,MdBusBuff, 8);
DelayNS(1);
for (i=24;i<32;i++)
MdBusBuff[i-24]=X4Dat[i];
I2C_WriteNByte (0xa0, 1,0x28,MdBusBuff, 8);
DelayNS(1);
for (i=32;i<40;i++)
MdBusBuff[i-32]=X4Dat[i];
I2C_WriteNByte (0xa0, 1,0x30,MdBusBuff, 8);
DelayNS(1);
for (i=40;i<48;i++)
MdBusBuff[i-40]=X4Dat[i];
I2C_WriteNByte (0xa0, 1,0x38,MdBusBuff, 8);
DelayNS(1);
for (i=48;i<56;i++)
MdBusBuff[i-48]=X4Dat[i];
I2C_WriteNByte (0xa0, 1,0x40,MdBusBuff, 8);
DelayNS(1);
for (i=48;i<56;i++)
MdBusBuff[i-48]=X4Dat[i];
I2C_WriteNByte (0xa0, 1,0x48,MdBusBuff, 8);
//EnTm0;
//EnTm1;
//EnUart0;
//EnUart1;
//EnI2C0;
//IRQEnable();
}
//RunHour=0;
if (RunHour!=TmpHour)
{
//IRQDisable();
TmpHour=RunHour;
//DisTm0;
//DisTm1;
//DisUart0;
//DisUart1;
WriteTmp[0]=RunHour/256;
WriteTmp[1]=RunHour%256;
I2C_WriteNByte (0xa0, 1,0xf0, WriteTmp, 2);
WriteTmp[0]=RunMin/256;
WriteTmp[1]=RunMin%256;
I2C_WriteNByte (0xa0, 1,0xf2, WriteTmp, 2);
WriteTmp[0]=ErrTimes/256;
WriteTmp[1]=ErrTimes%256;
I2C_WriteNByte (0xa0, 1,0xf4, WriteTmp, 2);
/*EnTm0;
EnTm1;
EnUart0;
EnUart1;*/
//IRQEnable();
}
/********************************************************************/
/* 读内部AD和按键 */
/********************************************************************/
/*DisTm0;
DisTm1;
DisUart0;
DisUart1;
DisI2C0;*/
/*if (IntAdRdRt>10)
{
for(i=1;i<6;i++) //读取内部AD的值
{
ReadIntAd(i);
}
IntAdRdRt=0;
}*/
//IRQDisable();
TpumVaccum=GetVaccum(IntAdDat[1]);
//IRQEnable();
//LkPtVaccum=(GetVaccum(IntAdDat[0]));
//TpumVaccumMain=TpumVaccum;
if(LkPtVaccum>1000)
LkPtVaccum=1000;
TpumVaccumMain=TpumVaccum;
LkPtVaccumMain=LkPtVaccum;
switch (VacumUnit)
{
case 0:
break;
case 1://pa
TpumVaccum=TpumVaccum*100.0;
LkPtVaccum=LkPtVaccum*100.0;
break;
case 2://atm
TpumVaccum=TpumVaccum/1000.0;
LkPtVaccum=LkPtVaccum/1000.0;
break;
case 3://torr
TpumVaccum=TpumVaccum*1.33;
LkPtVaccum=LkPtVaccum*1.33;
break;
default:
break;
}
EnShowVcm=1;
//DelayNS(1);
//EnI2C0; //
if ((KeyRdRt>10)&&(SpKeyDel==0))
{
KeyRdRt=0;
I2C_ReadNByte (0x70, 1,0x01, KeyReg, 1);
}
if ((KeyReg[0]==KeyStSp)||(KeyReg[0]==KeyZero))
{
DelayNS(80);
I2C_ReadNByte (0x70, 1,0x02, KeyRept, 1);
}
//I2C_ReadNByte (0x70, 1,0x02, KeyRept, 1);
/*EnTm0;
EnTm1;
EnUart0;
EnUart1;*/
/********************************************************************/
// 按键处理
/********************************************************************/
if (KeyReg[0]!=0)
{
switch (KeyReg[0])
{
case KeyStSp :
SpKeyDel=1;
Zeroing=0x00;
AutoZeroFg=0;
VdFg1=0;
VdFg2=0;
VdFg3=0;
VdFg4=0;
VdFg5=0;
VdFg6=0;
VdFg7=0;
VdFg8=0;
MustV3=0;
EnPe=0;
if (SysStd==StandBy)
{
V5Off;
//DelayNS(20);
//I2C_ReadNByte (0x70, 1,0x02, KeyRept, 1);
if (KeyRept[0]<=1)
{
//DelayNS(100);
//I2C_ReadNByte (0x70, 1,0x02, KeyRept, 1);
if (KeyRept[0]<=1)
{
SysStd = LeakDtc;
EnBeep=1;
}
}
else
{
if (KeyRept[0]>3)
{
KeyRept[0]=0;
Zeroing=0;
IO0CLR = BEEP; // BEEP 蜂鸣
DelayNS(100);
IO0SET = BEEP; // BEEP停止蜂鸣
DelayNS(40);
IO0CLR = BEEP; // BEEP 蜂鸣
DelayNS(40);
IO0SET = BEEP; // BEEP停止蜂鸣
DelayNS(40);
IO0CLR = BEEP; // BEEP 蜂鸣
DelayNS(40);
IO0SET = BEEP; // BEEP停止蜂鸣
if (1) //放气
{
V2Off;V3Off;V4Off;V5Off;
DelayNS(100);
V6On;
V1On;
StartLkDec=0;
}
}
}
}
else if (SysStd == Stop)
{
EnBeep=1;
if (StartDone==1)
{
SysStd=StandBy;
Zeroing=0;
}
else
SysStd = Start;
V5Off;
}
else if ((SysStd == LeakDtc)||(SysStd == Caling))
{
if ((SysStd == Caling))
I2C_WriteNByte (0xa0, 1,0xfe, WriteTmp, 2);
SysStd=StandBy;
EnBeep=1;
V2Off;V3Off;V4Off;V5Off;
V5Off;
/*if (1) //放气
{
;
DelayNS(100);
V6On;
V1On;
StartLkDec=0;
}
else
{
;
}*/
}
else if (SysStd==Start)
{
EnBeep=1;
V2Off;V3Off;V4Off;V5Off;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -