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

LCD and Keypad problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Need-Help
Guest







LCD and Keypad problem
PostPosted: Tue Aug 16, 2005 7:42 am     Reply with quote

Hi pro's

my problem is as follows i have the CCS prototyping board Rev 7 which have 2 inserts for LCD and Keypad when i place the Keypad and configure it to port B and LCD to port D, i keep getting this error message "Could not Detect target Chip" , when i remove both LCd and keypad i don't get that error, i m using lcd.c and kbd.c , and i m just trying to run the example program from CCS , by the way i have a 16F877A chip

Code:
/////////////////////////////////////////////////////////////////////////
////                           EX_LCDKB.C                            ////
////                                                                 ////
////  This program uses both the KBD.C and LCD.C drivers to allow    ////
////  keypad entry and LCD display.  All keys are echoed except *    ////
////  that will clear the display.  Either the kbd_getc or lcd_putc  ////
////  may be replaced with getc or putc to use just one device with  ////
////  the RS-232.                                                    ////
////                                                                 ////
////  Configure the CCS prototype card as follows:                   ////
////     Plug in both the LCD and KEYPAD.                            ////
////                                                                 ////
////  This example will work with the PCB, PCM and PCH compilers.    ////
////  The following conditional compilation lines are used to        ////
////  include a valid device for each compiler.  Change the device,  ////
////  clock and RS232 pins for your hardware if needed.              ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services         ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////


#if defined(__PCB__)
#include <16c56.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)

#elif defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#endif

#include <lcd.c>
#include <kbd.c>


void main() {
   char k;

   lcd_init();
   kbd_init();

   lcd_putc("\fReady...\n");

   while (TRUE) {
      k=kbd_getc();
      if(k!=0)
        if(k=='*')
          lcd_putc('\f');
        else
          lcd_putc(k);
   }
}


i double checked that my Keypad is
Code:
#define use_portb_kbd TRUE

and my LCD is
Code:
#define use_portd_lcd TRUE


i read some threads and the same problem happened with one dude ,, but he wasn't using the CCS prototyping board.

Can anyone help me this thing is driving me crazy
thanks
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Aug 16, 2005 8:18 am     Reply with quote

Sounds to me like one or more of the programming pin are also used for the keypad and/or lcd. You need pgc and pgd for programming,.... and also port
B on the ?keypad?. Check that those wires(pgc and pgd) are wired correct.
Need-help
Guest







PostPosted: Tue Aug 16, 2005 8:54 am     Reply with quote

from CCS schematics which was provided by the manufacter, its states that keypad to Port D and LCD to port B, i ve tried that ,,
again "Could Not Detect target Chip"..!!!!
valemike
Guest







PostPosted: Tue Aug 16, 2005 9:11 am     Reply with quote

Read treitmey's comment.

What is connected to RB6 and RB7? Question
Guest








PostPosted: Tue Aug 16, 2005 9:15 am     Reply with quote

valemike wrote:
Read treitmey's comment.

What is connected to RB6 and RB7? Question

// B0 enable
// B1 rs
// B2 rw
// B4 B4
// B5 B5
// B6 B6
// B7 B7
Guest








PostPosted: Tue Aug 16, 2005 9:15 am     Reply with quote

Anonymous wrote:
valemike wrote:
Read treitmey's comment.

What is connected to RB6 and RB7? Question

// B0 enable
// B1 rs
// B2 rw
// B4 B4
// B5 B5
// B6 B6
// B7 B7

THAT WAS THE lcd CONNECTION
valemike
Guest







PostPosted: Tue Aug 16, 2005 9:42 am     Reply with quote

Are you using a DIP chip? Try programming it OUT of the socket first, then see if your program runs. Looks like your stuff is disrupting ICSP.
Guest








PostPosted: Tue Aug 16, 2005 11:03 am     Reply with quote

valemike wrote:
Are you using a DIP chip? Try programming it OUT of the socket first, then see if your program runs. Looks like your stuff is disrupting ICSP.


yes its a dip Chip goes on a the board the board looks like this-->[/url]http://www.ccsinfo.com/spb.shtml[url]

i have the LCD to go on LCD port B which is to the right of the pic and the keypad to the bottom ,, unfortunally i don't have an external proto board to try it on,,, do u guys have any other suggestions[/url]
Guest








PostPosted: Tue Aug 16, 2005 12:29 pm     Reply with quote

No one..?????
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 16, 2005 12:38 pm     Reply with quote

Download the CCS ICD Trouble-shooting Guide:
http://www.ccsinfo.com/ccs_icd_trblsht.zip

On page 2 of the guide, it says:
To program and/or debug in circuit, two I/O pins (B6, B7) are reserved.
If debugging is not to be done, then these pins may also be used in the
target circuit. However, take care to ensure the target circuit has high
impedance during programming.
Guest








PostPosted: Wed Aug 17, 2005 8:22 am     Reply with quote

thank you ,, now the LCd works since i set it to Port B and download the program to the chip and then connect the LCD and unhook the ICD,,,,

But the keypad does not want to work for some reason i tried to set it to Port D
the kbd.c wasn't edited
Code:

// Un-comment the following define to use port B
//#define use_portb_kbd TRUE

// Make sure the port used has pull-up resistors (or the LCD) on
// the column pins
#if defined(__PCH__)
#if defined use_portb_kbd
   #byte kbd = 0xF81                   // This puts the entire structure
#else
   #byte kbd = 0xF83                   // This puts the entire structure
#endif
#else
#if defined use_portb_kbd
   #byte kbd = 6                  // on to port B (at address 6)
#else
   #byte kbd = 8                 // on to port D (at address 8)
#endif
#endif

#if defined use_portb_kbd
   #define set_tris_kbd(x) set_tris_b(x)
#else
   #define set_tris_kbd(x) set_tris_d(x)
#endif



//Keypad connection:   (for example column 0 is B2)
//                Bx:

#ifdef blue_keypad  ///////////////////////////////////// For the blue keypad
#define COL0 (1 << 2)
#define COL1 (1 << 3)
#define COL2 (1 << 6)

#define ROW0 (1 << 4)
#define ROW1 (1 << 7)
#define ROW2 (1 << 1)
#define ROW3 (1 << 5)

#else ////////////////////////////////////////////////// For the black keypad
#define COL0 (1 << 5)
#define COL1 (1 << 6)
#define COL2 (1 << 7)

#define ROW0 (1 << 1)
#define ROW1 (1 << 2)
#define ROW2 (1 << 3)
#define ROW3 (1 << 4)

#endif

#define ALL_ROWS (ROW0|ROW1|ROW2|ROW3)
#define ALL_PINS (ALL_ROWS|COL0|COL1|COL2)

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

#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() {
}

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   : set_tris_kbd(ALL_PINS&~COL0);
                    kbd=~COL0&ALL_PINS;
                    break;
         case 1   : set_tris_kbd(ALL_PINS&~COL1);
                    kbd=~COL1&ALL_PINS;
                    break;
         case 2   : set_tris_kbd(ALL_PINS&~COL2);
                    kbd=~COL2&ALL_PINS;
                    break;
       }

       if(kbd_down) {
         if((kbd & (ALL_ROWS))==(ALL_ROWS)) {
           kbd_down=FALSE;
           kchar=last_key;
           last_key='\0';
         }
       } else {
          if((kbd & (ALL_ROWS))!=(ALL_ROWS)) {
             if((kbd & ROW0)==0)
               row=0;
             else if((kbd & ROW1)==0)
               row=1;
             else if((kbd & ROW2)==0)
               row=2;
             else if((kbd & ROW3)==0)
               row=3;
             last_key =KEYS[row][col];
             kbd_down = TRUE;
          } else {
             ++col;
             if(col==3)
               col=0;
          }
       }
      kbd_call_count=0;
   }
  set_tris_kbd(ALL_PINS);
  return(kchar);
}


Any Sugestions..!!!!
Please
Guest








PostPosted: Wed Aug 17, 2005 8:22 am     Reply with quote

thank you ,, now the LCd works since i set it to Port B and download the program to the chip and then connect the LCD and unhook the ICD,,,,

But the keypad does not want to work for some reason i tried to set it to Port D
the kbd.c wasn't edited
Code:

// Un-comment the following define to use port B
//#define use_portb_kbd TRUE

// Make sure the port used has pull-up resistors (or the LCD) on
// the column pins
#if defined(__PCH__)
#if defined use_portb_kbd
   #byte kbd = 0xF81                   // This puts the entire structure
#else
   #byte kbd = 0xF83                   // This puts the entire structure
#endif
#else
#if defined use_portb_kbd
   #byte kbd = 6                  // on to port B (at address 6)
#else
   #byte kbd = 8                 // on to port D (at address 8)
#endif
#endif

#if defined use_portb_kbd
   #define set_tris_kbd(x) set_tris_b(x)
#else
   #define set_tris_kbd(x) set_tris_d(x)
#endif



//Keypad connection:   (for example column 0 is B2)
//                Bx:

#ifdef blue_keypad  ///////////////////////////////////// For the blue keypad
#define COL0 (1 << 2)
#define COL1 (1 << 3)
#define COL2 (1 << 6)

#define ROW0 (1 << 4)
#define ROW1 (1 << 7)
#define ROW2 (1 << 1)
#define ROW3 (1 << 5)

#else ////////////////////////////////////////////////// For the black keypad
#define COL0 (1 << 5)
#define COL1 (1 << 6)
#define COL2 (1 << 7)

#define ROW0 (1 << 1)
#define ROW1 (1 << 2)
#define ROW2 (1 << 3)
#define ROW3 (1 << 4)

#endif

#define ALL_ROWS (ROW0|ROW1|ROW2|ROW3)
#define ALL_PINS (ALL_ROWS|COL0|COL1|COL2)

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

#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() {
}

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   : set_tris_kbd(ALL_PINS&~COL0);
                    kbd=~COL0&ALL_PINS;
                    break;
         case 1   : set_tris_kbd(ALL_PINS&~COL1);
                    kbd=~COL1&ALL_PINS;
                    break;
         case 2   : set_tris_kbd(ALL_PINS&~COL2);
                    kbd=~COL2&ALL_PINS;
                    break;
       }

       if(kbd_down) {
         if((kbd & (ALL_ROWS))==(ALL_ROWS)) {
           kbd_down=FALSE;
           kchar=last_key;
           last_key='\0';
         }
       } else {
          if((kbd & (ALL_ROWS))!=(ALL_ROWS)) {
             if((kbd & ROW0)==0)
               row=0;
             else if((kbd & ROW1)==0)
               row=1;
             else if((kbd & ROW2)==0)
               row=2;
             else if((kbd & ROW3)==0)
               row=3;
             last_key =KEYS[row][col];
             kbd_down = TRUE;
          } else {
             ++col;
             if(col==3)
               col=0;
          }
       }
      kbd_call_count=0;
   }
  set_tris_kbd(ALL_PINS);
  return(kchar);
}


Any Sugestions..!!!!
Please
Guest








PostPosted: Wed Aug 17, 2005 8:27 am     Reply with quote

thank you (PCM programmer),, now the LCd works since i set it to Port B and download the program to the chip and then connect the LCD and unhook the ICD,,,,

But the keypad does not want to work for some reason i tried to set it to Port D
the kbd.c wasn't edited
Code:

// Un-comment the following define to use port B
//#define use_portb_kbd TRUE

// Make sure the port used has pull-up resistors (or the LCD) on
// the column pins
#if defined(__PCH__)
#if defined use_portb_kbd
   #byte kbd = 0xF81                   // This puts the entire structure
#else
   #byte kbd = 0xF83                   // This puts the entire structure
#endif
#else
#if defined use_portb_kbd
   #byte kbd = 6                  // on to port B (at address 6)
#else
   #byte kbd = 8                 // on to port D (at address 8)
#endif
#endif

#if defined use_portb_kbd
   #define set_tris_kbd(x) set_tris_b(x)
#else
   #define set_tris_kbd(x) set_tris_d(x)
#endif



//Keypad connection:   (for example column 0 is B2)
//                Bx:

#ifdef blue_keypad  ///////////////////////////////////// For the blue keypad
#define COL0 (1 << 2)
#define COL1 (1 << 3)
#define COL2 (1 << 6)

#define ROW0 (1 << 4)
#define ROW1 (1 << 7)
#define ROW2 (1 << 1)
#define ROW3 (1 << 5)

#else ////////////////////////////////////////////////// For the black keypad
#define COL0 (1 << 5)
#define COL1 (1 << 6)
#define COL2 (1 << 7)

#define ROW0 (1 << 1)
#define ROW1 (1 << 2)
#define ROW2 (1 << 3)
#define ROW3 (1 << 4)

#endif

#define ALL_ROWS (ROW0|ROW1|ROW2|ROW3)
#define ALL_PINS (ALL_ROWS|COL0|COL1|COL2)

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

#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() {
}

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   : set_tris_kbd(ALL_PINS&~COL0);
                    kbd=~COL0&ALL_PINS;
                    break;
         case 1   : set_tris_kbd(ALL_PINS&~COL1);
                    kbd=~COL1&ALL_PINS;
                    break;
         case 2   : set_tris_kbd(ALL_PINS&~COL2);
                    kbd=~COL2&ALL_PINS;
                    break;
       }

       if(kbd_down) {
         if((kbd & (ALL_ROWS))==(ALL_ROWS)) {
           kbd_down=FALSE;
           kchar=last_key;
           last_key='\0';
         }
       } else {
          if((kbd & (ALL_ROWS))!=(ALL_ROWS)) {
             if((kbd & ROW0)==0)
               row=0;
             else if((kbd & ROW1)==0)
               row=1;
             else if((kbd & ROW2)==0)
               row=2;
             else if((kbd & ROW3)==0)
               row=3;
             last_key =KEYS[row][col];
             kbd_down = TRUE;
          } else {
             ++col;
             if(col==3)
               col=0;
          }
       }
      kbd_call_count=0;
   }
  set_tris_kbd(ALL_PINS);
  return(kchar);
}


and then i tried to write a small program to display the keys pressed to HyperTerminal and it doesn't work




Code:

#include <16F877A.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#device ICD=TRUE
#use delay(clock=20000000)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)




#include <kbd.c>// kbd.c is a Generic keypad scan driver
                //to read the numbers on the keypad


void main()
{
 char k;

 printf("Start\n\r");

 while(1)
   {
    k = kbd_getc();
   
    if(k != 0)
      {
       if(k == '*')
         {
          putc('\f');
                 }
       else
         {
          putc(k);
         }
      }
   }

}

Any Sugestions..!!!!
Please
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 17, 2005 9:36 am     Reply with quote

Quote:

But the keypad does not want to work for some reason i tried to set it to
Port D the kbd.c wasn't edited

Well, if you had registered and logged in and stayed logged in,
you could delete two of those extra posts.

But anyway, the keypad requires pull-ups on the Row pins.
(Not the column pins, as the kbc.c file says).

So just add four 10K pullup resistors and it should work.
Almasri



Joined: 17 Aug 2005
Posts: 8

View user's profile Send private message MSN Messenger

PostPosted: Wed Aug 17, 2005 11:40 am     Reply with quote

Thank you Mr. PCM Programmer i got an account here, and i guess i ll be cleaner in my threads from now on,,

my question for you is how can i place pull up resistors on the CCS Prototyping Board since the the Keypad is placed in the bottom of the board r you suggesting to get an external protoboard and hook the keypad to it and let the ROW pins connected to the port D using 10K resistors is there an easier way of doing it than getting more hardware,
what does it mean when they say
Code:
Make sure the port used has pull-up resistors (or the LCD) on
// the column pins
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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