⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 term1.c

📁 使用单片机C8051F330对无线发射接收模块进行配置与控制,使组件成为无线通讯中的终端,可与基站进行双向通讯
💻 C
📖 第 1 页 / 共 2 页
字号:
    }

   if(FrameLength==1)                      //deal with the "$GPGGA" frame
    {
      if((RecvByte>7)&&(RecvByte<12)) 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+0xAA;                         //数据以十六进制方式传输
    CCF1=1;
    TDR=0xAA;						  //数据侦头
    while(!STI);         
    STI=0;
									  
    j=j+0x55;						  
    CCF1=1;
    TDR=0x55;						  //数据侦头
    while(!STI);       
    STI=0;
	
    j=j+ADDR_H;                       
    CCF1=1;
    TDR=ADDR_H;						  //模块地址高位
    while(!STI);
    STI=0;
	
    j=j+ADDR_L;						  
    CCF1=1;
    TDR=ADDR_L;						  //模块地址底位
    while(!STI);
    STI=0;
  
    j=j+ORDER;						  
    CCF1=1;
    TDR=ORDER;						  //位置应答命令0x1E
    while(!STI);
    STI=0;
	
    j=j+LENGTH;
    CCF1=1;	
    TDR=LENGTH;						  //有效数据长度
    while(!STI);
    STI=0;
//----------------------
//有效数据
   for (i=0;i<5;i++)                  //send UTC time
   {
      j=j+Date[i];
      CCF1=1;
      TDR=Date[i]; 
      while(!STI);
      STI=0;		   
   }	

//------------------------
//发送纬度   	
    j=j+Latitude_Integer;       CCF1=1;    TDR=Latitude_Integer;       while(!STI);    STI=0;     //纬度的整数部分\低位
    j=j+Latitude_Integer>>8;    CCF1=1;    TDR=Latitude_Integer>>8;    while(!STI);    STI=0;     //纬度的整数部分\高位

    j=j+Latitude_Decimal;       CCF1=1;    TDR=Latitude_Decimal;       while(!STI);    STI=0;	  //纬度的小数部分\低位	   
    j=j+Latitude_Decimal>>8;    CCF1=1;    TDR=Latitude_Decimal>>8;    while(!STI);    STI=0;	  //纬度的小数部分\高位	   
//------------------------
//发送经度
    j=j+Longitude_Integer;      CCF1=1;    TDR=Longitude_Integer;      while(!STI);    STI=0;	  //经度的整数部分\低位	   
    j=j+Longitude_Integer>>8;   CCF1=1;    TDR=Longitude_Integer>>8;   while(!STI);    STI=0;	  //经度的整数部分\高位	   

    j=j+Longitude_Decimal;      CCF1=1;    TDR=Longitude_Decimal;      while(!STI);    STI=0;	  //经度的小数部分\低位	   		 
    j=j+Longitude_Decimal>>8;   CCF1=1;    TDR=Longitude_Decimal>>8;   while(!STI);    STI=0;	  //经度的小数部分\高位	   		 
//------------------------
//信号有效 
    j=j+DGPS;
    CCF1=1;                  
    TDR=DGPS;				          //Send DGPS
    while(!STI);
    STI=0;	
//------------------------
//卫星颗数
      j=j+Planet_Quan;
      CCF1=1;
      TDR=Planet_Quan;
      while(!STI);
      STI=0;		   
//------------------------
//信号强度
    j=j+Dactyl;       CCF1=1;    TDR=Dactyl;       while(!STI);    STI=0;		//高
    j=j+Dactyl>>8;    CCF1=1;    TDR=Dactyl>>8;    while(!STI);    STI=0;		//底
//------------------------
//电池供电状态
	j=j+Batt_State;
	CCF1=1;
	TDR=Batt_State;
	while(!STI);
	STI=0;
//------------------------
//GPS天线状态
	j=j+GPS_Alarm;
	CCF1=1;
	TDR=GPS_Alarm;
	while(!STI);
	STI=0;
//------------------------
//余码和校验
    j=j%256;
	
    CK1=j/16;
    CK2=j%16;
    if (CK1>9) CK1=CK1+55;
    else CK1=CK1+48;

    CCF1=1;
    TDR=CK1;	
    while(!STI);
    STI=0; 
	
    if (CK2>9) CK2=CK2+55;
    else CK2=CK2+48;
	
    CCF1=1;
    TDR=CK2;	
    while(!STI);
    STI=0; 		
//------------------------




		 				   
}



/*
void Delay_1uS(void)
{
	unsigned char i;
	for(i=0;i<200;i++);
}
/*-------------------------------------------------------------
//
//-----------------------------------------------------------*/
void Variable_Init(void)
{
  RecvByte=0;
/*
  riqi[0]=0+0x30;
  riqi[1]=5+0x30;
  riqi[2]=0+0x30;
  riqi[3]=7+0x30;
  riqi[4]=2+0x30;
  riqi[5]=0+0x30;
*/
  GPS_Alarm = 0x85;

  weixing[0]=0+0x30;
  weixing[1]=0+0x30;

  GPS_Current_pre=0;
  GPS_Current=0;
  GPS_Alarm_js=0;

  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;
  }	
		
  SRI=0;

}

//----------------------------------------------------------------------------
//Interrupt Service Routine
//----------------------------------------------------------------------------
void PCA_ISR(void) interrupt 11
{
    static char SUTXST = 0;              //SW_UART TX????
	static char SURXST = 0;              //SW_UART RX????
	static unsigned RXSHIFT = 0;         //SW_UART RX?????
    unsigned int PCA_TEMP;               //??????,????PCA?????
	                                     //???

   // Check receive interrupt flag first; service if CCF0 is set.
	if (CCF0){
		CCF0 = 0;										// Clear interrupt flag.
		switch (SURXST){
			
			// State 0: START bit received.
			// In this state, a negative edge on SW_TX has caused the interrupt,
			// meaning a START has been detected and the PCA0CP0 registers have 
			// captured the value of PCA0.
			// - Check for receive enable and good START bit
			// - Switch PCA module 0 to software timer mode
			// - Add 3/2 bit time to module 0 capture registers to sample LSB.
			// - Increment RX state variable.
			case 0:
			    
				if (SREN & ~SW_RX){					// Check for receive enable and a good
													// START bit.  
																
					PCA_TEMP = (PCA0CPH0 << 8);	    // Read module 0 contents into
					PCA_TEMP |= PCA0CPL0;			// PCA_TEMP.

					PCA_TEMP += TH_TIME_COUNT;		// Add 3/2 bit times to PCA_TEMP

					PCA0CPL0 = PCA_TEMP;				// Restore PCA0CPL0 and PCA0CPH0
					PCA0CPH0 = (PCA_TEMP >> 8);	// with the updated value

					PCA0CPM0 = 0x49;				// Change module 0 to software
													// timer mode, interrupts enabled.

					SURXST++;							// Update RX state variable.
    			}
				break;
			
			// States 1-8: Bit Received
			// - Sample SW_RX pin
			// - Shift new bit into RXSHIFT
			// - Add 1 bit time to module 0 capture registers
			// - Increment RX state variable
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
			case 7:
			case 8:
					
				RXSHIFT = RXSHIFT >> 1;				// Shift right 1 bit
				if (SW_RX)								// If SW_RX=1, 
					RXSHIFT |= 0x80;					// shift '1' into RXSHIFT msb
				
				PCA_TEMP = (PCA0CPH0 << 8);		// Read module 0 contents into
				PCA_TEMP |= PCA0CPL0;				// PCA_TEMP.

				PCA_TEMP += TIME_COUNT;				// Add 1 bit time to PCA_TEMP

				PCA0CPL0 = PCA_TEMP;					// Restore PCA0CPL0 and PCA0CPH0
				PCA0CPH0 = (PCA_TEMP >> 8);		// with the updated value
				
				SURXST++;								// Update RX state variable.
				break;

			// State 9: 8-bits received, Capture STOP bit.
			// - Move RXSHIFT into RDR.
			// - Set SRI (indicate receive complete).
			// - Prepare module 0 for next transfer.
			// - Reset RX state variable.
			// - Trigger IE7 if user-level interrupt support is enabled.
			case 9:

				RDR = RXSHIFT;							// Move received data to receive register.
				SRI = 1;								// Set receive complete indicator.

				PCA0CPM0 = 0x11;						// Switch module 0 to negative capture
														// mode; interrupt enabled for START
														// detection.

				SURXST = 0;								// Reset RX state variable.

			
				break;
				
			}
		}
		
		// Check Transmit interrupt; service if CCF1 is set.
		else if (CCF1){ 
			CCF1 = 0;									// Clear interrupt flag
			switch (SUTXST){
				
				// State 0: Transmit Initiated.
				// Here, the user has loaded a byte to transmit into TDR, and set the
				// module 1 interrupt to initiate the transfer.
				// - Transmit START bit (drop SW_TX)
				// - Read PCA0, add one bit time, & store in module 1 capture registers
				//   for first bit.
				// - Increment TX state variable.
				case 0:
                    STXBSY = 1;                         // SW_UART TX?
					SW_TX = 0;							// Drop TX pin as START bit.
					
					PCA_TEMP = PCA0L;					// Read PCA counter value into
					PCA_TEMP |= (PCA0H << 8);		    // PCA_TEMP.

					PCA_TEMP += TIME_COUNT;			    // Add 1 bit time.

					PCA0CPL1 = PCA_TEMP;				// Store updated match value into
					PCA0CPH1 = (PCA_TEMP >> 8);	// module 1 capture/compare registers.

					PCA0CPM1 |= 0x48;					// Enable module 1 software timer.

					SUTXST++;							// Update TX state variable.				
					break;

				// States 1-9: Transmit Bit.
				// - Output LSB of TDR onto TX
				// - Shift TDR 1 bit right.
				// - Shift a '1' into MSB of TDR for STOP bit in State 9.
				// - Add 1 bit time to module 1 capture register
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 9:
					
					SW_TX = (TDR & 0x01);			// Output LSB of TDR onto SW_TX pin.
					TDR >>= 1;							// Shift TDR right 1 bit.
					TDR |= 0x80;						// Shift '1' into MSB of TDR for
															// STOP bit in State 9.

					PCA_TEMP = (PCA0CPH1 << 8);	// Read module 1 contents into
					PCA_TEMP |= PCA0CPL1;			// PCA_TEMP.

					PCA_TEMP += TIME_COUNT;			// Add 1 bit time to PCA_TEMP
	
					PCA0CPL1 = PCA_TEMP;				// Restore PCA0CPL1 and PCA0CPH1
					PCA0CPH1 = (PCA_TEMP >> 8);	// with the updated value	

					SUTXST++;                     // Update TX state variable.
					break;
					
				// State 10: Last bit has been transmitted.  Transmit STOP bit
				// and end transfer.  
				// - Transmit STOP bit
				// - Set TX Complete indicator, clear Busy flag
				// - Reset TX state
				// - Prepare module 1 for next transfer.
				// - Trigger IE7 interrupt if user-level interrupts enabled.
				case 10:

					STI = 1;								// Indicate TX complete.
					SUTXST = 0;							// Reset TX state.
					SW_TX = 1;							// SW_TX should remain high.

					PCA0CPM1 = 0x01;					// Disable module 1 software timer; leave
															// interrupt enabled for next transmit.					
					STXBSY = 0;							// SW_UART TX free.	
					break;
				}
}


}
/*
void send_wireless(void)
{
  short int j=0;

    STI=0;
    j=j+'$';
    CCF1=1;
    TDR='$';
    while(!STI);         //send startup signal:$SJQQC,
    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+'C';
    CCF1=1;	
    TDR='\n';
    while(!STI);
    STI=0;	

     STI=0;
    j=j+'$';
    CCF1=1;
    TDR='$';
    while(!STI);         //send startup signal:$SJQQC,
    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='W';
    while(!STI);
    STI=0;	

    j=j+'C';
    CCF1=1;	
    TDR='\n';
    while(!STI);
    STI=0;	

}
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -