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




Bookmarks