ME Labs, Inc.
719-520-5323
 
Home:
  Developer Resources:

Programming Clues
    Sample Programs
   
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Clues
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     
 

ME Labs, Inc. | 1-719-520-5323 | Example Program - T1G_1934X.pbp

PICBASIC PRO program to demonstrate using Timer1 gate in single-pulse mode to capture single pulse event times.
01' Name        : T1G_1934X.pbp
02' Compiler    : PICBASIC PRO Compiler 2.6
03' Assembler   : MPASM
04' Target PIC  : 40-pin 16F1934 or similar
05' Hardware    : LAB-X1 Experimenter Board
06' Oscillator  : 4MHz external crystal
07' Keywords    : LCDOUT
08' Description : PICBASIC PRO program to demonstrate using Timer1 gate
09' in single-pulse mode to capture single pulse event times.
10'
11 
12' Port B4 connects to port B5 (Timer1 gate), and provides pulse to
13' measure by setting B4 high, pausing, then to setting B4 low. Connect
14' B4 to B5 with a jumper or resistor.
15 
16 
17' Define LCD pins
18Define LCD_DREG  PORTD
19Define LCD_DBIT  4
20Define LCD_RSREG PORTE
21Define LCD_RSBIT 0
22Define LCD_EREG  PORTE
23Define LCD_EBIT  1
24 
25Pval Var Word    ' Holds pulse time from Timer1
26 
27   Gosub Init    ' Hardware initialization routine  
28    
29   Lcdout $fe, 1 ' Clear LCD at POR
30    
31mainloop:
32   PORTB.4 = 1   ' Toggle RB4 on Timer1 gate pin high
33   Pauseus 1550  ' Set pulse time by adjusting pause value here
34   PORTB.4 = 0   ' Toggle Timer1 gate pin low to stop Timer1
35    
36   Pval.LowByte = TMR1L   ' Read Timer1 value
37   Pval.HighByte = TMR1H
38    
39   Lcdout $fe, 1, "High Pulse = ",DEC Pval,"uS"
40    
41   Gosub Reset   ' Clear Timer1 count & reset T1 gate
42   Pause 500   
43   Goto mainloop ' Do it forever
44    
45Reset:
46   T1GCON.3 = 1  ' Reset Timer1 Gate Single-Pulse Acquisition Status bit
47   TMR1H = 0     ' Clear previous count
48   TMR1L = 0
49   Return
50    
51Init:
52   ANSELA = 0    ' porta all digital
53   ANSELB = 0    ' portb all digital
54   ANSELD = 0    ' portd all digital
55   ANSELE = 0    ' porte all digital
56    
57   TRISB = %00100000  ' RB5 = input for T1 gate, RB4 = output to gate
58   PORTB = 0          ' Hold T1 gate low at start
59    
60   T1CON = %00000001  ' Timer1 on, clock is internal Fosc/4
61   T1GCON = %11011000 ' Timer1 gate enabled, active high, single-pulse mode
62    
63   Return
64 
65 
66   End

Download the program file.