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 and a 4X4 Keypad

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



Joined: 23 Oct 2008
Posts: 4

View user's profile Send private message

PIC16F877A and a 4X4 Keypad
PostPosted: Thu Oct 23, 2008 4:24 am     Reply with quote

A relatively simple question for you guys.

How can I integrate a 4x4 keypad with a pic16f877a microcontroller using ccs?


Smile
Kabukiman
Guest







PostPosted: Thu Oct 23, 2008 6:18 am     Reply with quote

You can adjust the default driver kbd.c to your keypad 4x4 or
write your own function to read keypad.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 11:57 am     Reply with quote

Use the forum's search page:
http://www.ccsinfo.com/forum/search.php
Search for:
Quote:
4x4 keypad

You will find posts like this:
http://www.ccsinfo.com/forum/viewtopic.php?t=32297
Belial
Guest







PostPosted: Thu Oct 23, 2008 1:03 pm     Reply with quote

I make a function to read a keypad 4x4 myself, all keys are connected to
PORTC you can connect at any PORT with 8 pins

I don't know it's very efficient but works good luck.

Code:

 SET_TRIS_C(0b11110000);//you mus set in main function before infinite loop port configuration

void main{
  while(1){
      key = readkey(); // Call the function
     
      if(key!='\0')     // if key different '\0' show it else do nothing
      {
     
   
          if(x > 16 && y == 1){
          x=0;
          y=2;
          }else if(x>16 && y==2)
          {
           printf(lcd_putc,"\f");
           x=0;y=1;
          }
         
       
          x++;
          lcd_gotoxy(x,y);
          printf(lcd_putc,"%c",key);
          delay_ms(300);
         
      }
     
   }
}



Code:
char readkey()
{
     
     output_low(PIN_C1);
     output_low(PIN_C2);
     output_low(PIN_C3);
     output_high(PIN_C0);
       
     if(input_state(PIN_C4)==1)
     {
         return '1';
     
     }
     
     if(input_state(PIN_C5)==1)
     {
         return '4';
     
     }
     
     if(input_state(PIN_C6)==1)
     {
         return '7';
     
     }
     
     if(input_state(PIN_C7)==1)
     {
         return '*';
     
     }
     output_low(PIN_C0);
     
     
     
     
     
     output_low(PIN_C0);
     output_low(PIN_C2);
     output_low(PIN_C3);
     output_high(PIN_C1);
       
     if(input_state(PIN_C4)==1)
     {
         return '2';
     
     }
     
     if(input_state(PIN_C5)==1)
     {
         return '5';
     
     }
     
     if(input_state(PIN_C6)==1)
     {
         return '8';
     
     }
     
     if(input_state(PIN_C7)==1)
     {
         return '0';
     
     }
     output_low(PIN_C1);
     
     
     output_low(PIN_C0);
     output_low(PIN_C1);
     output_low(PIN_C3);
     output_high(PIN_C2);
       
     if(input_state(PIN_C4)==1)
     {
         return '3';
     
     }
     
     if(input_state(PIN_C5)==1)
     {
         return '6';
     
     }
     
     if(input_state(PIN_C6)==1)
     {
         return '9';
     
     }
     
     if(input_state(PIN_C7)==1)
     {
         return '#';
     
     }
     output_low(PIN_C2);
     
     
     
     
     
     output_low(PIN_C0);
     output_low(PIN_C1);
     output_low(PIN_C2);
     output_high(PIN_C3);
       
     if(input_state(PIN_C4)==1)
     {
         return 'A';
     
     }
     
     if(input_state(PIN_C5)==1)
     {
         return 'B';
     
     }
     
     if(input_state(PIN_C6)==1)
     {
         return 'C';
     
     }
     
     if(input_state(PIN_C7)==1)
     {
         return 'D';
     
     }
     output_low(PIN_C3);
     
     

      return '\0';
}
Legatus



Joined: 23 Oct 2008
Posts: 4

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 7:59 pm     Reply with quote

PCM programmer wrote:
Use the forum's search page:
http://www.ccsinfo.com/forum/search.php
Search for:
Quote:
4x4 keypad

You will find posts like this:
http://www.ccsinfo.com/forum/viewtopic.php?t=32297


Sorry, I should've searched the forums before posting.
Legatus



Joined: 23 Oct 2008
Posts: 4

View user's profile Send private message

PostPosted: Thu Oct 23, 2008 8:02 pm     Reply with quote

Quote:

if(x > 16 && y == 1){
x=0;
y=2;
}else if(x>16 && y==2)
{
printf(lcd_putc,"\f");
x=0;y=1;
}

x++;
lcd_gotoxy(x,y);
printf(lcd_putc,"%c",key);
delay_ms(300);


Please do correct me if i'm mistaken, these are for printing the pressed key to the lcd.
Guest








PostPosted: Fri Oct 24, 2008 8:19 am     Reply with quote

Yes this is for print to lcd
Legatus



Joined: 23 Oct 2008
Posts: 4

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 3:40 am     Reply with quote

Quote:
I make a function to read a keypad 4x4 myself, all keys are connected to PORTC you can connect at any PORT with 8 pins


How would I know which keypad pin is connected to which port pin?

Thanks.

Smile
kabukiman85



Joined: 30 Oct 2008
Posts: 2
Location: Barcelona Spain

View user's profile Send private message

Keypad
PostPosted: Thu Oct 30, 2008 5:30 am     Reply with quote

You can connect your keypad to any port with 8 pins in my example, I use 8 pins on PORTC.

This is my own made keypad 4x4 with mikroe schematics

Razz





I'm using it on EasyPic5 mikroe dev Board



Here are the schematics of this keypad

http://www.mikroe.com/pdf/keypad_board_schematic.pdf

Laughing
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Thu Oct 30, 2008 8:19 am     Reply with quote

kabukiman85 said:

You can connect your keypad to any port with 8 pins in my example, I use 8 pins on PORTC.

In fact the schematic shows PORTB, and I think it's right. If you use PORTB, you have internal pullups available, so you can be sure the state of any input is high, unless it's pulled down by one of the outputs. Anyway, on a lot of the processors, PORTC has all the communication pins. You wouldn't want to tie up the whole port with the keypad.
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