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

📄 cc2420.i

📁 使用avr--cc2420模块程序,需要原理图的联系 QQ:120304948
💻 I
📖 第 1 页 / 共 2 页
字号:
interrupt [2] void ext_int0_isr(void)
{
// Place your code here
    unsigned char i,j;

//	memset(cc2420_data_recive, 0x00, CC2420_MAX);
    if (PINB.7)
    {
   	    PORTB.0=0;
   	    i=spi(0x7f);
   	    if (PINB.7)
   	    {
   	        cc2420_data_recive[0] = spi(0x00);
   	        j = 0;
   	        while ((PINB.7 == 1) && (j < cc2420_data_recive[0]))
   	        { 
                #asm("wdr");
		        cc2420_data_recive[++j] = spi(0x00); 
		        if(j > 30) 
		            break;
   	        }
   	    }
        PORTB.0=1;
   	    receive_ok = 1;
/*		for (nloop = 0; nloop < (RECV_NO+1); nloop ++)
		{
			cc2420_data_temp[nloop] = cc2420_data_recive[nloop];
		}*/
        #asm("wdr");
   			            
   	    PORTB.0=0;
        i=spi(0x08);
        i=spi(0x08);
        PORTB.0=1;
    }
}

unsigned char cc2420_receive(unsigned char ncont)
{	
    unsigned char i,j;

    if (PINB.7)
    {
   	    PORTB.0=0;
   	    i=spi(0x7f);
   	    j = 0;
	    if (PINB.7)
	    { 
   	        cc2420_data_recive[0] = spi(0x00);
   	        j = 0;
   	        while ((PINB.7 == 1) && (j < cc2420_data_recive[0]))
   	        { 
                #asm("wdr");
		        cc2420_data_recive[++j] = spi(0x00); 
		        if(j > ncont) 
		            break;
   	        }
	    }
        PORTB.0=1;
        #asm("wdr");
   			            
   	    PORTB.0=0;
        i=spi(0x08);
        i=spi(0x08);
        PORTB.0=1;
        #asm("wdr");
        return 1;
    }
    return 0;
}

void cc2420_deal(void)
{
	unsigned char szsum;
	unsigned char nloop;
	unsigned int nTemp;

	for (nloop = 0; nloop < (15+1); nloop ++)
	{
		cc2420_data_temp[nloop] = cc2420_data_recive[nloop];
	}
	memset(cc2420_data_recive, 0x00, 30);
    if (cc2420_data_temp[1]==0x7e && cc2420_data_temp[2]==0x7e)
    {
	    szsum = 0x00;
	    for (nloop = 1; nloop < (15+1); nloop ++)
	    {
		    szsum += cc2420_data_temp[nloop];
	    }
        if (szsum == 0xff)
        {
            nTemp =  (unsigned int)cc2420_data_temp[4]*256 + (unsigned int)cc2420_data_temp[3];           
            if (nTemp == HOME_ID)
            {
        	    if (cc2420_data_temp[6] == 0x00 && cc2420_data_temp[5] == 0x00)
        	    {
                    if (cc2420_data_temp[13] == 0x26)
                    {
                        SET_OUT = cc2420_data_temp[14];

                        nloop = cc2420_data_temp[14] & 0x01;      //0x07
                        switch (nloop)
                        {
					        case 0:
						        if (on_ok)
						        {
                                    timer_delay(200);
                                    led_send0(0); 
                                    on_ok = 0;
                                }
                                timer_delay(1000);         //500
						        PORTD.5 = 0;
						        PORTD.4 = 0; 
						        PORTD.7 = 1;    //OFF
						        break;
					        case 1:
                                timer_delay(200);        //500
						        PORTD.5 = 1;
						        PORTD.4 = 0;
						        if (on_ok == 0)
						        {
                                    timer_delay(1000);
                                    led_send0(1);
                                    on_ok = 1;  
                                }
						        PORTD.7 = 0;    //ON
						        break;
          			    }
//					    temp_deal();
                	    data_proc();
          		    }
       		    }
        	    else
        	    {
//			        WORK_LED = !WORK_LED;    //ON
                    nTemp =  (unsigned int)cc2420_data_temp[6]*256 + (unsigned int)cc2420_data_temp[5];           
                    if (nTemp == MY_ID)
                    {
                
                        if (cc2420_data_temp[13] == 0x22)
                        {
                            SET_OUT = cc2420_data_temp[14];

                            nloop = cc2420_data_temp[14] & 0x01;  //0x07
                            switch (nloop)
                            {
					            case 0:
						            if (on_ok)
						            {
                                        timer_delay(200);
                                        led_send0(0); 
                                        on_ok = 0;
                                    }
                                    timer_delay(1000);         //500
						            PORTD.5 = 0;
						            PORTD.4 = 0; 
						            PORTD.7 = 1;    //OFF
						            break;
					            case 1:
                                    timer_delay(200);        //500
						            PORTD.5 = 1;
						            PORTD.4 = 0;
						            if (on_ok == 0)
						            {
                                        timer_delay(1000);
                                        led_send0(1);
                                        on_ok = 1;  
                                    }
						            PORTD.7 = 0;    //ON
						            break;
                            }
                        }
                        else if (cc2420_data_temp[13] == 0x2a)
                        {
                            if (cc2420_data_temp[14])
                            {
                    			study_ok = 0;
   								PORTD.7 = !PORTD.7;
  								timer_delay(500);
   								PORTD.7 = !PORTD.7;
    							EIFR=0x0D;
    							EIMSK=0x0D;     //0x0D  //0x01
    							int_start = 0;
        						count=0;
    							int_num = 0;
         			            study_key=0;
    							my_sp_status.timeout = 0;
							}
							else
							{
                    			study_ok = 1;
   								PORTD.7 = !PORTD.7;
  								timer_delay(500);
   								PORTD.7 = !PORTD.7;
    							EIFR=0x0D;
    							EIMSK=0x01;     //0x0D  //0x01
							}
                        }

//				        temp_deal();
                        data_proc();
                    }
                }
            }
        }
    }
}

void cc2420_test(void)
{
	unsigned char szsum;
	unsigned char nloop;
	unsigned int nTemp;

	memset(cc2420_data_recive, 0x00, 30);
    if (cc2420_receive(15+3))
    {
        if (cc2420_data_recive[1]==0x7e && cc2420_data_recive[2]==0x7e)
        {
	        szsum = 0x00;
	        for (nloop = 1; nloop < (15+1); nloop ++)
	        {
		        szsum += cc2420_data_recive[nloop];
	        }
            if (szsum == 0xff)
            {
                nTemp =  (unsigned int)cc2420_data_temp[4]*256 + (unsigned int)cc2420_data_temp[3];           
                if (nTemp == HOME_ID)
                {
        	        if (cc2420_data_temp[6] == 0x00 && cc2420_data_temp[5] == 0x00)
        	        {
                        if (cc2420_data_temp[13] == 0x26)
                        {
                            SET_OUT = cc2420_data_temp[14];

                            nloop = cc2420_data_temp[14] & 0x01;      //0x07
                            switch (nloop)
                            {
					            case 0:
						            if (on_ok)
						            {
                                        timer_delay(200);
                                        led_send0(0); 
                                        on_ok = 0;
                                    }
                                    timer_delay(1000);         //500
						            PORTD.5 = 0;
						            PORTD.4 = 0; 
						            PORTD.7 = 1;    //OFF
						            break;
					            case 1:
                                    timer_delay(200);        //500
						            PORTD.5 = 1;
						            PORTD.4 = 0;
						            if (on_ok == 0)
						            {
                                        timer_delay(1000);
                                        led_send0(1);
                                        on_ok = 1;  
                                    }
						            PORTD.7 = 0;    //ON
						            break;
          			        }
//					        temp_deal();
                	        data_proc();
          		        }
       		        }
        	        else
        	        {
//			            WORK_LED = !WORK_LED;    //ON
                        nTemp =  (unsigned int)cc2420_data_temp[6]*256 + (unsigned int)cc2420_data_temp[5];           
                        if (nTemp == MY_ID)
                        {
                
                            if (cc2420_data_temp[13] == 0x22)
                            {
                                SET_OUT = cc2420_data_temp[14];

                                nloop = cc2420_data_temp[14] & 0x01;  //0x07
                                switch (nloop)
                                {
					                case 0:
						                if (on_ok)
						                {
                                            timer_delay(200);
                                            led_send0(0); 
                                            on_ok = 0;
                                        }
                                        timer_delay(1000);         //500
						                PORTD.5 = 0;
						                PORTD.4 = 0; 
						                PORTD.7 = 1;    //OFF
						                break;
					                case 1:
                                        timer_delay(200);        //500
						                PORTD.5 = 1;
						                PORTD.4 = 0;
						                if (on_ok == 0)
						                {
                                            timer_delay(1000);
                                            led_send0(1);
                                            on_ok = 1;  
                                        }
						                PORTD.7 = 0;    //ON
						                break;
                                }
                            }
                        	else if (cc2420_data_temp[13] == 0x2a)
                        	{
                            	if (cc2420_data_temp[14])
                            	{
                    				study_ok = 0;
   									PORTD.7 = !PORTD.7;
  									timer_delay(500);
   									PORTD.7 = !PORTD.7;
    								EIMSK=0x0D;     //0x0D  //0x01
    								EIFR=0x0D;
    							    int_start = 0;
        						    count=0;
    							    int_num = 0;
         			                study_key=0;
   							        my_sp_status.timeout = 0;
								}
								else
								{
                    				study_ok = 1;
    								EIMSK=0x01;     //0x0D  //0x01
    								EIFR=0x0D;
   									PORTD.7 = !PORTD.7;
  									timer_delay(500);
   									PORTD.7 = !PORTD.7;
								}
                        	}
//				            temp_deal();
                            data_proc();
                        }
                    }
                }
            }
        }
    }
}

void data_proc(void)
{
    unsigned char i;
	unsigned char szsum;
	unsigned char nloop;
	unsigned char *pTemp;
	unsigned int nTemp;


    memset(cc2420_data_send, 0x00, 30);
        
//    i = ~(PINC & 0x08);
//    i = i >> 4;
	if (PIND.6)
		i = 0;
	else 
		i = 1;

	cc2420_data_send[0] = 15+2;      

	cc2420_data_send[1] = 0x7e;
	cc2420_data_send[2] = 0x7e;
	
	nTemp = HOME_ID;
	pTemp = (unsigned char*)&nTemp;
	cc2420_data_send[3] = *(pTemp + 0);
	cc2420_data_send[4] = *(pTemp + 1);

	nTemp = MY_ID;
	pTemp = (unsigned char*)&nTemp;
	cc2420_data_send[5] = *(pTemp + 0);
	cc2420_data_send[6] = *(pTemp + 1);

	cc2420_data_send[7] = 0x00;
	cc2420_data_send[8] = 0x00;
	cc2420_data_send[9] = 0x00;
	cc2420_data_send[10] = 0x00;
	cc2420_data_send[11] = 0x00;
	cc2420_data_send[12] = 0x00;   
	
	cc2420_data_send[13] = i;
	 
	cc2420_data_send[14] = SET_OUT; 
	
	szsum = 0x00;
	for (nloop = 1; nloop < 15; nloop ++)
	{
		szsum += cc2420_data_send[nloop];
	}
	cc2420_data_send[15] = 0xFF - szsum;

    cc2420_send(15+3);               
}

⌨️ 快捷键说明

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