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

📄 main.c

📁 RF transreceiver c code interfaced with pic controller in SPI mode
💻 C
字号:
/******************************************************************	PROJECT:CC1100 DEMO	PART:handset	RF:CC1100(Chipcon)   	MCU: PIC16F72(Microchip)	Designed : Louis 	Date :	2005-11	Checksum: 0x690a				******************************************************************/#include <pic.h>#include "pic_setting.h"#include "CC1100.h"#include "CC1100LIB.C"BYTE paTable[] = {0xC0, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F };BYTE txBuffer[] = {2, 1,0x01};BYTE rxBuffer[2];BYTE dpybuffer[10]={0x11,0xF9,0x23,0x61,0xC9,0x45,0x05,0xF1,0x01,0x41};//--------------------------------------------------------------//	INIT MCU//--------------------------------------------------------------void InitPIC16F72() {	TRISA=RACNF;	TRISB=RBCNF;	TRISC=RCCNF;	ADCON1=0x06; //ADC OFF	OPTION=0x87;		T1CON=0x31;	PORTC=0XFF;	//数码管 OFF	LED1=LED_ON;	LED2=LED_ON;		P_SCLK=0;	P_CSn=1;	P_SI=0;	Dly1mS(200);}//-------------------------------------------------------------// SCAN KEY//-------------------------------------------------------------BYTE KeyScan(void){	TMR0=0; T0IF=0;	OPTION=0x07;	//portb pull up	Dly1mS(2);	while(1)	{		if(T0IF) goto	l_exit_key;		Current_key=PORTB|0x0F;		if(Current_key!=Old_key)		{	  	Dly1mS(20);	  	Current_key=PORTB|0x0F;	  	if(Current_key!=Old_key)	//key state change?			{		  	Old_key=Current_key;		  	if(Old_key!=0xff)				{			  		Keyflag=1;	//new key				goto	l_exit_key;  				}		  	else       	    	Keyflag=0;	//key release					}	   	else		 	 Keyflag=0;		//niose			}		else			Keyflag=0;		////key state	do not be changed	}l_exit_key:	LED2=LED_OFF;	LED1=LED_OFF;	OPTION=0x87;	//disable pull up	return(Keyflag);	}//------------------------------------------------------------//TX OPTION//------------------------------------------------------------void TxCC1100(){	unsigned char	i;//	halSpiWriteReg(0x3E,0xC0);	//POWER=10DBM	halSpiWriteReg(CC1100_FREND0, 0x10);	Dly1mS(50);		for(i=0;i<4;i++)	{	    	halRfSendPacket(txBuffer, sizeof(txBuffer));		Dly1mS(50);	}//	halSpiWriteReg(0x3E,0x7f);	//POWER=0DBM	halSpiWriteReg(CC1100_FREND0, 0x11);	Dly1mS(50);	   	halRfSendPacket(txBuffer, sizeof(txBuffer));	Dly1mS(100);	PORTC=0xFF;	}//---------------------------------------------------------------//RX OPTION//---------------------------------------------------------------unsigned char RxCC1100(void){		unsigned char	length,i;	length = sizeof(rxBuffer);    if (halRfReceivePacket(rxBuffer, length))		{		 	i=rxBuffer[0];			 	PORTC=dpybuffer[i];		 	LED2=LED_ON;		 	LED1=LED_OFF;		 	return 1;					}	else	return 0;		}//---------------------------------------------------------------// MAIN PROGRAM//---------------------------------------------------------------void main() {	BYTE rfstate;	InitPIC16F72();	POWER_UP_RESET_CC1100();	halRfWriteRfSettings();	halSpiWriteBurstReg(CC1100_PATABLE, paTable, sizeof(paTable));	while(1)	{		rfstate=halSpiReadStatus(CC1100_MARCSTATE);		if((rfstate& 0x1f)==0x00)		{			LED1=LED_OFF;			LED2=LED_OFF;			POWER_UP_RESET_CC1100();			halRfWriteRfSettings();					}		KeyScan();		if(Keyflag)		{			txBuffer[1]=0;			if(Old_key==SW1_key)				txBuffer[1]=1;				if(Old_key==SW2_key)				txBuffer[1]=2;			if(Old_key==SW3_key)				txBuffer[1]=3;			if(Old_key==SW4_key)				txBuffer[1]=4;			txBuffer[2]=0x01;//			PORTC=dpybuffer[txBuffer[1]];	    	TxCC1100();					}		else		{				if(RxCC1100())			{				if(rxBuffer[1]==0x01) 				{							txBuffer[2]=0x07;					txBuffer[1]=rxBuffer[0];					halSpiStrobe(CC1100_SIDLE);					Dly1mS(500);					TxCC1100();					}				else					if(rxBuffer[1]==0x07) Dly1mS(500);								} 				}	 }}//===============================================================//	END//===============================================================

⌨️ 快捷键说明

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