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.
' 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

           

Download the program file.