如何使用射频模块进行PIC到PIC的无线通信

大家好,今天在这个项目中,我们将射频接收器和发射器模块与pic微控制器连接,并在两个不同的pic微控制器之间进行无线通信。
在这个项目中,我们将做以下事情:-
我们将使用 pic16f877a 作为发射器,使用pic18f4520作为接收器部分。
我们将键盘和lcd与pic微控制器连接。
在发射器方面,我们将键盘与pic接口并传输数据。在接收器侧,我们将无线接收数据并显示按下lcd上的哪个键。
我们将使用编码器和解码器ic来传输4位数据。
接收频率将为433mhz,使用市场上廉价的rf tx-rx模块。
433mhz射频发射器和接收器模块:
这些是我们在项目中使用的发射器和接收器模块。它是433 mhz最便宜的模块,这些模块在一个通道中接受串行数据。
如果我们看到模块的规格,变送器的额定工作电压为3.5-12v,发射距离为20-200米。它确实以433 mhz 频率的 am(音频调制)协议传输。我们可以以 4kb/s 的速度以 10mw 的功率传输数据。
在上图中,我们可以看到发射器模块的引脚。从左到右,引脚是vcc,data和gnd。我们还可以添加天线并将其焊接在上图中表示的点上。
对于接收器规格,接收器的额定电压为5v 直流,静态电流为 4ma作为输入。接收频率为433.92 mhz,灵敏度为-105db。
在上图中,我们可以看到接收器模块的引脚。四个引脚从左到右依次为vcc、数据、数据和gnd。中间的两个引脚在内部连接。我们可以使用任何一个或两个。但是,最好同时使用两者来降低噪声耦合。
此外,数据表中没有提到一件事,模块中间的可变电感或pot用于频率校准。如果我们无法接收传输的数据,则发射和接收频率可能不匹配。这是一个射频电路,我们需要将发射器调谐到完美的发射频率点。此外,与发射器相同,该模块也有一个天线端口;我们可以以线圈形式焊接焊丝,以获得更长的接收时间。
传输范围取决于提供给发射器的电压和两侧天线的长度。对于这个特定的项目,我们没有使用外部天线,而是在发射器侧使用了5v。我们检查了5米的距离,效果很好。
编码器和解码器的需求:
这种射频传感器几乎没有缺点:-
单向沟通。
只有一个通道
非常噪音干扰。
由于这个缺点,我们使用了编码器和解码器ic,ht12d和ht12e。d代表解码器,将在接收器侧使用,e代表编码器,将在发射器侧使用。该 ic 提供4 个通道。此外,由于编码和解码,噪声水平非常低。
在上图中,左边是解码器ht12d,右边是编码器ht12e。两个ic是相同的。a0 到 a7用于特殊编码。我们可以使用微控制器引脚来控制这些引脚并设置配置。另一侧需要匹配相同的配置。如果两种配置准确且匹配,我们可以接收数据。这 8 个引脚可以连接到gnd或vcc或保持打开状态。无论我们在编码器中进行什么配置,我们都需要匹配解码器上的连接。在本项目中,我们将为编码器和解码器保留这 8 个引脚。9 和 18 引脚分别为 vss 和 vdd。我们可以使用ht12d中的vt引脚作为通知目的。对于这个项目,我们没有使用它。te引脚用于传输使能或禁用引脚。
重要的部分是我们需要连接电阻的osc引脚,以便为编码器和解码器提供振荡。解码器需要比解码器更高的振荡。通常,编码器电阻值为1meg,解码器值为33k。我们将在项目中使用这些电阻器。
dout引脚是 ht12e 上的射频发射器数据引脚,ht12d中的din引脚用于连接射频模块数据引脚。
在ht12e中,ad8至ad11是四通道输入,通过rf模块进行转换和串行传输,而在ht12d中发生的情况恰恰相反,串行数据被接收和解码,我们在4个引脚d8至d11上获得4位并行输出。
所需组件:
2 - 面包板
1 - 液晶显示器 16x2
1 – 键盘
ht12d 和 ht12e 对
射频模块
1- 10k预设
2 – 4.7k 电阻器
1- 1m 电阻器
1- 33k 电阻器
2- 33pf 陶瓷电容器
1 – 20兆赫晶体
伯格斯
很少的单股线。
pic16f877a 单片机
pic18f4520 单片机
一把螺丝刀用于控制频率的锅,需要与人体绝缘。
电路图:
变送器侧电路图 (pic16f877a):
我们使用pic16f877a进行传输。六角键盘通过portb连接,4 个通道连接在portd的最后4位。
引脚如下-
1.ad11 = rd7
2.ad10 = rd6
3.ad9 = rd5
4.ad8 = rd4
接收器侧电路图 (pic18f4520):
在上图中,显示了接收器电路。液晶屏通过端口连接。我们在这个项目中使用了pic18f4520的内部振荡器。4 个通道的连接方式与我们之前在发射器电路中的连接方式相同。
这是发射器侧-
接收器侧位于单独的试验板中-
代码说明:
代码分为两部分,一部分用于发射器,另一部分用于接收器。
射频发射器的pic16f877a代码:
与往常一样,首先,我们需要在图片微控制器中设置配置位,定义一些宏,包括库和晶体频率。编码器 ic 的ad8-ad11端口定义为端口rf_tx。您可以在最后给出的完整代码中检查所有这些代码的代码。
我们使用了两个函数,void system_init(void)和void encode_rf_sender(char data)。
system_init用于引脚初始化和键盘初始化。键盘初始化从键盘库调用。
键盘端口也在键盘 .h中定义。我们使用trisd=0x00将portd作为输出,并将rf_tx端口设置为默认状态0x00。
void system_init(void){
trisd = 0x00;
rf_tx = 0x00;
keyboard_initialization();
}

encode_rf_sender
中,我们根据按下的按钮更改了 4 针状态。我们创建了 
16
个不同的
十六进制值
或 
portd 
状态,具体取决于按下的 
(4x4) 16
个不同的按钮。
void encode_rf_sender (char data){    
if(data=='1')
rf_tx=0x10;
if(data=='2')
rf_tx=0x20;
if(data=='3')
………  …. ..
…. ….
在main函数中,我们首先使用switch_press_scan()函数接收键盘按钮按下的数据,并将数据存储在键变量中。之后,我们使用encode_rf_sender()函数对数据进行编码并更改portd状态。
射频接收器的pic18f4520代码:
与往常一样,我们首先在pic18f4520中设置配置位。它与pic16f877a略有不同,您可以在随附的zip文件中检查代码。
我们包含了lcd头文件。使用portd线路定义了解码器ic跨portd的d8-d11端口连接#define rf_rx连接与编码器部分中使用的连接相同。lcd端口声明也在lcd.c文件中完成。
#include
#include supporing_cfilelcd.h
#define rf_rx portd
如前所述,我们为18f4520使用内部振荡器,我们使用了system_init函数,其中我们配置 18f4520 的oscon寄存器以将内部振荡器设置为8 mhz。我们还为lcd引脚和解码器引脚设置了tris位。由于ht-12d在d8-d11端口提供输出,我们需要将portd配置为输入以接收输出。
void system_init (void){
osccon = 0b01111110; // 8mhz, , intosc
//osctune = 0b01001111; // pll enable, max prescaler 8x4 = 32mhz    
trisb = 0x00;
trisd = 0xff; // last 4 bit as input bit.
}
我们将oscon寄存器配置为8mhz,还将端口 b作为输出,端口d作为输入。
下面的功能是使用上一个变送器部分中使用的完全相反的逻辑制作的。在这里,我们从端口 d获得相同的十六进制值,并通过该十六进制值确定在发射器部分中按下了哪个开关。我们可以识别每个按键并将相应的字符提交给lcd。
void rf_analysis (unsigned char recived_byte){    
if(recived_byte==0x10)
lcd_data('1');
if(recived_byte==0x20)
lcd_data('2');
if(recived_byte==0x30)
……. ….. …
… ………..
从lcd.c文件调用lcd_data。
在主函数中,我们首先初始化系统和lcd。我们获取一个可变字节,并存储从端口 d接收的十六进制值。然后通过该功能rf_analysis我们可以在lcd上打印字符。
void main(void) {
unsigned char byte = 0;
system_init();
lcd_init();   
while(1){
lcd_com(0x80); 
lcd_puts(circuitdigest);
lcd_com (0xc0);        
byte = rf_rx;                       
rf_analysis(byte);
lcd_com (0xc0);
}
return;
}
在运行它之前,我们已经调整了电路。首先,我们按下键盘中的“d”按钮。因此,0xf0由rf发射器连续传输。然后,我们调整接收器电路,直到lcd显示字符“d”。有时模块从制造商处正确调谐,有时则没有。如果一切都正确连接并且没有在lcd中得到按钮按下的值,则rf接收器可能未调谐。我们使用绝缘螺丝刀来减少由于我们的身体电感而导致的错误调谐可能性。
这就是如何将射频模块连接到 pic微控制器,并使用射频传感器在两个 pic 微控制器之间进行无线通信的方式。
pic code for transmitter side:
/*
* file:   main.c
* author: sourav gupta
* by:- circuitdigest.com
* created on april 13, 2018, 2:26 pm
*/
// pic16f877a configuration bit settings
// 'c' source line config statements
// config
#pragma config fosc = hs        // oscillator selection bits (hs oscillator)
#pragma config wdte = off       // watchdog timer enable bit (wdt disabled)
#pragma config pwrte = off      // power-up timer enable bit (pwrt disabled)
#pragma config boren = on       // brown-out reset enable bit (bor enabled)
#pragma config lvp = off         // low-voltage (single-supply) in-circuit serial programming enable bit (rb3/pgm pin has pgm function; low-voltage programming enabled)
#pragma config cpd = off        // data eeprom memory code protection bit (data eeprom code protection off)
#pragma config wrt = off        // flash program memory write enable bits (write protection off; all program memory may be written to by eecon control)
#pragma config cp = off         // flash program memory code protection bit (code protection off)
#include
#include
#include
#include supporing_cfile/keypad.h
#define rf_tx portd
/*
hardware related definition
*/
#define _xtal_freq 200000000 //crystal frequency, used in delay
/*
other specific definition
*/
void system_init(void);
void encode_rf_sender (char data);
void main(void){
system_init();
char key = 'n';
while(1){
key = switch_press_scan();
encode_rf_sender(key);
}
}
/*
*  system init
*/
void system_init(void){
trisd = 0x00;
rf_tx = 0x00;
keyboard_initialization();
}
void encode_rf_sender (char data){
if(data=='1')
rf_tx=0x10;
if(data=='2')
rf_tx=0x20;
if(data=='3')
rf_tx=0x30;
if(data=='4')
rf_tx=0x40;
if(data=='5')
rf_tx=0x50;
if(data=='6')
rf_tx=0x60;
if(data=='7')
rf_tx=0x70;
if(data=='8')
rf_tx=0x80;
if(data=='9')
rf_tx=0x90;
if(data=='0')
rf_tx=0x00;
if(data=='*')
rf_tx=0xa0;
if(data=='#')
rf_tx=0xb0;
if(data=='a')
rf_tx=0xc0;
if(data=='b')
rf_tx=0xd0;
if(data=='c')
rf_tx=0xe0;
if(data=='d')
rf_tx=0xf0;
}
pic code for receiver side:
/*
* file:   main.c
* author: sourav gupta
*circuitdigest.com
* created on 17 may 2018, 12:18
*/
// pic18f4520 configuration bit settings
// 'c' source line config statements
// config1h
#pragma config osc = intio7     // oscillator selection bits (internal oscillator block, clko function on ra6, port function on ra7)
#pragma config fcmen = off      // fail-safe clock monitor enable bit (fail-safe clock monitor disabled)
#pragma config ieso = off       // internal/external oscillator switchover bit (oscillator switchover mode disabled)
// config2l
#pragma config pwrt = off       // power-up timer enable bit (pwrt disabled)
#pragma config boren = sbordis  // brown-out reset enable bits (brown-out reset enabled in hardware only (sboren is disabled))
#pragma config borv = 3         // brown out reset voltage bits (minimum setting)
// config2h
#pragma config wdt = on         // watchdog timer enable bit (wdt enabled)
#pragma config wdtps = 32768    // watchdog timer postscale select bits (1:32768)
// config3h
#pragma config ccp2mx = portc   // ccp2 mux bit (ccp2 input/output is multiplexed with rc1)
#pragma config pbaden = off      // portb a/d enable bit (portb pins are configured as analog input channels on reset)
#pragma config lpt1osc = off    // low-power timer1 oscillator enable bit (timer1 configured for higher power operation)
#pragma config mclre = on       // mclr pin enable bit (mclr pin enabled; re3 input pin disabled)
// config4l
#pragma config stvren = on      // stack full/underflow reset enable bit (stack full/underflow will cause reset)
#pragma config lvp = off        // single-supply icsp enable bit (single-supply icsp disabled)
#pragma config xinst = off      // extended instruction set enable bit (instruction set extension and indexed addressing mode disabled (legacy mode))
// config5l
#pragma config cp0 = off        // code protection bit (block 0 (000800-001fffh) not code-protected)
#pragma config cp1 = off        // code protection bit (block 1 (002000-003fffh) not code-protected)
#pragma config cp2 = off        // code protection bit (block 2 (004000-005fffh) not code-protected)
#pragma config cp3 = off        // code protection bit (block 3 (006000-007fffh) not code-protected)
// config5h
#pragma config cpb = off        // boot block code protection bit (boot block (000000-0007ffh) not code-protected)
#pragma config cpd = off        // data eeprom code protection bit (data eeprom not code-protected)
// config6l
#pragma config wrt0 = off       // write protection bit (block 0 (000800-001fffh) not write-protected)
#pragma config wrt1 = off       // write protection bit (block 1 (002000-003fffh) not write-protected)
#pragma config wrt2 = off       // write protection bit (block 2 (004000-005fffh) not write-protected)
#pragma config wrt3 = off       // write protection bit (block 3 (006000-007fffh) not write-protected)
// config6h
#pragma config wrtc = off       // configuration register write protection bit (configuration registers (300000-3000ffh) not write-protected)
#pragma config wrtb = off       // boot block write protection bit (boot block (000000-0007ffh) not write-protected)
#pragma config wrtd = off       // data eeprom write protection bit (data eeprom not write-protected)
// config7l
#pragma config ebtr0 = off      // table read protection bit (block 0 (000800-001fffh) not protected from table reads executed in other blocks)
#pragma config ebtr1 = off      // table read protection bit (block 1 (002000-003fffh) not protected from table reads executed in other blocks)
#pragma config ebtr2 = off      // table read protection bit (block 2 (004000-005fffh) not protected from table reads executed in other blocks)
#pragma config ebtr3 = off      // table read protection bit (block 3 (006000-007fffh) not protected from table reads executed in other blocks)
// config7h
#pragma config ebtrb = off      // boot block table read protection bit (boot block (000000-0007ffh) not protected from table reads executed in other blocks)
// #pragma config statements should precede project file includes.
// use project enums instead of #define for on and off.
#include
#include supporing_cfilelcd.h
#define rf_rx portd
void system_init (void);
void rf_analysis (unsigned char recived_byte);
void main(void) {
unsigned char byte = 0;
system_init();
lcd_init();
while(1){
lcd_com(0x80);
lcd_puts(circuitdigest);
lcd_com (0xc0);
byte = rf_rx;
rf_analysis(byte);
lcd_com (0xc0);
}
return;
}
void system_init (void){
osccon = 0b01111110; // 8mhz, , intosc
//osctune = 0b01001111; // pll enable, max prescaler 8x4 = 32mhz
trisb = 0x00;
trisd = 0xff; // last 4 bit as input bit.
}
void rf_analysis (unsigned char recived_byte){
if(recived_byte==0x10)
lcd_data('1');
if(recived_byte==0x20)
lcd_data('2');
if(recived_byte==0x30)
lcd_data('3');
if(recived_byte==0x40)
lcd_data('4');
if(recived_byte==0x50)
lcd_data('5');
if(recived_byte==0x60)
lcd_data('6');
if(recived_byte==0x70)
lcd_data('7');
if(recived_byte==0x80)
lcd_data('8');
if(recived_byte==0x90)
lcd_data('9');
if(recived_byte==0x00)
lcd_data('0');
if(recived_byte==0xa0)
lcd_data('*');
if(recived_byte==0xb0)
lcd_data('#');
if(recived_byte==0xc0)
lcd_data('a');
if(recived_byte==0xd0)
lcd_data('b');
if(recived_byte==0xe0)
lcd_data('c');
if(recived_byte==0xf0)
lcd_data('d');
}

shell脚本启动java程序详情解说
如何将耦合线带通滤波器转换为HFSS模型呢?
未来的智能家居市场将会遍布智能镜子显示屏
荣耀9评测:华为荣耀9为什么如此热销,除了颜值高配置强还有这两个功能不容小觑
甲骨文将成为TikTok的“受信任的技术提供商”
如何使用射频模块进行PIC到PIC的无线通信
RCD吸收电路EMI影响与参数调整影响分析
聚焦离子束显微镜(FIB-SEM)材料分析
电感器芯的发展
智能感知与物联网技术研究所2021级硕士研究生中期报告(三)
ORB_FPGA单层图像金字塔的ORB特征提取方案分析
MAX9626, MAX9627, MAX9628 ADC驱
任正非在华为软件架构提出三大原则
百度网盘从存储工具到个人云服务操作系统
Lightning转30-pin适配器拆解:不可破解、不可仿造
天机董事长陈曦:工业机器人产品的进化之路
美光CEO认为中国存储器不具威胁 2032年自驾车传感器规模770亿
折衍射混合成像光学系统设计
微风吊扇温度控制电路图
新一代EliteSiC功率模块助力电动汽车高效充电