本帖最后由 huangchuncheng 于 2011-4-8 21:44 编辑
#include<reg52.h>
#include <stdlib.h>
#include <stdio.h>
int count;
int i,num;
sbit dula=P2^6;
sbit wela=P2^7;
unsigned char code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
display(int num);
sbit led=P2^4;
void main( )
{
led=0;
EA=1;
ET1=1;
TMOD=0x10;
TH1=(65536-65535)/256;
TL1=(65536-65535)%256;
TR1=1;
srand(count);
for(i=0; i<10;i++ )
num=rand()%10+1;
display(num);
led=1;
// printf( "%d\n", rand()%100+1);
}
void tim1() interrupt 3 using 3
{
TH1=(65536-65535)/256;
TL1=(65536-65535)%256;
count++;
}
display(num)
{
P0=table[num];
dula=1;
dula=0;
P0=0xc0;
wela=1;
wela=0;
}
怎么改才能产生随机数,srand和rand函数是啥用法?
} |