📄 main.c
字号:
_nop_();
// GPS_received_data_OK = 1;
// gps_point.orientation = 1;
if(GPS_received_data_OK)
{ //3
GPS_received_data_OK = 0;
// Read_GPS_GPRMC_C();
Read_GPS_GPGGA_B();
Read_GPS_GPRMC_B();
// Read_GPS_GPGGA_B();
// gps_point.orientation = 1;
if(GPGGA_flag == 1)
{ //2
OS_ENTER_CRITICAL();
GPGGA_flag = 0;
GPRMC_flag = 0;
// gps_point.orientation =1;
switch(gps_point.orientation)
{ //1
case 0x00:
_nop_();
L_X = 0;
L_Y = 0;
putbyte(0x55);
break;
case 0x01:
_nop_();
any_temp = gps_point.f_latitude;
Any_Point->Ny = (any_temp - Start_Point->Ny)*110946.306;
any_temp = gps_point.f_longitude;
Any_Point->Ex = (any_temp - Start_Point->Ex)*111320.448*cos(Start_Point->Ny*PI/180.);
Any_Point->Distance =sqrt( (Any_Point->Ex)*(Any_Point->Ex)+(Any_Point->Ny)*(Any_Point->Ny) );
// Any_Point->G = 10;
// if(Any_Point->Distance > 3100)
Any_Point->G = 1;
// else
// Any_Point->G = 10;
/*
if(Any_Point->Distance <= 500) Any_Point->G = DBSAE_Table[0];
if(Any_Point->Distance > 500 && Any_Point->Distance <= 1000) Any_Point->G = DBSAE_Table[0];
if(Any_Point->Distance > 1000 && Any_Point->Distance <= 2000) Any_Point->G = DBSAE_Table[1];
if(Any_Point->Distance > 2000 && Any_Point->Distance <= 3000) Any_Point->G = DBSAE_Table[2];
if(Any_Point->Distance > 3000 && Any_Point->Distance <= 4000) Any_Point->G = DBSAE_Table[3];
if(Any_Point->Distance > 4000 && Any_Point->Distance <= 5000) Any_Point->G = DBSAE_Table[4];
if(Any_Point->Distance > 5000 && Any_Point->Distance <= 6000) Any_Point->G = DBSAE_Table[5];
if(Any_Point->Distance > 6000 && Any_Point->Distance <= 7000) Any_Point->G = DBSAE_Table[6];
*/
L_X =(int)(Any_Point->Ex);
L_Y =(int)(Any_Point->Ny);
break;
case 2:
_nop_();
break;
default:
_nop_();
break;
} //1
OS_EXIT_CRITICAL();
send_data();
ReportTime_buf[1] = gps_point.OS_UTC.times.year_high*100-2000;
ReportTime_buf[1] = gps_point.OS_UTC.times.year_low+ReportTime_buf[1];
ReportTime_buf[2] = gps_point.OS_UTC.times.month;
ReportTime_buf[3] = gps_point.OS_UTC.times.date;
ReportTime_buf[5] = gps_point.OS_UTC.times.hour;
ReportTime_buf[6] = gps_point.OS_UTC.times.min;
ReportTime_buf[7] = gps_point.OS_UTC.times.sec;
day_count = ReportTime_buf[1];
day_count_temp2 = day_count/4;
if(gps_point.OS_UTC.times.year_low==0)
{
day_count_temp1 = gps_point.OS_UTC.times.year_high%4;
if(day_count_temp1!=0)
{
day_count_temp2 = day_count_temp2 - 1;
}
}
else
day_count_temp1 = day_count%4;
if(day_count_temp1==0)
day_count = day_count*365 + day_count_temp2 + 5;
else day_count = day_count*365 +1 + day_count_temp2 + 5;
switch(gps_point.OS_UTC.times.month)
{ //1
case 0x01:
day_count = day_count + gps_point.OS_UTC.times.date;
break;
case 0x02:
day_count = day_count + 31+ gps_point.OS_UTC.times.date;
break;
case 0x03:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + gps_point.OS_UTC.times.date;
break;
case 0x04:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31 + gps_point.OS_UTC.times.date;
break;
case 0x05:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31+ 30 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31+ 30 + gps_point.OS_UTC.times.date;
break;
case 0x06:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31+ 30 + 31 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31+ 30 + 31 + gps_point.OS_UTC.times.date;
break;
case 0x07:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31+ 30 + 31 + 30 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31+ 30 + 31 + 30 + gps_point.OS_UTC.times.date;
break;
case 0x08:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31+ 30 + 31 + 30 + 31 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31+ 30 + 31 + 30 + 31 + gps_point.OS_UTC.times.date;
break;
case 0x09:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31+ 30 + 31 + 30 + 31 + 31 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31+ 30 + 31 + 30 + 31 + 31 + gps_point.OS_UTC.times.date;
break;
case 0x0A:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31+ 30 + 31 + 30 + 31 + 31 + 30 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31+ 30 + 31 + 30 + 31 + 31 + 30 + gps_point.OS_UTC.times.date;
break;
case 0x0B:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31+ 30 + 31 + 30 + 31 + 31 + 30 + 31 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31+ 30 + 31 + 30 + 31 + 31 + 30 + 31 + gps_point.OS_UTC.times.date;
break;
case 0x0C:
if(day_count_temp1==0)
day_count = day_count + 31+ 29 + 31+ 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + gps_point.OS_UTC.times.date;
else
day_count = day_count + 31+ 28 + 31+ 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + gps_point.OS_UTC.times.date;
break;
}
ReportTime_buf[4] = day_count%7;
if(ReportTime_buf[4]==0) ReportTime_buf[4] = 7;
Int0Send_flag = 1;
if(gps_point.OS_UTC.times.hour>18&&gps_point.star_number>3)
{
if(TimeCorrect_flag)
{
TimeCorrect_flag = 0;
Int0Send_flag = 1;
IE0 = 1;
}
}
if(gps_point.OS_UTC.times.hour<18)
{
TimeCorrect_flag = 1;
}
if(gps_point.orientation == 0x01)
{
LED1=!LED1; //flash here
Process_GPS();
}
} //2
} //3
_nop_();
switch(gps_point.star_number)
{
case 0x00:
LED2 = 1;LED3 = 1;LED4 = 1;LED5 = 1;LED6 = 1;LED7 = 1;
break;
case 0x01:
LED2 = 0;LED3 = 1;LED4 = 1;LED5 = 1;LED6 = 1;LED7 = 1;
break;
case 0x02:
LED2 = 0;LED3 = 0;LED4 = 1;LED5 = 1;LED6 = 1;LED7 = 1;
break;
case 0x03:
LED2 = 0;LED3 = 0;LED4 = 0;LED5 = 1;LED6 = 1;LED7 = 1;
break;
case 0x04:
LED2 = 0;LED3 = 0;LED4 = 0;LED5 = 0;LED6 = 1;LED7 = 1;
break;
case 0x05:
LED2 = 0;LED3 = 0;LED4 = 0;LED5 = 0;LED6 = 0;LED7 = 1;
break;
case 0x06:
LED2 = 0;LED3 = 0;LED4 = 0;LED5 = 0;LED6 = 0;LED7 = 0;
break;
}
/*
if(gps_point.star_number>0) {LED2 = 0;LED3 = 1;LED4 = 1;LED5 = 1;LED6 = 1;LED7 = 1;}
if(gps_point.star_number>1) {LED2 = 0;LED3 = 0;LED4 = 1;LED5 = 1;LED6 = 1;LED7 = 1;}
if(gps_point.star_number>2) {LED2 = 0;LED3 = 0;LED4 = 0;LED5 = 1;LED6 = 1;LED7 = 1;}
if(gps_point.star_number>3) {LED2 = 0;LED3 = 0;LED4 = 0;LED5 = 0;LED6 = 1;LED7 = 1;}
if(gps_point.star_number>4) {LED2 = 0;LED3 = 0;LED4 = 0;LED5 = 0;LED6 = 0;LED7 = 1;}
if(gps_point.star_number>5) {LED2 = 0;LED3 = 0;LED4 = 0;LED5 = 0;LED6 = 0;LED7 = 0;}
*/
// gps_point.star_number = 0;
} //4
}
/*********************************************************************************/
/*************************** ************************************/
/*************************** funcitons body ************************************/
/*************************** ************************************/
/*********************************************************************************/
void MCU_init(void)
{
main_count = 0;
gps_en=1;
GPS_received_data_OK=0;
TCON = TCON|0x01;
TimeCorrect_flag = 1;
Int0Send_flag = 0;
}
void delay(uchar m)
{
uchar idata i,j,k;
for (i=0;i<=m;i++)
{
for (j=0;j<=m;j++)
{
for(k=0;k<=m;k++)
{
_nop_();
}
}
}
}
void delay20()
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void serial1(void) interrupt 20 using 1
{
if((SCON1&0x01)==1)
{
SCON1 = SCON1&0xFE;
if(gps_en)
{
r_buf[r_in ++] = SBUF1;
if(r_buf[r_in - 1]=='$')
{
r_in=1;
r_buf[0]='$';
}
if(r_buf[r_in - 1]==0x0a)
{
if(r_in>50) {GPS_received_data_OK = 1;GPS_received_data_OK1 = 1;}
r_in = 0;
}
}
}
else if((SCON1&0x02)==1)
{
SCON1 = SCON1&0xFD;
}
}
void serial0(void) interrupt 4 using 2
{
uchar idata com_receive_temp;
if((SCON0 & 0x01) == 0x01) //RI1=0;
{
SCON0 &= ~0x01;
}
if(((SCON0 & 0x02) == 0x02)&&buff_flag) //TI1=0;
{
SCON0 &= ~0x02;
}
}
void int0() interrupt 0 using 3
{
uchar idata i, InfoLength = 5, temp;
IE0 = 0;
if(Int0Send_flag)
{
Int0Send_flag = 0;
for(i=0;i<7;i++)
{
ReportTimetoMach[InfoLength] = ReportTime_buf[i+1];
if(ReportTime_buf[i+1]==0xAA)
{
InfoLength++;
ReportTimetoMach[InfoLength] = 0xAA;
}
InfoLength++;
}
ReportTimetoMach[InfoLength] = 0xAA;
InfoLength++;
ReportTimetoMach[InfoLength] = 0xCC;
InfoLength++;
temp = 0xAA;
for(i=1;i<InfoLength;i++)
{
temp ^= ReportTimetoMach[i];
}
ReportTimetoMach[InfoLength] = temp;
InfoLength++;
for(i=0;i<InfoLength;i++)
{
ES0 = 0;
TI0 = 0;
SBUF0 = ReportTimetoMach[i];
while(TI0==0);
TI0 = 0;
ES0 = 1;
}
}
}
timer3() interrupt 14 using 0
{
TMR3CN &=~0x84; //TF3=0 TR3=0;
main_count++;
TMR3CN |=0x04;;;//TR3 = 1
}
/******************************************************************************/
/* send data service function */
/* executes each 1s @ 11.0592 MHz Crystal Clock */
/******************************************************************************/
// 放入一个字节到发送缓冲区
void putbyte(uchar ch)
{
// ES0=0; /*暂停串行中断,以免数据比较时出错
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -