cc1100的通信程序

源代码在线查看: main._c

软件大小: 164 K
上传用户: 2000
关键词: 1100 cc 通信程序
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*C**************************************************************************
				* NAME:         main.c
				*----------------------------------------------------------------------------
				* Copyright (c) 2006 endylu
				*----------------------------------------------------------------------------
				* RELEASE:      M8-cc1100
				* REVISION:     1.0     
				*----------------------------------------------------------------------------
				* PURPOSE:
				* This is the demonstration software for MAGE8L
				*****************************************************************************/
				
				/*_____ I N C L U D E S ____________________________________________________*/
				
				#include 
				#include 
				#include "main.h"
				
				
				/*_____ M A C R O S ________________________________________________________*/
				
				
				/*_____ D E F I N I T I O N ________________________________________________*/
				
				INT8U PaTabel[8] = {0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0};
				INT8U arrRx[50];
				
				INT8U length;
				INT8U flag_receive;
				/*_____ D E C L A R A T I O N ______________________________________________*/
				
				
				/*F**************************************************************************
				* NAME: main
				*----------------------------------------------------------------------------
				* PARAMS:
				*
				* return:
				*----------------------------------------------------------------------------
				* PURPOSE: 
				*   Main user routine 
				*----------------------------------------------------------------------------
				* EXAMPLE:
				*----------------------------------------------------------------------------
				* NOTE:
				*----------------------------------------------------------------------------
				* REQUIREMENTS:
				*****************************************************************************/
				void main (void)
				{   
				    PORTD|=0X04;                  //GDO0上拉
					
				    DDRB|=1					PORTB|=1					
					CpuInit();
					POWER_UP_RESET_CC1100();
					halRfWriteRfSettings();
					halSpiWriteBurstReg(CCxxx0_PATABLE, PaTabel, 8);
					PORTB&=~(1					
					INT0_Init();
				    asm("sei");			          //开全局中断
					
				    halSpiStrobe(CCxxx0_SRX);
					while(1);
				}
						
				/*****************************************************************************************
				//函数名:void INT0_Init(void)
				//输入:无
				//输出:无
				//功能描述:外部中断0 初始化程序
				/*****************************************************************************************/
				void INT0_Init(void)
				{
				 MCUCR|=0x02;                      //falling_adge
				 GIFR=0X40;
				 INT0_enable();
				}
				
				
				//*****************************************************************************************
				//函数名:
				//输入:
				//输出:
				//功能描述:中断接收
				//*****************************************************************************************
				#pragma interrupt_handler int0:2
				void int0(void)
				{ 
				  uint8 i;
				  uint8 status[2];
				  
				  flag_receive=RECEIVE_error;
				  if(halSpiReadStatus(CCxxx0_RXBYTES) & BYTES_IN_RXFIFO)//如果接的字节数不为0
					{
					 length = halSpiReadReg(CCxxx0_RXFIFO);//读出第一个字节,此字节为该帧数据长度
					 halSpiReadBurstReg(CCxxx0_RXFIFO, arrRx, length); //读出所有接收到的数据
				     halSpiReadBurstReg(CCxxx0_RXFIFO, status, 2); 	//读出CRC校验位
				            
				     if(status[1] & CRC_OK)
				       {
					    flag_receive=RECEIVE_OK;
						
						PORTB|=1						for(i=2;i						     {
							 putchar(arrRx[i]);
							 }
						Delay_ms(100);
					    PORTB&=~(1				       }     
				    }
				  halSpiStrobe(CCxxx0_SFRX);		//清洗接收缓冲区
				  halSpiStrobe(CCxxx0_SRX);
				}
				
				void Delay_us(uint16 time) //set time 120 to 100us,set 1 to 3.5us;
					{while (time--);
					 _WDR();
					}
				void Delay_ms(uint16 time) 
					{while (time--)
					 Delay_us(1200);
					} 			

相关资源