📄 main.c
字号:
/***********************************************************************
program Information
Project : Cuckoo Rear Radar System
IC : PIC18F2480
XTAL : exteral crystal 4MHZ
software environment : Maplab 7.60 & MCC3.0
Frist programer : jackey
create data : 2007-9-21 11:07
next programer :
Company : BYD 15th division
/************************************************************************/
#define IN_Main
#include "config.h"
uchar SpeedCnt;
uchar Speed600ms;
uchar TimeTemp[6][2];
uchar LastDist[6];
uchar CANData_Addr_L,CANData_Addr_H;
uchar CANDiagnose_Addr_L,CANDiagnose_Addr_H;
union
{
struct
{
unsigned FrontLeft : 1;
unsigned FrontRight : 1;
unsigned BackLeft : 1;
unsigned BackRight : 1;
unsigned BackMiddle : 1;
unsigned : 3;
}Bit;
uchar Byte;
}SensorAbnormal;
union
{
struct
{
unsigned RemainRing : 1; //长鸣
unsigned Slow : 1; //2Hz
unsigned Quick : 1; //4Hz
unsigned NoSensor : 1; //无探头标志
unsigned NoBlock : 1; //无障碍物标志
unsigned flag125ms : 1;
unsigned flag250ms : 1;
unsigned Canflag50ms: 1;
}Bit;
uchar Byte;
}Alarm;
union
{
struct
{
unsigned backflag : 1; //flag to indicate back flag
unsigned SpeedFlag : 1;
unsigned backalarm : 1;
unsigned : 5;
}Bit;
uchar Byte;
}CarStatus;
#pragma config OSC = XT,WDT = OFF,LVP = OFF
#pragma code high_vector_section = 0x000008
void high_vector(void)
{
_asm
goto HighIntServe //跳到中断程
_endasm
}
#pragma code
void main( void )
{
uchar i,j,k,x,y;
CANData_Addr_L = 0xD0;
CANData_Addr_H = 0x01;
CANDiagnose_Addr_L = 0x00;
CANDiagnose_Addr_H = 0x00;
InitPort( );
InitCan( );
CarStatus.Bit.backalarm = 1;
while(1)
{
ClrWdt( );
CheckState( );
// CheckSpeed( );
j = 2;
x = 12;
y = 7;
if( CarStatus.Bit.backflag ) //有倒车信号则转到倒车状态处理
{
while( j-- )
{
i = 6;
while( i-- ) //i--
{
switch( i )
{
case 5:
FrontLSend40k( y );
ReadFront( i, j );
SentCan( );
break;
case 4:
FrontRSend40k( y );
ReadFront( i, j );
SentCan( );
break;
case 3:
BackLSend40k( y );
ReadFront( i, j );
SentCan( );
break;
case 2:
BackRSend40k( y );
ReadFront( i,j );
SentCan( );
break;
case 1:
BackLMSend40k( x );
ReadBack( i, j );
SentCan( );
break;
case 0:
BackRMSend40k( x );
ReadBack( i, j );
SentCan( );
break;
default:
break;
}
}
}
}
else//((!SensorAbnormal.Bit.SpeedFlag)&& (SensorAbnormal.Bit.SpeedFlag)) //驻车通道发射和接受,
{
CarStatus.Bit.backalarm = 1;
while( j-- )
{
i=6;
while( i-- > 4 ) //i--
{
// PORTA=(PORTA&0XDF)|0X10;
switch( i )
{
case 5:
FrontLSend40k( y );
ReadFront( i, j );
SentCan( );
break;
case 4:
FrontRSend40k( y );
ReadFront( i, j );
SentCan( );
break;
default:
break;
}//switch
}//while( i-- )
}//while( j-- )
}//else
// else //车速超过10km/h,雷达不工作,只是检测车速
// {
// ;
// }
Calculate( );
// SentBee();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -