📄 c_fad.h
字号:
#define Fad_sck HardL_LCD_4
#define Fad_Miso HardL_LCD_5
#define Fad_Mosi HardL_LCD_6
#define Fad_start HardL_LCD_7
//用户原点
unsigned int16 NorthMy;
//罗盘初始化
void init_spi()
{
output_high(Fad_start);
output_low(Fad_Miso);
output_low(Fad_Mosi);
output_low(Fad_sck);
}
//启动传输
void SpiStart()
{
output_low(Fad_start);
}
//结束传输
void SpiStop()
{
output_high(Fad_start);
}
//发送一字节
void SpiSend(unsigned char Sdata)
{
int8 i;
for(i=0; i<8; ++i)
{
output_bit(Fad_Mosi, shift_left(&Sdata,1,0));
output_high(Fad_sck);
output_low(Fad_sck);
}
}
//接收一字节
unsigned char SpiGet()
{
BYTE flashData;
int i;
for(i=0; i<8; ++i) // Get 8 bits of data
{
output_high(Fad_sck);
shift_left(&flashData, 1, input(Fad_Miso));
output_low(Fad_sck);
}
return flashData;
}
//硬磁补偿开始
unsigned char HardStart()
{
unsigned char ReData;
SpiStart();
SpiSend(0xA0);
ReData=SpiGet();
SpiStop();
if (ReData==0xA0)
{
return 1;
}
else
{
return 0;
}
}
//硬磁补偿结束
unsigned char HardStop()
{
unsigned char ReData;
SpiStart();
SpiSend(0xA1);
ReData=SpiGet();
SpiStop();
if (ReData==0xA1)
{
return 1;
}
else
{
return 0;
}
}
//正北校准
unsigned char North()
{
unsigned char ReData;
SpiStart();
SpiSend(0xB0);
ReData=SpiGet();
SpiStop();
if (ReData==0xB0)
{
return 1;
}
else
{
return 0;
}
}
//读原始方位角
unsigned int16 GetNorth()
{
unsigned char ReData1;
unsigned char ReData2;
unsigned char ReData3;
unsigned char ReData4;
unsigned int16 Chk;
unsigned int16 ChkSelf;
SpiStart();
SpiSend(0x5A);
ReData1=SpiGet();
ReData2=SpiGet();
ReData3=SpiGet();
ReData4=SpiGet();
SpiStop();
return (ReData1+ReData2*256);
//似乎没有校验
Chk=0x5A+ReData1+ReData2;
ChkSelf=make16(ReData3,ReData4);
if (Chk==ChkSelf)
{
return (ReData1+ReData2*256);
}
else
{
return 0xffff;
}
}
//设置相对原点
void SetOrg(unsigned int16 myNorthTmp)
{
NorthMy=myNorthTmp;
}
//获得用户相对方位角
unsigned int16 GetNorthMy()
{
unsigned int16 Northtmp;
Northtmp=GetNorth();
if (Northtmp<NorthMy)
{
Northtmp=360+Northtmp-NorthMy;
}else
{
Northtmp=Northtmp-NorthMy;
};
if (Northtmp>359)
{
Northtmp=0;
}
return Northtmp;
}
//显示方位
void dispNorth()
{
LCD_setpos(0,0);
LCD_disp_Putchar('N');
LCD_disp_Putchar(':');
//获得罗盘角度
NorthRad=GetNorthmy();
LCD_disp_valueInt16(NorthRad);
LCD_disp_Putchar(' ');
LCD_disp_Putchar(' ');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -