job 5

 int conv7segment(int number);

void beep(void);

main()

 {

 int i;

   TRISB = 0x00;

   CMCON = 0x07;

   TRISA = 0xFD;

   i=0;

   while (1)

   {

   PORTB =  conv7segment(i);

   while (PORTA.F0==0)

   {

   i++;

   PORTB =  conv7segment(i);

   beep();

   Delay_ms(10);

   if(i>9)

   {i=0;}

   }

  }

}

  int conv7segment(int number)

  {

   switch(number)

   {

     case 1: return 0x06;

     case 2: return 0x5b;

     case 3: return 0x4f;

     case 4: return 0x66;

     case 5: return 0x6d;

     case 6: return 0x7d;

     case 7: return 0x07;

     case 8: return 0x7f;

     case 9: return 0x6f;

     case 0: return 0x3f;

   }

}

 void beep(void)

 {

 int i_b;

    for(i_b=0;i_b<20;i_b++)

    {

    PORTA.F1 = 1;

    Delay_us(300);

    PORTA.F1 = 0;

    Delay_us(300);

    }

}

ความคิดเห็น