Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <main.h>
- #define led PIN_A0
- #define speak PIN_A1
- CHAR phut,giay,phut1,giay1,i;
- UNSIGNED char CONST ma[10] ={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xf8,0x80,0x90};
- void hien_thi()
- {
- output_d(0x01);
- output_c(ma[phut/10]);
- delay_ms(5);
- output_d(0x02);
- output_c(ma[(phut%10)]);
- delay_ms(5);
- output_d(0x04);
- output_c(ma[giay/10]);
- delay_ms(5);
- output_d(0x08);
- output_c(ma[giay%10]);
- delay_ms(5);
- output_d(0x10);
- output_c(ma[phut1/10]);
- delay_ms(5);
- output_d(0x20);
- output_c(ma[(phut1%10)]);
- delay_ms(5);
- output_d(0x40);
- output_c(ma[giay1/10]);
- delay_ms(5);
- output_d(0x80);
- output_c(ma[giay1%10]);
- delay_ms(5);
- }
- void dem(char time)
- {
- giay=giay+1;
- IF (giay == 60)
- {
- phut= phut + 1;
- giay=0;
- }
- for(i=1;i<=time;i++)
- {
- hien_thi();
- if (!input (PIN_B3)) break;
- }
- }
- #INT_RB
- void RB_isr(VOID)
- {
- IF (!input (PIN_B0)) //tang led 1
- { output_high(speak); // bat coi
- delay_ms (80);
- while(!input (PIN_B0))
- {giay1=giay1+1;
- IF (giay1 == 60)
- {
- phut1= phut1 + 1;
- giay1=0;
- if (phut1==61) phut1=0;
- }
- for(i=1;i<=10;i++)
- hien_thi();
- }
- output_low(speak); // tat coi
- }
- IF (!input (PIN_B1)) // giam led 1
- {
- output_high(speak); // bat coi
- output_low(speak); // tat coi
- delay_ms (80);
- while(!input (PIN_B1))
- {giay1=giay1-1;
- IF (giay1 == -1)
- {
- phut1= phut1 - 1;
- giay1=59;
- if (phut1==-1) phut1=60;
- }
- for(i=1;i<=10;i++)
- hien_thi();
- }
- }
- IF (input (PIN_B2) == 0) // tang led 2
- {
- output_high(speak);
- for(i=1;i<=15;i++) hien_thi();
- output_low(speak);
- phut=giay=0;
- output_low(led);
- }
- IF (input (PIN_B3) == 0) //giam led 2
- {
- output_high(speak);
- for(i=1;i<=10;i++) hien_thi();
- output_low(speak);
- while(input(PIN_B3)==1)
- {
- if (phut < phut1) dem(20);
- else if ((phut==phut1)&&(giay < giay1)) dem(20);
- else {output_high(led); break;}
- }
- }
- }
- void main()
- {
- //setup_comparator (NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard
- ext_INT_edge (L_TO_H); // Ngat canh len
- enable_interrupts (INT_RB) ; // Cho phep ngat port B
- enable_interrupts (GLOBAL) ; // Cho phep ngat toan cuc
- WHILE (TRUE)
- {
- hien_thi () ;
- //output_a(0xff);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement