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

📄 rfrecive.c

📁 基于AVR mega8的无线接收程序 解码芯片为PT2407
💻 C
字号:
/*******************************************************************
/Program Name:      Telecontrol Device Sink Terminal Program
/Program Function:  NO
/Program Explain:   include <config.h>
                    ICC-AVR application builder
                    Target : M8
                    Crystal: 8.0000Mhz
/Emport:			NO
/Export:			NO
/Date Created:      2008-3-11
/History Edition:   NO
/Author: 			Duan Jinlong
********************************************************************/
#include <config.h>      
void port_init(void)
{
 PORTB = 0xC0;		
 DDRB  = 0xC0;			  //PORTB is use to receive the data witch comes from PT2272;PORTD 2 is the signal of PT2272
 PORTC = 0xFF; 		     
 DDRC  = 0xFF;            //PORTC,0,1,2,3,is use to contorl the 74ls164;4,5 is use to contorl the led 
 PORTD = 0xF3;            //PORTD 0,1,2,4,5,6 is output I/O(portd3 is use to choice the mode of code send)
 DDRD  = 0xF3;            //PORTD2 is enable signal from  PT2272 
          
}

/*******************************************************************
/Subprogram Name:      watchdog_init()
/Subprogram Function:  initialization the watch dog
/Subprogram Explain:   WDR() is the command of clear the watch dog
/Emport:			   NO
/Export:			   NO
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
void watchdog_init(void)
{
 WDR (); //this prevents a timeout on enabling
 WDTCR |= (1<<WDCE) | (1<<WDE);/* 30-Oct-2006 Umesh*/  
 WDTCR = 0x09; //WATCHDOG ENABLED - dont forget to issue WDRs
}
/*******************************************************************
/Subprogram Name:      int0_isr()
/Subprogram Function:  Emport programmof INT0
/Subprogram Explain:   NO
/Emport:			   NO
/Export:			   NO
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
#pragma interrupt_handler int0_isr:iv_INT0
void int0_isr(void)
{
 Receive=PINB&0x3f;
 Int0Syb=1;
}

/*******************************************************************
/Subprogram Name: init_devices()
/Subprogram Function:  MCU  Device initialization
/Subprogram Explain:   NO
/Emport:			   NO
/Export:			   NO
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
void init_devices(void)
{
                      //stop errant interrupts until set up
 CLI();               //disable all interrupts
 port_init();
 watchdog_init();
 MCUCR = 0x03;
 GICR  = 0x40;
 TIMSK = 0x00;        //timer interrupt sources
 SEI();               //re-enable interrupts
                      //all peripherals are now initialized
}

/*******************************************************************
/Subprogram Name    :  main()
/Subprogram Function:  Main program
/Subprogram Explain :  Include all Application
/Emport:			   NO
/Export:			   NO
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
void main(void)
{Int0Syb=0;
 init_devices();
 while(1)
{ 
  WDR ();
  if(Get_Bit(PIND,3))			//if PORTD 5 IS 1,send analog signals									 
  {
   Value2BCD(Receive);  
   Set_Bit(PORTC,3);
   Clr_Bit(PORTC,4); 
   OP_HC164(DispValue[DispBuf[1]]);
   Delay(50,200);
   Set_Bit(PORTC,4);
   Clr_Bit(PORTC,3); 
   OP_HC164(DispValue[DispBuf[0]]);
   Delay(50,200); 
   }
  else
  {  
  	 if(Int0Syb==1)
	 { 
	 Leddisp();
	 Delay(50,2000);
	 Int0Syb=0; 
	 }
	 else
	 {
	 PORTD=0XFF;
	 
	 }
	 
    } 
}
}




/*******************************************************************
/Subprogram Name    :  Value2BCD()  
/Subprogram Function:  ADC Value change to BCD array 
/Subprogram Explain :  NO
/Emport:			   value   The value read from PT2272
/Export:			   NO
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
void Value2BCD(uint value) 
{ WDR (); 
  DispBuf[0]=value/10;
  DispBuf[1]=value%10;
}

/*******************************************************************
/Subprogram Name    :  Delay() 
/Subprogram Function:  Delay Time
/Subprogram Explain :                       
/Emport:			   NO
/Export:			   NO
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
void Delay(uint Time1,uint Time2)  
{  	 
 int  i,j;
   	 for(i=0;i<Time2;i++)
   	 {WDR ();
   	   for(j=0;j<Time1;j++){WDR (); }   	 
      }
}

/*******************************************************************
/Subprogram Name    :  OP_HC164()
/Subprogram Function:  Operate the 74ls164 to Send the data to the 7SEG LED 
/Subprogram Explain :  74HC164 device operation Drive function                     
/Emport:			   data --The data which will be send to
/Export:			   NO
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
void OP_HC164(uchar data)
{ 			             
  uchar i,Left_data,pp;
  WDR ();  			   	 		 //feed the dog
  Clr_Bit(PORTC,1);
  Delay(10,1);
  Set_Bit(PORTC,1);
  for(i=0;i<8;i++)
  {
   pp=data&0x80;          		 // make sure the shift data is 0 or 1
   data=(data<<1);
   if (pp==0)     
   {
    Clr_Bit(PORTC,1);
    Delay(10,1);
    Clr_Bit(PORTC,2);
    Delay(1,10);
    Set_Bit(PORTC,2);
   }
   else
   {
    Set_Bit(PORTC,1);
    Delay(10,1);
    Clr_Bit(PORTC,2);
    Delay(1,10);
    Set_Bit(PORTC,2);
   }
 }
}

/*******************************************************************
/Subprogram Name    :  Receive_PT2272()
/Subprogram Function:  Reveice the data from the PT2272
/Subprogram Explain :                      
/Emport:			   NO
/Export:			   data
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
uchar Receive_PT2272(void)
{ uchar data;
  WDR ();  				  //feed the dog
  data=0X3F&PINB;        //send the data to the 2262 
  return data;
}
/*******************************************************************
/Subprogram Name    :  Leddisp()
/Subprogram Function:  switch the led light
/Subprogram Explain :  NO            
/Emport:			   NO
/Export:			   key
/Date Created:         2008-3-11
/History Edition:      NO
/Author: 			   Duan Jinlong
********************************************************************/
void Leddisp(void)
{ WDR ();           //feed the dog
  switch (Receive)
  {
   case 0x3f: 
   			  PORTD=0x73;
			  Set_Bit(PORTC,3);
   			  Clr_Bit(PORTC,4); 
   			  OP_HC164(DispValue[0]);
			  //Delay(200,2000);
			  //PORTD=0xf3;
			  Int0Syb=0;
  	   	   	  break;
   case 0x3e: 
   			  Set_Bit(PORTC,3);
   			  Clr_Bit(PORTC,4); 
   			  OP_HC164(DispValue[1]);
   			  PORTD=0xf2;
			  //Delay(200,2000);
			  //PORTD=0xf3;
			  Int0Syb=0;
  	   		  break ;
   case 0x3d: 
   			  Set_Bit(PORTC,3);
   			  Clr_Bit(PORTC,4); 
   			  OP_HC164(DispValue[2]);
   			  PORTD=0xf1;

			  //Delay(200,2000);
			  //PORTD=0xf3;
			  Int0Syb=0;
    		  break ;
   case 0x3b: 
   			  Set_Bit(PORTC,3);
   			  Clr_Bit(PORTC,4); 
   			  OP_HC164(DispValue[3]);
   			  PORTD=0xE3;
 
			  //Delay(200,2000);
			  //PORTD=0xf3;
			  Int0Syb=0;
   			  break ;
   case 0x37: 
   			  Set_Bit(PORTC,3);
   			  Clr_Bit(PORTC,4); 
   			  OP_HC164(DispValue[4]);
   			  PORTD=0xD3;
			  
			  //Delay(200,2000);
			  //PORTD=0xf3;
			  Int0Syb=0;
   			  break ;
   case 0x2f: 
   			  Set_Bit(PORTC,3);
   			  Clr_Bit(PORTC,4); 
   			  OP_HC164(DispValue[5]);
   			  PORTD=0xB3;
			 // Delay(200,2000);
   			  //PORTD=0xf3;
			  Int0Syb=0;
			  break;
  }
   
}

⌨️ 快捷键说明

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