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

increment

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



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

increment
PostPosted: Sun May 16, 2010 9:02 pm     Reply with quote

What I need is when I press button2, I want to increment after 0.5 seconds the numbers shown at two 7-segment displays.
The code that I am using is below. When I press button2 it is incrementing very fast both digits.
Code:

if (input(button2) == 0)
  {
   increment = increment +1;
   vdezena = increment/10;
   vunit = increment - (vdezena*10);
   output_b(dezena[vdezena]);
   delay_ms(5);
   output_b(unit[vunit]);
   delay_ms(5);
  }

thank you very much

nina
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 16, 2010 9:13 pm     Reply with quote

Quote:
I want to increment after 0.5 seconds the numbers

The simple answer is to put a 500 ms delay statement at the start of
the if() block.

Ideally, you wouldn't check the switch with an if() statement, instead
you would use a debounce routine. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=42285&highlight=debounce+button
nina



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

increment
PostPosted: Mon May 17, 2010 9:52 am     Reply with quote

I tried put a delay after if but the 7 segment display responsible to show output_b(dezena[vdezena]) start flashing.

What can I do to solve this problem?

Thank you

Nina
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 17, 2010 5:50 pm     Reply with quote

Use the pushbutton code shown in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=19874&start=1


Connect a push-button switch and a pull-up resistor to a pin on your PIC:
Code:

           +5v
            |
            <
            > 4.7K       
            <         ___ Push button switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
                              --- GND
                               -   


Then change your main program so it's similar to this:
Code:

void main()
{
int8 increment = 0;

while(1)
  {
   wait_for_keypress();

   increment++;

   // Put the 7-segment code here.
   
  }

}
nina



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

increment
PostPosted: Wed May 19, 2010 5:00 pm     Reply with quote

Thank you for all responses...the way I solved the problem was:
Code:

while (input(button1) == 0)
{
output_b(dezena[vdezena]);
delay_ms(5);
output_b(unidade[vunidade]);
delay_ms(5);

if (input(button2) == 0)
  {
   a++;
   if (a == 50)
     {
      incrementa = incrementa +1;
      vdezena = incrementa/10;
      vunidade = incrementa - (vdezena*10);
      output_b(dezena[vdezena]);
      delay_ms(5);
      output_b(unidade[vunidade]);
      delay_ms(5);
      a = 0;
     }
  }
}

It is working but I would like to know if there is another way to do this...

tks again

nina
nina



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

increment
PostPosted: Sat May 22, 2010 1:55 pm     Reply with quote

What is the way and/or hardware that I can use to "save" some pins at PIC when using 7 segments display?
Suppose I need use 6 display 7 segments. How to "save" pins at PIC?

Thank you

Nina
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 22, 2010 2:04 pm     Reply with quote

I think you are asking how to multiplex the pins on one 7-segment display.
Normally, the multiplexing is done with several displays. 7 pins are used
on the PIC to display the segments. Then other pins on the PIC are
used to enable each display (each digit).
Scroll down to Figure 6 on this webpage. It shows how to connect the
wires.
http://www.melabs.com/resources/articles/ledart.htm
Is this what you really want to do ?
nina



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

multiplex
PostPosted: Sat May 22, 2010 3:41 pm     Reply with quote

That is what I am looking for...

Where can I find some examples (CCS) about multiplexing 7 segment display.

Thank you for this informations
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