...

반응형






#include<reg51.h>
sbit P1_0 = P1^0;
sbit P1_1 = P1^1;
sbit P1_2 = P1^2;
sbit P1_3 = P1^3;

int a=0;

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


char number=0x00;
char number1=0x00;
main()
{
 
 timersetting();
 interruptset();
 

 TR0=1;
 while(1)
 {
  if(a==0)
  {
  number++;
  P2 = number;
  P0 = number1;
  
  if(number==0x0a) number=0x10;
  if(number==0x1a) number=0x20;
  if(number==0x2a) number=0x30;
  if(number==0x3a) number=0x40;
  if(number==0x4a) number=0x50;
  if(number==0x5a) number=0x60;
  if(number==0x6a) number=0x70;
  if(number==0x7a) number=0x80;
  if(number==0x8a) number=0x90;
  if(number==0x9a) {number=0x00;++number1;}
  if(number1==0x0a) number1=0x00;
  
  timer_1sec();
  //delay(15);
  
  }
  
  if(a==1) 
  {
   if(P1_0==0)
   {
    number1++;
    if(number1==10) number1 = 0;
    P0 = number1;
    delay(500);
   }
     


   else if(P1_1==0)
   {
    number=number+16;
    if(number==0x9a) number=0x00;
    P2 = number;
    delay(500);
   }

  }
 }

  
  
  
  
}

 


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

 

void sinwho1(void) interrupt 2
{
 
 number++;
}

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

}

 


void interruptset(void)
{
 EA = 1;
 EX0 = 1;
 EX1 = 1;
 TCON = 0x05;     
 PX0=0;
}

 

void timersetting(void)
{
 TF0 = 0;
 TMOD = 0x00;
 TH0 = 0xe3;
 TL0 = 0x07;
}

void timer_1sec(void)
{
 int count = 0;
 do
 {
 if(TF0)
 {
  count++;
  TH0 = 0xE3;
  TL0 = 0x07;
  TF0 = 0;
 }
 }while(count<100);
}

반응형