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

Problem with keypad 4*4

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



Joined: 25 Mar 2010
Posts: 4

View user's profile Send private message Send e-mail

Problem with keypad 4*4
PostPosted: Thu Mar 25, 2010 3:01 am     Reply with quote

I'm having problems in compiling the key pad functions keypad.c 4 * 4. I use this function written by PCM programmer. I compiled the following error, please help me find the wrong reasons:
Quote:

The target "C: \ projectA \ project glcd \ GLCD.o" is already up to date.
Executing: "C: \ Program Files \ PICC \ CCSC.exe" + FM "main.c" + EXPORT + DF + LN + T + A + M + Z + Y = 9 + EA
*** Error 23 "C: \ PROGRA ~ 1 \ PICC \ devices \ 16F876A.h" Line 2 (8.9): Can not change device type this far into the code
*** Error 48 "C: \ PROGRA ~ 1 \ PICC \ devices \ 16F876A.h" Line 152 (1.23): Expecting a (
*** Error 48 "C: \ PROGRA ~ 1 \ PICC \ devices \ 16F876A.h" Line 152 (6.11): Expecting a (
--- Info 300 "C: \ PROGRA ~ 1 \ PICC \ devices \ 16F876A.h" Line 156 (6.11): More info: First Declaration of CCP_2
*** Error 31 "C: \ PROGRA ~ 1 \ PICC \ devices \ 16F876A.h" Line 156 (6.11): Identifier is already used in this scope
D: \ projectA \ project glcd \ main.o ===> 4 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED:

Below is the program:
Code:

//here is function keypad.c
#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);
}


Code:
//here is main program

#include <16F876A.h>
#include <GLCD.C>
#include <keypad.c>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=12000000)

void main()
{
char k;
char text1[3][25]={"hello world ","try to do","I must be susscess"};
glcd_init(ON);
kbd_init();
while(TRUE)
  {
   k=kbd_getc();
   if(k!=0)
     {
      if(k=='*')
         glcd_text57(0, 0, text1[0], 1, ON);
      else
         glcd_text57(0, 8, text1[1], 1, ON);
     }
  }
}

CCSC 4.057, and I use to write programs Mplab 8.43 communication with keypad 4 * 4. The compiler error is in driver 16F876A.h.
Thank you very much.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 25, 2010 11:57 am     Reply with quote

Quote:

Can not change device type this far into the code

See this recent thread about how to use multiple source files with MPLAB:
http://www.ccsinfo.com/forum/viewtopic.php?t=42061
ganyfun



Joined: 25 Mar 2010
Posts: 4

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 25, 2010 6:54 pm     Reply with quote

thank you very much!
I understand some things from your help. You can write your mail to some things does not know I can mail to ask you ? Thank you PCM Programmer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 25, 2010 10:44 pm     Reply with quote

It's better if you ask questions in this forum. Then everyone can
give an answer.
ganyfun



Joined: 25 Mar 2010
Posts: 4

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 28, 2010 3:27 am     Reply with quote

I compile successfully but when I download bitstream into microprocessor to display a line of text on screen of GLCD is not . It does not display as I want, do not show anything. PCM programmer can help me understand the cause is not. I want to test the code on the keypad for use in my module. Hope you help, thanks a lot!
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