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

📄 main.c

📁 基于CC1100和ATMEGA128开发的无线机器人控制程序
💻 C
字号:
/*******************************************************************************************************
 * Compiler:                WINAVR                                                             *
 * Target platform:         Chipcon CCxxx0 (any ATMEGA MCU)                                               *
 * Author:                  WangChaoyan                                                                         *
 *******************************************************************************************************
 * Revision history:    2001-02-28                                                             *
 ******************************************************************************************************/



#define __MAIN__
#include "include.h"
#include "RegSettings_Link.h"
#include "halsrf04.h"

	


/**********************************************************
					DEFINES
**********************************************************/

void intToAscii(UINT32 value);

RF_SETTINGS rfSettings;

BYTE paTable[1];

BYTE txBuffer[] = {20, 'H', 'E', 'L', 'L', 'O', ',', 'T', 'E', 'S','T', ' ','C', 'C','x', 'x', '0','0','!', '!', '!'};

BYTE rxBuffer[64];

BYTE BrBwTable[9][9];

BYTE asciiString[11];

void write(unsigned char *str)
{
	while (*str != 0) 
	{
		UART1_WAIT_AND_SEND(*str++);
	}
}


void writeln(unsigned char *str) 
{
	write(str);
	write("\n\r");
}




void sysInit(void);

int main(void)
{
	UINT32 i;
	UINT32 packetsSent = 0;
	
	
	for (i=0;i<100;i++) halWait(200);
	
	//系统初始化
	sysInit();
	
	//一些提示信息
	writeln("Welcome to IBSS");
	

	
	writeln("This is a Simple Demo RX  for CCxx00...");

	 // Reset CCxx00 and write rf setting to config registers
	 // CC1100芯片上电复位
    POWER_UP_RESET_CCxxx0();
		//寄存器设置
    halRfWriteRfSettings(&rfSettings);
    //发射功率设定
    halSpiWriteBurstReg(CCxxx0_PATABLE, paTable, sizeof(paTable));
	
	//提示信息
	writeln("Now Enjoying the show!!!");
	
	while(1)
	{
		
		//开始
		write("Sent start: ");
		
		//发送数据包
		halRfSendPacket(txBuffer, sizeof(txBuffer));
		
		//显示发送次数
		intToAscii(++packetsSent);
		write("Sent: ");
		write(asciiString);
		
		//发送完毕
		writeln(" - End sending! ");
		
		//等待一下,准备下一次发送
		for (i=0;i<2000;i++) halWait(200);
     
     
		
	}//while(1)

}


void sysInit(void)
{
	unsigned char i;
	//端口初始化
	PORT_INIT();
	//SPI 初始化
	SPI_INIT();
	
	//等待一下,晶振稳定
	for (i=0;i<5;i++) halWait(200);
	//初始化串口为: 9600,8N1
	INIT_UART1 ( UART_BAUDRATE_9K6, (
				UART_OPT_8_BITS_PER_CHAR |
				UART_OPT_NO_PARITY |
				UART_OPT_ONE_STOP_BIT ) );
	//串口开			
	ENABLE_UART1();	
	DISABLE_UART1_INT();
	
//	ENABLE_UART1_RX_INT();		// Enable Receive interrupt
	
//	ENABLE_GLOBAL_INT();	// Enable all interrupts
	

	SET_LED_RDY();
	
}




//-------------------------------------------------------------------------------------------------------
//  void intToAscii(UINT32 value)
//
//  DESCRIPTION:
//		Takes a 32 bits interger as input and converts it to ascii. Puts the result in the global
//      variable asciiString[]
//
//	ARGUMENTS:
//		UINT32 value
//			The value to be converted
//-------------------------------------------------------------------------------------------------------


void intToAscii(UINT32 value) 
{
    UINT8 i;
    UINT8 j = 0;
    UINT8 digit_start = 0;
    UINT16 digit = 0;
    UINT32 denom = 1000000000;

    if (value == 0) 
	{
        asciiString[0] = '0';
        asciiString[1] = NULL;
    } 
	else 
	{
        for(i = 10; i > 0; i--) 
		{
            digit = value / denom;
            if((digit_start == 1) || (digit != 0)) 
			{
                digit_start = 1;
                value %= denom;
                asciiString[j++] = (digit + '0');
            }
            denom /= 10;
        }
        asciiString[j++] = NULL;
    }
}// intToAscii






















⌨️ 快捷键说明

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