|
这是安卓的发送数据的程序:
mButtonF.setOnTouchListener(new Button.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
String message;
byte[] msgBuffer;
int action = event.getAction();
switch(action)
{
case MotionEvent.ACTION_DOWN:
try {
outStream = btSocket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
}
message = "1";
msgBuffer = message.getBytes();
try {
outStream.write(msgBuffer);
} catch (IOException e) {
Log.e(TAG, "ON RESUME: Exception during write.", e);
}
break;
case MotionEvent.ACTION_UP:
try {
outStream = btSocket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
}
message = "0";
msgBuffer = message.getBytes();
try {
outStream.write(msgBuffer);
} catch (IOException e) {
Log.e(TAG, "ON RESUME: Exception during write.", e);
}
break;
}
return false;
}
});
这是51单片机接收的程序:
#include<reg52.h>
unsigned char tab[]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,
0x1f,0x01,0x09};//数码管段码
unsigned char a,flag;
void main()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1;//开始接收
SM0=0;//8位UART
SM1=1;
EA=1;//中断
ES=1;
while(1)
{
if (flag==1)
{
P2=0X00;
P0=tab[a];
flag=0;
}
}
}
void mhp() interrupt 4//串口中断
{
RI=0;
a=SBUF-48;
flag=1;
}
问题是。。数码管完全没反应。我不懂是不是手机发送的数据有问题,还是单片机的程序有问题。求大神救救小弟一把吧~!
|
|