Pic887, New to programming, Clock.
Using PicBasic Pro (new to it this year) and I'm trying to make a relatively simple clock. I'm sure this code isn't that great and there are improvements I can make to it to make it shorter and more simple, but as of now it works ok.
I'm using 3 2-7-Segment displays that are multiplexed.
Anyways, here's the code I'm working off of (remember I just started, also this code still needs to add the 3rd set of 7 segments, but I could figure that out with the advancing from the first set!)
Pretty much I need some help getting each set of 7 segments to count on their own, and then advance the count on the next digit, but making that set of 7 segments still count on their own timer. Hopefully that made sense. I'd like it to just be some tips on how to do it, but if you have to just tell me flat out, that works too.
Thanks, if you have any questions I'll try to answer them the best I can, but remember I'm still new to this.
(If this needs to be posted somewhere else, I will move it)
Attachment 6445
Re: Pic887, New to programming, Clock.
Hi,
There seems to be something wrong with the attachment so I can't look at your code and I'm not exactly shure what you're asking. Do you have a 6 digit display that will display elapsed time in seconds or do you have 3pcs of 2-digit displays that will all display elapsed time in seconds but independently of each other or do you have a 6 digit display that will display elapsed time in hours:minutes:seconds format?
But basically, each time you increment a digit you check if it rolled over, if it did you increment the "next" digit, check if IT rolled over and so on. If you have three digits showing elapsed time in seconds then something like this:
Code:
Ones = Ones + 1
If Ones = 10 THEN ' A single digit can only display 0-9
Ones = 0
Tens = Tens + 1
If Tens = 10 THEN
Tens = 0
Hundreds = Hundreds + 1
ENDIF
ENDIF
The same tecnique can be adopted to any number of digits, to hours:minutes:seconds or a countdown timer etc.
/Henrik.
Re: Pic887, New to programming, Clock.
Yeah sorry about being so unclear. I'm using 3 sets of 2-7 segment displays. I pretty much need the first digit to count and then from there I can just up the count on the others once that digit hits 10.
Here's the code since I cannot get the attachment to ever work.
Cnt var word
Zero var Word
Digit var word
Pattern Var word
digit1 var porta.0
digit2 var porta.1
digit3 var porta.2
digit4 var porta.3
digit5 var porta.7
digit6 var porta.6
First var word
Second var word
Third var word
Fourth var word
Fifth var word
Sixth var word
i var word
ADCON1=7
TRISA=0
TRISB=0
INTCON=%00100000
OPTION_REG=%00000111
TMR0=217
ON INTERRUPT GOTO ISR
INTCON=%10100000
PHILL:
CNT=0
NXT:
zero=0
DIGIT=cnt DIG 5
GOSUB CONVERT
Fourth=~pATTERN
DIGIT=cnt DIG 4
GOSUB CONVERT
Third=~PATTERN
DIGIT=cnt DIG 3
GOSUB CONVERT
Second=~pATTERN
DIGIT=cnt DIG 2
GOSUB CONVERT
First=~PATTERN
DIGIT=cnt DIG 1
GOSUB CONVERT
Sixth=~pATTERN
DIGIT=cnt DIG 0
GOSUB CONVERT
Fifth=~PATTERN
FOR I=1 TO 10
PAUSE 1
NEXT I
cnt=cnt+1
Fifth = Fifth + 1
If Fifth = 10 THEN
Fifth = 0
sixth = sixth + 1
If sixth = 10 THEN
sixth = 0
First = First + 1
endif
endif
GOTO NXT
DISABLE
ISR:
TMR0=216
portb=First
digit5=0
digit6=0
digit4=0
digit3=0
DIGIT2=0
DIGIT1=1
PAUSE 1
DIGIT1=0
portb=Second
DIGIT2=1
PAUSE 1
digit2=0
portb=Third
digit3=1
PAUSE 1
digit3=0
portb=Fourth
digit4=1
PAUSE 1
digit4=0
portb=Fifth
digit5=1
pause 1
digit5=0
portb=Sixth
digit6=1
pause 5
digit6=0
INTCON.2=0
RESUME
ENABLE
CONVERT:
LOOKUP DIGIT,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],PATTERN
PATTERN= PATTERN^$FF
RETURN
END
Any questions I'll try to answer. Sorry for my slow response.