Time display on 7-seg 4 digits


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    May 2005
    Posts
    70

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    What is the question chai98a?

    -----------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

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

  4. #4
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    Let you show circuit daigram..and some detail of 3 bottom function.
    I never try about this

  6. #6
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default The Schematic

    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
    Attached Images Attached Images

  7. #7
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

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

    Sougata

  8. #8
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Some Logic help.

    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

  9. #9
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

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

    Sougata

  10. #10
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Thank you.

    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.

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    And who says that religions where out-of-date?

    Sounds really cool to me!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #12
    abeltcb's Avatar
    abeltcb Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chai98a View Post
    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

  13. #13
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    here is circuit ...
    I cannot attached some picture file..
    Attached Images Attached Images  

Similar Threads

  1. Hdsp 21xx display
    By Original in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th June 2012, 20:07
  2. lumex 4 line display
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th August 2009, 17:55
  3. Alarm Time
    By Santana in forum Code Examples
    Replies: 1
    Last Post: - 8th December 2006, 13:58
  4. SMART Serial 4 Digit LCD Display (SMARD4)
    By paul borgmeier in forum Adverts
    Replies: 0
    Last Post: - 5th January 2005, 05:50
  5. WRITE not working
    By servo260 in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 29th December 2004, 02:02

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts