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

📄 board._c

📁 chipcom公司CC1100无线模块底层驱动程序
💻 _C
📖 第 1 页 / 共 2 页
字号:
/****************************************************/
/* Application note                                 */
/* Reference design : CC1100 RF Test Board          */
/* File:         board.c                            */
/* Revision:  1.0                                   */
/* Description:                                     */
/* Microcontroller:ATmega48/48V                     */
/* Author:  Zcg, Field Applications Engineer, SunRay*/
/****************************************************/
 
#include "iom88v.h"
#include "macros.h" 
#include "main.h"
#include "CC1100.h"
#include "board.h"
#include "simpleio.h"

INT8U Test_RFTx_Buf[MAX_DATA_TEST];		//测试数据缓冲区

INT8U UartReceive_Buf[MAX_UT_BUFF];     //射频发送(串口接收)缓存
INT8U RFReceive_Buf[MAX_RF_BUFF];       //射频接收(串口发送)缓存

INT8U RFSend_Start;
INT8U RFSendCnt;        //射频发送计数器,记录要发送的字节个数
INT8U RFReceiveCnt;     //串口接收计数器

INT8U RFReceiveLen;     //串口发送字节长度

INT8U RFSendFlg;        //当串口接收完一包数据,置该标志
INT8U RFReceiveFlg;     //当射频接收完一包数据,置该标志


INT8U RXOTFlg;          //串口接收数据超时标志
INT8U RXOTCnt;          //串口接收数据超时计数器

INT8U Baud_Set_Num;		//跳线开关波特率
INT8U Chno_Set_Num;		//跳线开关信道值

INT8U  Beep_Flag;		//蜂鸣器开启标志
INT16U Beep_Time;		//蜂鸣器开启时间

const SYS_SETTINGS Sys_Set[8] =
{
	{T_T0_18MS,0x40,0x03,0xC4,0x86,0x10,600},//000 600
	{T_T0_10MS,0x9F,0x01,0xF5,0x83,0x15,1200},//001 1200
	{T_T0_8MS ,0xCF,0x00,0xC6,0x83,0x15,2400},//010 2400
	{T_T0_4MS ,0x67,0x00,0xC7,0x83,0x40,4800},//011 4800
	{T_T0_2MS ,0x33,0x00,0xC8,0x83,0x34,9600},//100 9600
	{T_T0_2MS ,0x19,0x00,0xC9,0x83,0x34,19200},//101 19200
	{T_T0_2MS ,0x0C,0x00,0xCA,0x83,0x34,38400},//110 38400
	{T_T0_2MS ,0x08,0x00,0xCB,0x83,0x45,57600},//111 57600
};



INT8U paTable[8] = {0x8D,0x8D,0x8D,0x8D,0x8D,0x8D,0x8D,0x8D};
#if 0
INT8U rfSettings[39] = {
	0x06,   //*0x0B IOCFG2    GDO2 output pin configuration.
    0x2E,   //*0x2E IOCFG1    GDO1 output pin configuration.
    0x2E,   //*0x0C IOCFG0   GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.
    0x07, 	// FIFOTHR  RX FIFO and TX FIFO thresholds
	0xD3, 	// SYNC1  Sync word, high byte
	0x91, 	// SYNC0  Sync word, low byte
    0xFF,   // PKTLEN    Packet length.
    0x24,   //*0x00 PKTCTRL1  Packet automation control.
    0x45,   //*0x12 PKTCTRL0  Packet automation control.
    0x00,   // ADDR      Device address.
    0x00,   // CHANNR    Channel number.
    0x0C,   //*0x06 FSCTRL1   Frequency synthesizer control.
    0x00,   // FSCTRL0   Frequency synthesizer control.
    0x10,   // FREQ2     Frequency control word, high byte.
    0xA7,   // FREQ1     Frequency control word, middle byte.
    0x62,   // FREQ0     Frequency control word, low byte.
    0xF5,   //* MDMCFG4   Modem configuration.
    0x83,   //* MDMCFG3   Modem configuration.
    0x03,   //*0x00 MDMCFG2   Modem configuration.
    0x22,   // MDMCFG1   Modem configuration.
    0xF8,   // MDMCFG0   Modem configuration.
    0x15,   // DEVIATN   Modem deviation setting (when FSK modulation is enabled).
	0x0E,   //*0x07 MCSM2     Main Radio Control State Machine configuration.
	0x30,   // MCSM1     Main Radio Control State Machine configuration.
    0x18,   // MCSM0     Main Radio Control State Machine configuration.
    0x15,   //*0x16 FOCCFG    Frequency Offset Compensation Configuration.
    0x6C,   // BSCFG     Bit synchronization Configuration.
    0x03,   // AGCCTRL2  AGC control.
    0x40,   // AGCCTRL1  AGC control.
    0x91,   // AGCCTRL0  AGC control.
	0x87,   // WOREVT1  0x1E  //定义EVENT0时间
	0x6B,   // WOREVT0  0x1F  //...
	0xF8,   // WORCTRL  0x20  //关闭RC,定义EVENT1时间
    0x56,   // FREND1    Front end RX configuration.
    0x10,   // FREND0    Front end RX configuration.
    0xA9,   //* FSCAL3    Frequency synthesizer calibration.
    0x2A,   //* FSCAL2    Frequency synthesizer calibration.
    0x0D,   //* FSCAL1    Frequency synthesizer calibration.
    0x11,   //* FSCAL0    Frequency synthesizer calibration.
};
#endif
#define RF_CENTER	461
#define RF_461
#if 1
const RF_SETTINGS rfSettings = {
	0x06,   //*0x0B IOCFG2    GDO2 output pin configuration.
    0x2E,   //*0x2E IOCFG1    GDO1 output pin configuration.
    0x2E,   //*0x0C IOCFG0   GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.
    0x07, 	// FIFOTHR  RX FIFO and TX FIFO thresholds
	0xD3, 	// SYNC1  Sync word, high byte
	0x91, 	// SYNC0  Sync word, low byte
    0xFF,   // PKTLEN    Packet length.
    0x04,   //*0x00 PKTCTRL1  Packet automation control.
    0x45,   //*0x12 PKTCTRL0  Packet automation control.
    0x00,   // ADDR      Device address.
    0x00,   // CHANNR    Channel number.
    0x06,//0x0C,   //*0x06 FSCTRL1   Frequency synthesizer control.
    0x00,   // FSCTRL0   Frequency synthesizer control.
#ifdef RF_433
    0x10,   // FREQ2     Frequency control word, high byte.
    0xA7,   // FREQ1     Frequency control word, middle byte.
    0x62,   // FREQ0     Frequency control word, low byte.
#endif
#ifdef RF_461
    0x11,   // FREQ2     Frequency control word, high byte.
    0xBB,   // FREQ1     Frequency control word, middle byte.
    0x13,   // FREQ0     Frequency control word, low byte.
#endif
    0xF5,   // MDMCFG4   Modem configuration.
    0x83,   // MDMCFG3   Modem configuration.
    0x03,   //*0x00 MDMCFG2   Modem configuration.
    0x22,   // MDMCFG1   Modem configuration.
    0xF8,   // MDMCFG0   Modem configuration.
    0x15,   // DEVIATN   Modem deviation setting (when FSK modulation is enabled).
	0x0E,   //*0x07 MCSM2     Main Radio Control State Machine configuration.
	0x30,   // MCSM1     Main Radio Control State Machine configuration.
    0x18,   // MCSM0     Main Radio Control State Machine configuration.
    0x16,//0x15,   //*0x16 FOCCFG    Frequency Offset Compensation Configuration.
    0x6C,   // BSCFG     Bit synchronization Configuration.
    0x03,   // AGCCTRL2  AGC control.
    0x40,   // AGCCTRL1  AGC control.
    0x91,   // AGCCTRL0  AGC control.
	0x87,   // WOREVT1  0x1E  //定义EVENT0时间
	0x6B,   // WOREVT0  0x1F  //...
	0xF8,   // WORCTRL  0x20  //关闭RC,定义EVENT1时间
    0x56,   // FREND1    Front end RX configuration.
    0x10,   // FREND0    Front end RX configuration.
    0xE9,//0xA9,   //*0xE9 FSCAL3    Frequency synthesizer calibration.
    0x2A,//0x2A,   //*0x2A FSCAL2    Frequency synthesizer calibration.
    0x00,//0x0D,   //*0x00 FSCAL1    Frequency synthesizer calibration.
    0x1F,//0x11,   //*0x1F FSCAL0    Frequency synthesizer calibration.
};
#endif
INT8U RFState;          //保存射频状态,共两种状态:发送、接收状态


INT8U CC1100IntHFlg;    //CC1100产生高电平中断标志
INT8U CC1100IntLFlg;

/*
************************************************************
*Description:RF收发中断处理函数
*Arguments  :none
*Returns    :none
*Notes      :
************************************************************
*/
#pragma interrupt_handler IntPCINT2:iv_PCINT2
void IntPCINT2 (void)
{
	if (GDO2_STATE != 0x00)
	{
	    CC1100IntHFlg = TRUE;   //上升沿中断,等待下降沿中断
		if(RFSend_Start==TRUE)
		{
			TXEN_SET_L;//打开功率放大
			RXEN_SET_L;//打开功率放大
		}
	}
	if ((CC1100IntHFlg == TRUE) && (GDO2_STATE == 0x00))
	{
	    CC1100IntHFlg = FALSE;  //下降沿中断
		CC1100IntLFlg = TRUE;

		if(RFSend_Start==TRUE)
		{
			TXEN_SET_H;//关闭功率放大
			RXEN_SET_H;//关闭功率放大
			RFSend_Start=FALSE;
		}
	}
}
/*
************************************************************
*Description:初始化IO端口
*Arguments  :none
*Returns    :none
*Notes      :
************************************************************
*/
void port_init(void)
{
	DDRB =0x00;
	PORTB=0x3F;
	
	DDRD =0x08;//PD3 KEY
	PORTD=0xD0;
	
	BEEP_INIT();
	BEEP_OFF();

	TXEN_OUT;
	TXEN_SET_H;
	RXEN_OUT;
	RXEN_SET_H;
}
/*
************************************************************
*Description:初始化串口
*Arguments  :none
*Returns    :none
*Notes      :
************************************************************
*/
void uart0_init(void)
{
	UBRR0H = Sys_Set[Baud_Set_Num].ubrr0h_val;
	UBRR0L = Sys_Set[Baud_Set_Num].ubrr0l_val;

	UCSR0C = BIT(UCSZ01) | BIT(UCSZ00); //Set frame format: 8data, 1stop bit, asyn mode
	UCSR0B = BIT(RXEN0) | BIT(TXEN0);   //使能串口发送、接收
	EN_RX_INT();
}
/*
************************************************************
*Description:串口发送中断函数
*Arguments  :none
*Returns    :none
*Notes      :
************************************************************
*/
#pragma interrupt_handler uart0_tx_isr:iv_USART0_UDRE
void uart0_tx_isr (void)
{
	UDR0 = RFReceive_Buf[RFReceiveCnt];
	RFReceiveCnt++;
	if (RFReceiveCnt == RFReceiveLen)
	{
	    DIS_TX_INT();  //串口数据发送完毕,关闭发送空中断
	}
}
/*
************************************************************
*Description:串口接收中断函数
*Arguments  :none
*Returns    :none
*Notes      :利用超时处理来决定一包数据是否接收完成
************************************************************
*/
#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr (void)
{
	RXOTCnt = 0;
	RXOTFlg = TRUE;

	UartReceive_Buf[RFSendCnt] = UDR0;
	RFSendCnt++;
	if (RFSendCnt == MAX_DATA_NUM)         //1字节的包长 + 60字节数据(共61字节)最大60字节
	{
		RXOTFlg = FALSE;

		RFSendFlg = TRUE;        //接收完最大一包数据,准备射频发送
		DIS_RX();   //禁止串口接收
		DIS_RX_INT();            //禁止串口接收中断
	}
}
/*
************************************************************
*Description:初始化软件定时器
*Arguments  :none
*Returns    :none
*Notes      :
************************************************************
*/
void timer0_init(void)
{
	TCCR0B |= (BIT(CS02) | BIT(CS00)); //1024分频,开始计数
	TIMSK0 |= BIT(TOIE0);              //使能Timer0溢出中断
	TCNT0 = Sys_Set[Baud_Set_Num].tcnt0_val;
}

/*
************************************************************
*Description:串口接收的超时处理中断时间函数
*Arguments  :none
*Returns    :none
*Notes      :超时10ms
************************************************************
*/
#pragma interrupt_handler IntTimer0:iv_TIMER0_OVF
void IntTimer0 (void)
{
    TCNT0   = Sys_Set[Baud_Set_Num].tcnt0_val;

	if(Beep_Flag==TRUE)
	{
		if(Beep_Time++>50)
		{
			BEEP_OFF();
			Beep_Time=0;
			Beep_Flag=FALSE;
		}
	}

	if (RXOTFlg == TRUE)
	{
		RXOTCnt++;
		if (RXOTCnt == 2)
		{
		    RXOTFlg = FALSE;
			RFSendFlg = TRUE; 	//接收超时
			DIS_RX();   		//禁止串口接收

⌨️ 快捷键说明

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