...

반응형





#include<reg51.h>
#include<stdlib.h>

int a=0;
sbit P2_4 = P2^4;
sbit P2_5 = P2^5;
sbit P2_6 = P2^6;
sbit P2_7 = P2^7;

void delay(unsigned int a);
void interruptset(void);
void timersetting(void);
void timer_1sec(void);

main()
{
 unsigned char number,number1;
 timersetting();
 interruptset();
 TR0=1;

 while(1)
 {
  if(a==0)
  {
  
  number1 = (rand()%6)+1;
  if(number==number1)
  {
   number1 = (rand()%6)+1;
  }
  number=number1;
  
  if(number==1) number=1;
  if(number==2) number=2;
  if(number==3) number=3;
  if(number==4) number=4;
  if(number==5) number=5;
  if(number==6) number=6;
  
  P2 = number;
  P2_4 = 1;
  P2_5 = 1;
  P2_6 = 1;
  P2_7 = 1;  

  delay(80);

  }
 }
  
}

 

void delay(unsigned int a)
{
 int i,j;
 for(i=0;i<a;i++)
  for(j=0;j<100;j++);
}

 

void sinwho(void) interrupt 0
{
 if(a==0)
 {
  a=1;
  delay(100);
  return;
 }

 else
 {
  a=0;  
  delay(50);
  return;
 }
}

void interruptset(void)
{
 EA = 1;
 EX0 = 1;
 TCON = 0x01;     
}    

반응형