📄 term3.c
字号:
//
void SYSCLK_Init (void)
{
OSCICN |= 0x03; // Configure internal oscillator for
// its maximum frequency
RSTSRC = 0x04; // Enable missing clock detector
}
//-----------------------------------------------------------------------------
// UART0_Init
//-----------------------------------------------------------------------------
//
// Configure the UART0 using Timer1, for <BAUDRATE> and 8-N-1.
//
void UART0_Init (void)
{
SCON0 = 0x10; // SCON0: 8-bit variable bit rate
// 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)
{
}
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:采样数字 Y:基准(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;
}
/*****************************************
* 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;
// IsGpsFrame++;
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,m,n;
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+'-';
CCF1=1;
TDR='-';
while(!STI);
STI=0;
j=j+'N';
CCF1=1;
TDR='N';
while(!STI);
STI=0;
j=j+'a';
CCF1=1;
TDR='a';
while(!STI);
STI=0;
j=j+'v';
CCF1=1;
TDR='v';
while(!STI);
STI=0;
j=j+'i';
CCF1=1;
TDR='i';
while(!STI);
STI=0;
j=j+',';
CCF1=1;
TDR=',';
while(!STI);
STI=0;
//--------------------
//访问终端的地址
m = ADDRESS /10000+48;
n = ADDRESS %10000;
j=j+m;
CCF1=1;
TDR=m;
while(!STI);
STI=0;
m = n /1000+48;
n = n %1000;
j=j+m+48;
CCF1=1;
TDR=m;
while(!STI);
STI=0;
m = n /100+48;
n = n %100;
j=j+m;
CCF1=1;
TDR=m;
while(!STI);
STI=0;
m = n /10+48;
n = n %10+48;
j=j+m;
CCF1=1;
TDR=m;
while(!STI);
STI=0;
j=j+n;
CCF1=1;
TDR=n;
while(!STI);
STI=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -