CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

decrement counter in real time

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kamillas



Joined: 24 Oct 2011
Posts: 50

View user's profile Send private message

decrement counter in real time
PostPosted: Sun Mar 04, 2012 1:28 pm     Reply with quote

In my program, I want the LCD displays the value of my delay_ms, as a counter decrement to zero,
example:
time of 500 ms, the display shows me
temp = 500 = 499= 498= 497=496=495=494=.........=0ms
and this account will display in real time, a counter will décémenter


Code:
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock= 4000000)
#use standard_io(a)
#include <lcd_flex>
int  time = 500 ;


#include <stdlib.h>

void main() {
 
   port_b_pullups(TRUE);

   while (TRUE) {
   
        output_high(PIN_A0);               
        delay_ms( time );
        output_low(PIN_A0);


I want to decrement time, real-time.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Mar 04, 2012 2:03 pm     Reply with quote

thats what the PIC timers are for

timer 1 and timer 3 come to mind -

read how they work when driven by Fosc.....

however updating the LCD display at a 1 msec rate
may prove more of a challenge than you expect

your pic will certainly be busy enough
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 04, 2012 5:09 pm     Reply with quote

Quote:
time of 500 ms, the display shows me
temp = 500 = 499= 498= 497=496=495=494=.........=0ms
and this account will display in real time, a counter will décémenter

You can't do this. No one can see numbers that exist for only 1 ms.
Also, the typical 16x2 lcd has a very slow optical update rate.
You probably can only update the lcd at maybe 4 times per second.
I can't test this right now, but that's what I recall from earlier experiments.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

LCD timer limits
PostPosted: Sun Mar 04, 2012 5:46 pm     Reply with quote

What I THINK you are asking for is NOT realistic.

I understand that PCM programmer is now your LCD hero!!

You should have got the message, by now, that an LCD is a VERY VERY SLOW device:-

(1) It will NOT be able to refresh fast enough to count 10ms never mind 1ms.
(2) Even IF it could. ALL that you would SEE is a blur.

An LED matrix CAN work fast enough.
Your eyes will still NOT be able to follow the changing display.

You need to change your design brief.

I'm happy to give guidance/clues/help BUT I will NOT write code.

You COULD get an LCD to count down in 100ms steps, and your eyes MAY be able to follow it.

Is this counter/timer just a small part of a larger project? (If it is please enlighten us.)

Tell us what you REALLY want, and we MAY try to assist.

Mike
kamillas



Joined: 24 Oct 2011
Posts: 50

View user's profile Send private message

for 10ms
PostPosted: Mon Mar 05, 2012 5:41 am     Reply with quote

PCM programmer wrote:

You can't do this. No one can see numbers that exist for only 1 ms.
Also, the typical 16x2 lcd has a very slow optical update rate.
You probably can only update the lcd at maybe 4 times per second.
I can't test this right now, but that's what I recall from earlier experiments.




and if I want, show 500ms, decrementing by 10 ms means that the LCD as I see it: time = 500 ms, after, time = 490, after, time = 480 .......... . up, time = 0, it can be done? in this case what I do.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 5:57 am     Reply with quote

PARTIAL CODE FRAGMENT...

i=500;
do {
your print statement goes here......;
delay_ms(10);
i=i-10;
while(i!=0);
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 6:21 am     Reply with quote

You still won't see it though.
The normal way to do this is to have the fast counter running, and only _write_ the data to the LCD perhaps 10* per second. Most multiplexed LCD's take something like 1/4 second to actually update anyway. Then when whatever happens that is meant to record the time, occurs, you take the full reading from the counter and write this.
If you look at digital watches with stopwatch functions, the display shows the seconds, and then when you hit the 'stop', the tenths and hundredths are displayed.

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 7:39 am     Reply with quote

'we' all know that, but unless he does it, he'll not understad why...
some learn by doing, others read the datasheets...
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 12:56 pm     Reply with quote

More practical might be to count down seconds and show a "spinning baton" made of | / - \ characters to indicate fractions of a second.
_________________
The search for better is endless. Instead simply find very good and get the job done.
kamillas



Joined: 24 Oct 2011
Posts: 50

View user's profile Send private message

1 S
PostPosted: Mon Mar 05, 2012 3:03 pm     Reply with quote

temtronic wrote:
PARTIAL CODE FRAGMENT...

i=500;
do {
your print statement goes here......;
delay_ms(10);
i=i-10;
while(i!=0);


For example, if I have a delay_ms(10000), and I want to display every 1000 ms (1s) is a decrement a counter to 0,
example: lcd displays: time = 10 seconds, after it appears, time = 9 seconds, until ......, time = 0 seconds, what method is used for its
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 3:47 pm     Reply with quote

You could try something like this...

PARTIAL CODE FRAGMENT...
version 2
Code:

i=10;
do {
your print statement goes here......;
delay_ms(1000);
i=i-1;
}while(i!=0);

...or a variation thereof.
kamillas



Joined: 24 Oct 2011
Posts: 50

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 5:54 am     Reply with quote

temtronic wrote:
You could try something like this...

PARTIAL CODE FRAGMENT...
version 2
Code:

i=10;
do {
your print statement goes here......;
delay_ms(1000);
i=i-1;
}while(i!=0);

...or a variation thereof.



Thanks temtronic
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group