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

📄 f334.c

📁 使用单片机C8050F330对无线发射接受模块进行配置与控制,使组件成为一个无线通讯中的基站.
💻 C
📖 第 1 页 / 共 3 页
字号:
    while(!STI);
    STI=0;
	
    for (i=0;i<4;i++)           //send horizontal AdResult ?????
    {
      j=j+S_AdResult2[i];
      CCF1=1;
      TDR=S_AdResult2[i];
      while(!STI);
      STI=0;	
    }          
          
    j=j+',';                 
    CCF1=1;
    TDR=',';	
    while(!STI);
    STI=0;           
	
    for (i=0;i<4;i++)           //send ????
    {
      j=j+S_AdResult3[i];
      CCF1=1;
      TDR=S_AdResult3[i];
      while(!STI);
      STI=0;	
    }          
          
    j=j+',';                 
    CCF1=1;
    TDR=',';	
    while(!STI);
    STI=0;         
    
    for (i=0;i<4;i++)           //send ????
    {
      j=j+S_AdResult4[i];
      CCF1=1;
      TDR=S_AdResult4[i];
      while(!STI);
      STI=0;	
    }          
          
    j=j+',';                 
    CCF1=1;
    TDR=',';	
    while(!STI);
    STI=0;         
    
    for (i=0;i<3;i++)          //send general PulseCount/s
    {
      j=j+S_Pulse_s[i];
      CCF1=1;
      TDR=S_Pulse_s[i];
      while(!STI);
      STI=0;
    }

    j=j+',';                 
    CCF1=1;
    TDR=',';	
    while(!STI);
    STI=0;       

    for (i=0;i<3;i++)
    {
      j=j+fm[i];
      CCF1=1;
      TDR=fm[i];
      while(!STI);
      STI=0;
    }  

    j=j+',';                 
    CCF1=1;
    TDR=',';	
    while(!STI);
    STI=0;       
 
    for (i=0;i<2;i++)          //send general PulseCount/s
    {
      j=j+GPS_Alarm[i];
      CCF1=1;
      TDR=GPS_Alarm[i];
      while(!STI);
      STI=0;
    }  
	 
    j=j+',';                 
    CCF1=1;
    TDR=',';	
    while(!STI);
    STI=0;       
 
    j=j+b_light;
    CCF1=1;
    TDR=b_light;
    while(!STI);
    STI=0;
		 
    CCF1=1;
    TDR='*';	
    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; 			
	
    CCF1=1; //SEND CR
    TDR=13;	
    while(!STI);
    STI=0; 	
	
    CCF1=1;//SEND LF
    TDR=10;	
    while(!STI);
    STI=0; 	

}

void Key_scan(void)
{
  unsigned char key_buf=0;

  if (PWR_KEY==0)
  {
    key_buf=99;
  }

  if (key_buf==key_pre)
  {
    if (key_buf!=0)
    {
      key_work=0x55;
    }
    else
    {
      key_work=0;
	  key_press_time=0;
    }
  }
  else
  {
    key_pre=key_buf;
	key_press_time=0;
  }
}


void Key_process(void)
{
      if ((key_work==0x55) && (key_time==0))
      {
  	     key_work=0;key_time=1000; //key_zt==0  关机 key_zt==99 开机


         if (key_zt==0)    //如果当前状态是关机状态,此时有按键信号,则开机,延时开背光
         {
		    key_zt=99;
            S2410_PWR=0;
            LcdBackLight_Delay_AfterS2410=1800;
			GPS_SW=0;
            DAC0=0x0800;
            Control_inf(88,0,1);
         }
         else if (key_zt==99) //如果当前状态是开机状态,此时有按键信号,则判断长按,关机
         {                    //如果不长按,key_zt 不能变
		   DAC0=0x0000;
	       Control_inf(88,0,0);
         }
      }
}

void Delay_1uS(void)
{
	unsigned char i;
	for(i=0;i<200;i++);
}

/***************************************************************************
	??16????BH1415H
****************************************************************************
**/
void send_contr_word(unsigned int Cotrdata)
{
	unsigned int C_word;
	unsigned char i;
	bh_en=0;
	for(i=0;i<16;i++)
	{
		C_word=Cotrdata&0x0001;
		if (C_word!=0)
		{
			bh_clk=1;Delay_1uS();
			bh_data=0;Delay_1uS();
			bh_clk=0;Delay_1uS();
		}
		else
		{
			bh_clk=1;Delay_1uS();
			bh_data=1;Delay_1uS();
			bh_clk=0;Delay_1uS();
		}
		Cotrdata=_iror_(Cotrdata,1);
	}
	bh_data=1;
	bh_clk=1;
	bh_en=1;
}
/***************************************************************************

??????:??????,????1?,?????,1???
	
****************************************************************************
**/
void Control_inf(unsigned char dx1,dx2,dx3)			
{
	unsigned int control_data;

	control_data=dx1 * 10+dx2;							/*?????????????????*/											
	control_data=control_data | 0x0800;					/*??????????,1????*/		
	control_data=(control_data & 0xcfff);				/*D12?D13????????,0x00*/	
	
	if(dx3)
	{
		control_data=((control_data & 0x3fff) | 0x4000);	/*D14?D15????????,0x01*/
	}
	else control_data=control_data & 0x3fff;
	send_contr_word(control_data);						/*Send the Control work of 16 bit*/
}

void Variable_Init(void)
{
  RecvByte=0;
  LcdBackLight_Delay_AfterS2410=0;

  key_press_time=0;

  key_zt=0;key_time=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[0]=8+0x30;GPS_Alarm[1]=5+0x30;
  weixing[0]=0+0x30;weixing[1]=0+0x30;
  GPS_Current_pre=0;GPS_Current=0;
  GPS_time=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;
  }	
		
  fm[0]=0x30;
  fm[1]=0x30;
  fm[2]=0x30;
  fmbak=0;
  
  SRI=0;
  surt_js=0;
  b_light=0x30;
}

//----------------------------------------------------------------------------
//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;
				}
}


}

⌨️ 快捷键说明

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