?? bdtrv20.c
字號:
/**************************************
File : BDTRV20.C
Project : BDTRV20_MCU_V07
Description :
Created : 2004
Last updata : 2004
Author : wangwenyu
Compile Tool : Keil
Target Device : SST89V564RD
Circuit Board : 7700
************************************
Modification History
************************************
Version : v1.4
Date : MM/DD/YYYY
Modifier :
Description :
**********************************
-- Copyright (c)
*************************************/
#include <SST89V564.H>
#include <ABSACC.H>
#include <CTYPE.H>
#include "head_def.h"
/*********************************************************************/
//unsigned char code DataStr[]=__DATE__;
//unsigned char code TimeStr[]=__TIME__;
/*********************************************************************/
void init4136(void);//SI4136 initialization.
void RunIAPCode(void);
extern InitModule(void);//Initialize the BD-RF-Module.
extern InitMCU(void);//Initialize the MCU.
extern senddsp(void);//Send data to DSP through Parallel port.
extern wdt(void);//Watchdog timer.
extern delay(unsigned char time);//Delay subprogram.
extern BootDSP(void);//Initialize the DSP for run code.
extern InitDSP(void);//Initialize the Port of DSP.
extern rdDSP(void);//Read data from DSP and send through serial port.
extern InitMoudel(void);//Initialize the BD-RF-Moudle.
extern rev_frame(void);
extern ch_frame(void);
extern sd_uart(void);
//extern func_cf(void);
//extern func_ci(void);
extern WriteCont(unsigned char CMD,unsigned char addr,unsigned char DataArray[],unsigned char offset);
extern unsigned char READ(unsigned char CMD,unsigned char addr);
/*********************************************************************/
void main(void)
{
unsigned char i;
//Initialize the Registers of the MCU.
InitMCU();
RunIAP=0;
IAP=1;
//
moto_fg=1; //系統默認為motonola二進制形式
cf_rst =0;
u_cf_fg=0;//
u_ay_fg =1;//
u_fg=1;//
sec_fg =1;//
u_gd_fg =0;
while(1)
{
while(Dtime!=0)
{
P34=~P34;
if (RunIAP==1)
{
RunIAP=0;
RunIAPCode();
}
}
IAP=0;
goto RUN;
}
RUN:
TR0 = 0;//Stop the timer 0.
ET0 = 0;//Disable the interruption T0.
ES = 0;
TR1 = 0;
PCON = 0x00;
TH1 = 0xfa; //Set baud rate to 9600bps.
TL1 = 0xfa;
TR1 = 1;
//Initialize the flags.
flagint=0;
flagserial=0;
//Iniatialize the RF Moudel.
InitModule();
delay(5);
//Initialize SI4136.
init4136(); //SI4136 initialization.
//Boot the DSP5402.
delay(10); //Delay 500ms for boot DSP.
BootDSP();
//Enable the interruptions.
EX0=1;//Enable the interruption 0.
ES=1;//Enable the serial interruption.
EA=1;//Open the interruptions.
//Initlizate the Parallel Port of DSP.
InitDSP();
/******************************************************/
delay(100);
/* delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);
delay(200);*/
//Initilze the Position.
if (READ(0x03,0x00)=='$')
{
delay(100);
//delay(200);
rdata[0] = READ(0x03,0);
rdata[1] = READ(0x03,1);
i=2;
while((rdata[i-2] != 0x0d)&&(rdata[i-1] != 0x0a))
{
rdata[i] = READ(0x03,i);
i++;
if (i>63)
{
rdata[i-2] = 0x0d;
rdata[i-1] = 0x0a;
}
}
if (i < 63)
{
RXLen = i;
senddsp();
long_asc[0]=rdata[21];
long_asc[1]=rdata[22];
long_asc[2]=rdata[23];
long_asc[3]=rdata[24];
lat_asc[0]=rdata[7];
lat_asc[1]=rdata[8];
lat_asc[2]=rdata[9];
lat_asc[3]=rdata[10];
for(i=0;i<12;i++)
{
if (i<=3)
{
lat_par=lat_par<<8;
lat_par|= READ(0x03,(0x90+i));
}
else if(i>3&&i<=7)
{
long_par=long_par<<8;
long_par|= READ(0x03,(0x90+i));
}
else if(i>7&&i<=11)
{
high_par=high_par<<8;
high_par|= READ(0x03,(0x90+i));
}
}
/* for (i=0;i< RXLen;i++)
{
SBUF =rdata[i];
while(!TI);
TI =0;
}
/*TX_Busy = 1;
TXLen = RXLen;
for (i=0;i<RXLen;i++)
{
sdata[i] = rdata[i];
}
TXCont = 0;
SBUF = sdata[TXCont++];*/
}
}
//Initilze the Beam.
if (READ(0x03,0x40)=='$')
{
//delay(200);
delay(100);
rdata[0] = READ(0x03,0x40);
rdata[1] = READ(0x03,0x41);
i=2;
while((rdata[i-2] != 0x0d)&&(rdata[i-1] != 0x0a))
{
rdata[i] = READ(0x03,i+0x40);
i++;
if (i>31)
{
rdata[i-2] = 0x0d;
rdata[i-1] = 0x0a;
}
}
if (i < 31)
{
RXLen = i;
channel_beam_1=rdata[7]-0x30;
channel_beam_2=rdata[9]-0x30;
senddsp();
/* for (i=0;i< RXLen;i++)
{
SBUF =rdata[i];
while(!TI);
TI =0;
}
/*while(TX_Busy) ;
TX_Busy = 1;
TXLen = RXLen;
for (i=0;i<RXLen;i++)
{
sdata[i] = rdata[i];
}
TXCont = 0;
SBUF = sdata[TXCont++]; */
}
}
//Initilze the initial value.
if (READ(0x03,0x60)=='$')
{
delay(100);
//delay(200);
rdata[0] = READ(0x03,0x60);
rdata[1] = READ(0x03,0x61);
i=2;
while((rdata[i-2] != 0x0d)&&(rdata[i-1] != 0x0a))
{
rdata[i] = READ(0x03,i+0x60);
i++;
if (i>31)
{
rdata[i-2] = 0x0d;
rdata[i-1] = 0x0a;
}
}
if (i < 31)
{
RXLen = i;
senddsp();
pps_asc[0]=rdata[9];
pps_asc[1]=rdata[10];
pps_asc[2]=rdata[11];
pps_asc[3]=rdata[12];
/************************/
for(i=0;i<12;i++)
{
if (i<=3)
{
ay_par=ay_par<<8;
ay_par|= READ(0x03,(0xA0+i));
}
else if(i>3&&i<=7)
{
az_par=az_par<<8;
az_par|= READ(0x03,(0xA0+i));
}
}
/**************************/
/* for (i=0;i< RXLen;i++)
{
SBUF =rdata[i];
while(!TI);
TI =0;
}
/*while(TX_Busy) ;
TX_Busy = 1;
TXLen = RXLen;
for (i=0;i<RXLen;i++)
{
sdata[i] = rdata[i];
}
TXCont = 0;
SBUF = sdata[TXCont++];*/
}
}
for (i=0;i<255;i++)
{rdata[i] = 0xff;}
//ES=1;//Enable the serial interruption.
/*******************************************************/
while(1)
{wdt();
if (moto_fg ==0) //ASCII
{
if (flagserial==1) //Wether having received data from the serial port.
{
flagserial=0; //Reset the flag.
/************************************/
if ((toupper(rdata[3])=='L')&(toupper(rdata[4])=='L')&(toupper(rdata[5])=='A'))
{
WriteCont(0x02,0x00,rdata,0);
WriteCont(0x02,0x10,rdata,16);
WriteCont(0x02,0x20,rdata,32);
WriteCont(0x02,0x30,rdata,48);
}
if ((toupper(rdata[3])=='C')&(toupper(rdata[4])=='H')&(toupper(rdata[5])=='S'))
{
WriteCont(0x02,0x40,rdata,0);
WriteCont(0x02,0x50,rdata,16);
}
if ((toupper(rdata[3])=='O')&(toupper(rdata[4])=='F')&(toupper(rdata[5])=='S'))
{
WriteCont(0x02,0x60,rdata,0);
WriteCont(0x02,0x70,rdata,16);
WriteCont(0x02,0x80,rdata,32);
}
/***********************************/
if ((rdata[3]=='t'||rdata[3]=='T')&&
(rdata[4]=='m'||rdata[4]=='M')&&
(rdata[5]=='o'||rdata[5]=='O')) //ASCII TO motonola binary
moto_fg =1;
else
senddsp();
for (i=0;i<=254;i++)
{rdata[i] = 0xff;}
}
if (flagint==1) //Wether having received interrupt from the DSP.
{
flagint=0; //Reset the flag.
rdDSP();
}
if (TX == 1)
{
TX = 0;
TXCont = 0;
SBUF = sdata[TXCont++];
}
}
else //motonola binary
{
if (flagserial ==1)//串口接收完數據標志
{
flagserial =0;
rev_frame();
}
if (flagint ==1)//讀DSP標志
{
flagint =0;
rdDSP(); //讀DSP數據
if (sdata[3]=='L'&&sdata[4]=='L'&&sdata[5]=='A')
{
sec_fg =1; //置秒標志
}
ch_frame();//存取對應DSP數據
}
if (sec_fg&&u_fg)//串口發送標志
{
sec_fg =0; //清秒標志
//u_fg =0;
sd_uart(); //串口發送數據
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -