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

interrupts with a 4x4 keypad

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



Joined: 28 Apr 2012
Posts: 10

View user's profile Send private message

interrupts with a 4x4 keypad
PostPosted: Sat Apr 28, 2012 9:09 pm     Reply with quote

Can you explain how to use interrupts with a 4x4 keypad to check for the button presses while other coding executes ?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Apr 28, 2012 9:23 pm     Reply with quote

You need to learn how to use search before coming in here and asking
questions:

http://www.ccsinfo.com/forum/viewtopic.php?t=19726
_________________
Google and Forum Search are some of your best tools!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 29, 2012 8:14 pm     Reply with quote

Quote:

Can you explain how to use interrupts with a 4x4 keypad to check for the
button presses while other coding executes ?

The link below has sample code to do that. It polls the keypad at 10 ms
intervals in a Timer interrupt routine. If a key is pressed, it puts the
key in a circular buffer which you can check from your main code.
It's similar to Ex_sisr.c, except it's for the keypad. With this method
you no longer have to worry about polling the keypad. It's done for you
in the background. All you have to do is to occasionally check if a key
is available in the buffer, and then get it:
http://www.ccsinfo.com/forum/viewtopic.php?t=42707&start=4
vpowerrc



Joined: 28 Apr 2012
Posts: 10

View user's profile Send private message

PostPosted: Mon Apr 30, 2012 11:42 am     Reply with quote

I tried that code on Proteus. But it didn't display anything. Why is that ?
Here's my diagram:



Actually this is what I want to do:

I'm building a alarm clock. Actually i developed it to get inputs from keypad successfully without using interrupts (just using a while(true) condition in the main method). I coded it to get inputs from user to set the clock and 3 alarms. I managed to store them in the eeprom also. But problem arises when I want to compare the alarms and the real time.
Because in the main method, I need to check for a key press as well as comparing alarm time and the real time. When I put both codes there It won't detect the keypress as it did before.

My code
Code:

#include <16f877a.h> //PIC utilizado
#device adc=10

#FUSES NOWDT,HS, NOPROTECT,NOLVP, NOWRT

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3)

#INCLUDE "lcd.c" //Incluyo LCD.C
#include "ds1307.c"

#define use_portb_kbd TRUE
#INCLUDE "kbd.c"

void showtime();
void settime();
void setalarm1();
void setalarm2();
void setalarm3();
void mainmenu();
void mainmenud();

int h;
char s;
char m;
char k;

int ht;
int mt;

int ha1;
int ma1;
int ha2;
int ma2;
int ha3;
int ma3;

int d;
char st[6];
int n=1;
char al1[5];
int n1=1;
char al2[5];
int n2=1;
char al3[5];
int n3=1;
   byte sec;
   byte min;
   byte hrs;
   byte day;

void main(){
lcd_init();
kbd_init();
port_b_pullups(TRUE);  // Need to pull up the keypad row pins
lcd_putc("\System Active\n");



while(TRUE) {

 /*THis is the code for comparing alarms and real time

ds1307_init();

//reading alarm times from eeprom

  ha1=(read_eeprom(5)-'0')*10+read_eeprom(6)-'0' ;
  ma1=(read_eeprom(7)-'0')*10+read_eeprom(8)-'0' ;
  ha2=(read_eeprom(9)-'0')*10+read_eeprom(10)-'0' ;
  ma2=(read_eeprom(11)-'0')*10+read_eeprom(12)-'0' ;
  ha3=(read_eeprom(13)-'0')*10+read_eeprom(14)-'0' ;
  ma3=(read_eeprom(15)-'0')*10+read_eeprom(16)-'0' ;





 
//get real time from clock
   ds1307_get_time(hrs,min,sec);

//comparing
if( ((hrs==ha1)&&(min==ma1))||((hrs==ha2)&&(min==ma2))||((hrs==ha3)&&(min==ma3)))
output_high(PIN_D3);

  */



  m=kbd_getc();
 if(m!=0) {
   if(m=='A'){
  lcd_putc('\f');
 mainmenu();
}
   }
}
}



void mainmenu(){
lcd_putc('\f');

lcd_putc("\Main Menu\n");

while(TRUE)
  {
  m=kbd_getc();
 if(m!=0)
   if(m=='A'){
 
showtime();
}
if(m=='B'){
 
settime();
}
if(m=='C'){
 
setalarm1();
}
 }
}


void showtime(){

lcd_init();  //initialize lcd

//initialize 1307

  ds1307_init();
  ht=(read_eeprom(1)-'0')*10+read_eeprom(2)-'0' ;
  mt=(read_eeprom(3)-'0')*10+read_eeprom(4)-'0' ;


  ds1307_set_date_time(0,0,0,0,ht,mt,00); //day, month,year,dow,hr,min.sec
 
  while(1)
  {
   //ds1307_get_date(day,month,year,dow);
   ds1307_get_time(hrs,min,sec);
  lcd_gotoxy(1,1);
    printf(lcd_putc,"Time : %02d:%02d:%02d",hrs,min,sec);
     }
   }

void settime(){
set:
d=1;
n=1;
 lcd_putc("\fSet Time...\n");
  while(TRUE)
{
k=kbd_getc();
if(k!=0)
      if(k=='#')
      {
          lcd_putc('\f'); 
        lcd_putc("Time Set\n");
         lcd_putc(st[1]);
         lcd_putc(st[2]);               
          lcd_putc(" :");
           lcd_putc(st[3]);
        lcd_putc(st[4]);
         delay_ms(100);
         
        }
        else if(k=='*') {
         goto set;
                 }
        else if(k=='A') {
          lcd_putc('\f');
         lcd_putc("\fSet Time...\n");
         d=1; 
         n=1;
            }
        else if(k=='A'||k=='B'||k=='C'||k=='D') {
         goto set;
               }
                  else {
         
         if(n==5){
         lcd_putc('\f');
         lcd_putc("Unknown format");
         delay_ms(30);
         lcd_putc('\f');
         goto set;
          }
        st[n]=k; 
       
         if(n==3)
         lcd_putc(" :");
       
       

 if(((n==4))&&((((st[1]-'0')*10+(st[2]-'0'))>24)||(((st[3]-'0')*10+(st[4]-'0'))>59))){
         lcd_putc('\f');
         lcd_putc("Unknown format");
         delay_ms(30);
         lcd_putc('\f');
         goto set;
         }
 if(n<=5){
         lcd_putc(k); 
         
         write_eeprom(d,st[n]);
         d++;
        n++;
}
}
}
}

   void setalarm1(){
set:
d=5;
n1=1;
 lcd_putc("\fSet Alarm 1...\n");
  while(TRUE)
{
k=kbd_getc();
if(k!=0)
      if(k=='#')
      {
          lcd_putc('\f'); 
        lcd_putc("Alarm 1 Set\n");
         lcd_putc(al1[1]);
         lcd_putc(al1[2]);               
          lcd_putc(" :");
           lcd_putc(al1[3]);
        lcd_putc(al1[4]);
         delay_ms(100);
         setalarm2();
        }
        else if(k=='*') {
         goto set;
                 }
       
        else if(k=='A'||k=='B'||k=='C'||k=='D') {
         goto set;
               }
                   else {
         
         if(n1==5){
         lcd_putc('\f');
         lcd_putc("Unknown format");
         delay_ms(30);
         lcd_putc('\f');
         goto set;
          }
        al1[n1]=k; 
       
         if(n1==3)
         lcd_putc(" :");

 if(((n1==4))&&((((al1[1]-'0')*10+(al1[2]-'0'))>24)||(((al1[3]-'0')*10+(al1[4]-'0'))>59))){
         lcd_putc('\f');
         lcd_putc("Unknown format");
         delay_ms(30);
         lcd_putc('\f');
         goto set;
 }
 if(n1<=5){
         lcd_putc(k); 
         
         write_eeprom(d,al1[n1]);
         d++;
        n1++;
}
}
}
}

void setalarm2(){
set:
d=9;
n2=1;
 lcd_putc("\fSet Alarm 2...\n");
  while(TRUE)
{
k=kbd_getc();
if(k!=0)
      if(k=='#')
      {
          lcd_putc('\f'); 
        lcd_putc("Alarm 2 Set\n");
         lcd_putc(al2[1]);
         lcd_putc(al2[2]);               
          lcd_putc(" :");
           lcd_putc(al2[3]);
        lcd_putc(al2[4]);
         delay_ms(100);
         setalarm3();
        }
        else if(k=='*') {
         goto set;
                 }
       
        else if(k=='A'||k=='B'||k=='C'||k=='D') {
         goto set;
               }
                   else {
         
         if(n2==5){
         lcd_putc('\f');
         lcd_putc("Unknown format");
         delay_ms(30);
         lcd_putc('\f');
         goto set;
          }
        al2[n2]=k; 
       
         if(n2==3)
         lcd_putc(" :");

 if(((n2==4))&&((((al2[1]-'0')*10+(al2[2]-'0'))>24)||(((al2[3]-'0')*10+(al2[4]-'0'))>60))){
         lcd_putc('\f');
         lcd_putc("Unknown format");
         delay_ms(30);
         lcd_putc('\f');
         goto set;
 }
 if(n2<=5){
         lcd_putc(k); 
         
         write_eeprom(d,al2[n2]);
         d++;
        n2++;
}
}
}
}

void setalarm3(){
set:
d=13;
n3=1;
 lcd_putc("\fSet Alarm 2...\n");
  while(TRUE)
{
k=kbd_getc();
if(k!=0)
      if(k=='#')
      {
          lcd_putc('\f'); 
        lcd_putc("Alarm 2 Set\n");
         lcd_putc(al3[1]);
         lcd_putc(al3[2]);               
          lcd_putc(" :");
           lcd_putc(al3[3]);
        lcd_putc(al3[4]);
         delay_ms(100);
       
        }
        else if(k=='*') {
         goto set;
                 }
       
        else if(k=='A'||k=='B'||k=='C'||k=='D') {
         goto set;
               }
                   else {
         
         if(n3==5){
         lcd_putc('\f');
         lcd_putc("Unknown format");
         delay_ms(30);
         lcd_putc('\f');
         goto set;
          }
        al3[n3]=k; 
       
         if(n3==3)
         lcd_putc(" :");

 if(((n3==4))&&((((al3[1]-'0')*10+(al3[2]-'0'))>24)||(((al3[3]-'0')*10+(al3[4]-'0'))>60))){
         lcd_putc('\f');
         lcd_putc("Unknown format");
         delay_ms(30);
         lcd_putc('\f');
         goto set;
 }
 if(n3<=5){
         lcd_putc(k); 
         
         write_eeprom(d,al3[n3]);
         d++;
        n3++;
}
}
}
}
   


Can you please help me Smile This is for my project.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 30, 2012 12:53 pm     Reply with quote

Quote:
I tried that code on Proteus. But it didn't display anything. Why is that ?

I don't know. I tested it in real hardware. I can't help with a Proteus project.
vpowerrc



Joined: 28 Apr 2012
Posts: 10

View user's profile Send private message

PostPosted: Mon Apr 30, 2012 7:24 pm     Reply with quote

what about this ? Do you have any idea to do it ?
vpowerrc



Joined: 28 Apr 2012
Posts: 10

View user's profile Send private message

PostPosted: Tue May 01, 2012 10:19 am     Reply with quote

somebody please
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