Advertisement
Guest User

dong ho bam giay

a guest
Jul 29th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.81 KB | None | 0 0
  1. #include <main.h>
  2. #define led PIN_A0
  3. #define speak PIN_A1
  4.  
  5. CHAR phut,giay,phut1,giay1,i;
  6. UNSIGNED char CONST ma[10] ={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xf8,0x80,0x90};
  7.  
  8.  
  9. void hien_thi()
  10. {  
  11.       output_d(0x01);
  12.       output_c(ma[phut/10]);
  13.       delay_ms(5);
  14.       output_d(0x02);
  15.       output_c(ma[(phut%10)]);
  16.       delay_ms(5);
  17.       output_d(0x04);
  18.       output_c(ma[giay/10]);
  19.       delay_ms(5);
  20.       output_d(0x08);
  21.       output_c(ma[giay%10]);
  22.       delay_ms(5);
  23.       output_d(0x10);
  24.       output_c(ma[phut1/10]);
  25.       delay_ms(5);
  26.       output_d(0x20);
  27.       output_c(ma[(phut1%10)]);
  28.       delay_ms(5);
  29.       output_d(0x40);
  30.       output_c(ma[giay1/10]);
  31.       delay_ms(5);
  32.       output_d(0x80);
  33.       output_c(ma[giay1%10]);
  34.       delay_ms(5);
  35. }
  36. void dem(char time)
  37. {
  38.       giay=giay+1;
  39.       IF (giay == 60)
  40.       {
  41.       phut= phut + 1;
  42.       giay=0;
  43.       }
  44.       for(i=1;i<=time;i++)
  45.       {
  46.       hien_thi();
  47.       if (!input (PIN_B3)) break;
  48.       }
  49. }
  50. #INT_RB
  51.  
  52. void  RB_isr(VOID)
  53. {  
  54.    IF (!input (PIN_B0))                      //tang led 1
  55.    {  output_high(speak);                       // bat coi
  56.       delay_ms (80);
  57.       while(!input (PIN_B0))
  58.       {giay1=giay1+1;
  59.       IF (giay1 == 60)
  60.       {
  61.       phut1= phut1 + 1;
  62.       giay1=0;
  63.       if (phut1==61) phut1=0;
  64.       }
  65.       for(i=1;i<=10;i++)
  66.       hien_thi();
  67.       }
  68.       output_low(speak);                        // tat coi
  69.    }
  70.  
  71.    IF (!input (PIN_B1))                     // giam led 1
  72.    {
  73.       output_high(speak);                       // bat coi
  74.       output_low(speak);                        // tat coi
  75.       delay_ms (80);
  76.       while(!input (PIN_B1))
  77.       {giay1=giay1-1;
  78.       IF (giay1 == -1)
  79.       {
  80.       phut1= phut1 - 1;
  81.       giay1=59;
  82.       if (phut1==-1) phut1=60;
  83.       }
  84.       for(i=1;i<=10;i++)
  85.       hien_thi();
  86.       }
  87.    }
  88.  
  89.    IF (input (PIN_B2) == 0)                      // tang led 2
  90.    {
  91.       output_high(speak);
  92.       for(i=1;i<=15;i++)  hien_thi();
  93.       output_low(speak);
  94.       phut=giay=0;
  95.       output_low(led);
  96.      
  97.    }
  98.  
  99.    IF (input (PIN_B3) == 0)                        //giam led 2
  100.    {
  101.       output_high(speak);
  102.       for(i=1;i<=10;i++)  hien_thi();
  103.       output_low(speak);
  104.       while(input(PIN_B3)==1)
  105.       {
  106.       if (phut < phut1) dem(20);
  107.       else if ((phut==phut1)&&(giay < giay1)) dem(20);
  108.       else {output_high(led); break;}
  109.       }
  110.    }
  111. }
  112. void main()
  113. {
  114.    //setup_comparator (NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard
  115.    ext_INT_edge (L_TO_H);          // Ngat canh len
  116.    enable_interrupts (INT_RB) ;    // Cho phep ngat port B
  117.    enable_interrupts (GLOBAL) ;    // Cho phep ngat toan cuc
  118.    WHILE (TRUE)
  119.    {
  120.       hien_thi () ;
  121.       //output_a(0xff);
  122.    }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement