Time display on 7-seg 4 digits
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
Are the shift registers cascades
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.
Code:
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.
Use a blanking Blinking Scheme
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.