📄 main.c
字号:
#include <reg52.h>
#include <absacc.h>
#include <BIANLIANG.h>
extern void Display_zijian();
extern void clrlcd();
extern void intlcd();
extern void Delay(int count);
extern void scankey();
extern void idle();
extern void Clr_WDog();
extern void Displaycheck();
extern unsigned char GetKey();
//**********************************************************************************************Get_Time()函数
Get_Time() //转换当前日期和时间
{
Clr_WDog();
P11=1;
P10=1;
YEAR=OLD_YEAR/16*10+OLD_YEAR%16;
MONTH=OLD_MONTH/16*10+OLD_MONTH%16;
DAY=OLD_DAY/16*10+OLD_DAY%16;
HOUR=OLD_HOUR/16*10+OLD_HOUR%16;
MINUTE=OLD_MIN/16*10+OLD_MIN%16;
SECOND=OLD_SEC/16*10+OLD_SEC%16;
}
//********************************************************************************************Clk_Init()函数
void Clk_Init(void) //初始化时钟
{
TCLKA=0x25;
TCLKB=0x0A;
}
//********************************************************************************************Initiate() 函数
void Initiate() //系统初始化
{
Clk_Init(); //初始化时钟
clrlcd(); //清显示屏(其中包括初始化显示屏)
}
//******************************************************************************************ZiJian_Ram() 函数
ZiJian_Ram()
{
Clr_WDog();
P11=1;
P10=1;
RAM_ZIJIAN=0X99;
if(RAM_ZIJIAN!=0x99) FL_ZJRAM=0; // 如果自检失败,FL_ZJRAM=0
else FL_ZJRAM=1;
}
//***************************************************************************************ZiJian_Clk() 函数
ZiJian_Clk()
{
unsigned char clk_sec;
Clr_WDog();
P11=1;
P10=1;
clk_sec=TMIAO;
Delay(800);
if(clk_sec==TMIAO) FL_ZJCLK=0; // 如果自检失败,FL_ZJCLK=0
else FL_ZJCLK=1;
}
//****************************************************************************************ZiJian_Io() 函数
ZiJian_Io()
{
Clr_WDog();
P11=1;
P10=1;
FL_ZJIO=0;
P17=0;
if((KAIGUANLIANG&0xC0)==0)
{
P17=1;
if((KAIGUANLIANG|0x3F)==0XFF) FL_ZJIO=1; // 自检成功,FL_ZJIO=1
}
}
//*******************************************************************************************SelfTest() 函数
SelfTest() // 自检
{
Clr_WDog();
Display_zijian(); //先显示“自检中……”
ZiJian_Ram(); //自检RAM
ZiJian_Clk(); //自检时钟
ZiJian_Io(); //自检端口
}
//*******************************************************************************************Get_1s_speed()函数
Get_1s_speed() //计算每秒的速度
{
Clr_WDog();
/*特征系数为CANSHU转/公里,每转有8个脉冲,则得到(8*CANSHU)脉冲/公里,现假设已测得2秒内共计有A个脉冲,
则1800A为每小时的脉冲数,(1800A/(8*CANSHU)=225A/CANSHU)公里/小时即为该秒内的速度。*/
P11=1;
P10=1;
temp_long=t1_dif_pls_2s;
temp_long*=225;
temp_long=temp_long+CANSHU/2; //为纠正为“4舍5入”,人为加上(CANSHU/2)
speed_1sec=temp_long/CANSHU;
if(speed_1sec>=MAXSPEED) FL1_OVERSPEED=1;
else FL1_OVERSPEED=0;
}
//*******************************************************************************************Write_Curday() 函数
void Write_Curday()
{
Clr_WDog();
P11=1;
P10=1;
index_threeday=(index_threeday+1)%3;
day_three[index_threeday][0]=OLD_YEAR;
day_three[index_threeday][1]=OLD_MONTH;
day_three[index_threeday][2]=OLD_DAY;
}
//*******************************************************************************************Get_15mSpeed() 函数
void Get_15mSpeed(uchar number) //将停车前15分钟的每分钟的平均速度排好序
{
uchar i,j;
Clr_WDog();
P11=1;
P10=1;
for(i=0;i<15;i++)
{ Clr_WDog(); //清w-dog
for(j=0;j<21;j++)
{ new_speed_15min[i][j]=speed_15min[number][j];
Clr_WDog(); //清w-dog
}
number=(number+14)%15;
}
}
//*******************************************************************************************Wr_stp_3d() 函数
void Wr_stp_3d()
{
uchar xdata i,j,k;
Clr_WDog();
P11=1;
P10=1;
i=index_threeday;
for(j=0;j<3;j++)
{ Clr_WDog(); //清w-dog
i=(i+1)%3;
for(k=0;k<3;k++)
{ stop_3day[3*j+k]=day_three[i][k];
Clr_WDog(); //清w-dog
}
}
stop_3day[9]=temp_date[3]; //停车的时间(时、分)
stop_3day[10]=temp_date[4];
}
//*******************************************************************************************Get_20sdata() 函数
void Get_20sdata() //将当前20秒数据计算出速度,排好序,并加上停车时间,存放于原处
{
uchar xdata j;
unsigned int xdata old_index,new_index,old_pulse,new_pulse,dif;
Clr_WDog();
P11=1;
P10=1;
//sec_temp_data[]中共存放有21秒数据,计算速度时,先得到脉冲差=(当前脉冲数-1秒前的脉冲数),再求该125毫秒的瞬时速度
sec_hang=(sec_hang+1)%10;
for(j=0;j<6;j++)
{
Clr_WDog(); //清w-dog
sec_data[sec_hang][j]=sec_temp_data[504+j];
}
old_index=0; //老数据下标指向最老的数据的脉冲数的高字节
new_index=24; //新数据下标指向次老的数据的脉冲数的高字节
for(j=0;j<160;j++)
{
Clr_WDog(); //清w-dog
old_pulse=sec_temp_data[old_index];
old_pulse<<=8;
old_index++; //老数据下标指向最老的数据的脉冲数的低字节
old_pulse+=sec_temp_data[old_index]; //得到老脉冲数
old_index+=2; //老数据下标指向下一个的数据的脉冲数的高字节
new_pulse=sec_temp_data[new_index];
new_pulse<<=8;
new_index++; //新数据下标指向当前的数据的脉冲数的低字节
new_pulse+=sec_temp_data[new_index]; //得到新脉冲数
new_index++; //新数据下标指向下一个的数据的脉冲数的高字节
dif=new_pulse-old_pulse; //得到脉冲差
/* 特征系数为CANSHU转/公里,每转有8个脉冲,则得到(8*CANSHU)脉冲/公里,现假设已测得一秒内共计有A个脉冲,
则3600A为每小时的脉冲数,(3600A/(8*CANSHU)=450A/CANSHU)公里/小时即为该秒内的速度。 */
temp_long=dif;
temp_long=temp_long*450; //temp_long已定义,长整型数
temp_long=temp_long+CANSHU/2; //为纠正成4舍5入,人为加上(CANSHU/2)
sec_data[sec_hang][2*j+6]=temp_long/CANSHU; //存进速度
new_index++; //新数据下标指向新数据的开关量
sec_data[sec_hang][2*j+7]=sec_temp_data[new_index]; //存进开关量
}
sec_data[sec_hang][324]=0; //特别将最后1次速度记为0
//记录下当前驾驶证号码
for(j=0;j<18;j++)
{
Clr_WDog(); //清w-dog
num_10[sec_hang][j]=cur_id[7+j];
}
}
//*******************************************************************************************Copy_20sdata() 函数
void Copy_20sdata()
{
unsigned int ind_tmp;
Clr_WDog();
P11=1;
P10=1;
//sec_cur_data[]数组记录26秒数据,有624字节;sec_temp_data[]数组存放前21秒数据加上停车时间,共510个字节
copy_sec_index=sec_index; //复制数组当前下标
ind_tmp=0;
do
{
Clr_WDog(); //清w-dog
copy_sec_index=(copy_sec_index+1)%624;
sec_temp_data[ind_tmp]=sec_cur_data[copy_sec_index];
ind_tmp++;
copy_sec_index++;
sec_temp_data[ind_tmp]=sec_cur_data[copy_sec_index];
ind_tmp++;
copy_sec_index++;
sec_temp_data[ind_tmp]=sec_cur_data[copy_sec_index];
ind_tmp++;
}while(ind_tmp<504);
//复制完成后, 前21秒数据依时间顺序存放于sec_temp_data[]数组的前504个字节
sec_temp_data[504]=OLD_YEAR;
sec_temp_data[505]=OLD_MONTH;
sec_temp_data[506]=OLD_DAY;
sec_temp_data[507]=OLD_HOUR;
sec_temp_data[508]=OLD_MIN;
sec_temp_data[509]=OLD_SEC;
}
//*******************************************************************************************Save_Ovrec() 函数
void Save_Ovrec()
{
//overtime_rec[21][28],共21行,每行28个字节。前18个字节为驾驶证号码,后10个字节为开车时间和停车时间
uchar xdata i;
Clr_WDog();
P11=1;
P10=1;
k_temp=num_ovrec;
for(j_temp=0;j_temp<21;j_temp++)
{
Clr_WDog(); //清w-dog
i=0;
for(l_temp=0;l_temp<5;l_temp++)
{
Clr_WDog(); //清w-dog
if(overtime_rec[j_temp][18+l_temp]==all_drv_rec[driver_cur][l_temp]) i++;
}
if(i==5) //如果超时记录中有一条记录的起始时间和当前驾驶员的超时记录起始时间相同
{
k_temp=j_temp;
num_ovrec=(num_ovrec+19)%20; //num_ovrec自减1
}
}
for(l_temp=0;l_temp<18;l_temp++) //写下驾驶证号
{ overtime_rec[k_temp][l_temp]=id1[driver_cur][7+l_temp];
Clr_WDog(); //清w-dog
}
for(l_temp=0;l_temp<10;l_temp++) //写下当前驾驶员超时记录的起始和结束时间
{ overtime_rec[k_temp][18+l_temp]=all_drv_rec[driver_cur][l_temp];
Clr_WDog(); //清w-dog
}
}
//*******************************************************************************************Wr_Time() 函数
void Wr_Time()
{
Clr_WDog();
P11=1;
P10=1;
temp_date[0]=OLD_YEAR;
temp_date[1]=OLD_MONTH;
temp_date[2]=OLD_DAY;
temp_date[3]=OLD_HOUR;
temp_date[4]=OLD_MIN;
}
//*******************************************************************************************Get_Pls_Cur() 函数
void Get_Pls_Cur() //求出当前时刻的脉冲数
{
Clr_WDog();
P11=1;
P10=1;
//存入计数器的高字节
pulse_cur_time=hi_counter; //将脉冲量的高字节存入pulse_cur_time
pulse_cur_time<<=16; //pulse_end_rec左移2个字节
//写入计数器的低2个字节,取自TH0和TH1
j_temp=TH0;
k_temp=TL0;
if(j_temp!=TH0)
{
j_temp=TH0;
k_temp=TL0;
}
temp1_all=j_temp; //将脉冲量的低字节的第1个字节存入temp1_all
temp1_all<<=8; //将temp1_all左移1个字节
temp1_all+=k_temp; //将脉冲量的低字节的第2个字节累加入temp1_all
pulse_cur_time+=temp1_all; //将temp1_all加入pulse_cur_time
}
//*******************************************************************************************Get_All_Lich() 函数
void Get_All_Lich()
{
unsigned int xdata i,k;
Clr_WDog(); //清w-dog
P11=1;
P10=1;
pulse_anydate=0;
i=index_stp_pls;
for(k=0;k<48;k++)
{ Clr_WDog(); //清w-dog
pulse_anydate+=pulse_spd_buf[i];
i=(i+359)%360;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -