/* Copyright(C) by mukawa@ac.wakwak.com */ #include <16F84A.h> #fuses HS,NOWDT,PUT #use delay(clock=20000000) #use fast_io(A) #use fast_io(B) #byte port_a=5 #byte port_b=6 int8 counter; #INT_RTCC rtccisr() { ++counter; set_timer0(0xff); } /* 10km/h = 7.1 plus/sec * 20km/h = 14.2 plus/sec * 30km/h = 21.2 plus/sec * 40km/h = 28.3 plus/sec * 50km/h = 35.4 plus/sec * 60km/h ((60 * 1000 * 100 * 10 mm) / 392.5mm) / (60 * 60) = 42.5 plus/sec * 70km/h = 49.5 plus/sec * 80km/h = 56.6 plus/sec * 90km/h = 63.7 pulse/sec * 100km/h = 70.8 plus/sec */ main() { int8 c10, c1, dodown; set_tris_a(4); //set RA2 = input, nokori = output set_tris_b(0); //set all output setup_counters(RTCC_EXT_L_TO_H, WDT_18MS); enable_interrupts(INT_RTCC); enable_interrupts(GLOBAL); output_low(PIN_A4); // A4 gate CLOSE dodown = 0; // do nothing. output_low(PIN_A0); // LED OFF output_low(PIN_B0); // RELAY OFF for(;;) { if(input(PIN_A2)) { // if light off, continue if(dodown == 1) { output_low(PIN_A0); // LED OFF output_low(PIN_B0); // RELAY OFF dodown = 0; // light beam up } delay_ms(1000); // 1 sec timer continue; } // count speed pulse !! set_timer0(0xfe); counter = 0; output_high(PIN_A4); // A4 gate OPEN delay_ms(1000); // 1 sec timer output_low(PIN_A4); // A4 gate CLOSE if(dodown == 1) { if(counter > 21) { // when 30km/h over, light up ! output_low(PIN_A0); // LED OFF output_low(PIN_B0); // RELAY OFF dodown = 0; // light beam up } } else { if(counter < 7) { // when 10km/h under, light down ! output_high(PIN_A0); // LED ON output_high(PIN_B0); // RELAY ON dodown = 1; // light beam down } } } }