'12f683 30.01.14 Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY Define CONF_WORD = 0x33c4 OSCCON = %01100000 'Internal 4MHz osc CMCON0 = 7 'Comparators off WPU = 0 'Internal pull-ups = off OPTION_REG = %10000000 'Pull ups, TMR0, Prescaler T1CON = %00111001 '0x30 = 8:1, so thats 1MHz/8= 125KHz or 8uSec PIE1.TMR1IE = 1 'Timer 1 Overflow Interrupt Enable bit PIR1.TMR1IF = 0 'Timer 1 Overflow Interrupt Flag bit-1 = Timer 1 register overflowed (must be cleared in software) TMR1L = %11011100 TMR1H = %00001011 INTCON = %11000000 ANSEL = %00000011 '0x03 'Selecting pins Analogue Digital etc ADCON0 = %00000101 'A/D 0x85? TRISIO.0 = 1 'PIN 7 as AN in (TRISIO = %00001011) TRISIO.1 = 1 'PIN 6 as AN in TRISIO.2 = 0 'PIN 5 as GLED TRISIO.3 = 1 'PIN 5 as input (IN ONLY) TRISIO.4 = 0 'PIN 4 TRISIO.5 = 0 Dim an0 As Word 'Use DIM or SYMBOL Dim an1 As Word an0 = 0 an1 = 0 Dim t As Word 't = Ticks in the INTERRUPT Dim firstpulse As Word 'Check Byte or word Dim secondpulse As Word Enable loop: Adcin 0, an0 'Sets first pulse Adcin 1, an1 'Sets second pulse If an0 >= 100 Then GP2 = 0 'ON IN SIMULATOR = OFF firstpulse = an0 WaitMs an0 firstpulse = 0 Else GP2 = 1 'OFF IN SIMULATOR = ON Endif WaitMs 5000 If an1 >= 100 Then GP2 = 0 'ON IN SIMULATOR = OFF secondpulse = an1 WaitMs an1 secondpulse = 0 Else GP2 = 1 'OFF IN SIMULATOR = ON Endif WaitMs 5000 Goto loop End On Interrupt Save System PIR1.TMR1IF = 0 t = t + 1 TMR1L = %11011100 'L + H = decimal 65536-62500=3036] = 8uSec*62500 = 0.5Sec==Count up from 3036 decimal To 65536 TMR1H = %00001011 '='Then roll over To 0000 Count And generate an Interrupt every 0.5sec Resume