' Name : T1G_1934X.pbp ' Compiler : PICBASIC PRO Compiler 2.6 ' Assembler : MPASM ' Target PIC : 40-pin 16F1934 or similar ' Hardware : LAB-X1 Experimenter Board ' Oscillator : 4MHz external crystal ' Keywords : LCDOUT ' Description : PICBASIC PRO program to demonstrate using Timer1 gate ' in single-pulse mode to capture single pulse event times. ' ' Port B4 connects to port B5 (Timer1 gate), and provides pulse to ' measure by setting B4 high, pausing, then to setting B4 low. Connect ' B4 to B5 with a jumper or resistor. ' Define LCD pins Define LCD_DREG PORTD Define LCD_DBIT 4 Define LCD_RSREG PORTE Define LCD_RSBIT 0 Define LCD_EREG PORTE Define LCD_EBIT 1 Pval Var Word ' Holds pulse time from Timer1 Gosub Init ' Hardware initialization routine Lcdout $fe, 1 ' Clear LCD at POR mainloop: PORTB.4 = 1 ' Toggle RB4 on Timer1 gate pin high Pauseus 1550 ' Set pulse time by adjusting pause value here PORTB.4 = 0 ' Toggle Timer1 gate pin low to stop Timer1 Pval.LowByte = TMR1L ' Read Timer1 value Pval.HighByte = TMR1H Lcdout $fe, 1, "High Pulse = ",DEC Pval,"uS" Gosub Reset ' Clear Timer1 count & reset T1 gate Pause 500 Goto mainloop ' Do it forever Reset: T1GCON.3 = 1 ' Reset Timer1 Gate Single-Pulse Acquisition Status bit TMR1H = 0 ' Clear previous count TMR1L = 0 Return Init: ANSELA = 0 ' porta all digital ANSELB = 0 ' portb all digital ANSELD = 0 ' portd all digital ANSELE = 0 ' porte all digital TRISB = %00100000 ' RB5 = input for T1 gate, RB4 = output to gate PORTB = 0 ' Hold T1 gate low at start T1CON = %00000001 ' Timer1 on, clock is internal Fosc/4 T1GCON = %11011000 ' Timer1 gate enabled, active high, single-pulse mode Return End