微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 51单片机+315M无线射频模块接受程序

51单片机+315M无线射频模块接受程序

时间:11-30 来源:互联网 点击:
用的就是那种最普通的 最便宜的 大约几块钱 的315兆的无线模块接受发射,不带解码的,433m的程序也是一样的不用修改

压缩包中的内容:


上位机以及完整程序在文件夹中,大家可自己下载
地址是:http://www.51hei.com/bbs/dpj-19033-1.html

下面是接受端的源代码:
#include
#include "string.h"

//液晶块
#define LCM_RW P3_6 //定义引脚
#define LCM_RS P3_5
#define LCM_E P3_7
#define LCM_Data P1
#define Busy 0x80 //用于检测LCM状态字中的Busy标识
typedef int byte;
typedef unsigned int word;

void Read_Temp(void);
void mychar(char,char);

void WriteDataLCM(unsigned char WDLCM);
void WriteCommandLCM(unsigned char WCLCM,BuysC);
unsigned char ReadDataLCM(void);
unsigned char ReadStatusLCM(void);
void LCMInit(void);
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
void Delay5Ms(void);
void Delay400Ms(void);

void delay(word useconds)
{
for(;useconds>0;useconds--);
}

void mychar(char xx,char yy)
{

DisplayOneChar(0,0,0x54);
DisplayOneChar(1,0,0x65);
DisplayOneChar(2,0,0x6D);
DisplayOneChar(3,0,0x70);
DisplayOneChar(4,0,0x65);
DisplayOneChar(5,0,0x72);
DisplayOneChar(6,0,0x61);
DisplayOneChar(7,0,0x74);
DisplayOneChar(8,0,0x75);
DisplayOneChar(9,0,0x72);
DisplayOneChar(10,0,0x65);
DisplayOneChar(11,0,0x3A);
///////////////////////自定义字符
WriteCommandLCM(0x48, 0); //第一行
WriteDataLCM(0x06);
WriteCommandLCM(0x49, 0); //第2行
WriteDataLCM(0x09);
WriteCommandLCM(0x4a, 0); //第3
WriteDataLCM(0x09);
WriteCommandLCM(0x4b, 0); //第4
WriteDataLCM(0x06);
WriteCommandLCM(0x4c, 0); //第5
WriteDataLCM(0x00);
WriteCommandLCM(0x4d, 0); //第6
WriteDataLCM(0x00);
WriteCommandLCM(0x4e, 0); //第7
WriteDataLCM(0x00);
WriteCommandLCM(0x4f, 0); //第8
WriteDataLCM(0x00);
DisplayOneChar(xx,yy,0x01);
DisplayOneChar(xx+1,yy,0x43);
}
//写数据
void WriteDataLCM(unsigned char WDLCM)
{
ReadStatusLCM(); //检测忙
LCM_Data = WDLCM;
LCM_RS = 1;
LCM_RW = 0;
LCM_E = 0; //若晶振速度太高可以在这后加小的延时
LCM_E = 0; //延时
LCM_E = 1;
}

//写指令
void WriteCommandLCM(unsigned char WCLCM,BuysC) //BuysC为0时忽略忙检测
{
if (BuysC) ReadStatusLCM(); //根据需要检测忙
LCM_Data = WCLCM;
LCM_RS = 0;
LCM_RW = 0;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
}

//读状态
unsigned char ReadStatusLCM(void)
{
LCM_Data = 0xFF;
LCM_RS = 0;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
while (LCM_Data & Busy); //检测忙信号
return(LCM_Data);
}

void LCMInit(void) //LCM初始化
{
LCM_Data = 0;
WriteCommandLCM(0x38,0); //三次显示模式设置,不检测忙信号
Delay5Ms();
WriteCommandLCM(0x38,0);
Delay5Ms();
WriteCommandLCM(0x38,0);
Delay5Ms();

WriteCommandLCM(0x38,1); //显示模式设置,开始要求每次检测忙信号
WriteCommandLCM(0x08,1); //关闭显示
WriteCommandLCM(0x01,1); //显示清屏
WriteCommandLCM(0x06,1); // 显示光标移动设置
WriteCommandLCM(0x0C,1); // 显示开及光标设置
}

//按指定位置显示一个字符
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;
X |= 0x80; //算出指令码
WriteCommandLCM(X, 0); //这里不检测忙信号,发送地址码
WriteDataLCM(DData);
}

//按指定位置显示一串字符 ***原来的遇到空格0x20就不显示***
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
unsigned char ListLength,j;
ListLength = strlen(DData);
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
if (X <= 0xF) //X坐标应小于0xF
{
for(j=0;j{
DisplayOneChar(X, Y, DData[j]); //显示单个字符
X++;
}
}
}

//5ms延时
void Delay5Ms(void)
{
unsigned int TempCyc = 5552;
while(TempCyc--);
}

//400ms延时
void Delay400Ms(void)
{
unsigned char TempCycA = 5;
unsigned int TempCycB;
while(TempCycA--)
{
TempCycB=7269;
while(TempCycB--);
};
}

sbit W_IN = P2^1;
sbit W_OUT = P2^0;

unsigned char w_data;//接收时用于存储两

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top