//用来产生随机数
#include <stdio.h>
#include <stdlib.h>
#include <REGX51.H>
#define random(x) rand()%x
void Delay(int a);
unsigned char r; //全局变量,随机数种子
main()
{
unsigned char a;
TMOD = 0x00; //timer0
TH0 = 0xff;
TL0 = 0x00;
IE = 0x82;
TR0 = 1; //开定时
while(1)
{
srand(r);
a = random(0xff);
P1 = a;
Delay(10);
}
}
void Delay(int a)
{
int b;
for(;a!=0;a--)
for(b=1000;b!=0;b--);
}
void Timer0() interrupt 1
{
TH0 = 0xF0;
TL0 = 0x00;
r++;
}