digital clock

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 2
Reputation: vedybird is an unknown quantity at this point 
Solved Threads: 0
vedybird vedybird is offline Offline
Newbie Poster

digital clock

 
0
  #1
Mar 13th, 2007
i face a problem, im doing a programing that program into the PIC16F684. im doing a digital clock, now i only able to show the second value that display 1 to 60, i dont know how to do the minute value. im using while loop.
  1. while(1 == 1)
  2. {
  3. if (0 == DisplayLED)
  4. {
  5. RA5 = LEDDigit[DisplayValue %10] >> 6;
  6. PORTC = LEDDigit[DisplayValue %10] & 0x03F;
  7. }
  8. else
  9. {
  10. RA5 = LEDDigit[(DisplayValue /10) & 0x0F] >> 6;
  11. PORTC = LEDDigit[(DisplayValue /10) & 0x0F] & 0x03F;
  12. }
  13. TRISA = TRISA ^ 0b011111;
  14. PORTA = PORTA & 0b111100;
  15. DisplayLED = DisplayLED ^ 1; // Other Digit Next
  16.  
  17. NOP();
  18. for (i = 0; i < 660; i++);
  19. NOP();
  20.  
  21. j = j + 1;
  22. if (100 == j)
  23. {
  24. DisplayValue++;
  25. j = 0;
  26. }
  27. }
how to add the minutes value? as well hour and day...thank... S.O.S.....
Last edited by WaltP; Mar 13th, 2007 at 1:51 pm. Reason: Please use CODE tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: digital clock

 
0
  #2
Mar 14th, 2007
Well first I'd probably rename DisplayValue to be something more meaningful like DisplaySeconds.

Then I might add
  1. if ( DisplaySeconds == 60 ) {
  2. DisplaySeconds = 0;
  3. DisplayMinutes++;
  4. }

I gather from your code you have a pair of 7-segment displays for displaying seconds.
Do you have another pair for the minutes as well.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 2
Reputation: vedybird is an unknown quantity at this point 
Solved Threads: 0
vedybird vedybird is offline Offline
Newbie Poster

digital clock

 
0
  #3
Mar 14th, 2007
yeah, i got the right circuit diagram just dont know how to write the program to apply the minutes. i had connected 4 7segments to the 4 transistors and the 4 transistors connected to RA0, RA1, RA2 and RA3 on the PIC16F684.
should i add another if...else statement in the while loop? where should i add into if yes. thank
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,678
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 264
Lerner Lerner is online now Online
Posting Virtuoso

Re: digital clock

 
0
  #4
Mar 14th, 2007
Here's an algorhithm in C/C++. You can convert it into whatever you're using.
  1. int sec = 0;
  2. int min = 0;
  3. int hour = 0;
  4. while(1)
  5. {
  6. sleep(1000); //delay in milliseconds
  7. ++sec;
  8. if(sec == 60)
  9. {
  10. sec = 0;
  11. ++min;
  12. if(min == 60)
  13. {
  14. min = 0;
  15. ++hour;
  16. if(hour == 24)
  17. {
  18. hour = 0;
  19. }
  20. }
  21. }
  22. display(hour, min, sec);
  23. }
Last edited by Lerner; Mar 14th, 2007 at 3:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: digital clock

 
0
  #5
Mar 14th, 2007
Well what you do in software depends entirely on what you've done with the hardware.

Say for example, you use 4 bits to drive one 7-segment display, then use the other 4 bits to choose one of 4 displays

Say
bit 7 selects the 10's for M
bit 6 selects the units for M
bit 5 selects the 10's for S
bit 4 selects the units for S
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 2
Reputation: nagarajuamrabad is an unknown quantity at this point 
Solved Threads: 0
nagarajuamrabad nagarajuamrabad is offline Offline
Newbie Poster

Re: digital clock

 
0
  #6
Jul 30th, 2009
plz i need full program of digital clock in c++

giv me peply
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 2
Reputation: nagarajuamrabad is an unknown quantity at this point 
Solved Threads: 0
nagarajuamrabad nagarajuamrabad is offline Offline
Newbie Poster

Re: digital clock

 
0
  #7
Jul 30th, 2009
digital clock program code is needed..try to solve my probs.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,189
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 149
firstPerson's Avatar
firstPerson firstPerson is online now Online
Veteran Poster

Re: digital clock

 
0
  #8
Jul 30th, 2009
when your display value reaches 60, you add 1 to minutes, and
keep doing this until your minutes adds to 1 hour;

Try this circular loop :
  1. displayValue = ++displayValue % 60;
  2. min = displayValue % 60 + displayValue/60
  3. hour = min % 60 + min/60
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC