主程序
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "hc05.h"
#include "usart2.h"
#include "string.h"
#include "key.h"
#include "pwm.h"
//显示ATK-HC05模块的主从状态
void HC05_Role_Show(void)
{
LCD_ShowString(30,140,200,16,16,"ROLE:Slave "); //从机
}
//显示ATK-HC05模块的连接状态
void HC05_Sta_Show(void)
{
if(HC05_LED)LCD_ShowString(120,140,120,16,16,"STA:Connected "); //连接成功
else LCD_ShowString(120,140,120,16,16,"STAisconnect"); //未连接
}
int main(void)
{
u8 t;
// u8 key;
u8 sendmask=0;
u8 sendcnt=0;
u8 sendbuf[20];
u8 reclen=0;
SystemInit();
delay_init(72); //延时函数初始化
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(9600); //串口初始化为9600
LED_Init(); //初始化与LED连接的硬件接口
KEY_Init(); //初始化按键
LCD_Init(); //初始化LCD
 WM_Init(900,0); //不分频。PWM频率=72000/900=8Khz
 OINT_COLOR=RED;
LCD_ShowString(30,30,200,16,16,"ALIENTEK STM32 ^_^");
LCD_ShowString(30,50,200,16,16,"HC05 BLUETOOTH COM TEST");
LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK");
while(HC05_Init()) //初始化ATK-HC05模块
{
LCD_ShowString(30,90,200,16,16,"ATK-HC05 Error!");
delay_ms(500);
LCD_ShowString(30,90,200,16,16,"Please Check!!!");
delay_ms(100);
}
LCD_ShowString(30,90,200,16,16,"WK_UP:ROLE KEY0:SEND/STOP");
LCD_ShowString(30,110,200,16,16,"ATK-HC05 Standby!");
LCD_ShowString(30,160,200,16,16,"Send:");
LCD_ShowString(30,180,200,16,16,"Receive:");
 OINT_COLOR=BLUE;
HC05_Role_Show();
while(1)
{
if(t==50)
{
if(sendmask) //定时发送
{
sprintf((char*)sendbuf,"ALIENTEK HC05 %d\r\n",sendcnt);
LCD_ShowString(30+40,160,200,16,16,sendbuf); //显示发送数据
u2_printf("ALIENTEK HC05 %d\r\n",sendcnt); //发送到蓝牙模块
sendcnt++;
if(sendcnt>99)sendcnt=0;
}
HC05_Sta_Show();
t=0;
}
if(USART2_RX_STA&0X8000) //接收到一次数据了
{
LCD_Fill(30,200,240,320,WHITE); //清除显示
reclen=USART2_RX_STA&0X7FFF; //得到数据长度
USART2_RX_BUF[reclen]=0; //加入结束符
if(reclen==9||reclen==8) //控制DS1检测
{
if(strcmp((const char*)USART2_RX_BUF,"+LED1 ON")==0)
TIM_SetCompare3(TIM3,400); //打开LED1 PB0连接PA6
if(strcmp((const char*)USART2_RX_BUF,"+LED1 OFF")==0)
{
TIM_SetCompare3(TIM3,0);
LED1=1;
} //关闭LED1和LED0
if(strcmp((const char*)USART2_RX_BUF,"+LED0 ON")==0)
LED1=0; //打开LED1
if(strcmp((const char*)USART2_RX_BUF,"+LED0 OFF")==0)
LED1=1; //关闭LED1
}
LCD_ShowString(30,200,209,119,16,USART2_RX_BUF);//显示接收到的数据
USART2_RX_STA=0;
}
t++;
}
}
|