jayanth.devarayanadurga
Banned
- Joined
- Dec 4, 2012
- Messages
- 4,280
- Helped
- 822
- Reputation
- 1,654
- Reaction score
- 791
- Trophy points
- 1,393
- Location
- Bangalore, India
- Activity points
- 0
If you clap once the LED turns ON after 2 sec. If clapped twice within 2 sec then LED turns OFF.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 #include <16f877a.h> #device adc=10 #fuses HS,NOWDT,NOLVP,NOCPD,NODEBUG #use delay(clock=4M) #define useTimer1 //#define useTimer2 float volt, oldval, volt1; int count = 0; unsigned int8 time = 0, clap = 0; #ifdef useTimer1 #INT_TIMER1 void TIMER1_isr(void) { if(interrupt_active(int_timer1)) { time++; } set_timer1(0x0BDB); clear_interrupt(int_timer1); } #elif useTimer2 #int_timer2 void timer2_isr(void) { ; } #endif void clear(){ clap = 0; time = 0; diaable_interrupts(INT_TIMER1); } void main() { set_tris_a(0xff); set_tris_b(0x00); set_tris_c(0x00); set_tris_d(0x00); //Analog module configuration for reading the voltage from the PIN_AN0 setup_comparator(NC_NC_NC_NC); setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(AN0); set_adc_channel(0); setup_vref(FALSE); //Timer Configuration #ifdef useTimer1 //Timer1 //Prescaler 1:8; TMR1 Preload = 3035; Actual Interrupt Time : 500 ms setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); set_timer1(0x0BDB); #elif //Code for Timer2 configuration #endif enable_interrupts(GLOBAL); while(1) { delay_us(20); read_adc(adc_start_only); delay_us(100); volt = read_adc(adc_read_only); volt = volt * 30.0/ 1023.0; if((volt > 5) && (clap == 0){ clap++; enable_interrupts(INT_TIMER1); } if((volt > 5) && (clap == 1){ if(time < 4){ clap++; output_low(PIN_C2); clear(); } } if((clap == 1) && (time > 4)){ output_high(PIN_C2); clear(); } } }