如下程序是个蓝牙开关程序,共有六路,我想把前四路输出由锁定状态改成点动状态,就是手机那边改成触摸一下执行一下,触摸不离开就一直执行,松手后输出停止,请问高手们需要怎么改,谢谢!
单片机源程序如下:
#include<reg52.h>
#include<string.h>
sfr AUXR = 0x8E;
sfr T2H = 0xD6;
sfr T2L = 0xD7;
#define uchar unsigned char
#define uint unsigned int
sbit power1=P1^2;//继电器端口依次类推
sbit power2=P1^3;
sbit power3=P1^4;
sbit power4=P1^5;
sbit power5=P1^6;
sbit power6=P1^7;
uchar temp;
bit flag;
void UART_Send_Byte(uchar mydata)//发送一个字节
{
SBUF=mydata;
while(!TI);
TI=0;
}
void UART_Send_Str(uchar *s)//发送字符串
{
while (*s)
{
UART_Send_Byte(*s++);
}
}
void UartInit(void) //9600bps@11.0592MHz
{
SCON = 0x50; //8位数据,可变波特率
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
AUXR |= 0x04; //定时器2时钟为Fosc,即1T
T2L = 0xE0; //设定定时初值
T2H = 0xFE; //设定定时初值
AUXR |= 0x10; //启动定时器2
EA = 1;
ES = 1;
}
void main(void)
{
UartInit();
UART_Send_Str("AT+VERSION");//发送AT指令,测试模块是否正常
while(1)
{
if(flag)
{
flag=0;
if(temp=='2') power1=0; //如果接收到的数据是0x02小灯亮
else if(temp=='1') power1=1;//否则如果接收到是0x01,则熄灭
if(temp=='8') power2=0; //
else if(temp=='4') power2=1;//
if(temp=='7') power3=0; //
else if(temp=='9') power3=1;//
if(temp=='b') power4=0; //
else if(temp=='a') power4=1;//
if(temp=='d') power5=0; //
else if(temp=='c') power5=1;//
if(temp=='e') power6=0; //
else if(temp=='f') power6=1;//
}
}
}
void serial_IT(void) interrupt 4
{
RI=0;
temp = SBUF;//串口接收到的数据给temp
UART_Send_Byte(temp);//单片机接收到数据后发给电脑串口助手
flag=1;
}
|