Labview串口通信问题 求高手答案
时间:10-02
整理:3721RD
点击:
我要做一个PC_MCU的串口实验,单片机开发板是PL2303的USB转串口,我用LV写的程序是串口的,单片机程序运行无误如下:
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uchar code press_p00[26]={196,250,176,180,193,203,80,48};
uchar key;
void cpubbs_delay_1ms(uint x)
{
uint j;
uchar i;
for(j=0;j<x;j++)
{
for(i=0;i<120;i++);
}
}
void cpubbs_scankey(void)
{
key=~P1^0;
if(key)
{
cpubbs_delay_1ms(20);
key=~P1^0;
if(key)
key=~P1^0;
else
key=0;
}
else
key=0;
}
void cpubbs_serial_send(key)
{
uchar i;
switch(key)
{
case 1:
for(i=0;i<8;i++)
{
//cpubbs_reset_wdt();
SBUF=press_p00;
while(TI==0);
TI=0;
}
break;
default:
break;
}
}
main()
{
key=0;
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
SCON=0x50;
PCON=0x00;
ES=1;
EA=1;
TR1=1;
//cpubbs_init_wdt();
while(1)
{
//cpubbs_reset_wdt();
while(key==0)
{
//cpubbs_reset_wdt();
cpubbs_scankey();
}
cpubbs_serial_send(key);
key=0;
}
}
可是不知道咋回事 就是不能成功,请高手详解
前面板
后面板