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

pic16f877a timer

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



Joined: 04 Aug 2020
Posts: 1

View user's profile Send private message

pic16f877a timer
PostPosted: Tue Aug 04, 2020 6:39 am     Reply with quote

Hello Dear,

I have a 1 button if I press 3 seconds than continue to project.

How I can do that ?

Thank you

Code:

// 4-Digit digital counter using PIC16F877A
// Common anode 7-segment display
// https://simple-circuit.com/
 
#include <16F877A.h>
#use delay(crystal=8000000)
 
short s;                       // Used to know button position
unsigned int digit, digit1, digit10, digit100,digit1000;
unsigned long i = 0;
unsigned int seg(unsigned int num) {
  switch (num) {
    case 0 : return 0xC0;
    case 1 : return 0xF9;
    case 2 : return 0xA4;
    case 3 : return 0xB0;
    case 4 : return 0x99;
    case 5 : return 0x92;
    case 6 : return 0x82;
    case 7 : return 0xF8;
    case 8 : return 0x80;
    case 9 : return 0x90;
    }
}
void main(){
  while(TRUE){
    if(input(PIN_D0) == 1)
      s = 1;
    if(s == 1) {
      if(input(PIN_D0) == 0) {
       s = 0;
       i++;
       if(i > 9999)
         i = 0;
      }
    }
    digit = i % 10;
    digit1 = seg(digit);
    output_c(0x0F);           // Turn off all displays
    output_b(digit1);         // Send ones digit
    output_c(0x07);           // Turn on display for ones
    delay_ms(2);
    digit = (i / 10) % 10;
    digit10 = seg(digit);
    output_c(0x0F);           // Turn off all displays
    output_b(digit10);        // Send tens digit
    output_c(0x0B);           // Turn on display for tens
    delay_ms(2);
    digit = (i / 100) % 10;
    digit100 = seg(digit);
    output_c(0x0F);           // Turn off all displays
    output_b(digit100);       // Send hundreds digit
    output_c(0x0D);           // Turn on display for hundreds
    delay_ms(2);
    digit = (i / 1000) % 10;
    digit1000 = seg(digit);
    output_c(0x0F);           // Turn off all displays
    output_b(digit1000);      // Send thousands digit
    output_c(0x0E);           // Turn on display for thousands
    delay_ms(2);
    }
}
temtronic



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

View user's profile Send private message

PostPosted: Tue Aug 04, 2020 7:39 am     Reply with quote

You can check the CCS manual... !!!

'How do I wait only a specified time for a button press?'

is in the FAQ section.
Slightly modified, it could do what you want...

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Aug 04, 2020 7:53 am     Reply with quote

Or look at previous threads. For example:

<http://www.ccsinfo.com/forum/viewtopic.php?t=58888>
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