📄 main.c
字号:
void BcdToString(char Bcd[],char Str[],char len)
{
char i,j,t;
i=0;
j=0;
t=len;
while(t-->0)
{
Str[i]=((Bcd[j]&0xf0)>>4);
if(Str[i]>9)
Str[i]+=55;
else Str[i]+=48;
i++;
Str[i]=Bcd[j++]&0x0f;
if(Str[i]>9)
Str[i]+=55;
else Str[i]+=48;
i++;
}
Str[len]='\0';
}
/****************************************************************************
* 名称:main()
* 功能:主函数,MDT。
****************************************************************************/
int main(void)
{ // char TempBuf[60]
char ReNum[20];//,data_buf[80];
char CarNum[8],*PT;
//uint8 data_buf[80];
//char *CarKey,*wData;
uint8 LastKey;
uint16 i,j,k;
uint32 t;//,KeyNop;
uint8 FlashBackLed;
uint8 EmaillFlag,LoopReRFID;
uint16 KeyConter;
/**********************************/
start:
IintVariable();
FlashBackLed=0;
IO0DIR|= SEL_GPS|SEL_RFID|POWER_ONOFF;
IO0SET = SEL_GPS;
IO0SET = POWER_ONOFF;
InitBeep();
Beep(100);
InitKeyboard();
InitEeprom();
//MSpiIni();
InitLcm19264();
InitWatchDog();
InitRfid();
/*******************************/
InitCom(9600);
UART1Init(9600);
#ifdef version
LCM_DispStr(3,6,"System Booting....");
// LCM_DispStr(4,8,"System Booting");
// ResetGM8125();
LCM_DispStr(4,6,"..................");
// IintGM8125(GM8125_SINGLE);
// GM8125SelChannel(GM8125_S_RFIDUART);
DelayMS(50);
CLRLCD(0);
#endif
/*******************************************************************************/
//DayTimeIint();
RTCInit();
I2cInit(30000);
IRQEnable();
#ifdef USE_WATCHDOG
WdtFeed();
#endif
InitMdtPram();
/*********************************************login system******************************************/
#ifdef TEST_RFID
test:
#endif
CLRLCD(0);
DispDate(1,8,"s");
DispTime(1,19,"s");
LCM_DispStr(2,8,(char *)SystemLoginStr1);//LCM_DispStr(2,8,"system login");
#ifdef USE_WATCHDOG
WdtFeed();
#endif
//DelayMS(300);
/**************************read RFID ********************************************/
/**************************read RFID ********************************************/
VICIntEnClr = 1<<6;
Uart1MuxSel(UART1RFID);
#ifdef USERFID
// while(1)
// RfidBuzzer();
LoopReRFID=0;
// RFIDLoginLoop:
Uart1MuxSel(UART1RFID);
LCM_DispStr(3,8,(char *)ReadRFIDStr1);// LCM_DispStr(3,8,"Reading RFID");
DelayMS(100);
memset((char *)CarNum,0,sizeof(CarNum));
while(ReadRfidCarNum((uint8 *)CarNum))
{
#ifdef USE_WATCHDOG
WdtFeed();
#endif
/* #ifdef DEBUG
LCM_DispStr(3,8," ");
LCM_DispStr(3,8,(char *)ReadRfidFailed);
DelayMS(300);
LCM_DispStr(3,8," ");
LCM_DispStr(3,8,(char *)ReadRFIDStr1);
t=IO0PIN;
if((t&EXINT0)==0)
goto ExitReRFID;
if(++LoopReRFID<5)
;
else
goto ExitReRFID;
#endif*/
}
//RfidBuzzer();
LCM_DispStr(4,8,(char *)ReadRfidOK);
Beep(50);
//#ifdef DEBUG
BcdToString(&CarNum[2],ReNum,8);
LCM_DispStr(5,8,(char *)ReNum); //display car ID
// LCM_DispStr(6,8,"Send to server Verifying ID CAR");
// DelayMS(100);
//#endif
memset((char *)DriverID,0,sizeof(DriverID));
strcpy((char *)DriverID,(char *)ReNum); //read rfid car id to driver id
DelayMS(300);
#ifdef TEST_RFID
goto test;
#endif
LCM_DispStr(7,8,(char *)SystemLoginStr2); //LCM_DispStr(7,8,"Login Success");
DelayMS(400);
#ifdef DEBUG
ExitReRFID:
#endif
#else
memset((char *)DriverID,0,sizeof(DriverID));
strcpy((char *)DriverID,"123456"); //read rfid car id to driver id
LCM_DispStr(7,8,(char *)SystemLoginStr2); //LCM_DispStr(7,8,"Login Success");
DelayMS(400);
#endif
#ifdef USE_WATCHDOG
WdtFeed();
#endif
/********************************************************************/
LDGSMSendPointer=0;
GSMSendPointer=0;
CLRLCD(0);
LCM_DispPageCh(LOGINMENU);
LCM_DispStr(2,10,(char *)DriverID);
memset((char *)Odometer,0,sizeof(Odometer));
//LCM_DispStr(3,10,(char *)Odometer);
MenuStateFlag=LOGIN_MENU;//display main menu
DisplayPage=0;
DisplayCy=3;
DisplayCx=9;//+strlen((char *)Odometer);
InputLength=0;
InputLengthMax=ODOMETER_MAX_LENGTH;
LCM_DispStr(DisplayCy,DisplayCx,"_");
DispTime(0,24,"sy");
memset((char *)InputBuffer,0,sizeof(InputBuffer));
/********************************************************************/
/*test*/
//TestEEPROM();
/*******************************************/
KeyConter=0;
// DispTime(0,22,"sy");
//DispDate(1,21,"sy");
// DispRevSignal(8);
GsmSignal=8;
Key=0;
EmaillFlag=0;
DealPointer=0;
// DispKeyState(1,29,KeyBoardState);
//IO0CLR = BEEPCON;//TEST
IO0SET = KEYBOARD_LED;
//Timer0Init();
VICIntEnable = 1<<7;//0x00000080; // 使能UART1中断
//VICIntEnClr = 0x00000080;
//GM8125SelChannel(GM8125_S_GPSUART);
Uart1MuxSel(UART1RFID);
VICIntEnable = 1<<6;
/**************************main loop*************************************************/
while(1)
{
#ifdef USE_WATCHDOG
WdtFeed();
#endif
if(Receiving|ReceHead) //receove byte interval limit
{if(++UARTReceieTimerLimit>2000)
Receiving=0;
}
else
{
UARTReceieTimerLimit=0;
if(++UARTNoReceieTC>60000)
{ UARTNoReceieTC=0;
DealPointer=0;
ReceivePointer=0;
GSMDealPointer=0;
GSMReceivePointer=0;
}
}
// if(ReceiveEvent!=0)
//ReceiveEventDeal();
if(TimerEvent!=0)
TimerEventDeal();
// if(MenuStateFlag==MAIN_MENU)
/***************************Timer flash deal*********************************/
if(++i>30000)
{
i=0;
/*
if(MenuState==MAINMENU_NUMBER)
{
CLRLCD(0);
MainMenu(HOME,0);
MenuState=MAINMENU_NUMBER;
}
*/
NewMessage=CheckNewMessageNum();
if(NewMessage!=0)
{
LCM_DispChar(0,29,30);
LCM_DispChar(0,30,31);
}
if(MenuStateFlag==MAIN_MENU)
DispTime(7,24,"sy");
else
DispTime(0,24,"sy");
//DispDate(1,21,"sy");
//DispRevSignal(GsmSignal);
if(FlashBackLed<20)
{
Lcm19264BackLightOn();
IO0SET = KEYBOARD_LED;
FlashBackLed++;
}
else
{
IO0CLR = KEYBOARD_LED;
Lcm19264BackLightOff();
}
}
/************************scan keyboard****************************/
Key=0;
t=IO0PIN;
if((t&EXINT0)==0) //keyboard deal
{
j=0;
if(k++>500)
{
k=0;
Key=MDTGetKeyboard();
IO0SET = KEYBOARD_LED; //ON LED
Lcm19264BackLightOn();
if(Key==NowKey)
{
if(MenuPressKeyFlag==0)
{
LastKey=NowKey;
NowKey=Key;
Key=0;
}
else
{
if(++MenuPressKeyFlag>200) //Key true
{
LastKey=NowKey;
NowKey=Key;
MenuPressKeyFlag=1;
}
else
{
LastKey=NowKey;
NowKey=Key;
Key=0;
}
}
}
else //key ture
{
LastKey=NowKey;
NowKey=Key;
if(MenuPressKeyFlag==0)
{
t=IO0PIN;
while((t&EXINT0)==0) t=IO0PIN; //keyboard deal
}
}
FlashBackLed=0;
}
}
else {k=0;
if(j++>5000)
{
LastKey=NowKey;
NowKey=Key;
Key=0;
j=0;
}
}
/**************************menu deal *********************************************/
if(Key!=0)//&(KeyOnePress!=0x81)
{
KeyConter=0;
VICIntEnClr=0x00020000;
Key=KeyBoardTest(0,Key);
/* if(NewJobFlag!=0)
if(MenuStateFlag==MAIN_MENU)
{Key =F1;
VICIntEnClr = 0x00000010;
}*/
MenuStateFlag=KeyBoardDeal(Key,MenuStateFlag);
Key=0;
EXTINT = 0x08;
//VICIntEnable = 0x00020000;
if(MenuStateFlag!=MAIN_MENU)
EmaillFlag=0;
}
if (MenuStateFlag==READ_RFID)
goto start;
/**********************new job deal ********************************************/
if(NewJobFlag!=0)
{ /*
if((FlashNewJobFlag!=0)&(MenuStateFlag==MAIN_MENU))
{
CLRLCD(0);
FlashNewJobFlag=0;
LCM_DispStr(3,3,"*******************");
LCM_DispStr(4,3,"* *");
//LCM_DispStr(5,3,"* new job receive *");
LCM_DispStr(5,3,(char *)MainMenuString1);
LCM_DispStr(6,3,"* *");
LCM_DispStr(7,3,"*******************");
}
*/
}
/**********************news ACK and deal*************************************************************/
if(rcv_new>0)
{
while(rcv_new>0)
{
UART0_SendStr((uint8 *)"OK"); //ANCK
rcv_new--;
}
}
if(ReceiveEvent!=NO_EVENT)//&(MenuState==MAINMENU_NUMBER))
{
DealReceiveGSM();
}
/*********************************Waiting ACK deal************************************/
if(WaitingACK)
{
/*if(ACK!=0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -