PDA

View Full Version : Time display on 7-seg 4 digits



chai98a
- 28th January 2007, 05:19
Here is sample code of time display on 7 seg
we try on pic16f877a ,DS1307


Code:
Define LOADER_USED 1
define OSC 4
include"modedefs.bas"
Digits VAR PORTD
SEGMENTS VAR PORTC
SO var portc.6 ' tx
DPIN var PORTd.5 'I2C DATA PIN ds1307,with 4K7 pull up
CPIN var PORTd.6 'I2C CLOCK PIN with pulled up resister 4K7

B1 var byte
B2 var byte
B3 var byte
I VAR BYTE
N VAR BYTE
VALUE VAR WORD

BB var byte
B_H var byte
B_L var byte
B_W VAR WORD
SEC VAR BYTE
M VAR BYTE
HR VAR BYTE
TIMES VAR WORD

TRISB = $00
Portb = $00
TRISc = $00 ' Set segment pins to output
'portc = $00
TRISd = $00 ' Set digit pins to output
'portd = $ff

' Setting time & date to 21:58:00
I2CWRITE DPIN,CPIN,$D0,$00,[$00,$26,$11] ' Write to DS1307

pause 10

loop:
i2cread dpin,cpin,$d0,$00,[b1,b2,b3]
pause 10

BB=B1
gosub conv
SEC = ((B_H*10)+B_L)
'serout SO,t9600,["sec ",#SEC,10]
BB=B2
gosub conv
M=(B_H*10)+ B_L
'serout SO,t9600,["Min ",#M,10]
BB=B3
gosub conv
hR=(B_H*10)+ B_L
'serout SO,t9600,["Hour ",#HR,":",#M,":",#SEC,10]
VALUE = ((HR*100) + M)
'serout SO,t9600,["TIMES ",#TIMES,10]
gosub display_time
pause 1
goto loop
conv:
B_L=BB&%00001111
B_H=BB&%11110000
B_H=B_H>>4

return

display_TIME:
dot var byte

For i = 0 To 4 ' Loop through 4 digits

n = Value Dig i ' Get digit to display

' Gosub display1 ' Display the value
Digits = $ff

Lookup n, [$3F, $06, $5B, $4F, $66, $6D, $7D, $07, $7F, $6F,_
$77, $7C, $39, $5E, $79, $71, $0FF], Segments

if dot < 100 then ' Flishing dot precess
If i = 2 then segments = segments + 128 'Digit 2 show dot
Digits = ~Dcd i
dot = dot+1
else
dot = dot+1
If dot < 254 then
Digits = ~Dcd i
else
dot = 0
digits = ~dcd i
endif
endif

PAUSE 1 'INCREASE BRITE OF LED

NEXT i

RETURN

End

sayzer
- 28th January 2007, 10:06
What is the question chai98a?

-----------------

chai98a
- 29th January 2007, 02:02
About code is work no problem we post for share idea for other peple.
"Code Example " is forums for place with sample code with working right...

charudatt
- 14th February 2007, 19:13
Hello chai98a

Thank you for your code. I am also trying the same stuff with some 10 voice alarms at this end. I have 3 buttons to spare to enter the alarm.

I am looking for some Idea to SET the RTC clock time with just three buttons and 4 digit display.

Any help.

chai98a
- 16th February 2007, 06:10
Let you show circuit daigram..and some detail of 3 bottom function.
I never try about this

charudatt
- 16th February 2007, 06:43
Hello Chai98a,

Ok, here's the schematic. I have just 3 buttons to set the RTC time.

That is not the problem but the problem is the way to set the RTC with a 4 digit - 7 Segment display.

The display type is 74HC595 connected to each of the digit.

regards

sougata
- 18th February 2007, 15:08
Dear Charu,

It is important to know how you have hooked up your 74HC595 to your displays. With the OE (Pin 13) tied to ground and the RESET(Pin 10) tied to the VDD. You should be dealing with at least 3 pins , Shift_Clock (Pin 11), Serial Data In (Pin 14) and Latch (Pin 12) hooked to your PIC. If you have multiple digits each driven by a 74HC595 then Pin9 from the first one goes to PIN 14 of the second and so on. Thus you share the Clock and the Latch of all thems in common. Normally you would hookup the Q0to Q7 outputs of the shift register to the seven segment --> dp,G,F,E,D,C,B,A . This is so because the bit you stuff in first goes to the last (shifted as supposed to be)

Now for some code examples:

Lets assume S_CLK is an alias for the clock line, S_DAT is an alias for the Serial Data line and S_LAT is an alias for the Latch Line.

Also let the characters to load for each display is DISP1, DISP2, and so on.

Please note that you would need a lookup table to convert binary values into proper segment data before dumping.




S_DAT= 0 : S_CLK= 0 : S_LAT= 0 ' MAKE SURE THE CONTROL LINES ARE LOW

S_DAT = DISP4.0 : S_CLK=1:S_CLK = 0 ' PUSH THE FIRST BIT
S_DAT = DISP4.1 : S_CLK=1:S_CLK = 0 ' PUSH NEXT
S_DAT = DISP4.1 : S_CLK=1:S_CLK = 0 ' PUSH NEXT
"
"
"
"
' REPEAT FOR OTHER DISPLAY DATA AS WELL
S_LAT = 1 : S_DAT = 0 : S_LAT = 0 ' LATCH THE DATA ON THE 595



This could be done in modular way using FOR-NEXT loop. But if you are using an array for your display data then PBP does not support modifiers like
S_DAT = DISP[0].I
But it can be done by dumping it to a temporary variable.

Hope this helps.

I have used 595s in moving display app and cascades 24 of them. PCB layout and some sort of slew rate control, shared line drive and termination may be necessary if it is a long chain. For such app consider using STP16C596.

charudatt
- 18th February 2007, 16:55
Hello Sougata,

I have got the code up and working for the HC595 and is working good. The clock is up and running and I can enter the alarm timing and trigger segment perfectly, so the problem is not the code help in driving the HC595 but some logic help in setting the clock with 3 pins and 4 digits for Hours and Mins.

I would be working on setting two digits at a time which would be for Hours and Mins, Blank the other two digits so that it does not confuse. 1 switch to shift between Hours , mins , Ack change and come out of the setting mode and the other two switches simply to incr , decr the values of Hours and Mins.

Just wondering if there was any other way of setting the clock with three buttons and 4 digits.

regards

sougata
- 19th February 2007, 06:29
Dear Charu,

There are a number of possibilities. With your circuit posted I have found that it is using a solid state voice recorder as well. So it can be like this:

Let us assume the switches are mode, plus and minus.

1. When the mode switch is pressed once
--> Annonce "Set Minutes", Blank the Hour, and directly increment of decrement minute variable in the clock.

2. When presssed again
--> Annonce "Set Hour", Blank the minutes and inc/dec Hour

3. One more press
--> Set Alarm Minutes

4. One more press
--> Set Alarm Hours

5. Quit

You can also use a counter in the background which increments automatically and is cleared on any press of either the plus or minus button. So when your counter reaches a preset number of seconds you can use this to auto quit from the menu. I use this type of setting in all my menu driven app. So pressing a menu button and doing nothing for sometime returns the system to its normal operating condition.

charudatt
- 19th February 2007, 07:05
Hello Sougata,

As I told you , the alarm part of the project is complete and is fully functional. Its a bit complicated as it includes 10 preset alarms in day and each of the alarm can have any segment palyed from the audio chip as preset by the user.

OK , I got the cue from your post on how to go about setting the RTC time in Hours and Mins.

Thank you.

Project:

Basically this is a Mantra Chanter I made for a religious faction called Brahmakumari for their deciples. It is just supposed to chant a particular mantra preset by the user, at a particular time in the day. There are in all 10 alarms and upto 16 mantras to choose from. Mantra is stored on API4000 OTP voice module from Aplus capable of storing upto 60 Mins of audio at 8 Kbps sampling rate.

mister_e
- 19th February 2007, 13:07
And who says that religions where out-of-date?

Sounds really cool to me!

abeltcb
- 23rd February 2007, 02:31
Here is sample code of time display on 7 seg
we try on pic16f877a ,DS1307


Code:
Define LOADER_USED 1
define OSC 4
include"modedefs.bas"
Digits VAR PORTD
SEGMENTS VAR PORTC
SO var portc.6 ' tx
DPIN var PORTd.5 'I2C DATA PIN ds1307,with 4K7 pull up
CPIN var PORTd.6 'I2C CLOCK PIN with pulled up resister 4K7
.....................................

End
Hi,
I would like to try your code, do you have the circuit?
thanks

chai98a
- 5th March 2007, 07:24
here is circuit ...
I cannot attached some picture file..