求大神们看看我这个程序哪里有逻辑问题啊!急急急
时间:10-02
整理:3721RD
点击:
要求我,做一个编程,有开关控制的,如果开关是闭合,就会进行下一步,反之开关是开,不会进行任何东西。
如果闭合开关,有两种模式选择:
1,老人做 坐起 运动,一坐一起算一次,程序计算到5次的时候就会自己停止,把做了5次的时间发给串口。
2.30秒里面老人做 坐起 运动,时间30秒到,时间停止,程序把老人做了多少次坐起 运动的次数 发给 串口。
(PS:老人做 坐起 运动就是一个 开关的原理,用的是ZIGBEE无限传输,分别用!SIT@,还有!STAND@代替。)
#include<DS89C4xx.h>
void read_zigbee(void);
sbit LED=P2^0;
sbit SW = P2^2;
sbit start_button=P2^4;
unsigned int x,y,z,q;
unsigned int time;
unsigned char i,k,RI1;
unsigned char code start_header='!';
unsigned char code end_header='@';
unsigned char zigbeerxd[25];
unsigned char read[25];
unsigned char rawdata[5];
unsigned char get_raw;
unsigned char read_count;
unsigned char count;
unsigned char timer;
void main (void)
{
LED=0;
timer=0;
SW=0;
time=0;
read_count=0;
k=0;
RI_0=0;
z=0;//mode 1 constant
q=0;//mode 2 constant
start_button=0;
while(1)
{
if(start_button==1) //if press the start button:can select two modes
{ if(SW==1&&z==0)//mode 1 which is 5 times test.
{
read_zigbee();
for(x=0;x<21;x++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
timer++;
if(time==10)
{
LED=1;
TR0=0;
timer=0;
x=0;
z=1;
}
}
if(SW==0&&q==0)//mode 2 which is 30s test.
{
read_zigbee();
for(y=0;y<21;y++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
timer++;
if(timer==30)
{
LED=1;
TR0=0;
timer=0;
y=0;
q=1;
}
}
}
}
}
void read_zigbee(void)
{
if(read_count!=count) //checking is there any unread data?
{
if(read_count==25) //go back to start position of array
read_count=0;
read[read_count]=zigbeerxd[read_count];//read the data
if(i==1)
{
if(read[read_count]==end_header)
{
k=0;//reset the values
i=0;
read_count++;
time++;
get_raw=1;//raise the get_raw flag
}
else if(k<=7)//To prevent array over flow
{
rawdata[k]=read[read_count];//store the data in rawdata[]array
k++;
read_count++;
}
}
else if(read[read_count]==start_header)
{
i++;
read_count++;
}
else if(read[read_count]!=start_header)
{
read_count++;
}
}
}
void serial_int(void) interrupt 4
{
if(RI_0==1)
{
if(count==25) count=0;
zigbeerxd[count]=SBUF0; //Storing the data from serial buffer into array
count++; //increase the count
RI_0=0;
}
}
如果闭合开关,有两种模式选择:
1,老人做 坐起 运动,一坐一起算一次,程序计算到5次的时候就会自己停止,把做了5次的时间发给串口。
2.30秒里面老人做 坐起 运动,时间30秒到,时间停止,程序把老人做了多少次坐起 运动的次数 发给 串口。
(PS:老人做 坐起 运动就是一个 开关的原理,用的是ZIGBEE无限传输,分别用!SIT@,还有!STAND@代替。)
#include<DS89C4xx.h>
void read_zigbee(void);
sbit LED=P2^0;
sbit SW = P2^2;
sbit start_button=P2^4;
unsigned int x,y,z,q;
unsigned int time;
unsigned char i,k,RI1;
unsigned char code start_header='!';
unsigned char code end_header='@';
unsigned char zigbeerxd[25];
unsigned char read[25];
unsigned char rawdata[5];
unsigned char get_raw;
unsigned char read_count;
unsigned char count;
unsigned char timer;
void main (void)
{
LED=0;
timer=0;
SW=0;
time=0;
read_count=0;
k=0;
RI_0=0;
z=0;//mode 1 constant
q=0;//mode 2 constant
start_button=0;
while(1)
{
if(start_button==1) //if press the start button:can select two modes
{ if(SW==1&&z==0)//mode 1 which is 5 times test.
{
read_zigbee();
for(x=0;x<21;x++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
timer++;
if(time==10)
{
LED=1;
TR0=0;
timer=0;
x=0;
z=1;
}
}
if(SW==0&&q==0)//mode 2 which is 30s test.
{
read_zigbee();
for(y=0;y<21;y++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
timer++;
if(timer==30)
{
LED=1;
TR0=0;
timer=0;
y=0;
q=1;
}
}
}
}
}
void read_zigbee(void)
{
if(read_count!=count) //checking is there any unread data?
{
if(read_count==25) //go back to start position of array
read_count=0;
read[read_count]=zigbeerxd[read_count];//read the data
if(i==1)
{
if(read[read_count]==end_header)
{
k=0;//reset the values
i=0;
read_count++;
time++;
get_raw=1;//raise the get_raw flag
}
else if(k<=7)//To prevent array over flow
{
rawdata[k]=read[read_count];//store the data in rawdata[]array
k++;
read_count++;
}
}
else if(read[read_count]==start_header)
{
i++;
read_count++;
}
else if(read[read_count]!=start_header)
{
read_count++;
}
}
}
void serial_int(void) interrupt 4
{
if(RI_0==1)
{
if(count==25) count=0;
zigbeerxd[count]=SBUF0; //Storing the data from serial buffer into array
count++; //increase the count
RI_0=0;
}
}
自己顶!自己顶!自己顶!自己顶!自己顶!自己顶!自己顶!自己顶!自己顶!