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

📄 main.c

📁 单片机与a7105组成无线收发程序2.4G多通道
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************
;copyright    :shenzhen 
;filename     :main.c
;mcu          :w78e52b
;crystal      :33.177MHZ
;cycle        :0.36us
;RF           :7105
;rf crystal   :16MHZ
;RF rate      :250K(默认,可以通过按键修改)
;startdate    :2008.10.7
;enddate      :
;writeby      :dengyih
;revision     :B
;describe     :7105 参数测试(可以测试通信)
;notice       :
;complier     :Keil C
;***********************************************************************
;                            --------------------
;                     P1.0  |1                 40|  VCC
;                     P1.1  |2                 39|  P0.0     ----  LCD_DATA0
;   RF_SCK  ----      P1.2  |3                 38|  P0.1     ----  LCD_DATA1
;   RF_SDIO ----      P1.3  |4                 37|  P0.2     ----  LCD_DATA2
;                     P1.4  |5                 36|  P0.3     ----  LCD_DATA3
;   RF_SCS  ----      P1.5  |6                 35|  P0.4     ----  LCD_DATA4
;                     P1.6  |7                 34|  P0.5     ----  LCD_DATA5
;                     P1.7  |8                 33|  P0.6     ----  LCD_DATA6
;                  RST/Vpd  |9                 32|  P0.7     ----  LCD_DATA7
;                 RXD/P3.0  |10                31|  /EA/Vpp
;                 TXD/P3.1  |11                30|  ALE/PROG
;  RF_GPIO2 --- /INT0/P3.2  |12                29|  /PSEN
;  RF_GPIO1 --- /INT1/P3.3  |13                28|  P2.7     ----  KEY4
;                  T0/P3.4  |14                27|  P2.6     ----  KEY3
;  RX\TX   ---     T1/P3.5  |15                26|  P2.5     ----  KEY2
;                 /WR/P3.6  |16                25|  P2.4     ----  KEY1
;                 /RD/P3.7  |17                24|  P2.3
;                    XTAL2  |18                23|  P2.2     ----  LCD_RW
;                    XTAL1  |19                22|  P2.1     ----  LCD_RS
;                      VSS  |20                21|  P2.0     ----  LCD_EN
;                            --------------------
;                                   W78E52B
;***********************************************************************/

#include "..\header\main.h"
#include "..\header\maindef.h"


bit Wait_Ack = 0;		// 等待RF应答
bit Clr_Screen = 0;		// 刷新屏幕

U8 Timer0_Cnt = 0;		// 定时器0计数器

U8 System_Mode = NORMAL_MODE;	// rf 工作模式

enum Rf_Status Rf_Mode_Cnt; 
U8 Add_Key_Cnt = 0;
U8 Dec_Key_Cnt = 0;

U8 Rf_Rate_Cnt = 5;				// default 250k
U8 Rf_Channel_Cnt = 3;			// default 第4个通道
U8 Rf_Rec_Channel = (3 << 3);	// default frequency 2.412GHZ(2.400G + (3*8)*500K))

U8 Rf_Rec_Buf[RF_DATA_PACKET_SIZE] = {0};
U8 Rf_Send_Buf[RF_DATA_PACKET_SIZE] = {0};

U8 const code HexDispArray[16] = "0123456789ABCDEF";


// 主程序入口
void main(void)
{
	EA = 0;
	delay_2us(5000);
	ini_mcu();
	delay_2us(5000);

	ini_lcd();
	delay_2us(50000);

	lcd_printf_string("COOLWAVE", ROW(0x00)|LEN(0x08)|COL(0x00));
	lcd_printf_string(" A7105  ", ROW(0x01)|LEN(0x08)|COL(0x00));

	ini_rf();
	ini_rf();
	ini_rf();

	delay_2us(5000);

	while(1)
	{
		if(System_Mode)					
		{
		
		}
		else
		{
			key_scan();
			dispose_key_info();
			if(IE1)					// 是否接收到RF数据(查询方式接收)
			{
				IE1 = 0;
				rec_rf_data();
				dispose_rf_data();	// 处理接收到的RF数据
			}       
			dispose_timer0();		// 处理定时器0
		}
	}
}

/***********************************************************
name:		ini_mcu
input:		none
output:		none
describe:	初始化MCU
notice:
creat date: 2008-7-24
creator:	dengyihong
************************************************************/
void ini_mcu(void)
{
    PSW = 0x00;
 	PCON = 0x00;
 	IP = 0x00;             // 设置中断优先级
	IE = 0x00;             //  EA   -    ET2  ES   ET1  EX1  ET0  EX0 , disable all interrupt

    ini_int1();
    ini_timer0();
}

/**********************************************************
name:		ini_int1
input:		none
output:		none
describe:	设置 int1中断方式
notice:
creat date:	2008-7-24
creator:	dengyihong
**********************************************************/
void ini_int1(void)
{
    IT1 = 1;				// 下降沿中断
    IE1 = 0;
	EX1 = 0;				//disable int1 中断
}


/***********************************************************
name:		ini_timer0
input:		none
output:		none
describe:	初始化定时器0
notice:
creat date:	2008-7-24
creator:	dengyihong
************************************************************/
void ini_timer0(void)
{
	TF0 = 0;
    TH0 = 0x94;
 	TL0 = 0x00;					// 定时10ms

    TMOD = 0x01;				// timer0 工作在方式1
//	ET0 = 0x01;					// 允许timer0中断
//	TR0 = 1;					// enable timer0
}


/**********************************************************
name:		dispose_key_info
input:		none
output:		none
describe:	处理按键信息
notice:
creat date:	2008-7-24
creator:	dengyihong
**********************************************************/
void dispose_key_info(void)
{
    U8 i = 0;

    if(Key_Msg)				// 是否有按键消息
    {
        Key_Msg = 0;
        switch(Key_Value)
        {
            case MODE_KEY:
				 if(Rf_Mode_Cnt == SEND_KEY)
				 {
				     Rf_Mode_Cnt = REC_STATUS; 
				 }
				 else
				 {
				 	 Rf_Mode_Cnt++;	
				 }

				 switch(Rf_Mode_Cnt)
				 {
				 	 case REC_STATUS:
				     	  lcd_printf_string("Rec     ", ROW(0x00)|LEN(0x08)|COL(0x00));
				 	 	  lcd_printf_string("  Status", ROW(0x01)|LEN(0x08)|COL(0x00)); 
						  A7105_entry_rx();
					 break;

					 case SET_RF_RATE:
						  lcd_printf_string("Set Rate", ROW(0x00)|LEN(0x08)|COL(0x00));
						  display_rf_rate();
					 break;

					 case SET_RF_CHANNEL:
						  lcd_printf_string("Set Freq", ROW(0x00)|LEN(0x08)|COL(0x00));
						  display_rf_channel();
					 break;

					 case SEND_STATUS:

						  lcd_printf_string("Send....", ROW(0x00)|LEN(0x08)|COL(0x00));
						  lcd_printf_string("        ", ROW(0x01)|LEN(0x08)|COL(0x00));

					 	  System_Mode = TEST_MODE;
						  ini_rf();									// 重新初始化,使7105进入直接模式
						  //ini_rf();
						  //ini_rf();
						  IE1 = 0;

						  while(1)
						  {							  					  
						  	  key_scan();
						  	  if(Key_Msg)							// 按下任意键退出
							  {
								  Key_Msg = 0;
							  	  lcd_printf_string("COOLWAVE", ROW(0x00)|LEN(0x08)|COL(0x00));
				 	 	  		  lcd_printf_string(" A7105  ", ROW(0x01)|LEN(0x08)|COL(0x00));
								  System_Mode = NORMAL_MODE;
								  Rf_Mode_Cnt = REC_STATUS; 
						  		  ini_rf();
						  		  ini_rf();
						  		  ini_rf();								
								  IE1 = 0;
								  break;
							  }
							  
						  }
					 break;

					 default:

					 break;
				 }
				 				 
            break;

            case DEC_KEY:
				 switch(Rf_Mode_Cnt)
				 {
				 	 case SET_RF_RATE:
				 		  if(Rf_Rate_Cnt)
						  {
					    	  Rf_Rate_Cnt--;
						  }
						  //A7105_setup_data_rate(Rf_Rate_Cnt);		// 设置 RF rate 
						  display_rf_rate();
						  ini_rf();
						  						  
					 break;								 

					 case SET_RF_CHANNEL:
						  if(Rf_Channel_Cnt)
						  {
							  Rf_Channel_Cnt--;
						  }
						  Rf_Rec_Channel = Rf_Channel_Cnt << 3; 
						  //A7105_setup_channel(Rf_Rec_Channel);					// 设置channel
						  display_rf_channel();	
					   	  ini_rf();
						  					  					  
					 break;

					 default:

					 break;
				 }
            break;

            case ADD_KEY:
				 switch(Rf_Mode_Cnt)
				 {
				 	 case SET_RF_RATE:
	 					  if(Rf_Rate_Cnt < 7)
						  {
						  	  Rf_Rate_Cnt++;
						  }
						  //A7105_setup_data_rate(Rf_Rate_Cnt);		// 设置 RF rate 
						  display_rf_rate();
						  ini_rf();
						  
					 break;

					 case SET_RF_CHANNEL:
						  if(Rf_Channel_Cnt < 20)
						  {
						  	  Rf_Channel_Cnt++;
						  }
						  Rf_Rec_Channel = Rf_Channel_Cnt << 3; 
						  //A7105_setup_channel(Rf_Rec_Channel);					// 设置channel
						  display_rf_channel();
						  ini_rf();
						  
					 break;

					 default:

					 break;
				 }
            break;

⌨️ 快捷键说明

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