Multiplexing indicators


+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305

    Default Multiplexing indicators

    What I'm trying to end up with is a clock displaying seconds, minutes, hours and maybe a few other things.

    What I've been experimenting with so far is the seconds and minutes displays. The displays are 5082-7300 are hooked up to portc and there LEDs on portd.0 and portb.1. The LEDs are just so I know the program is running. I thought I had a schematic but I saved it in wrong format so I can update it later if needed.

    Code:
    ''*  Notes   :This program will blink a light on portd.1 at      *
    '*          :about a 1 hz rate w/ LED on portb.1 set to 100cps  *
    '*          :                                                   *
    '****************************************************************
    ' This program will count from 0 to 59 using porte.0 and porte.1
    ' without writing a 60.
    ' Now trying to get the displays to sequence they look like they're 
    ' always on.
    'rearranging port outs to resemble final diagram output on portc
    ' portc outputs one and tens properly when latched from porte.1
    
    '--------------------------------------------------clock variables
    
    ticks VAR BYTE
    seconds VAR BYTE
    minutes VAR BYTE
    hours VAR BYTE
    days VAR BYTE
    '-----------------------------------------------my variables
    secondschanged VAR BYTE 'seconds
    x VAR BYTE
    out_tens VAR BYTE
    minutes_changed VAR BYTE 'minutes
    minutes_count VAR BYTE
    tens_minutes VAR BYTE
    out_tens_minutes VAR BYTE
    
    '---------------------------------------------------testing variables
    led1 VAR portb.1
    led2   VAR portd.0 ' blinks at pause rate
    
    trisc = %00000000
    trise = %001
    portc = 0
    porte = 0
    
    cmcon = %00000111 ' comparators off
    adcon0 = %00000000 ' adc off
    adcon1 = %11000110 ' sets AN ports to digital
    ccp1con = %00000000 ' turns comparator module off
    
    latch_enable VAR porte.0' pin 8 on 16f877a
    second_latch_enable VAR porte.1 'pin 9 on 16f877a 
    tens_seconds VAR BYTE ' something for the tens digit to display
    
    '-------------------------------------------DT interrupt area
    wsave   VAR BYTE    $70     SYSTEM    ' alternate save location for W 
                                          ' if using $70, comment wsave1-3
    INCLUDE "DT_INTS-14.bas"    ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
    
    DEFINE osc4
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = %00000001                ; Prescaler = 1:1, TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    preload VAR WORD
    
    preload = 60643 '60643 yeilds exactly 100 Hz w/ 1:1 prescaler 
          
    tmr1l = preload.LowByte
    tmr1h = preload.HighByte
    
    seconds = 0
    tens_seconds = 0
    minutes_count = 0
    tens_minutes = 0
    
    Main:
    '--------------------------------------------increment seconds
    IF ticks > 50 THEN 'seconds counting to 59
         ticks = 0
         seconds = seconds + 1
                 IF seconds > 9 THEN 
                 tens_seconds = tens_seconds + 1
                 seconds = 0
                 ENDIF
          portc = (portc & %11110000) | seconds'tell the port which bits to use
                IF tens_seconds > 5 THEN
                tens_seconds = 0
                minutes_changed = 1
                ENDIF
          out_tens = tens_seconds * 16
          trise = %110 ' porte.0
          portc = (portc & %00001111) | out_tens 'tell the port which bits to use
          HIGH latch_enable  ' enable write
          PAUSE 5
          LOW latch_enable 'disable write
          PAUSE 5
    ENDIF
    
    '-----------------------------------------------increment minutes
    IF minutes_changed = 1 THEN
             minutes_changed = 0
             minutes_count = minutes_count + 1
                 IF minutes_count > 9 THEN 
                 minutes_count = 0
                 tens_minutes = tens_minutes + 1
                 ENDIF
         portc = (portc & %11110000) | minutes_count'tell the port which bits to use
               IF tens_minutes > 5 THEN tens_minutes = 0
              out_tens_minutes = tens_minutes * 16
              trise = %101 ' porte.1
              portc = (portc & %00001111) | out_tens_minutes 'tell the port which bits to use
              HIGH second_latch_enable 'disable write
              PAUSE 5
              LOW second_latch_enable
              PAUSE 5
    ENDIF         
    porte = 0         
    
    TOGGLE led2
    GOTO Main
    
    '---[TMR1 - interrupt handler]------------------------------------
    ToggleLED1:
               t1con.0 = 0
               tmr1l = preload.LowByte
               tmr1h = preload.HighByte
               t1con.0 = 1
         TOGGLE led1
         ticks = ticks + 1
    @ INT_RETURN
    
    END
    First, I know it's running fast. I got impatient waiting for the digits to turn over so I sped it up. I'll fix that later.

    The problem I'm having is with the ones digit in the minutes display. In my program I initially set all the indicators to zero but the minutes ones digit sets to a 1 immediately. As the program counts the ones and tens seconds display works well. When it comes time to chalk up another minute the ones digit shows the correct count only for a second, or as long as the seconds display is zero, then goes back to being a 1.

    Can anybody tell me why or how to fix it so the digit retains the correct number?

    Most of the time your thoughts are always welcome.

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,256

    Default Re: Multiplexing indicators

    First time through, minutes_changed is not initialized to a value (unless I missed it).

    What if you set it to 0 at the top?

    Robert


    EDIT: You set it to a byte, maybe you get "unlucky" and hit a 0.
    Last edited by Demon; - 23rd February 2012 at 21:36.

  3. #3
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305

    Default Re: Multiplexing indicators

    It's always the simplest of things that get you. So in case anyone is interested, tt turns out setting TRISE, GPIOE and GPIOC at the end of the main loop solves the problem. I also set TRISE as an input early on but it wasn't necessary.

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    
    '--------------------------------------------------clock variables
    ticks var byte
    seconds var byte
    minutes var byte
    hours var byte
    days var byte
    '-----------------------------------------------my variables
    secondschanged var byte 'seconds
    out_tens var byte
    minutes_changed var byte 'minutes
    minutes_count var byte
    tens_minutes var byte
    out_tens_minutes var byte
    '---------------------------------------------------testing variables
    led1 var portb.1
    led2   var portd.0 ' blinks at pause rate
    trisc = %00000000
    trise = %111
    portc = 0
    porte = 0
    cmcon = %00000111 ' comparators off
    adcon0 = %00000000 ' adc off
    adcon1 = %11000110 ' sets AN ports to digital
    ccp1con = %00000000 ' turns comparator module off
    latch_enable var porte.0' pin 8 on 16f877a
    second_latch_enable var porte.1 'pin 9 on 16f877a 
    tens_seconds var byte ' something for the tens digit to display
    '-------------------------------------------DT interrupt area
    wsave   VAR BYTE    $70     SYSTEM    ' alternate save location for W 
                                          ' if using $70, comment wsave1-3
    INCLUDE "DT_INTS-14.bas"    ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
    define osc4
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    T1CON = %00000001                ; Prescaler = 1:1, TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    preload var word
    preload = 60643 '60643 yeilds exactly 100 Hz w/ 1:1 prescaler 
          
    tmr1l = preload.lowbyte
    tmr1h = preload.highbyte
    'seconds = 0
    'tens_seconds = 0
    'minutes_count = 0
    tens_minutes = 0
     
    
    Main:
    '--------------------------------------------increment seconds
    if ticks > 10 then 'seconds counting to 59
         ticks = 0
         seconds = seconds + 1
                 if seconds > 9 then 
                 tens_seconds = tens_seconds + 1
                 seconds = 0
                 endif
          portc = (portc & %11110000) | seconds'tell the port which bits to use
                if tens_seconds > 5 then
                tens_seconds = 0
                minutes_changed = 1
                endif
          out_tens = tens_seconds * 16
          trise = %110 ' porte.0
          portc = (portc & %00001111) | out_tens 'tell the port which bits to use
          high latch_enable  ' enable write
          pause 5
          low latch_enable 'disable write
          pause 5
    endif
    '-----------------------------------------------increment minutes
    if minutes_changed = 1 then
             minutes_changed = 0
             minutes_count = minutes_count + 1
                 if minutes_count > 9 then 
                 tens_minutes = tens_minutes + 1
                 minutes_count = 0
                 endif
         portc = (portc & %11110000) | minutes_count'tell the port which bits to use
               if tens_minutes > 5 then
               tens_minutes = 0
               endif
              out_tens_minutes = tens_minutes * 16
              trise = %101 ' porte.1
              portc = (portc & %00001111) | out_tens_minutes 'tell the port which bits to use
              high second_latch_enable 'disable write
              pause 5
              low second_latch_enable
              pause 5
    endif         
    porte = 0         
    trise = %111
    portc = 0
    toggle led2
    pause 100
    GOTO Main
    '---[TMR1 - interrupt handler]------------------------------------
    ToggleLED1:
               t1con.0 = 0
               tmr1l = preload.lowbyte
               tmr1h = preload.highbyte
               t1con.0 = 1
         TOGGLE LED1
         ticks = ticks + 1
    @ INT_RETURN
    End

Tags for this Thread

Posting Permissions

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