-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c.orig
120 lines (82 loc) · 2.66 KB
/
main.c.orig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*--------------------------------------------------------------------------------------------------*/
/* --- -----------------实验内容 -------------------------------------------------------------------*/
/* --- 1-学习蓝牙传输无线控制方法--------------------------------------------------------------------*/
/* --- 实验步骤:
1-在工程开源地址下载蓝牙控制APP并安装在安卓系统手机中(可能有部分手机不支持)
2-下载程序,打开电源,手机蓝牙打开搜索蓝牙设备,找到一个JDY-31-SPP的型号进行配对,配对密码为1234
3-打开蓝牙APP,选择蓝牙设备,连接蓝牙,显示已连接蓝牙后即可进行控制
/* --- 实验平台:逐梦壹号STC32智能小车--------------------------------------------------------------*/
/* --- QQ交流群:702805632 -------------------------------------------------------------------------*/
/* --- 工程开源地址:-------------------------------------------------------------------------------*/
/* --oshwhub.com/wei-lai-dian-zi-gong-zuo-shi/qian-ru-shi-ji-yu-stc32-de-zhi-nen-xiao-che-she-ji ---*/
/*--------------------------------------------------------------------------------------------------*/
#include <STC32G.H>
#include "intrins.h"
#include "delay.h"
#include "motor.h"
#include "timer.h"
#include "uart1.h"
#include "sr04.h"
#include "uart2.h"
#include "Bluetooth.h"
#include "beep.h"
#include "LED.h"
sbit XJ_L = P3^3;
sbit XJ_R = P4^7;
sbit XJ_ML = P3^2;
sbit XJ_MR = P0^6;
/********************* 主函数 *************************/
void main()
{
WTST = 0; //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
EAXFR = 1; //扩展寄存器(XFR)访问使能
CKCON = 0; //提高访问XRAM速度
// 通用端口初始化,准双向口,其他端口初始化采用或运算完成
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
Motor_Init_Port(); //电机初始化
Timer4Init(); //定时器4初始化,计数时间使用
Uart1_Init(); //串口1初始化,使用计时器1
Uart2_Init(); //串口2初始化,使用计时器2
BeepInit();
Timer0Init(); // 蜂鸣器使用
Timer3Init(); // 超声波模块使用
LEDInit();
while (1)
{
// 接受蓝牙缓存
UART2_Rx_buff();
update_car(uart2temp);
if (XJ_L || XJ_R || XJ_ML || XJ_MR)
{
Car_Stop()
LED_L = 1;
LED_R = 1;
DealBeep_with_BLE(5, 35);
delay_with_BLE(5);
DealBeep_with_BLE(5, 35);
delay_with_BLE(50);
}
else
{
Counter_Number_DATA();
if (S <= 20)
{
LED_L = 1;
LED_R = 1;
delay_with_BLE(50);
LED_L = 0;
LED_R = 0;
delay_with_BLE(50);
}
}
}
}