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

Driver kbd doesn't work [Solved]

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



Joined: 17 Nov 2014
Posts: 8

View user's profile Send private message

Driver kbd doesn't work [Solved]
PostPosted: Sun Mar 31, 2019 10:19 am     Reply with quote

I have found the following driver on this forum but it doesn't work.
Does anybody have any idea where is the problem ?
Note, with the same keypad and the official kbd driver it works but i need 16 keys keypad.

Code:
//Keypad connection:
#define row0 PIN_B4
#define row1 PIN_B5
#define row2 PIN_B6
#define row3 PIN_B7
#define col0 PIN_B0
#define col1 PIN_B1
#define col2 PIN_B2
#define col3 PIN_B3

// Keypad layout:
char const KEYS[4][4] =
{{'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'*','0','#','D'}};


#define KBD_DEBOUNCE_FACTOR 33 // Set this number to apx n/333 where
// n is the number of times you expect
// to call kbd_getc each second

void kbd_init()
{
//set_tris_b(0xF0);
//output_b(0xF0);
port_b_pullups(true); 
}

short int ALL_ROWS (void)
{
if(input (row0) & input (row1) & input (row2) & input (row3))
   return (0);
else
   return (1);
}



char kbd_getc()
{
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;

byte kchar;
byte row;

kchar='\0';

if(++kbd_call_count>KBD_DEBOUNCE_FACTOR)
  {
   switch (col)
     {
      case 0:
        output_low(col0);
        output_high(col1);
        output_high(col2);
        output_high(col3);
        break;
   
      case 1:
        output_high(col0);
        output_low(col1);
        output_high(col2);
        output_high(col3);
        break;

      case 2:
        output_high(col0);
        output_high(col1);
        output_low(col2);
        output_high(col3);
        break;

      case 3:
        output_high(col0);
        output_high(col1);
        output_high(col2);
        output_low(col3);
        break;
      }

   if(kbd_down)
     {
      if(!ALL_ROWS())
        {
         kbd_down=false;
         kchar=last_key;
         last_key='\0';
        }
     }
   else
     {
      if(ALL_ROWS())
        {
         if(!input (row0))
            row=0;
         else if(!input (row1))
            row=1;
         else if(!input (row2))
            row=2;
         else if(!input (row3))
            row=3;

         last_key =KEYS[row][col];
         kbd_down = true;
        }
      else
        {
         ++col;
         if(col==4)
            col=0;
        }
     }
   kbd_call_count=0;
  }
return(kchar);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 31, 2019 10:29 am     Reply with quote

Post a test program that uses this keypad driver.

Post the full test program, with:
#include for the PIC
#fuses
#use delay

#include for the keypad driver

main()
{

etc.
michaeltolini



Joined: 17 Nov 2014
Posts: 8

View user's profile Send private message

PostPosted: Sun Mar 31, 2019 12:42 pm     Reply with quote

Code:

#include <16F887.h>

#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES NOBROWNOUT               //No brownout reset
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES BORV40                   //Brownout reset at 4.0V
#FUSES NOWRT                    //Program memory not write protected

#use delay(internal=8000000)

#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)


#ZERO_RAM

#include <flex_full_lcd.c>

#include <kbd_16_keys.c>

char k;
   
///////////////////////////////MAIN MENU///////////////////////////////////////
void main()
   {
   
   
   lcd_init();
   kbd_init();
   
   port_b_pullups(1);

   
   
   lcd_putc("\f TOOL LIFETIME");
   lcd_putc("\n<#=ENTER *=SKIP>");   
                         
   while(true)
   {
      k=kbd_getc();
      if(k!=0)
        if(k=='*')
          lcd_putc("\f ");
        else
       
        lcd_putc(k);
   }
   }
michaeltolini



Joined: 17 Nov 2014
Posts: 8

View user's profile Send private message

PostPosted: Sun Mar 31, 2019 12:44 pm     Reply with quote

Thanks for noticing me Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Sun Mar 31, 2019 12:46 pm     Reply with quote

and one critical thing. What processor.

The line that leaps out as possibly giving problems, is:

port_b_pullups(true);

Some chips require every pullup bit set separately, so would need

port_b_pullups(0b11110000;

rather than the simple 'true' value. This would stop the keypad from working.
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 31, 2019 2:48 pm     Reply with quote

hmm..you got me confused... are you saying..
1) the CCS supplied driver works fine with a 12 key kpd.
2) the 'found' driver works fine with a 12 key kpd.
3) the 'found' driver does NOT work with 16 key kpd?

if #3, it might be wiring...

Jay
michaeltolini



Joined: 17 Nov 2014
Posts: 8

View user's profile Send private message

PostPosted: Sun Mar 31, 2019 3:51 pm     Reply with quote

I mean the keypad works with kbc.c but doesn't with the driver i found here
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 31, 2019 4:30 pm     Reply with quote

The easy way would be to take the working kbd.c that CCS supplies, copy it, then using the CCS version, modify the copy to accept the 4th column. From a hardware aspect you're only adding one I/O line and maybe a resistor. Software is just the additional 4th column code.

If I had a 4x4 kpd, I'd do it but I only have 4x3 kpds here...
Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 31, 2019 5:23 pm     Reply with quote

michaeltolini wrote:
I mean the keypad works with kbc.c but doesn't with the driver i found here

Did you modify the following line, like Ttelmah said:

Change this line in your program from this:
Quote:
port_b_pullups(1);

To this:
Code:
port_b_pullups(0xF0);
temtronic



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

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 8:05 am     Reply with quote

curious.. I looked at the datasheet and that PIC has INDIVIDUAL pullups, so 'TRUE' will not work, you need to Mr. T's 0xF0 format.

Jay
michaeltolini



Joined: 17 Nov 2014
Posts: 8

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 3:27 pm     Reply with quote

Finally i modified the original kbd.c and added the 4th column
Thanks for your help Smile
temtronic



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

View user's profile Send private message

PostPosted: Tue Apr 02, 2019 4:56 am     Reply with quote

I hope you really modified a COPY and not the original code... Smile
There's nothing worse than taking good, working code...making 'one little' change' and then having to spend an entire weekend trying to get back to the original..... Sad
Yeah , BTDT.....
I even make copies of copies now.....
Every project has it's own folder, copy of the device header and my library files,like kbd, LCD,etc. There can be 50-60-100 versions to the program, ALL are in the folder. HDs have LOTS of space and I have little time.

Jay
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