请问C51单片机在每隔3秒产生两个0-9的随机数,如第一个数大于7,P1.7亮1.5秒,如果第一个数小于等于7,第

请问C51单片机在每隔3秒产生两个0-9的随机数,如第一个数大于7,P1.7亮1.5秒,如果第一个数小于等于7,第二个数大于7,则P1.6亮,两个数都小于等于7,P1.5亮的程序,求大神赐教,谢谢

#include<reg52.h>
#include<stdlib.h>
#define uchar unsigned char
#define uint unsigned int
uchar num;
sbit p17=P1^7;
sbit p16=P1^6;
sbit p15=P1^5;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
void main()
{
uchar temp1,temp2;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EA=1;
srand(9); //写入随意值初始化随机函数
temp1=rand();
temp2=rand();
if(temp1>7)
{
p17=0;p15=1;p16=1;
TR0=1;
num=0;
while(num<30);
TR0=0;
}
if((temp1<7)&&(temp2>7)
{
p16=0;p15=1;p17=1;
TR0=1;
num=0;
while(num<30);
TR0=0;
}
if((temp1<7)&&(temp2<7)
{
p15=0;p16=1;p17=1;
TR0=1;
num=0;
while(num<30);
TR0=0;
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-05
这似乎不难吧,自己琢磨琢磨就出来了
第2个回答  2013-09-05
这么简单的程序,哥们还是自己写啊
相似回答