Counting led blinks..


Results 1 to 40 of 93

Threaded View

  1. #10
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi,
    I searched in the forum and found a peice of code by Bruce...
    Code:
    DEFINE LCD_DREG PORTBDEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    PAUSE 100
    
    
    TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter
    TRISB.0 = 0 ' RB0 = output for LED
    CMCON = 7   ' All digital
    
    
    i var byte
    i=0
    ' Assign prescaler to WDT for 1:1 prescale on TMR0
    ' TMR0 clock will be from your external input on RA4/T0CKI
    ' Increment on high-to-low transitions
     OPTION_REG = 111000
     
    ' If you prefer, then increment on low-to-high transitions
    ' OPTION_REG = 101000
    Lcdout $fe, 128, "Counter: ", #i 
    pause 100
    Main:
        TMR0 = 0     ' Clear TMR0 count before start
        
    Loop1:
        WHILE TMR0 = 0 ' Wait for high-to-low transition
        WEND           ' on RA4/T0CKI
        PORTB.0 = 1    ' LED on to indicate transition seen 
        i=i+1       ' Increment
        Lcdout $fe, 128, "Counter: ", #i   
        PAUSE 200
        PORTB.0 = 0    ' LED off
        GOTO Main      ' Start over
        END
    Everytime I press RA.4 it toggle RB0, I also put a variable that will display the value to the LCD, from the code I observed (please correct me if I wrong).
    a. Timer0 is selected
    b. The signal entry is RA.4
    c. It increments on low-to-high transitions
    d. Pre scale value is 1:2 (000 of Bits 2,1)
    d. The configuration setting used OPTION_REG = 111000

    So if connect the multi coin acceptor to the RA.4 this should count the number of pulse?

    thanks in advance,
    tacbanon
    Last edited by tacbanon; - 1st October 2011 at 06:01.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts