標題:
51單片機藍牙通信程序
[打印本頁]
作者:
1600755741
時間:
2024-3-7 11:10
標題:
51單片機藍牙通信程序
常見的普中51開發(fā)板結(jié)合藍牙模塊的串口通信
單片機源程序如下:
#include<reg52.h>
#include "lcd1602.h"
#include "public.h"
#include "Uart.h"
#include "matrix-buttons.h"
#include "string.h"
#include "Interu.h"
#include "function.h"
#include "LEDrun.h"
#include "BEEP.h"
u8 flag = 0;
unsigned char mark;
unsigned char* zoom; //選擇數(shù)據(jù)緩沖區(qū)
unsigned char* str;
unsigned char* judge;
u8 z1=0,z2=0;
void main()
{
Init0();
Init1();
lcd1602_init();
UartInit();
str=UART_GetString();
while(1)
{
flag = key_matrix_ranks_scan();
if(flag ==1)
{
SendString("receive mode");
str=UART_GetString();
lcd1602_show_string(0,0,"Receive Mode");
Beep(); //接收數(shù)據(jù)時蜂鳴器響一下
Delay2000ms();
lcd1602_clear();
zoom = str;
judge = str;
while(1)
{
lcd1602_show_string(0,0,str);
if(str != judge)
{Beep();}
flag = key_matrix_ranks_scan();
if(flag == 11) //右移選擇
{
zoom++;
mark = *zoom;
z1++;
}
if(flag == 9) //左移選擇
{
zoom--;
mark = *zoom;
z1--;
}
if(flag == 6) //向上
{
zoom= zoom-16;
mark = *zoom;
z2= z2-16;
}
if(flag == 14) //向下
{
zoom=zoom+16; //由于LCD為16*2,所以移動16位
mark = *zoom;
z2= z2+16;
}
// lcd1602_show_string(z1,z2,zoom);
// lcd1602_show_string(z1,z2," ");
}
}
}
}
void send() interrupt 2 //用于發(fā)送選中的數(shù)據(jù)返回PC端
{
lcd1602_clear();
lcd1602_show_string(0,0,"Send Mode");
*judge = mark;
lcd1602_show_string(0,1,"Sending:");
SendString("reply:");
SendChar(mark);
Delay2000ms();
lcd1602_clear();
lcd1602_show_string(0,0,"Done!");
Ledrun();
Delay500ms();
lcd1602_clear();
}
復(fù)制代碼
原理圖: 無
仿真: 無
代碼:
Bluetooth.zip
(82.01 KB, 下載次數(shù): 12)
2024-3-7 11:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1