📄 comsub.c
字号:
#include "comsub.h"
#include "common.h"
#include "fm1808.h"
const prog_uint16_t yearday[200] = {366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366, //2000-2024年
365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365, //2025-2049年
365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365, //2050-2074年
365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365,366,365,365,365}; //2075-2099年
//---非闰年各月份天数表(1~12月,数组0空置)
const prog_char monthday[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
const prog_char runmonthday[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
void test(void)
{uchar i;
send_data1();
for(i=0;i<20;i++)
Putc(i);
}
void Get_time(void)
{uchar i,temp=0x55;
Send0[0]=13;
Send0[1]=0x55;
Send0[2]=0x7a;
Send0[3]=0x02;
Send0[4]=0x00;
Send0[5]=0x06;
Send0[6]=0x00;
CLOCK_RTIME();
for(i=7;i<13;i++)
{Send0[i]=SYS_Time[i-7];
}
for(i=2;i<13;i++)
temp^=Send0[i];
Send0[13]=temp;
}
void get_send(uchar j)
{uchar i;
FM_CS;
Send0[0]=j;
for(i=1;i<=j;i++)
{ Send0[i]=*send_p;
send_p++;
}
}
void send_no_data(uchar j)
{uchar i,temp=0x55;
Send0[0]=7;
Send0[1]=0x55;
Send0[2]=0x7a;
Send0[3]=j;
Send0[4]=0x00;
Send0[5]=0x00;
Send0[6]=0x00;
for(i=2;i<7;i++)
temp^=Send0[i];
Send0[7]=temp;
}
void Get_tzxs(void)
{uchar *p1,i,temp=0x55;
Send0[0]=10;
Send0[1]=0x55;
Send0[2]=0x7a;
Send0[3]=0x04;
Send0[4]=0x00;
Send0[5]=0x03;
Send0[6]=0x00;
FM_CS;
p1=Tzx_Buf;
for(i=7;i<10;i++)
{Send0[i]=*p1;
p1++;
}
for(i=2;i<10;i++)
temp^=Send0[i];
Send0[10]=temp;
}
void Get_driver(void)
{uchar *p1,i,temp=0x55;
Send0[0]=28;
Send0[1]=0x55;
Send0[2]=0x7a;
Send0[3]=0x01;
Send0[4]=0x00;
Send0[5]=21;
Send0[6]=0x00;
FM_CS;
p1=Driver_now__Buf+1;
for(i=7;i<28;i++)
{Send0[i]=*p1;
p1++;
}
for(i=2;i<28;i++)
temp^=Send0[i];
Send0[28]=temp;
}
void Get_qiche(void)
{uchar *p1,i,temp=0x55;
Send0[0]=48;
Send0[1]=0x55;
Send0[2]=0x7a;
Send0[3]=0x06;
Send0[4]=0x00;
Send0[5]=41;
Send0[6]=0x00;
FM_CS;
p1=Qiche_Buf;
for(i=7;i<48;i++)
{Send0[i]=*p1;
p1++;
}
for(i=2;i<48;i++)
temp^=Send0[i];
Send0[48]=temp;
}
//字节异或
uchar com_xor(uint a)
{uchar temp;
uint i;
uchar *p1;
p1=com1subbuf;
temp=*p1;
p1++;
for(i=1;i<a;i++)
{temp^=*p1;
p1++;
}
return temp;
}
//BCD时间转十六进制
uchar timeb2h(uchar a)
{
uchar temp;
temp = (a & 0xf0);
temp >>= 4;
temp *= 10;
temp += (a & 0x0f);
return (temp);
}
//时间HEX格式转BCD
uchar timeh2b(uchar a)
{
uchar temp;
temp = a / 10;
temp <<= 4;
temp += a % 10;
return (temp);
}
//时间点time自2000年1月1日00:00起的分钟数
void timepastforint(void)
{
uchar i;
itimelen = 0;
for (i=0; i<itime[0]; i++)
{
itimelen += pgm_read_word(&yearday[i]);
}
if (pgm_read_word(&yearday[itime[0]])==366) //若是闰年
{
for (i=1; i<itime[1]; i++)
{
itimelen += pgm_read_byte(&runmonthday[i]);
}
}
else
{
for (i=1; i<itime[1]; i++)
{
itimelen += pgm_read_byte(&monthday[i]);
}
}
itimelen += itime[2] - 1;
itimelen *= 1440; //天数转换成分钟数
itimelen += itime[3]*60 + itime[4];
i=0;
}
void locatetime(void)
{
uchar i,j,k;
ulong t;
t = itimelen;
for (i=0; i<5; i++)
{
time[i] = 0;
}
for (i=0; i<99; i++)
{
if (t>=(pgm_read_word(&yearday[i])*1440))
{
t -= pgm_read_word(&yearday[i])*1440;
time[0]++;
}
else
break;
}
time[1] = 1;
if (pgm_read_word(&yearday[time[0]])==366)
{
for (i=1; i<12; i++)
{
if ((pgm_read_byte(&runmonthday[i])*1440)<=t)
{
t -= pgm_read_byte(&runmonthday[i])*1440;
time[1]++;
}
else
break;
}
}
else
{
for (i=1; i<12; i++)
{
if (t>=(pgm_read_byte(&monthday[i])*1440))
{
t -= pgm_read_byte(&monthday[i])*1440;
time[1]++;
}
else
break;
}
}
time[2] = 1;
while (t>=1440)
{
time[2]++;
t -= 1440;
}
while (t>=60)
{
time[3]++;
t -= 60;
}
time[4] = t;
for(i=0;i<5;i++)
{j=(uchar)(time[i]/10);
k=(uchar)(time[i]%10);
time[i]=j*16+k;
}
}
uchar comtime(uchar *p)
{
if(time[0]<*p)
return TRUE;
else
{
if (time[0] > *p) ///2006_1_3 time[0])
return FALSE;
else
{
if (time[1]<*(p+1))
return TRUE;
else
{
if (time[1]>*(p+1))
return FALSE;
else
{
if (time[2]<*(p+2))
return TRUE;
else
{
if (time[2]>*(p+2))
return FALSE;
else
{
if (time[3]<*(p+3))
return TRUE;
else
{
if (time[3]>*(p+3))
return FALSE;
else
{
if (time[4]<*(p+4))
return TRUE;
else
{
if (time[4]>*(p+4))
return FALSE;
else
return TRUE;
}
}
}
}
}
}
}
}
}
}
void Ini_speed(void)
{DDRD&=0XEF;
speed_cap=0;
speed_cn=0;
TCCR1A=0;
TCCR1C=0;
TIMSK=0X24;
ETIMSK=0X00;
TIFR=0X00;
ETIFR=0X00;
TCNT1=0x0000;
TCCR1B=0X81;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -