How to blink 8 LEDs at different rates- concurrently?


Results 1 to 15 of 15

Threaded View

  1. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    OUCH!

    After running my loop in the SIM.
    I realized the timing was Waaaayyyyy OFF.
    Fortunately, the other examples were "OFF" too ... just not as far.

    I've always said PAUSE is the worst statement in the BASIC language.
    It got me again.

    Here's a version that should compensate ...
    It uses the CCP module in "Compare" mode to create a precise 10mS interval.
    So when you give a delay value of 50, it actually takes 500mS, on the nose.

    Sorry, it's more than 8 lines now.
    Code:
    DEFINE OSC 4
    DEFINE BLINKYFREQ 100  ; 10mS periods
    
    DATA 50,22,38,75,17,40,62,13  ; default periods for each Output
    ;----------------------------------------------------------------
    CCPR1val  CON EXT      : @CCPR1val = (OSC*1000000/4)/ BLINKYFREQ
    CCPR1     VAR WORD EXT : @CCPR1 = CCPR1L
    Timer1    VAR WORD EXT : @Timer1 = TMR1L
    CCPIF     VAR PIR1.2
    
    LoopLED   VAR BYTE[8]
    LoopCON   VAR BYTE[8]
    x         VAR BYTE
    
    ;----[Initialize]------------------------------------------------
    FOR x = 0 to 7         ; load the periods from EEPROM
        READ x, LoopCON(x)
    NEXT X
    ;-- setup CCP1 and Start Timer1 --
    CCPR1   = CCPR1val     ; set compare value
    CCP1CON = %00001011    ; compare mode, special event 
    Timer1  = 0            ; clear Timer1
    T1CON.0 = 1            ; start Timer1
    
    TRISB = 0              ; PORTB all OUTPUT
    
    ;----[Main Program Loop]----------------------------------------
    Main: 
        x = (x + 1) // 8
        PORTB.0(x) = !(LoopLED(x) < LoopCON(x))
        LoopLED(x) = (LoopLED(x) + 1) // (LoopCON(x) << 1)
        IF x != 7 THEN Main
      Waiting: IF !CCPIF THEN Waiting
        CCPIF = 0
    GOTO Main
    Cheers,
    Last edited by Darrel Taylor; - 26th April 2010 at 03:59. Reason: Minor modifications
    DT

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