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

16f877a and keypad as time input

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



Joined: 09 Feb 2013
Posts: 1
Location: Philippines

View user's profile Send private message

16f877a and keypad as time input
PostPosted: Sat Feb 09, 2013 6:33 am     Reply with quote

hello folks, i'm having a problem. I'm making a clock. I have code for the real time clock, it's just that I want that I can first enter the current time before the clock starts ticking. I'm using PIC16f877a and a keypad as an input medium.

Currently, I can enter digits to 4 segments by a 4X3 keypad, and I'm using 4511 ICs for the common cathode seven segments.

Here's my code:

Code:


#include <16F877A.H>
#fuses HS, NOWDT
//#fuses INTRC_IO
#fuses NOBROWNOUT
//#fuses NOMCLR
#fuses NOLVP
#include "KBD.C"   //keypad library
char k,temp;
int h1,h2,m1,m2,flag;
#use delay(clock=20M)
#define PIN_SEG1 PIN_C0
#define PIN_SEG2 PIN_C1
#define PIN_SEG3 PIN_C2
#define PIN_SEG4 PIN_C3
#define LED PIN_D0

void getkeypadval(){
   Delay_ms(1);
   k=kbd_getc();
   if(k!=0){
      temp=k;   
      ++flag;      
      };
}

void set_h1(){
      output_a(temp);   
      output_low(PIN_SEG1);output_high(PIN_SEG1);
}
void set_h2(){
      output_a(temp);
      output_low(PIN_SEG2);output_high(PIN_SEG2);
}
void set_m1(){
      output_a(temp);
      output_low(PIN_SEG3);output_high(PIN_SEG3);
}
void set_m2(){
      output_a(temp);
      output_low(PIN_SEG4);output_high(PIN_SEG4);
}
void main(){
   for(;;){
      getkeypadval();
      if(flag==1){
         set_h1();
      }
      if(flag==2){
         set_h2();
      }
      if(flag==3){
         set_m1();
      }
      if(flag==4){
         set_m2();
         
      }
      if(temp=='*'){
         

      };
}
}



my problem is the trapping, that time clock is 24Hours format.

here's the proteus schematic diagram.




i want the user to only enter 0,1 and 2 for the first segment(h1)
numbers 0 to 3 for the second seven segment(h2)
numbers 0 to 5 for the third(m1)
and lastly 0 to 9 for the last segment(m2)

thanks a lot in advance sirs
_________________
Help there? Smile
Mike Walne



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

View user's profile Send private message

PostPosted: Sat Feb 09, 2013 7:10 am     Reply with quote

Your schematic is too small to be of any value.

Forget Proteus.

Surely you want 0-9 for the hours units.

Simply ignore values which are outside the acceptable range.

Build some real hardware, come back if (when) you're stuck.

Mike
temtronic



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

View user's profile Send private message

PostPosted: Sat Feb 09, 2013 10:27 am     Reply with quote

You really should look at the examples in the examples folder that CCS kindly supplies.There is an example that contains the information you need....
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