?? receive.txt
字號(hào):
#include "reg52.h"
#include "intrins.h"
#include "CC1100.h"
#define INT8U unsigned char
#define INT16U unsigned int
#define WRITE_BURST 0x40 //連續(xù)寫(xiě)入
#define READ_SINGLE 0x80 //讀
#define READ_BURST 0xC0 //連續(xù)讀
#define BYTES_IN_RXFIFO 0x7F //接收緩沖區(qū)的有效字節(jié)數(shù)
#define CRC_OK 0x80 //CRC校驗(yàn)通過(guò)位標(biāo)志
#define INT8U unsigned char
#define INT16U unsigned int
sbit GDO0 =P3^2;
sbit GDO2 =P3^3;
sbit CSN =P1^4;
sbit MOSI =P1^5;
sbit MISO =P1^6;
sbit SCLK =P1^7;
sbit spz =P2^4;
sbit LED1 = P2^1;
sbit LED2 = P2^1;
sbit key =P2^0;
/****************************************************************************************
//全局變量定義
/****************************************************************************************/
//INT16U TimeOutCount[2]={0,0}; //超時(shí)計(jì)數(shù)器
INT8U code PaTabel[8] = {0xC0, 0xC8, 0x85, 0x51, 0x3A, 0x06, 0x1C, 0x6C};
//*****************************************************************************************
//函數(shù)名:delay(unsigned int s)
//輸入:時(shí)間
//輸出:無(wú)
//功能描述:普通廷時(shí)
//*****************************************************************************************
delay(unsigned int s)
{
unsigned int i;
for(i=0; i<s; i++);
for(i=0; i<s; i++);
}
void halWait(INT16U timeout) {
do {
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
} while (--timeout);
}
/*****************************************************************************************
//函數(shù)名:UartInit()
//輸入:無(wú)
//輸出:無(wú)
//功能描述:串口初始化程序
/*****************************************************************************************/
void UartInit(void)
{
SCON = 0x50; // uart in mode 1 (8 bit), REN=1
TMOD = TMOD | 0x20 ; // Timer 1 in mode 2
TH1 = 0xFD; // 9600 Bds at 11.059MHz
TL1 = 0xFD; // 9600 Bds at 11.059MHz
TR1 = 1; // Timer 1 run
}
/*****************************************************************************************
//函數(shù)名:void TimerInit(void)
//輸入:無(wú)
//輸出:無(wú)
//功能描述:定時(shí)器0初始化程序
/*****************************************************************************************/
void SpiInit(void)
{
CSN=0;
SCLK=0;
CSN=1;
}
/*****************************************************************************************
//函數(shù)名:CpuInit()
//輸入:無(wú)
//輸出:無(wú)
//功能描述:SPI初始化程序
/*****************************************************************************************/
CpuInit(void)
{
UartInit();
// TimerInit();
SpiInit();
delay(5000);
}
/*
//*****************************************************************************************
//函數(shù)名:ResetTimer(INT8U n)
//輸入:要復(fù)位的計(jì)時(shí)器
//輸出:無(wú)
//功能描述:復(fù)位計(jì)時(shí)器
//*****************************************************************************************
void ResetTimer(INT8U n)
{
ET0 = 0; // Disable Timer0 interrupt
timer[n & 0x01] = 0; // Clear timer[n]
ET0 = 1; // Enable Timer0 interrupt
}
//*****************************************************************************************
//函數(shù)名:INT16U ReadTimer(INT8U n)
//輸入:要讀的計(jì)時(shí)器
//輸出:讀出值
//功能描述:讀計(jì)時(shí)器
//*****************************************************************************************
INT16U ReadTimer(INT8U n)
{
INT16U tmp;
ET0 = 0; // Disable Timer0 interrupt
tmp = timer[n]; // Clear timer[n]
ET0 = 1; // Enable Timer0 interrupt
return tmp;
}
*/
/*****************************************************************************************
//函數(shù)名:SendCh(ch)
//輸入:無(wú)
//輸出:無(wú)
//功能描述:串口發(fā)送一個(gè)字符
/*****************************************************************************************/
void SendCh(INT8U ch)
{
SBUF = ch;
while(!TI);
TI = 0;
}
/*****************************************************************************************
//函數(shù)名:void SendStr(INT8U *arr)
//輸入:發(fā)送的字符串
//輸出:無(wú)
//功能描述:發(fā)送一個(gè)字符串
/*****************************************************************************************/
//void SendStr(INT8U *arr)
//{
// INT8U i;
// i = 0;
// while(arr[i] != '\0')
// {
// SendCh(arr[i]);
// i++;
// }
//}
//*****************************************************************************************
//函數(shù)名:SpisendByte(INT8U dat)
//輸入:發(fā)送的數(shù)據(jù)
//輸出:無(wú)
//功能描述:SPI發(fā)送一個(gè)字節(jié)
//*****************************************************************************************
INT8U SpiTxRxByte(INT8U dat)
{
INT8U i,temp;
temp = 0;
SCLK = 0;
for(i=0; i<8; i++)
{
if(dat & 0x80)
{
MOSI = 1;
}
else MOSI = 0;
dat <<= 1;
SCLK = 1;
_nop_();
_nop_();
temp <<= 1;
if(MISO)temp++;
SCLK = 0;
_nop_();
_nop_();
}
return temp;
}
//*****************************************************************************************
//函數(shù)名:void RESET_CC1100(void)
//輸入:無(wú)
//輸出:無(wú)
//功能描述:復(fù)位CC1100
//*****************************************************************************************
void RESET_CC1100(void)
{
CSN = 0;
while (MISO);
SpiTxRxByte(CCxxx0_SRES); //寫(xiě)入復(fù)位命令
while (MISO);
CSN = 1;
}
//*****************************************************************************************
//函數(shù)名:void POWER_UP_RESET_CC1100(void)
//輸入:無(wú)
//輸出:無(wú)
//功能描述:上電復(fù)位CC1100
//*****************************************************************************************
void POWER_UP_RESET_CC1100(void)
{
CSN = 1;
halWait(1);
CSN = 0;
halWait(1);
CSN = 1;
halWait(41);
RESET_CC1100(); //復(fù)位CC1100
}
//*****************************************************************************************
//函數(shù)名:void halSpiWriteReg(INT8U addr, INT8U value)
//輸入:地址和配置字
//輸出:無(wú)
//功能描述:SPI寫(xiě)寄存器
//*****************************************************************************************
void halSpiWriteReg(INT8U addr, INT8U value)
{
CSN = 0;
while (MISO);
SpiTxRxByte(addr); //寫(xiě)地址
SpiTxRxByte(value); //寫(xiě)入配置
CSN = 1;
}
//*****************************************************************************************
//函數(shù)名:void halSpiWriteBurstReg(INT8U addr, INT8U *buffer, INT8U count)
//輸入:地址,寫(xiě)入緩沖區(qū),寫(xiě)入個(gè)數(shù)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -