?? f334.c
字號(hào):
// level of STOP bit is ignored
// RX enabled
// ninth bits are zeros
// clear RI0 and TI0 bits
if (SYSCLK/BAUDRATE/2/256 < 1) {
TH1 = -(SYSCLK/BAUDRATE/2);
CKCON &= ~0x0B; // T1M = 1; SCA1:0 = xx
CKCON |= 0x08;
} else if (SYSCLK/BAUDRATE/2/256 < 4) {
TH1 = -(SYSCLK/BAUDRATE/2/4);
CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 01
CKCON |= 0x09;
} else if (SYSCLK/BAUDRATE/2/256 < 12) {
TH1 = -(SYSCLK/BAUDRATE/2/12);
CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 00
} else {
TH1 = -(SYSCLK/BAUDRATE/2/48);
CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 10
CKCON |= 0x02;
}
TL1 = TH1; // init Timer1
TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload
TMOD |= 0x20;
TR1 = 1; // START Timer1
TI0 = 1; // Indicate TX0 ready
}
void SW_UART_Init (void)
{
PCA0MD = 0x02; //PCA counter use SYSCLK/4 as timebase
PCA0CPM1 = 0x49; //PCA0CPM1:capture triggered by
//negative edge on P0.3,enable module1
//interrupt
PCA0CPM0 = 0x11; //PCA0CPM0:software timer mode,enable
//module 0 interrupt
PCA0CN |= 0x40; //enables the PCA Counter/Timer.
CCF0 = 0;
CCF1 = 0;
SRI = 0; //????????
STI = 0; // ????????
SW_TX = 1; // TX????????
STXBSY = 0; // ??SW_UART???
SREN = 1; //????
}
//-----------------------------------------------------------------------------
// ???0???
//-----------------------------------------------------------------------------
void Timer0_Init (void)
{
TMOD|=0X06; //COUNT0
TL0=0X0FF; //interrupt when every pulse come
TH0=0X0FF;
EA=1;
ET0=1; //COUNT0 INT ENABLE
TR0=1; //COUNT0 START
}
void Timer0_ISR (void) interrupt 1
{
Pulse_s++;
}
//-----------------------------------------------------------------------------
// ADC0_Init ADBUSY, LP tracking, no Interrupt, ADC disabled
//-----------------------------------------------------------------------------
//
// Configure ADC0 to use ADBUSY as conversion source, and to sense the output
// of the temp sensor. Disables ADC end of conversion interrupt. Leaves ADC
// disabled.
//
void AD_Init (void)
{
ADC0CN = 0x40; // ADC0 disabled; LP tracking
// mode; ADC0 conversions are initiated
// on a write to ADBusy
AMX0P = 0x0a; // Temp sensor selected at + input
AMX0N = 0x11; // Single-ended mode
ADC0CF = (SYSCLK/3000000) << 3; // ADC conversion clock <= 3MHz
ADC0CF &= ~0x04; // Make ADC0 right-justified
REF0CN = 0x0E; // enable temp sensor, VREF = VDD, bias
// generator is on.
//EIE1 |= 0x08; // Enable ADC0 interrupt
ADC0CN = 0x80;
AD0BUSY = 1;
}
void Timer3_ISR (void) interrupt 14 //2.5ms
{
TMR3CN &= ~0x80;
key_scan_time++;
count_time++;
key_press_time++;
if (LcdBackLight_Delay_AfterS2410>0) LcdBackLight_Delay_AfterS2410--;
else if (key_zt==99)
{
LcdBackLight_Delay_AfterS2410=0;
BG_EN=0;
}
if ((key_press_time>400) && (key_zt==99))
{
BG_EN=1;
S2410_PWR=1;
key_press_time=0;
key_zt=0;
}
if (key_time>0) key_time--;else key_time=0;
test++;
if (GPS_Alarm_js>0) GPS_Alarm_js--;else GPS_Alarm_js=0;
if (GPS_time>0) GPS_time--;else GPS_time=0;
if (FM_delay>0) FM_delay--;else FM_delay=0;
}
void Measure (void)
{
// (X*5-Y)/25=Z X:采樣數(shù)字 Y:基準(zhǔn)(mV) Z:角度
AMX0P = 0x0a;
AMX0N = 0x11;
AD0INT = 0;
AD0BUSY = 1;
while (!AD0INT); // Wait for conversion to complete
AD0INT = 0; // Clear end-of-conversion indicator
TL_Adresult=ADC0; // Store latest ADC conversion
AMX0P = 0x00;
AMX0N = 0x11;
AD0INT = 0;
AD0BUSY = 1;
while (!AD0INT); // Wait for conversion to complete
AD0INT = 0; // Clear end-of-conversion indicator
GPS_Current=ADC0; // Store latest ADC conversion
}
//-----------------------------------------------------------------------------
// ???3???
//-----------------------------------------------------------------------------
void Timer3_Init ()
{
TMR3CN = 0x00;
CKCON |= 0x40;
TMR3RL = -60000;
TMR3 = TMR3RL;
EIE1 |= 0x80;
TMR3CN |= 0x04;
}
//-----------------------------------------------------------------------------
// 數(shù)模轉(zhuǎn)換初始化
//-----------------------------------------------------------------------------
void DA_Init (void)
{
IDA0CN = 0xb2; //D/A允許,定時(shí)器3溢出觸發(fā),1mA滿度電流輸出
REF0CN = 0x0E; //使用內(nèi)部電壓基準(zhǔn)
}
/*****************************************
* Uart Interrupt
*
*****************************************/
void Rcv_INT(void) interrupt 4
{
unsigned char tmp;
RI0=0;
tmp=RecvByte;
UartBuff=SBUF0;
RecvByte++;
if (RecvByte<HeaderLength+1)
{
Header[tmp]=UartBuff;
}
if(RecvByte==HeaderLength)
{
if((Header[0]=='$')&&(Header[1]=='G')&&(Header[2]=='P')&&(Header[3]=='G')&&(Header[4]=='G')&&(Header[5]=='A'))
{ //if it is a "$GPGGA" frame
FrameLength=1;
}
else if((Header[0]=='$')&&(Header[1]=='G')&&(Header[2]=='P')&&(Header[3]=='R')&&(Header[4]=='M')&&(Header[5]=='C'))
{ //if it is a "$GPGGA" frame
FrameLength=3;
}
else
{
FrameLength=2; //if it is other frame,discard it
}
}
if(FrameLength==2) //deal with other frame
{
if(UartBuff==0x0D) CRByte=UartBuff; //received CR
if(UartBuff==0x0A) LFByte=UartBuff; //received LF
if(CRByte&&LFByte) //received CR and LF,end of frame
{
RecvByte=0; //clear byte counter
FrameLength=0; //clear frame length
CRByte=0; //clear CR byte
LFByte=0; //clear LF byte
for (ii=0;ii<9;ii++) // Longitude
{
Longitude[ii]=0x30;
}
for (ii=0;ii<10;ii++) // Latitude
{
Latitude[ii]=0x30;
}
DGPS=0x30;
for (ii=0;ii<4;ii++) // HDOP
{
HDOP[ii]=0x30;
}
//IsGpsFrame=1;
//gps_ok=99;
}
}
if(FrameLength==1) //deal with the "$GPGGA" frame
{
if((RecvByte>7)&&(RecvByte<18)) UTCtime[tmp-7]=UartBuff; //received UTCtime
if((RecvByte==20)&&(UartBuff==',')) FrameLength=2;//????,???????,???????
if((RecvByte>18)&&(RecvByte<28)) Longitude[tmp-18]=UartBuff; //received jing du
if((RecvByte>30)&&(RecvByte<41)) Latitude[tmp-30]=UartBuff; //received wei du
if (RecvByte==44) DGPS=UartBuff;
if((RecvByte>45)&&(RecvByte<48)) weixing[tmp-45]=UartBuff; //received weixing ge shu
else if ((RecvByte>48)&&(RecvByte<53)&&(UartBuff!=','))
{
HDOP[tmp-48]=UartBuff;
}
if(RecvByte>60) //52
{
if(UartBuff==0x0D) CRByte=UartBuff; //received CR
if(UartBuff==0x0A) LFByte=UartBuff; //receive
if(CRByte&&LFByte) //received CR and LF,end of frame
{
RecvByte=0; //clear byte counter
FrameLength=0; //clear frame length
CRByte=0; //clear CR byte
LFByte=0; //clear LF byte
IsGpsFrame=1;
gps_ok=99;
}
}
}
if(FrameLength==3) //deal with the "$GPGGA" frame
{
if((RecvByte>55)&&(RecvByte<62)) riqi[tmp-55]=UartBuff; //received Data
if(RecvByte>62) //52
{
if(UartBuff==0x0D) CRByte=UartBuff; //received CR
if(UartBuff==0x0A) LFByte=UartBuff; //receive
if(CRByte&&LFByte) //received CR and LF,end of frame
{
RecvByte=0; //clear byte counter
FrameLength=0; //clear frame length
CRByte=0; //clear CR byte
LFByte=0; //clear LF byte
//IsGpsFrame=1;
//gps_ok=99;
}
}
}
TI0=0;
}
void Send_GPS(void)
{
unsigned char i;
unsigned char CK1;
unsigned char CK2;
short int j=0;
STI=0;
j=j+'$';
CCF1=1;
TDR='$';
while(!STI); //send startup signal:$SJQQB,
STI=0;
j=j+'S';
CCF1=1;
TDR='S';
while(!STI);
STI=0;
j=j+'J';
CCF1=1;
TDR='J';
while(!STI);
STI=0;
j=j+'Q';
CCF1=1;
TDR='Q';
while(!STI);
STI=0;
j=j+'Q';
CCF1=1;
TDR='Q';
while(!STI);
STI=0;
j=j+'C';
CCF1=1;
TDR='C';
while(!STI);
STI=0;
j=j+',';
CCF1=1;
TDR=',';
while(!STI);
STI=0;
if ((riqi[5]>0x39) || (riqi[5]<0x30)) riqi[5]=5+0x30;
if ((riqi[4]>0x31) || (riqi[4]<0x30)) riqi[4]=0+0x30;
if ((riqi[3]>0x39) || (riqi[3]<0x30)) riqi[3]=2+0x30;
if ((riqi[2]>0x31) || (riqi[2]<0x30)) riqi[2]=1+0x30;
if ((riqi[1]>0x39) || (riqi[1]<0x30)) riqi[1]=5+0x30;
if ((riqi[0]>0x33) || (riqi[0]<0x30)) riqi[0]=2+0x30;
for (i=0;i<6;i++) //send UTC time
{
j=j+riqi[i];
CCF1=1;
TDR=riqi[i];
while(!STI);
STI=0;
}
for (i=0;i<6;i++) //send UTC time
{
j=j+UTCtime[i];
CCF1=1;
TDR=UTCtime[i];
while(!STI);
STI=0;
}
j=j+',';
CCF1=1;
TDR=',';
while(!STI);
STI=0;
for (i=0;i<9;i++) //send Longitude
{
j=j+Longitude[i];
CCF1=1;
TDR=Longitude[i];
while(!STI);
STI=0;
}
j=j+',';
CCF1=1;
TDR=',';
while(!STI);
STI=0;
for (i=0;i<10;i++) //send Latitude
{
j=j+Latitude[i];
CCF1=1;
TDR=Latitude[i];
while(!STI);
STI=0;
}
j=j+',';
CCF1=1;
TDR=',';
while(!STI);
STI=0;
j=j+DGPS;
CCF1=1; //snd DGPS
TDR=DGPS;
while(!STI);
STI=0;
j=j+',';
CCF1=1;
TDR=',';
while(!STI);
STI=0;
for (i=0;i<4;i++) //send HDOP
{
j=j+HDOP[i];
CCF1=1;
TDR=HDOP[i];
while(!STI);
STI=0;
}
j=j+',';
CCF1=1;
TDR=',';
while(!STI);
STI=0;
for (i=0;i<4;i++) //send gyro AdResult
{
j=j+S_AdResult0[i];
CCF1=1;
TDR=S_AdResult0[i];
while(!STI);
STI=0;
}
j=j+',';
CCF1=1;
TDR=',';
while(!STI);
STI=0;
for (i=0;i<4;i++) //send vertical AdResult ?????
{
j=j+S_AdResult1[i];
CCF1=1;
TDR=S_AdResult1[i];
while(!STI);
STI=0;
}
j=j+',';
CCF1=1;
TDR=',';
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -