| | |
digital clock
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 2
Reputation:
Solved Threads: 0
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.
how to add the minutes value? as well hour and day...thank... S.O.S.....
c Syntax (Toggle Plain Text)
while(1 == 1) { if (0 == DisplayLED) { RA5 = LEDDigit[DisplayValue %10] >> 6; PORTC = LEDDigit[DisplayValue %10] & 0x03F; } else { RA5 = LEDDigit[(DisplayValue /10) & 0x0F] >> 6; PORTC = LEDDigit[(DisplayValue /10) & 0x0F] & 0x03F; } TRISA = TRISA ^ 0b011111; PORTA = PORTA & 0b111100; DisplayLED = DisplayLED ^ 1; // Other Digit Next NOP(); for (i = 0; i < 660; i++); NOP(); j = j + 1; if (100 == j) { DisplayValue++; j = 0; } }
Last edited by WaltP; Mar 13th, 2007 at 1:51 pm. Reason: Please use CODE tags
Well first I'd probably rename DisplayValue to be something more meaningful like DisplaySeconds.
Then I might add
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.
Then I might add
C++ Syntax (Toggle Plain Text)
if ( DisplaySeconds == 60 ) { DisplaySeconds = 0; DisplayMinutes++; }
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.
•
•
Join Date: Mar 2007
Posts: 2
Reputation:
Solved Threads: 0
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
should i add another if...else statement in the while loop? where should i add into if yes. thank
•
•
Join Date: Jul 2005
Posts: 1,678
Reputation:
Solved Threads: 264
Here's an algorhithm in C/C++. You can convert it into whatever you're using.
C++ Syntax (Toggle Plain Text)
int sec = 0; int min = 0; int hour = 0; while(1) { sleep(1000); //delay in milliseconds ++sec; if(sec == 60) { sec = 0; ++min; if(min == 60) { min = 0; ++hour; if(hour == 24) { hour = 0; } } } display(hour, min, sec); }
Last edited by Lerner; Mar 14th, 2007 at 3:55 pm.
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
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
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 :
keep doing this until your minutes adds to 1 hour;
Try this circular loop :
C++ Syntax (Toggle Plain Text)
displayValue = ++displayValue % 60; min = displayValue % 60 + displayValue/60 hour = min % 60 + min/60
![]() |
Similar Threads
- The Vending Machine Game (Posting Games)
- Alarm digital clock assembly language for 8085 microprocessor (Assembly)
- need source code for digital alarm clock using pic16f84a (Assembly)
- Analog clock (Java)
- Timer Question (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Validating input into array C++
- Next Thread: Very simple question
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






