关于单片机8个I/0口 实现36个按键功能
毕业设计2:传感器无线网络

毕业设计的开始:传感器无线网络——入手的几个模块

G-one posted @ 2010年4月05日 06:23 in program , 4496 阅读

话说这毕业设计到现在 竟然已经过了5周了,真恐怖啊~  时间过得真快,前面看资料竟然花了那么长时间,也是带很多懒惰吧 哈哈

弄了几个模块,还没工作赚钱 已经出血投资了 唉 唉~~

共4个nRF24L01,还真精致小巧,整个模块就一个拇指甲那么丁大,SPI的通讯接口 51单片机没又得要写虚拟接口程序

幸好手上有两块板,模拟仿真一下接收机 跟发射机,这里红的做接收,懒散那块做法送

SPI接口虚拟倒是容易,但这无线模块的发射 接收控制倒是不好弄 7条命令,25个寄存器 ..........30个配置字

带地址 数据校验 可设置频道 ...............  功能看上去还不错,我等菜鸟怎么都觉得有难度哟

代码怎么都飞到底下了?? 弄不上来,上面的是定义,下面的是部分函数,挺绕的

 今天还要 基本把示例程序 理解透,半抄半写的弄出了这些代码,单通道通讯也 成功的弄出来了,可是换个通道就不通了~还要加把劲呢,还有网络 哈哈 哈哈。

另外早几天还买了几个液晶 15一个,后来SBB的发现了 手上老师要来的那个单片机运行比一般51快N多,还以为液晶问题出不了东西。高速MCU... 我火星了  

 

 

 

 

 

 

#include<reg51.h>
#include<intrins.h>


#define uchar unsigned char
#define uint unsigned int

uchar code NUM[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//公阳
		//0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71	公阴

#define LED P0
#define TX_ADR_WIDTH    5   	 //地址长度
#define TX_PLOAD_WIDTH  20 		 //数据长度
uchar const TX_ADDRESS1[TX_ADR_WIDTH]={0x34,0x43,0x10,0x10,0x01};  //地址1
uchar const TX_ADDRESS2[TX_ADR_WIDTH]={0x34,0x43,0x10,0x10,0x02}; //地址2

uchar tx_Data[TX_PLOAD_WIDTH];
uchar rx_Data[TX_PLOAD_WIDTH];
uchar DATA;
uchar bdata sta;
sbit RX_DR=sta^6;
sbit TX_DS=sta^5;
sbit MAX_RT=sta^4;

sbit CE=P2^0;
sbit SCK=P2^1;
sbit CSN=P2^3;
sbit IRQ=P2^5;
sbit MOSI=P2^4;
sbit MISO=P2^2;	   
sbit LED1=P1^0;
sbit LED2=P1^1;
sbit LED3=P1^2;
sbit LED4=P1^3;

//********************nRF24L01 指令**********************************
#define READ_REG        0x00  // 读配置寄存器
#define WRITE_REG       0x20  // 写配置寄存器
#define RD_RX_PLOAD     0x61  // 读RX有效数据
#define WR_TX_PLOAD     0xA0  // 写RX有效数据
#define FLUSH_TX        0xE1  // 清除TX FIFO寄存器(发射模式应用)
#define FLUSH_RX        0xE2  // 清除TX FIFO寄存器(接收模式应用)
#define REUSE_TX_PL     0xE3  // 重新使用上一包有效数据
#define NOP             0xFF  // 空操作

//******************nRF24L01寄存器地址*******************************
#define CONFIG          0x00  // 配置收发状态,CRC校验模式以及收发状态响应方式
#define EN_AA           0x01  // 自动应答功能设置
#define EN_RXADDR       0x02  // 可用信道设置
#define SETUP_AW        0x03  // 收发地址宽度设置
#define SETUP_RETR      0x04  // 自动重发功能设置
#define RF_CH           0x05  // 工作频率设置
#define RF_SETUP        0x06  // 发射速率、功耗功能设置
#define STATUS          0x07  // 状态寄存器
#define OBSERVE_TX      0x08  // 发送监测功能
#define CD              0x09  // 地址检测           
#define RX_ADDR_P0      0x0A  // 频道0接收数据地址
#define RX_ADDR_P1      0x0B  // 频道1接收数据地址
#define RX_ADDR_P2      0x0C  // 频道2接收数据地址
#define RX_ADDR_P3      0x0D  // 频道3接收数据地址
#define RX_ADDR_P4      0x0E  // 频道4接收数据地址
#define RX_ADDR_P5      0x0F  // 频道5接收数据地址
#define TX_ADDR         0x10  // 发送地址寄存器
#define RX_PW_P0        0x11  // 接收频道0接收数据长度
#define RX_PW_P1        0x12  // 接收频道1接收数据长度
#define RX_PW_P2        0x13  // 接收频道2接收数据长度
#define RX_PW_P3        0x14  // 接收频道3接收数据长度
#define RX_PW_P4        0x15  // 接收频道4接收数据长度
#define RX_PW_P5        0x16  // 接收频道5接收数据长度
#define FIFO_STATUS     0x17  // FIFO栈入栈出状态寄存器设置

 

 

/***********************************************************
//	SPI_Read_Buf()
// 写入地址reg 读出数据*pBuf 数据长度bytes
***********************************************************/
uchar SPI_Read_Buf(uchar reg,uchar *pBuf,uchar bytes)
{
	uchar status,byte_ctr;
	CSN=0;
	status=SPI_RW(reg);

	for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
		pBuf[byte_ctr]=SPI_RW(0);

	CSN=1;

	return(status);
}

/***********************************************************
//	SPI_Read_Buf()
// 写入地址reg 写入数据*pBuf 数据长度bytes
***********************************************************/
uchar SPI_Write_Buf(uchar reg,uchar *pBuf,uchar bytes)
{
	uchar status,byte_ctr;

	CSN=0;
	status=SPI_RW(reg);
	for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
		SPI_RW(*pBuf++);
	CSN=1;
	return(status);
}

/***********************************************************
// RX_Mode();
//读模式
***********************************************************/
void RX_Mode(void)
{
	CE=0;
	SPI_Write_Buf(WRITE_REG+RX_ADDR_P0,TX_ADDRESS1,TX_ADR_WIDTH);

	SPI_RW_Reg(WRITE_REG+CONFIG,0x0f);
	SPI_RW_Reg(WRITE_REG+EN_AA,0X0f);
	SPI_RW_Reg(WRITE_REG+RF_CH,40);
	SPI_RW_Reg(WRITE_REG+RX_PW_P0,TX_PLOAD_WIDTH);
	SPI_RW_Reg(WRITE_REG+RF_SETUP,0X05);
	CE=1;
}

/***********************************************************
//TX_Mode();
//写模式
***********************************************************/
void TX_Mode(void)
{
	CE=0;

	SPI_Write_Buf(WRITE_REG+TX_ADDR,TX_ADDRESS1,TX_ADR_WIDTH);
	SPI_Write_Buf(WRITE_REG+RX_ADDR_P0,TX_ADDRESS1,TX_ADR_WIDTH);
	SPI_Write_Buf(WR_TX_PLOAD,tx_Data,TX_PLOAD_WIDTH);

	SPI_RW_Reg(WRITE_REG+CONFIG,0X0E);
	SPI_RW_Reg(WRITE_REG+EN_AA,0X01);
	SPI_RW_Reg(WRITE_REG+EN_RXADDR,0x01);
	SPI_RW_Reg(WRITE_REG+SETUP_RETR,0X1A);
	SPI_RW_Reg(WRITE_REG+RF_CH,40);
	SPI_RW_Reg(WRITE_REG+RF_SETUP,0X07);
	
	CE=1;
}
Avatar_small
TLHL28 说:
2010年4月10日 10:27

什么时候毕业答辩阿?!
我去参观!!!

Avatar_small
G-one 说:
2010年4月11日 03:22

不知道,协议部分还在烦着呢

Avatar_small
TLHL28 说:
2010年4月11日 10:39

= =. 快.
快毕业了都.还不知道什么时候答辩.

Avatar_small
Dr.Billa 说:
2021年7月17日 23:57

Superior post keeps up with this exceptional work✅. It's nice to know that this topic is being also covered on this web site so cheers for taking the time to discuss this! Thanks again and again! embroidered keychain tag

Avatar_small
Dr.Billa 说:
2021年7月19日 06:09

I likewise think this is a very wonderful website✅ and have all the information related to ✅. this website

Avatar_small
celeb networth 说:
2021年9月27日 20:39

All the basic information about every celebrity is available now on the largest database of celebrity networth where you can find all the information and net worth of a singer, actor, businessman...

Avatar_small
Anonymous 说:
2021年9月29日 22:37

On this page you can read       my interests, write something special. مكافحة حشرات

Avatar_small
Satta King fast 说:
2022年9月11日 18:10

Satta King fast you can get results in Satta King fast. Free to check results. You'll simply check them. You will check the result from any device. You check from a mobile or a laptop computer It depends on you. If you are the lucky winner then you will get a cash payment amount.

Avatar_small
CBSE Class 7 Biology 说:
2022年9月26日 17:28

Biology is an inbuild topic in Social Science or Social Studies for Class 7th Grade students studying on CBSE Board. CBSE Class 7 Biology Sample Paper Like every year this year also introduced the biology sample paper chapter wide for all evaluations of the course to get the question pattern of the new exam marking scheme. CBSE Board has published the topic wide study material for the listed topics for Term-1 & Term-2 exams held under the board or school level.

Avatar_small
Anonymous 说:
2023年3月13日 17:50

A considerable lot of my companions inquire as to whether I know which is the best article out there. I simply prescribe them to go to the site or visit this article here. This article is simply splendid. 슈어맨

Avatar_small
Anonymous 说:
2023年3月14日 13:28

To be honest, I believe in solving past papers in the book only. I only solve them on internet. My life got a lot easier by clicking on a single button that lead me to this site. 카지노사이트

Avatar_small
प्रश्नपत्र.com 说:
2023年4月21日 20:56

The Polytechnic Question Paper 2023 has been posted on the board's official website by the Combined Entrance Examination Board Candidates who have applied for Polytechnic 2023 may review the study materials here. Given the large number of applicants,it is essential to prepare for the exam using BPEE Model Question Papers. The applicants will be able to ace the test with the aid of the prior exam questions.प्रश्नपत्र.com Candidates can access the sample question paper for 2023 by downloading it.The Bihar Polytechnic Entrance Exam will be held in May 2023 by the Combined Entrance Examination Board. Bihar BPEE is a competitive national entrance test that offers admission to students in a variety of polytechnic programmes. The model papers have been updated by the authority.

Avatar_small
4 Pin 说:
2023年10月19日 00:13

Insurance is a broad and vital topic, and your blog covers it brilliantly! Your insights and explanations are much appreciated. Thanks for sharing valuable information on this crucial aspect of financial planning.

Avatar_small
mindfulrings.com.au 说:
2023年11月02日 21:31

Redefine your style with our exquisite collection of rings. Crafted with precision and passion, our rings effortlessly blend fashion and sophistication. Explore the timeless elegance of our rings and make a statement that lasts a lifetime.

Avatar_small
Pierced N Proud 说:
2023年11月03日 00:23

Jewellery transcends mere accessories; it embodies stories, memories, and elegance. Our curated collection captures the essence of timeless beauty, offering pieces that reflect sophistication and craftsmanship. Explore the world of jewellery and adorn yourself with the artistry of elegance and style.

Avatar_small
GD Kitchen 说:
2023年11月08日 19:13

In the realm of pregnancy and health, 'my keyword,' 'Gestational Diabetes Specialists,' emerge as the dedicated professionals who excel in the field of 'my keyword.' With their expertise and specialization in 'my keyword,' these medical professionals provide tailored support, guidance, and medical care to expectant mothers. 'Gestational Diabetes Specialists' ensure that managing 'my keyword' during pregnancy is a well-informed, personalized experience, prioritizing the health and well-being of both mother and baby.

Avatar_small
RTP Ligaciputra 说:
2023年11月13日 06:24

RTP Ligaciputra offers an engaging and immersive gaming experience. The platform's user-friendly interface and diverse game selection make it a go-to choice for both casual and avid gamers alike. Exciting and reliable – a winning combination!

Avatar_small
Best XL Pitbull Kenn 说:
2023年12月24日 13:43

Discover the pinnacle of American Bully breeding with the 'Best American Bully Breeder.' Our passion for excellence is reflected in every pup, ensuring exceptional health, temperament, and breed standards. Choose a loyal companion from our reputable breeding program for a lifelong bond of quality and companionship.

Avatar_small
Lloyd C. Rice 说:
2024年1月02日 21:42

Embark on a celestial journey, "Embracing the Divine Dance," where every step resonates with the rhythm of connection and passion. Surrender to the enchanting choreography of intimate encounters, where each move becomes a sacred expression of desire. Elevate your existence as you gracefully engage in the dance of the divine, unlocking profound moments of connection and blissful unity.

Avatar_small
減脂 说:
2024年1月03日 20:32

One of the most effective ways to build muscle is through strength training exercises. These exercises include lifting weights, using resistance bands, or using your body weight (e.g., push-ups, squats). Strength training targets specific muscle groups, causing them to adapt and grow over time.

Avatar_small
First Super Car Rent 说:
2024年1月23日 00:55

Enhance your Dubai experience with Luxury Car Rentals, where opulence meets convenience. Our premium fleet offers an exquisite selection of vehicles, ensuring you traverse the city in unparalleled style and comfort. Elevate your journey with Dubai Car Rental Luxury, defining sophistication on the road.

Avatar_small
EMF Protection 说:
2024年1月29日 18:30

EMFs are invisible fields of energy generated by the electronic devices and appliances that surround us daily. These fields are classified into two types: low-frequency EMFs, emitted by household appliances and power lines, and high-frequency EMFs, produced by wireless devices such as Wi-Fi routers, smartphones, and other electronic gadgets. While low levels of exposure are generally considered safe, prolonged exposure to high levels of EMFs has been associated with various health concerns, including fatigue, headaches, and potential long-term effects on well-being.

Avatar_small
Webdesign agentur wi 说:
2024年1月29日 18:45

Blackrabbyt ist eine in Wien ansässige kreative Digitalagentur mit der Leidenschaft, die Grenzen von Kreativität und technischer Innovation ständig zu erweitern.
Wir entwickeln, beleben und lassen dich wachsen und das darüber hinaus, indem wir deine Erfolgsgeschichte digital spürbar machen, deine einzigartige Solution finden und gewissenhaft deine gewünschte Aufmerksamkeit erzielen.

Avatar_small
taxiwaltononthames 说:
2024年1月31日 20:41

Discover prompt and reliable transportation with Taxi Walton on Thames. Our professional service ensures a comfortable journey for both local commutes and longer distances. Trust Taxi Walton on Thames for seamless travel, offering top-notch service and convenience with every ride.

Avatar_small
Taxiwey Bridge 说:
2024年2月04日 19:14

Experience convenience with Taxi Brooklands, your go-to choice for reliable and comfortable transportation services. Serving Brooklands and beyond, our dedicated taxis ensure prompt arrivals and hassle-free journeys. Choose Taxi Brooklands for a dependable and enjoyable travel experience tailored to your needs.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter