久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5611|回復: 8
打印 上一主題 下一主題
收起左側

nrf24l01無線芯片的開發板范例-AVR(已驗證通過)

[復制鏈接]
跳轉到指定樓層
樓主
ID:465246 發表于 2019-4-2 19:25 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include "main.h"
#include "nRF24L01.h"


/*Bit field operations*/
#define SetBit( Byte, Bit )  ( Byte ) |= ( 1<<( Bit ) )
#define ClrBit( Byte, Bit )  ( Byte ) &= ~( 1<<( Bit ) )
#define GetBit( Byte, Bit )  ( ( Byte ) & ( 1<<( Bit ) ) )
#define ComBit( Byte, Bit )  ( Bytes ) ^= ( 1<<( Bit ) )
#define SetBits( Byte, Bits ) ( Byte ) |= ( Bits )
#define ClrBits( Byte, Bits ) ( Byte ) &= ~( Bits )
#define GetBits( Byte, Bits ) ( ( Byte ) & ( Bits ) )
#define ComBits( Byte, Bits ) ( Byte ) ^= ( Bits )

#define M32_MOSI   PB5
#define M32_MISO   PB6
#define M32_SCK    PB7
/*
================================================================================
Function   : USART_SendChar( )
Description: Send a single byte via the USART
InPut      : -dt, The value you want to send
Output     : None
================================================================================
*/
void USART_SendChar( unsigned char dt )
{
                UCSRA |= ( 1<<TXC );
                UDR = dt;
                while( !( UCSRA & ( 1<<TXC ) ) );
}
/*
================================================================================
Function   : USART_SendArray( )
Description: Send a array of data via the USART port
InPut      : -pBuff, The buffer to store the data
             -nBytes, How many bytes do you want to send ?
Output     : None
================================================================================
*/
void USART_SendArray( unsigned char* pBuff, unsigned char nBytes )
{
        unsigned char btmp;
        for( btmp = 0; btmp < nBytes; btmp ++ )
        {
                USART_SendChar( *( pBuff + btmp ) );
        }
}
/*
================================================================================
Function   : USART_SendStr( )
Description: Send a string of data via the USART port
InPut      : pstr->the string to be sent
Output     : None
================================================================================
*/
void USART_SendStr( char *pstr )
{
    while( *pstr )
    {
        USART_SendChar( *pstr++ );
    }
}
/*
================================================================================
Function   : USART_Init( ),
Description: Initialize the USART port
InPut      : None
Output     : None
================================================================================
*/
#define Bandrate    9600
#define F_CPU       12000000
void USART_Init( void )
{

        UCSRB = 0x00; //disable while setting baud rate
        UCSRA = 0x00;
        UCSRC = 0x86;
        UBRRL = ( F_CPU / 16 / Bandrate - 1 ) % 256;
        UBRRH = ( F_CPU / 16 / Bandrate - 1 ) >> 8;
        UCSRB = 0x98;

}
/*
================================================================================
Function : SPI_Init( )
Description : Initialize the SPI bus
Input : None
Output: None
================================================================================
*/
/*void SPI_Init( void )
{
    //IO config
    PORTB |= ( 1<<0 ) | ( 1<<5 ) | ( 1<<3 ) | ( 1<<2 ) | ( 1<<4 );
    DDRB |= ( 1<<0 ) | ( 1<<2 ) | ( 1<<3 ) | ( 1<<5 );
    DDRB &= ~( 1<<4 );
    SPCR = (1<<SPE) | (1<<MSTR);
}*/

void SPI_Init( void )
{
    /*IO config*/
    PORTB |= ( 1<<0 ) | ( 1<<5 ) | ( 1<<6 ) | ( 1<<7 ) | ( 1<<4 );
    DDRB |= ( 1<<7 ) | ( 1<<5 ) | ( 1<<0 ) | ( 1<<4 );
    DDRB &= ~( 1<<6 );
    SPCR = (1<<SPE) | (1<<MSTR);
}
/*
================================================================================
Function : SPI_ExchangeByte( )
Description : Exchange a byte via the SPI bus
Input : -value, The byte sent
Output: The byte read.
================================================================================
*/
INT8U SPI_ExchangeByte( INT8U value )
{
    SPDR = value;
        while ( !(SPSR & (1<<SPIF)) );
        return SPDR;
}

INT8U testbuffer[32];
int main( void )
{
    INT8U tmp;
        unsigned char ReplayData[] = {"我很好!\r\n"};


        SPI_Init( );
        USART_Init( );
        L01_Init( );       
                L01_SetRXMode( );
L01_WriteHoppingPoint( 0 );
USART_SendStr( "nRF24L01P接收測試開始!\r\n" );
        while( 1 )
    {
        for( tmp = 0; tmp < 32; tmp ++ )
        {
            testbuffer[tmp] = tmp+0x20;
        }
                L01_FlushRX( );
                L01_FlushTX( );
                L01_WriteRXPayload_InAck( ReplayData, sizeof( ReplayData ) );
                while( 1 )
                {
                        tmp = L01_ReadStatusReg( );
//                        USART_SendChar(tmp);  //for test
                        tmp &= ( 1<<TX_DS ) | ( 1<<MAX_RT ) | ( 1<<RX_DR );               
                        if( tmp != 0 )
                        {
                                break;
                        }
                }
         
        if( tmp & ( 1<<TX_DS ) )
        {
         //   USART_SendStr( "發送成功\r\n" );
        }
        else if( tmp & ( 1<<MAX_RT ) )
        {
         //   USART_SendStr( "發送失敗\r\n" );
        }
        else if( tmp & ( 1<<RX_DR )  )
        {
                        L01_WriteRXPayload_InAck( testbuffer, 32 );
            USART_SendStr( "收到數據:" );
                        tmp = L01_ReadRXPayload( testbuffer );
                        USART_SendArray( testbuffer, tmp );
                        USART_SendStr( "回復數據:" );
                        USART_SendStr( ( char*) ReplayData );
        }
        L01_ClearIRQ( IRQ_ALL );
    }
        return 0;
}


AVR_M16(ICC).rar

161.42 KB, 下載次數: 32, 下載積分: 黑幣 -5

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:120111 發表于 2019-4-29 09:53 來自手機 | 只看該作者
買了這個模塊還沒開始用,正好學習一下
回復

使用道具 舉報

板凳
ID:6428 發表于 2019-6-29 13:49 | 只看該作者
不錯學習下
回復

使用道具 舉報

地板
ID:6428 發表于 2019-6-29 13:49 | 只看該作者
不錯學習下
回復

使用道具 舉報

5#
ID:574631 發表于 2019-6-29 16:31 來自手機 | 只看該作者
太好了正找這個 謝謝
回復

使用道具 舉報

6#
ID:552794 發表于 2019-6-30 13:38 | 只看該作者
版主:這是Nordic的RFID產品,該公司還有BLE4.0的nRF51822產品,版主是否也用了?很想同版主交流。
回復

使用道具 舉報

7#
ID:6428 發表于 2019-9-6 13:43 | 只看該作者
謝謝分享0
回復

使用道具 舉報

8#
ID:633275 發表于 2019-12-3 11:16 | 只看該作者
AVR才開始學習,之前用PIC搞過,謝謝分享
回復

使用道具 舉報

9#
ID:702817 發表于 2020-3-5 12:35 | 只看該作者
喜歡的內容
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲精品免费在线 | 欧区一欧区二欧区三免费 | 亚洲激情第一页 | 另类一区 | 日韩高清一区 | 北条麻妃一区二区三区在线视频 | 亚洲综合电影 | www.99久久.com| 亚洲人成在线播放 | 午夜视频一区 | 一级黄色录像片子 | 日韩在线中文字幕 | av中文在线| 国产高清视频在线观看 | 久久www免费人成看片高清 | 黄视频国产 | 成人午夜电影在线观看 | 国产精品久久久久久亚洲调教 | 亚洲 中文 欧美 日韩 在线观看 | 亚洲欧洲在线看 | 欧美日韩一区二区三区四区 | 亚洲精品一区二三区不卡 | 亚洲97 | 午夜久久久久久久久久一区二区 | 欧美一级二级视频 | 国产91精品久久久久久久网曝门 | www国产成人免费观看视频,深夜成人网 | 99精品久久 | 国产精品99久久久精品免费观看 | 国产成人jvid在线播放 | 网站黄色在线免费观看 | 7777在线视频免费播放 | www.狠狠操 | 日韩在线视频一区 | 成人免费在线观看 | 国产视频一区二区在线观看 | 亚洲精品福利在线 | 最近中文字幕第一页 | 中文在线一区二区 | 亚洲国产一区视频 | 精品国产欧美一区二区 |