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