Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

toggle led every 1sec rtc/7-segment clock display xc8

Status
Not open for further replies.

saramah

Member level 3
Joined
Apr 25, 2018
Messages
64
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
689
All things are going correct in my clock with rtc and 6-digit 7segments to display the h/m/s coded in xc8.
I intend to put led in between hour and minute segments that will blink every 500 mses ON and 500msec OFF. For that I dont want to configure it with timer inerrupt.
With the below code, and this has been put under //main()


Code C - [expand]
1
2
3
4
LEDPORT|=1<<secLed;
 __delay_ms(500);
 LEDPORT&=~(1<<secLed);
__delay_ms(500);



If I use delay loop, instead of above inbuilt delay function(" __delay_ms()" ), the same things is happening,
The things are,
When start sumulation in proteus, the display of all segments are disappearing due to this delay and again appearing and continue the things coninuously in same manner.
So, how can i get rid of from this manner.
thx
 

Without seeing all the code I would guess you are blocking execution of the display routine.
Every time your main code is executed, which I would guess is in a loop selecting which digit is showing, you introduce a 1 second delay with your new code.
Instead, if you are keeping a count of seconds in your timer, use something like this:

if(Seconds & 0x01) LEDPORT |= (1 << secLed);
<secled;
else LEDPORT &= ~(1 <<secled);[ code]
< secLed);

I've assumed your variable counting seconds is called 'Seconds' in the example.
What it does is check the least significant bit of the seconds count, in other words whether the second number is odd or even and it then sets or resets the 'secLed' bit accordingly.

Brian.</secled);[></secled;
 

Hi,

From your question.... I assume you didn't write the clock code on your own?

Klaus
 

In your code if you have not used timer interrupt for display driving and if you have used 1 ms delay for each digit display then there will be 6 ms delay for digits display.
Find how much delay the RTC read code takes in the main loop.

solution

//say 6 ms for digits display
//say 650 ms for rtc read
//650 + 6 = 656 ms, 1000 ms - 656 = 344 ms
//call __delay_ms(344);
//Led = ~Led;
 

hi,
betwixt::
Code:
if(Seconds & 0x01) LEDPORT |= (1 << secLed);
<secled;
else LEDPORT &= ~(1 <<secled);
 < secLed);
Doing so, then get 2hz. 1sec on and 1sec off.
i need 1hz. ie, 500ms on and 500off.
for that i have this..
Code:
    if ((sec & 0x01)|| (sec | 0x01))
    {
     
        blink_led = 1;
        for (int i=0; i<=1500; i++);
        
            blink_led = 0;
        
    }

Is this will correct, i am using 8mhz internal crystal with 16f887.


@baileychic::
i am not getting extected output. ie, disappearing remains on display.
u said -
Code:
//say 650 ms for rtc read
how do i calculate this rtc read code delay>>will u plaese explain..

@KlausST::
I have not write all at all, am customize the code for my own purpose from several site. and expecting to discover good one with the help of you. Tnx Kst.
Tnx all of you.
 

Hi,

I can only repeat what Brian already wrote:
Without seeing all the code I would guess
But "guessing" is not a professional way to design software or hardware.

So if you expect to get good and useful answers, then you need to provide good and useful informations first.

More detailed:
The answer depends on how your current code works. There are several ways:
* untimed loop reading RTC
* timed by microcontroller timer
* timed by RTC
* interrupt driven, or polling
....and so on...

Klaus
 

Doing so, then get 2hz. 1sec on and 1sec off.
i need 1hz. ie, 500ms on and 500off.
That isn't what the subject heading says and 1 second off then one second on is 0.5Hz not 2Hz!

However, adding a delay will never work, what you are doing is stopping execution of the program completely until the delay ends, that means all the other functions, including driving the LED are also stopped. You need a method that allows the remainder of the program to continue running and just check to see if the LED should toggle as part of normal operation.

Again, without seeing your full code it is difficult to advise but by far the best method is to use interrupts, if you don't want to do that, how do you count seconds at the moment? If you are counting something to wait until one second has elapsed, use that counter instead of "Seconds" in the code I gave and it should work as you want it.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top