Very tired.
If I go for a nap, then when I wake up it will be bedtime
If I go for a nap, then when I wake up it will be bedtime
#define RELOAD_VALUE 8 //generates a 1ms pulse with 4MHz xtal by counting 250 - 2 = 248 unsigned char counter; void interrupt() { counter++; //indicate we've had an int TMR0 = RELOAD_VALUE; INTCON = 0x20; // enable tmr0 ints & clear tmr0 int flag } void main() { TRISIO = 0x3b; //all gpio as inputs, GPIO.2 PIN 5 as output b'0011 1011' CMCON = 0x07; // comparators off, GPIO 0 & 1 & 2 as digitals OPTION_REG = 0x81; //pullups disabled, prescaler div by 4 for TMR0: fosc /4 then /4 = 4us: 250 of which are 1ms while ( GPIO.B1 == 1 ) // wait for start from gun trigger { } TMR0 = RELOAD_VALUE; INTCON.T0IE = 1; //enable tmr0 overflow ints INTCON.T0IF = 0; //clear tmr0 int just in case INTCON.GIE = 1; //and enable interrrupts. while( GPIO.B0 == 1 ) //keep generating pulses until we reach the set count of ms in the 3 4017 decade counters { if ( counter ) //got an interrupt? { GPIO.b2 = 1; //yup, set output bit counter = 0; } delay_us( 100 ); //wait 100us GPIO.b2 = 0; //clear output bit // delay_ms( 1 ); }; while ( 1 ); //all done, just sit here until reset. /*{ if ( counter ) { GPIO.b1 = 1; counter = 0; } delay_us( 100 ); GPIO.b1 = 0; // delay_ms( 1 ); };; //all done.*/ }
Comment