• PicŪ Basic


  • CountUntil

    A library module for use withLibrary Manager by JohnGB. This module has been written by Tim Box (Tim on PDS forum). The library module is offered on an as-is basis with no warranty as to its effectiveness, operation or reliability. Users use it at their own risk.

    Adds a new command called CountUntil

    Syntax

    Variable = CountUntil Port1, Pin1, Port2, Pin2, StopPinLevel

    Overview

    Count the number of pulses that appear on pin Until another pin equals the trigger level, and store the result in variable

    Operators

    Variable - a user-defined variable (byte word or dword).

    Port1 - a port or a byte variable or constant that represents the port address that the pulse is being counted on

    Pin1 - a pin number between 0 and 7 represented as a constant or byte that the pulse is being counted on

    Port2 - a port or a byte variable or constant that represents the port address that stops the count

    Pin2 - a pin number between 0 and 7 represented as a constant or byte that stops the count

    StopPinLevel - a constant or variable that represents the logic level to stop the counting 0 or 1

    Code:
    ' Count the pulses that occur on PORTA.0 until PORTA.1 goes high and display the results. 
        Dim WRD As Word          ' Declare a word size variable 
    
    Loop:
        Cls  
        WRD = CountUntil PORTA,0,PORTA,1,1  ' Variable WRD will contain the Count result
        Cursor 1 , 1 
        Print Dec WRD , " "      ' Display the decimal result on the LCD 
        GoTo Loop                ' Do it indefinitely
    Notes:

    The counter is incremented on the rising edge of a transition (low to high).

    The maximum value the count can obtain is 65535


    Download module

    Download: CountUntil