View previous topic :: View next topic |
Author |
Message |
Leordxz
Joined: 09 Feb 2013 Posts: 1 Location: Philippines
|
16f877a and keypad as time input |
Posted: Sat Feb 09, 2013 6:33 am |
|
|
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? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Feb 09, 2013 7:10 am |
|
|
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
|
|
Posted: Sat Feb 09, 2013 10:27 am |
|
|
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.... |
|
|
|